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