]> SALOME platform Git repositories - modules/paravis.git/blob - src/ParaView/vtkWrap.c
Salome HOME
Merge from BR_PORTING_VTK6 01/03/2013
[modules/paravis.git] / src / ParaView / vtkWrap.c
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    vtkWrap.c
5
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13
14 =========================================================================*/
15
16 #include "vtkWrap.h"
17 #include "vtkParseData.h"
18 #include "vtkParseExtras.h"
19 #include "vtkParseString.h"
20 #include <stdlib.h>
21 #include <string.h>
22 #include <ctype.h>
23
24 /* -------------------------------------------------------------------- */
25 /* Common types. */
26
27 int vtkWrap_IsVoid(ValueInfo *val)
28 {
29   if (val == 0)
30     {
31     return 1;
32     }
33
34   return ((val->Type & VTK_PARSE_UNQUALIFIED_TYPE) == VTK_PARSE_VOID);
35 }
36
37 int vtkWrap_IsVoidFunction(ValueInfo *val)
38 {
39   unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
40
41   if (t == VTK_PARSE_FUNCTION_PTR || t == VTK_PARSE_FUNCTION)
42     {
43     /* check for signature "void (*func)(void *)" */
44     if (val->Function->NumberOfParameters == 1 &&
45         val->Function->Parameters[0]->Type == VTK_PARSE_VOID_PTR &&
46         val->Function->Parameters[0]->NumberOfDimensions == 0 &&
47         val->Function->ReturnValue->Type == VTK_PARSE_VOID)
48       {
49       return 1;
50       }
51     }
52
53   return 0;
54 }
55
56 int vtkWrap_IsVoidPointer(ValueInfo *val)
57 {
58   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
59   return (t == VTK_PARSE_VOID && vtkWrap_IsPointer(val));
60 }
61
62 int vtkWrap_IsCharPointer(ValueInfo *val)
63 {
64   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
65   return (t == VTK_PARSE_CHAR && vtkWrap_IsPointer(val));
66 }
67
68 int vtkWrap_IsVTKObject(ValueInfo *val)
69 {
70   unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
71   return (t == VTK_PARSE_OBJECT_PTR &&
72           val->Class[0] == 'v' && strncmp(val->Class, "vtk", 3) == 0);
73 }
74
75 int vtkWrap_IsSpecialObject(ValueInfo *val)
76 {
77   unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
78   return ((t == VTK_PARSE_OBJECT ||
79            t == VTK_PARSE_OBJECT_REF) &&
80           val->Class[0] == 'v' && strncmp(val->Class, "vtk", 3) == 0);
81 }
82
83 int vtkWrap_IsQtObject(ValueInfo *val)
84 {
85   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
86   if (t == VTK_PARSE_QOBJECT &&
87       val->Class[0] == 'Q' && isupper(val->Class[1]))
88     {
89     return 1;
90     }
91   return 0;
92 }
93
94 int vtkWrap_IsQtEnum(ValueInfo *val)
95 {
96   unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
97   if ((t == VTK_PARSE_QOBJECT || t == VTK_PARSE_QOBJECT_REF) &&
98       val->Class[0] == 'Q' && strncmp("Qt::", val->Class, 4) == 0)
99     {
100     return 1;
101     }
102   return 0;
103 }
104
105
106 /* -------------------------------------------------------------------- */
107 /* The base types, all are mutually exclusive. */
108
109 int vtkWrap_IsObject(ValueInfo *val)
110 {
111   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
112   return (t == VTK_PARSE_OBJECT ||
113           t == VTK_PARSE_QOBJECT);
114 }
115
116 int vtkWrap_IsFunction(ValueInfo *val)
117 {
118   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
119   return (t == VTK_PARSE_FUNCTION);
120 }
121
122 int vtkWrap_IsStream(ValueInfo *val)
123 {
124   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
125   return (t == VTK_PARSE_ISTREAM ||
126           t == VTK_PARSE_OSTREAM);
127 }
128
129 int vtkWrap_IsNumeric(ValueInfo *val)
130 {
131   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
132
133   t = (t & ~VTK_PARSE_UNSIGNED);
134   switch (t)
135     {
136     case VTK_PARSE_FLOAT:
137     case VTK_PARSE_DOUBLE:
138     case VTK_PARSE_CHAR:
139     case VTK_PARSE_SHORT:
140     case VTK_PARSE_INT:
141     case VTK_PARSE_LONG:
142     case VTK_PARSE_ID_TYPE:
143     case VTK_PARSE_LONG_LONG:
144     case VTK_PARSE___INT64:
145     case VTK_PARSE_SIGNED_CHAR:
146     case VTK_PARSE_SSIZE_T:
147     case VTK_PARSE_BOOL:
148       return 1;
149     }
150
151   return 0;
152 }
153
154 int vtkWrap_IsString(ValueInfo *val)
155 {
156   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
157   return (t == VTK_PARSE_STRING ||
158           t == VTK_PARSE_UNICODE_STRING);
159 }
160
161 /* -------------------------------------------------------------------- */
162 /* Subcategories */
163
164 int vtkWrap_IsBool(ValueInfo *val)
165 {
166   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
167   return (t == VTK_PARSE_BOOL);
168 }
169
170 int vtkWrap_IsChar(ValueInfo *val)
171 {
172   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
173   return (t == VTK_PARSE_CHAR);
174 }
175
176 int vtkWrap_IsInteger(ValueInfo *val)
177 {
178   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
179
180   if (t != VTK_PARSE_UNSIGNED_CHAR)
181     {
182     t = (t & ~VTK_PARSE_UNSIGNED);
183     }
184   switch (t)
185     {
186     case VTK_PARSE_SHORT:
187     case VTK_PARSE_INT:
188     case VTK_PARSE_LONG:
189     case VTK_PARSE_ID_TYPE:
190     case VTK_PARSE_LONG_LONG:
191     case VTK_PARSE___INT64:
192     case VTK_PARSE_UNSIGNED_CHAR:
193     case VTK_PARSE_SIGNED_CHAR:
194     case VTK_PARSE_SSIZE_T:
195       return 1;
196     }
197
198   return 0;
199 }
200
201 int vtkWrap_IsRealNumber(ValueInfo *val)
202 {
203   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
204   return (t == VTK_PARSE_FLOAT || t == VTK_PARSE_DOUBLE);
205 }
206
207 /* -------------------------------------------------------------------- */
208 /* These are mutually exclusive, as well. */
209
210 int vtkWrap_IsScalar(ValueInfo *val)
211 {
212   unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
213   return (i == 0);
214 }
215
216 int vtkWrap_IsPointer(ValueInfo *val)
217 {
218   unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
219   return (i == VTK_PARSE_POINTER && val->Count == 0 &&
220           val->CountHint == 0 && val->NumberOfDimensions <= 1);
221 }
222
223 int vtkWrap_IsArray(ValueInfo *val)
224 {
225   unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
226   return (i == VTK_PARSE_POINTER && val->NumberOfDimensions <= 1 &&
227           (val->Count != 0 || val->CountHint != 0));
228 }
229
230 int vtkWrap_IsNArray(ValueInfo *val)
231 {
232   int j = 0;
233   unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
234   if (i != VTK_PARSE_ARRAY || val->NumberOfDimensions <= 1)
235     {
236     return 0;
237     }
238   for (j = 0; j < val->NumberOfDimensions; j++)
239     {
240     if (val->Dimensions[j] == NULL || val->Dimensions[j][0] == '\0')
241       {
242       return 0;
243       }
244     }
245   return 1;
246 }
247
248
249 /* -------------------------------------------------------------------- */
250 /* Other type properties, not mutually exclusive. */
251
252 int vtkWrap_IsNonConstRef(ValueInfo *val)
253 {
254   return ((val->Type & VTK_PARSE_REF) != 0 &&
255           (val->Type & VTK_PARSE_CONST) == 0);
256 }
257
258 int vtkWrap_IsConstRef(ValueInfo *val)
259 {
260   return ((val->Type & VTK_PARSE_REF) != 0 &&
261           (val->Type & VTK_PARSE_CONST) != 0);
262 }
263
264 int vtkWrap_IsRef(ValueInfo *val)
265 {
266   return ((val->Type & VTK_PARSE_REF) != 0);
267 }
268
269 int vtkWrap_IsConst(ValueInfo *val)
270 {
271   return ((val->Type & VTK_PARSE_CONST) != 0);
272 }
273
274 /* -------------------------------------------------------------------- */
275 /* Hints */
276
277 int vtkWrap_IsNewInstance(ValueInfo *val)
278 {
279   return ((val->Type & VTK_PARSE_NEWINSTANCE) != 0);
280 }
281
282 /* -------------------------------------------------------------------- */
283 /* Constructor/Destructor checks */
284
285 int vtkWrap_IsConstructor(ClassInfo *c, FunctionInfo *f)
286
287 {
288   size_t i, m;
289   const char *cp = c->Name;
290
291   if (cp && f->Name && !vtkWrap_IsDestructor(c, f))
292     {
293     /* remove namespaces and template parameters from the name */
294     m = vtkParse_UnscopedNameLength(cp);
295     while (cp[m] == ':' && cp[m+1] == ':')
296       {
297       cp += m + 2;
298       m = vtkParse_UnscopedNameLength(cp);
299       }
300     for (i = 0; i < m; i++)
301       {
302       if (cp[i] == '<')
303         {
304         break;
305         }
306       }
307
308     return (i == strlen(f->Name) && strncmp(cp, f->Name, i) == 0);
309     }
310
311   return 0;
312 }
313
314 int vtkWrap_IsDestructor(ClassInfo *c, FunctionInfo *f)
315 {
316   size_t i;
317   const char *cp;
318
319   if (c->Name && f->Name)
320     {
321     cp = f->Signature;
322     for (i = 0; cp[i] != '\0' && cp[i] != '('; i++)
323       {
324       if (cp[i] == '~')
325         {
326         return 1;
327         }
328       }
329     }
330
331   return 0;
332 }
333
334 int vtkWrap_IsSetVectorMethod(FunctionInfo *f)
335 {
336   if (f->Macro && strncmp(f->Macro, "vtkSetVector", 12) == 0)
337     {
338     return 1;
339     }
340
341   return 0;
342 }
343
344 int vtkWrap_IsGetVectorMethod(FunctionInfo *f)
345 {
346   if (f->Macro && strncmp(f->Macro, "vtkGetVector", 12) == 0)
347     {
348     return 1;
349     }
350
351   return 0;
352 }
353
354 /* -------------------------------------------------------------------- */
355 /* Argument counting */
356
357 int vtkWrap_CountWrappedParameters(FunctionInfo *f)
358 {
359   int totalArgs = f->NumberOfParameters;
360
361   if (totalArgs > 0 &&
362       (f->Parameters[0]->Type & VTK_PARSE_BASE_TYPE)
363        == VTK_PARSE_FUNCTION)
364     {
365     totalArgs = 1;
366     }
367   else if (totalArgs == 1 &&
368            (f->Parameters[0]->Type & VTK_PARSE_UNQUALIFIED_TYPE)
369             == VTK_PARSE_VOID)
370     {
371     totalArgs = 0;
372     }
373
374   return totalArgs;
375 }
376
377 int vtkWrap_CountRequiredArguments(FunctionInfo *f)
378 {
379   int requiredArgs = 0;
380   int totalArgs;
381   int i;
382
383   totalArgs = vtkWrap_CountWrappedParameters(f);
384
385   for (i = 0; i < totalArgs; i++)
386     {
387     if (f->Parameters[i]->Value == NULL ||
388         vtkWrap_IsArray(f->Parameters[i]) ||
389         vtkWrap_IsNArray(f->Parameters[i]))
390       {
391       requiredArgs = i+1;
392       }
393     }
394
395   return requiredArgs;
396 }
397
398 /* -------------------------------------------------------------------- */
399 /* Check whether the class is derived from vtkObjectBase. */
400
401 int vtkWrap_IsVTKObjectBaseType(
402   HierarchyInfo *hinfo, const char *classname)
403 {
404   HierarchyEntry *entry;
405
406   if (hinfo)
407     {
408     entry = vtkParseHierarchy_FindEntry(hinfo, classname);
409     if (entry)
410       {
411       if (vtkParseHierarchy_IsTypeOf(hinfo, entry, "vtkObjectBase"))
412         {
413         return 1;
414         }
415       return 0;
416       }
417     }
418
419   /* fallback if no HierarchyInfo */
420   if (strncmp("vtk", classname, 3) == 0)
421     {
422     return 1;
423     }
424
425   return 0;
426 }
427
428 /* -------------------------------------------------------------------- */
429 /* Check if the WRAP_SPECIAL flag is set for the class. */
430
431 int vtkWrap_IsSpecialType(
432   HierarchyInfo *hinfo, const char *classname)
433 {
434   HierarchyEntry *entry;
435
436   if (hinfo)
437     {
438     entry = vtkParseHierarchy_FindEntry(hinfo, classname);
439     if (entry && vtkParseHierarchy_GetProperty(entry, "WRAP_SPECIAL"))
440       {
441       return 1;
442       }
443     return 0;
444     }
445
446   /* fallback if no HierarchyInfo */
447   if (strncmp("vtk", classname, 3) == 0)
448     {
449     return -1;
450     }
451
452   return 0;
453 }
454
455 /* -------------------------------------------------------------------- */
456 /* Check if the class is derived from superclass */
457
458 int vtkWrap_IsTypeOf(
459   HierarchyInfo *hinfo, const char *classname, const char *superclass)
460 {
461   HierarchyEntry *entry;
462
463   if (strcmp(classname, superclass) == 0)
464     {
465     return 1;
466     }
467
468   if (hinfo)
469     {
470     entry = vtkParseHierarchy_FindEntry(hinfo, classname);
471     if (entry && vtkParseHierarchy_IsTypeOf(hinfo, entry, superclass))
472       {
473       return 1;
474       }
475     }
476
477   return 0;
478 }
479
480 /* -------------------------------------------------------------------- */
481 /* Make a guess about whether a class is wrapped */
482
483 int vtkWrap_IsClassWrapped(
484   HierarchyInfo *hinfo, const char *classname)
485 {
486   if (hinfo)
487     {
488     HierarchyEntry *entry;
489     entry = vtkParseHierarchy_FindEntry(hinfo, classname);
490
491     if (entry)
492       {
493       if (!vtkParseHierarchy_GetProperty(entry, "WRAP_EXCLUDE") ||
494           vtkParseHierarchy_GetProperty(entry, "WRAP_SPECIAL"))
495         {
496         return 1;
497         }
498       }
499     }
500   else if (strncmp("vtk", classname, 3) == 0)
501     {
502     return 1;
503     }
504
505   return 0;
506 }
507
508 /* -------------------------------------------------------------------- */
509 /* Check whether the destructor is public */
510 int vtkWrap_HasPublicDestructor(ClassInfo *data)
511 {
512   FunctionInfo *func;
513   int i;
514
515   for (i = 0; i < data->NumberOfFunctions; i++)
516     {
517     func = data->Functions[i];
518
519     if (vtkWrap_IsDestructor(data, func) &&
520         func->Access != VTK_ACCESS_PUBLIC)
521       {
522       return 0;
523       }
524     }
525
526   return 1;
527 }
528
529 /* -------------------------------------------------------------------- */
530 /* Check whether the copy constructor is public */
531 int vtkWrap_HasPublicCopyConstructor(ClassInfo *data)
532 {
533   FunctionInfo *func;
534   int i;
535
536   for (i = 0; i < data->NumberOfFunctions; i++)
537     {
538     func = data->Functions[i];
539
540     if (vtkWrap_IsConstructor(data, func) &&
541         func->NumberOfParameters == 1 &&
542         func->Parameters[0]->Class &&
543         strcmp(func->Parameters[0]->Class, data->Name) == 0 &&
544         func->Access != VTK_ACCESS_PUBLIC)
545       {
546       return 0;
547       }
548     }
549
550   return 1;
551 }
552
553 /* -------------------------------------------------------------------- */
554 /* Get the size for subclasses of vtkTuple */
555 int vtkWrap_GetTupleSize(ClassInfo *data, HierarchyInfo *hinfo)
556 {
557   HierarchyEntry *entry;
558   const char *classname = NULL;
559   size_t m;
560   int size = 0;
561
562   entry = vtkParseHierarchy_FindEntry(hinfo, data->Name);
563   if (entry && vtkParseHierarchy_IsTypeOfTemplated(
564         hinfo, entry, data->Name, "vtkTuple", &classname))
565     {
566     /* attempt to get count from template parameter */
567     if (classname)
568       {
569       m = strlen(classname);
570       if (m > 2 && classname[m - 1] == '>' &&
571           isdigit(classname[m-2]) && (classname[m-3] == ' ' ||
572           classname[m-3] == ',' || classname[m-3] == '<'))
573         {
574         size = classname[m-2] - '0';
575         }
576       free((char *)classname);
577       }
578     }
579
580   return size;
581 }
582
583 /* -------------------------------------------------------------------- */
584 /* This sets the CountHint for vtkDataArray methods where the
585  * tuple size is equal to GetNumberOfComponents. */
586 void vtkWrap_FindCountHints(
587   ClassInfo *data, FileInfo *finfo, HierarchyInfo *hinfo)
588 {
589   int i;
590   int count;
591   const char *countMethod;
592   FunctionInfo *theFunc;
593
594   /* add hints for vtkInformation get methods */
595   if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkInformation"))
596     {
597     countMethod = "Length(temp0)";
598
599     for (i = 0; i < data->NumberOfFunctions; i++)
600       {
601       theFunc = data->Functions[i];
602
603       if (strcmp(theFunc->Name, "Get") == 0 &&
604           theFunc->NumberOfParameters >= 1 &&
605           theFunc->Parameters[0]->Type == VTK_PARSE_OBJECT_PTR &&
606           (strcmp(theFunc->Parameters[0]->Class,
607                   "vtkInformationIntegerVectorKey") == 0 ||
608            strcmp(theFunc->Parameters[0]->Class,
609                   "vtkInformationDoubleVectorKey") == 0))
610         {
611         if (theFunc->ReturnValue && theFunc->ReturnValue->Count == 0 &&
612             theFunc->NumberOfParameters == 1)
613           {
614           theFunc->ReturnValue->CountHint = countMethod;
615           }
616         }
617       }
618     }
619
620   /* add hints for array GetTuple methods */
621   if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkDataArray"))
622     {
623     countMethod = "GetNumberOfComponents()";
624
625     for (i = 0; i < data->NumberOfFunctions; i++)
626       {
627       theFunc = data->Functions[i];
628
629       if ((strcmp(theFunc->Name, "GetTuple") == 0 ||
630            strcmp(theFunc->Name, "GetTupleValue") == 0) &&
631           theFunc->ReturnValue && theFunc->ReturnValue->Count == 0 &&
632           theFunc->NumberOfParameters == 1 &&
633           theFunc->Parameters[0]->Type == VTK_PARSE_ID_TYPE)
634         {
635         theFunc->ReturnValue->CountHint = countMethod;
636         }
637       else if ((strcmp(theFunc->Name, "SetTuple") == 0 ||
638                 strcmp(theFunc->Name, "SetTupleValue") == 0 ||
639                 strcmp(theFunc->Name, "GetTuple") == 0 ||
640                 strcmp(theFunc->Name, "GetTupleValue") == 0 ||
641                 strcmp(theFunc->Name, "InsertTuple") == 0 ||
642                 strcmp(theFunc->Name, "InsertTupleValue") == 0) &&
643                theFunc->NumberOfParameters == 2 &&
644                theFunc->Parameters[0]->Type == VTK_PARSE_ID_TYPE &&
645                theFunc->Parameters[1]->Count == 0)
646         {
647         theFunc->Parameters[1]->CountHint = countMethod;
648         }
649       else if ((strcmp(theFunc->Name, "InsertNextTuple") == 0 ||
650                 strcmp(theFunc->Name, "InsertNextTupleValue") == 0) &&
651                theFunc->NumberOfParameters == 1 &&
652                theFunc->Parameters[0]->Count == 0)
653         {
654         theFunc->Parameters[0]->CountHint = countMethod;
655         }
656       }
657     }
658
659   /* add hints for interpolator Interpolate methods */
660   if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkAbstractImageInterpolator"))
661     {
662     countMethod = "GetNumberOfComponents()";
663
664     for (i = 0; i < data->NumberOfFunctions; i++)
665       {
666       theFunc = data->Functions[i];
667
668       if (strcmp(theFunc->Name, "Interpolate") == 0 &&
669            theFunc->NumberOfParameters == 2 &&
670            theFunc->Parameters[0]->Type == (VTK_PARSE_DOUBLE_PTR|VTK_PARSE_CONST) &&
671            theFunc->Parameters[0]->Count == 3 &&
672            theFunc->Parameters[1]->Type == VTK_PARSE_DOUBLE_PTR &&
673            theFunc->Parameters[1]->Count == 0)
674         {
675         theFunc->Parameters[1]->CountHint = countMethod;
676         }
677       }
678     }
679
680   for (i = 0; i < data->NumberOfFunctions; i++)
681     {
682     theFunc = data->Functions[i];
683
684     /* hints for constructors that take arrays */
685     if (vtkWrap_IsConstructor(data, theFunc) &&
686         theFunc->NumberOfParameters == 1 &&
687         vtkWrap_IsPointer(theFunc->Parameters[0]) &&
688         vtkWrap_IsNumeric(theFunc->Parameters[0]) &&
689         theFunc->Parameters[0]->Count == 0 &&
690         hinfo)
691       {
692       count = vtkWrap_GetTupleSize(data, hinfo);
693       if (count)
694         {
695         char counttext[24];
696         sprintf(counttext, "%d", count);
697         theFunc->Parameters[0]->Count = count;
698         vtkParse_AddStringToArray(
699           &theFunc->Parameters[0]->Dimensions,
700           &theFunc->Parameters[0]->NumberOfDimensions,
701           vtkParse_CacheString(finfo->Strings, counttext, strlen(counttext)));
702         }
703       }
704
705     /* hints for operator[] index range */
706     if (theFunc->IsOperator && theFunc->Name &&
707         strcmp(theFunc->Name, "operator[]") == 0)
708       {
709       if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkTuple"))
710         {
711         theFunc->SizeHint = "GetSize()";
712         }
713       else if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayCoordinates") ||
714                vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayExtents") ||
715                vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArraySort"))
716         {
717         theFunc->SizeHint = "GetDimensions()";
718         }
719       else if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayExtentsList") ||
720                vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayWeights"))
721         {
722         theFunc->SizeHint = "GetCount()";
723         }
724       }
725     }
726 }
727
728 /* -------------------------------------------------------------------- */
729 /* This sets the NewInstance hint for generator methods. */
730 void vtkWrap_FindNewInstanceMethods(
731   ClassInfo *data, HierarchyInfo *hinfo)
732 {
733   int i;
734   FunctionInfo *theFunc;
735
736   for (i = 0; i < data->NumberOfFunctions; i++)
737     {
738     theFunc = data->Functions[i];
739     if (theFunc->Name && theFunc->ReturnValue &&
740         vtkWrap_IsVTKObject(theFunc->ReturnValue) &&
741         vtkWrap_IsVTKObjectBaseType(hinfo, theFunc->ReturnValue->Class))
742       {
743       if (strcmp(theFunc->Name, "NewInstance") == 0 ||
744           strcmp(theFunc->Name, "CreateInstance") == 0 ||
745           (strcmp(theFunc->Name, "CreateLookupTable") == 0 &&
746            strcmp(data->Name, "vtkColorSeries") == 0) ||
747           (strcmp(theFunc->Name, "CreateImageReader2") == 0 &&
748            strcmp(data->Name, "vtkImageReader2Factory") == 0) ||
749           (strcmp(theFunc->Name, "CreateDataArray") == 0 &&
750            strcmp(data->Name, "vtkDataArray") == 0) ||
751           (strcmp(theFunc->Name, "CreateArray") == 0 &&
752            strcmp(data->Name, "vtkAbstractArray") == 0) ||
753           (strcmp(theFunc->Name, "CreateArray") == 0 &&
754            strcmp(data->Name, "vtkArray") == 0) ||
755           (strcmp(theFunc->Name, "GetQueryInstance") == 0 &&
756            strcmp(data->Name, "vtkSQLDatabase") == 0) ||
757           (strcmp(theFunc->Name, "CreateFromURL") == 0 &&
758            strcmp(data->Name, "vtkSQLDatabase") == 0) ||
759           (strcmp(theFunc->Name, "MakeTransform") == 0 &&
760            vtkWrap_IsTypeOf(hinfo, data->Name, "vtkAbstractTransform")))
761         {
762         theFunc->ReturnValue->Type |= VTK_PARSE_NEWINSTANCE;
763         }
764       }
765     }
766 }
767
768
769 /* -------------------------------------------------------------------- */
770 /* Expand all typedef types that are used in function arguments */
771 void vtkWrap_ExpandTypedefs(
772   ClassInfo *data, FileInfo *finfo, HierarchyInfo *hinfo)
773 {
774   int i, j, n;
775   FunctionInfo *funcInfo;
776   const char *newclass;
777
778   n = data->NumberOfSuperClasses;
779   for (i = 0; i < n; i++)
780     {
781     newclass = vtkParseHierarchy_ExpandTypedefsInName(
782       hinfo, data->SuperClasses[i], NULL);
783     if (newclass != data->SuperClasses[i])
784       {
785       data->SuperClasses[i] =
786         vtkParse_CacheString(finfo->Strings, newclass, strlen(newclass));
787       free((char *)newclass);
788       }
789     }
790
791   n = data->NumberOfFunctions;
792   for (i = 0; i < n; i++)
793     {
794     funcInfo = data->Functions[i];
795     if (funcInfo->Access == VTK_ACCESS_PUBLIC)
796       {
797       for (j = 0; j < funcInfo->NumberOfParameters; j++)
798         {
799         vtkParseHierarchy_ExpandTypedefsInValue(
800           hinfo, funcInfo->Parameters[j], finfo->Strings, data->Name);
801         }
802       if (funcInfo->ReturnValue)
803         {
804         vtkParseHierarchy_ExpandTypedefsInValue(
805           hinfo, funcInfo->ReturnValue, finfo->Strings, data->Name);
806         }
807       }
808     }
809 }
810
811
812 /* -------------------------------------------------------------------- */
813 /* get the type name */
814
815 const char *vtkWrap_GetTypeName(ValueInfo *val)
816 {
817   unsigned int aType = val->Type;
818   const char *aClass = val->Class;
819
820   /* print the type itself */
821   switch (aType & VTK_PARSE_BASE_TYPE)
822     {
823     case VTK_PARSE_FLOAT:          return "float";
824     case VTK_PARSE_DOUBLE:         return "double";
825     case VTK_PARSE_INT:            return "int";
826     case VTK_PARSE_SHORT:          return "short";
827     case VTK_PARSE_LONG:           return "long";
828     case VTK_PARSE_VOID:           return "void ";
829     case VTK_PARSE_CHAR:           return "char";
830     case VTK_PARSE_UNSIGNED_INT:   return "unsigned int";
831     case VTK_PARSE_UNSIGNED_SHORT: return "unsigned short";
832     case VTK_PARSE_UNSIGNED_LONG:  return "unsigned long";
833     case VTK_PARSE_UNSIGNED_CHAR:  return "unsigned char";
834     case VTK_PARSE_ID_TYPE:        return "vtkIdType";
835     case VTK_PARSE_LONG_LONG:      return "long long";
836     case VTK_PARSE___INT64:        return "__int64";
837     case VTK_PARSE_UNSIGNED_LONG_LONG: return "unsigned long long";
838     case VTK_PARSE_UNSIGNED___INT64:   return "unsigned __int64";
839     case VTK_PARSE_SIGNED_CHAR:    return "signed char";
840     case VTK_PARSE_BOOL:           return "bool";
841     case VTK_PARSE_UNICODE_STRING: return "vtkUnicodeString";
842     case VTK_PARSE_SSIZE_T:        return "ssize_t";
843     case VTK_PARSE_SIZE_T:         return "size_t";
844     }
845
846   return aClass;
847 }
848
849 /* -------------------------------------------------------------------- */
850 /* variable declarations */
851
852 void vtkWrap_DeclareVariable(
853   FILE *fp, ValueInfo *val, const char *name, int i, int flags)
854 {
855   unsigned int aType;
856   int j;
857
858   if (val == NULL)
859     {
860     return;
861     }
862
863   aType = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
864
865   /* do nothing for void */
866   if (aType == VTK_PARSE_VOID ||
867       (aType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_FUNCTION)
868     {
869     return;
870     }
871
872   /* add a couple spaces */
873   fprintf(fp,"  ");
874
875   /* for const * return types, prepend with const */
876   if ((flags & VTK_WRAP_RETURN) != 0)
877     {
878     if ((val->Type & VTK_PARSE_CONST) != 0 &&
879         (aType & VTK_PARSE_INDIRECT) != 0)
880       {
881       fprintf(fp,"const ");
882       }
883     }
884   /* do the same for "const char *" with initializer */
885   else
886     {
887     if ((val->Type & VTK_PARSE_CONST) != 0 &&
888         aType == VTK_PARSE_CHAR_PTR &&
889         val->Value &&
890         strcmp(val->Value, "0") != 0 &&
891         strcmp(val->Value, "NULL") != 0)
892       {
893       fprintf(fp,"const ");
894       }
895     }
896
897   /* print the type name */
898   fprintf(fp, "%s ", vtkWrap_GetTypeName(val));
899
900   /* indirection */
901   if ((flags & VTK_WRAP_RETURN) != 0)
902     {
903     /* ref and pointer return values are stored as pointers */
904     if ((aType & VTK_PARSE_INDIRECT) == VTK_PARSE_POINTER ||
905         (aType & VTK_PARSE_INDIRECT) == VTK_PARSE_REF)
906       {
907       fprintf(fp, "*");
908       }
909     }
910   else
911     {
912     /* objects refs and pointers are always handled via pointers,
913      * other refs are passed by value */
914     if (aType == VTK_PARSE_CHAR_PTR ||
915         aType == VTK_PARSE_VOID_PTR ||
916         aType == VTK_PARSE_OBJECT_PTR ||
917         aType == VTK_PARSE_OBJECT_REF ||
918         aType == VTK_PARSE_OBJECT ||
919         vtkWrap_IsQtObject(val))
920       {
921       fprintf(fp, "*");
922       }
923     /* arrays of unknown size are handled via pointers */
924     else if (val->CountHint)
925       {
926       fprintf(fp, "*");
927       }
928     }
929
930   /* the variable name */
931   if (i >= 0)
932     {
933     fprintf(fp,"%s%i", name, i);
934     }
935   else
936     {
937     fprintf(fp,"%s", name);
938     }
939
940   if ((flags & VTK_WRAP_ARG) != 0)
941     {
942     /* print the array decorators */
943     if (((aType & VTK_PARSE_POINTER_MASK) != 0) &&
944         aType != VTK_PARSE_CHAR_PTR &&
945         aType != VTK_PARSE_VOID_PTR &&
946         aType != VTK_PARSE_OBJECT_PTR &&
947         !vtkWrap_IsQtObject(val) &&
948         val->CountHint == NULL)
949       {
950       if (val->NumberOfDimensions == 1 && val->Count > 0)
951         {
952         fprintf(fp, "[%d]", val->Count);
953         }
954       else
955         {
956         for (j = 0; j < val->NumberOfDimensions; j++)
957           {
958           fprintf(fp, "[%s]", val->Dimensions[j]);
959           }
960         }
961       }
962
963     /* add a default value */
964     else if (val->Value)
965       {
966       fprintf(fp, " = %s", val->Value);
967       }
968     else if (aType == VTK_PARSE_CHAR_PTR ||
969              aType == VTK_PARSE_VOID_PTR ||
970              aType == VTK_PARSE_OBJECT_PTR ||
971              aType == VTK_PARSE_OBJECT_REF ||
972              aType == VTK_PARSE_OBJECT ||
973              vtkWrap_IsQtObject(val))
974       {
975       fprintf(fp, " = NULL");
976       }
977     else if (val->CountHint)
978       {
979       fprintf(fp, " = NULL");
980       }
981     else if (aType == VTK_PARSE_BOOL)
982       {
983       fprintf(fp, " = false");
984       }
985     }
986
987   /* finish off with a semicolon */
988   if ((flags & VTK_WRAP_NOSEMI) == 0)
989     {
990     fprintf(fp, ";\n");
991     }
992 }
993
994 void vtkWrap_DeclareVariableSize(
995   FILE *fp, ValueInfo *val, const char *name, int i)
996 {
997   char idx[32];
998   int j;
999
1000   idx[0] = '\0';
1001   if (i >= 0)
1002     {
1003     sprintf(idx, "%d", i);
1004     }
1005
1006   if (val->NumberOfDimensions > 1)
1007     {
1008     fprintf(fp,
1009             "  static int %s%s[%d] = ",
1010             name, idx, val->NumberOfDimensions);
1011
1012     for (j = 0; j < val->NumberOfDimensions; j++)
1013       {
1014       fprintf(fp, "%c %s", ((j == 0) ? '{' : ','), val->Dimensions[j]);
1015       }
1016
1017     fprintf(fp, " };\n");
1018     }
1019   else if (val->Count != 0 || val->CountHint)
1020     {
1021     fprintf(fp,
1022             "  %sint %s%s = %d;\n",
1023             (val->CountHint ? "" : "const "), name, idx,
1024             (val->CountHint ? 0 : val->Count));
1025     }
1026   else if (val->NumberOfDimensions == 1)
1027     {
1028     fprintf(fp,
1029             "  const int %s%s = %s;\n",
1030             name, idx, val->Dimensions[0]);
1031     }
1032 }