]> SALOME platform Git repositories - modules/paravis.git/blob - src/ParaView/vtkParseData.c
Salome HOME
Merge from BR_PORTING_VTK6 01/03/2013
[modules/paravis.git] / src / ParaView / vtkParseData.c
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    vtkParseData.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   Copyright (c) 2010 David Gobbi.
17
18   Contributed to the VisualizationToolkit by the author in May 2010
19   under the terms of the Visualization Toolkit 2008 copyright.
20 -------------------------------------------------------------------------*/
21
22 #include "vtkParseData.h"
23 #include <stdlib.h>
24 #include <string.h>
25
26 /* Initialize the FileInfo struct */
27 void vtkParse_InitFile(FileInfo *file_info)
28 {
29   /* file info */
30   file_info->FileName = NULL;
31   file_info->NameComment = NULL;
32   file_info->Description = NULL;
33   file_info->Caveats = NULL;
34   file_info->SeeAlso = NULL;
35
36   file_info->NumberOfIncludes = 0;
37   file_info->Includes = NULL;
38   file_info->MainClass = NULL;
39   file_info->Contents = NULL;
40
41   file_info->Strings = NULL;
42 }
43
44 /* Free the FileInfo struct */
45 void vtkParse_FreeFile(FileInfo *file_info)
46 {
47   int i, n;
48
49   n = file_info->NumberOfIncludes;
50   for (i = 0; i < n; i++)
51     {
52     vtkParse_FreeFile(file_info->Includes[i]);
53     free(file_info->Includes[i]);
54     }
55   if (file_info->Includes)
56     {
57     free(file_info->Includes);
58     }
59
60   vtkParse_FreeNamespace(file_info->Contents);
61   file_info->Contents = NULL;
62 }
63
64 /* Initialize a TemplateInfo struct */
65 void vtkParse_InitTemplate(TemplateInfo *info)
66 {
67   info->NumberOfParameters = 0;
68   info->Parameters = NULL;
69 }
70
71 /* Copy a TemplateInfo struct */
72 void vtkParse_CopyTemplate(TemplateInfo *info, const TemplateInfo *orig)
73 {
74   int i, n;
75
76   n = orig->NumberOfParameters;
77   info->NumberOfParameters = n;
78   info->Parameters = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
79
80   for (i = 0; i < n; i++)
81     {
82     info->Parameters[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
83     vtkParse_CopyValue(info->Parameters[i], orig->Parameters[i]);
84     }
85 }
86
87 /* Free a TemplateInfo struct */
88 void vtkParse_FreeTemplate(TemplateInfo *template_info)
89 {
90   int j, m;
91
92   m = template_info->NumberOfParameters;
93   for (j = 0; j < m; j++)
94     {
95     vtkParse_FreeValue(template_info->Parameters[j]);
96     }
97
98   free(template_info);
99 }
100
101
102 /* Initialize a Function struct */
103 void vtkParse_InitFunction(FunctionInfo *func)
104 {
105 #ifndef VTK_PARSE_LEGACY_REMOVE
106   int i;
107 #endif
108
109   func->ItemType = VTK_FUNCTION_INFO;
110   func->Access = VTK_ACCESS_PUBLIC;
111   func->Name = NULL;
112   func->Comment = NULL;
113   func->Class = NULL;
114   func->Signature = NULL;
115   func->Template = NULL;
116   func->NumberOfParameters = 0;
117   func->Parameters = NULL;
118   func->ReturnValue = NULL;
119   func->Macro = NULL;
120   func->SizeHint = NULL;
121   func->IsStatic = 0;
122   func->IsVirtual = 0;
123   func->IsPureVirtual = 0;
124   func->IsOperator = 0;
125   func->IsVariadic = 0;
126   func->IsConst = 0;
127   func->IsExplicit = 0;
128   func->IsLegacy = 0;
129
130 #ifndef VTK_PARSE_LEGACY_REMOVE
131   /* everything below here is legacy information, *
132    * maintained only for backwards compatibility  */
133   func->NumberOfArguments = 0;
134   func->ReturnType = VTK_PARSE_VOID;
135   func->ReturnClass = NULL;
136   func->HaveHint = 0;
137   func->HintSize = 0;
138   func->ArrayFailure = 0;
139   func->IsPublic = 0;
140   func->IsProtected = 0;
141
142   for (i = 0; i < MAX_ARGS; i++)
143     {
144     func->ArgTypes[i] = 0;
145     func->ArgClasses[i] = 0;
146     func->ArgCounts[i] = 0;
147     }
148 #endif
149 }
150
151 /* Copy a Function struct */
152 void vtkParse_CopyFunction(FunctionInfo *func, const FunctionInfo *orig)
153 {
154   int i, n;
155
156   func->ItemType = orig->ItemType;
157   func->Access = orig->Access;
158   func->Name = orig->Name;
159   func->Comment = orig->Comment;
160   func->Class = orig->Class;
161   func->Signature = orig->Signature;
162   func->Template = NULL;
163
164   if (orig->Template)
165     {
166     func->Template = (TemplateInfo *)malloc(sizeof(TemplateInfo));
167     vtkParse_CopyTemplate(func->Template, orig->Template);
168     }
169
170   n = orig->NumberOfParameters;
171   func->NumberOfParameters = n;
172   if (n)
173     {
174     func->Parameters = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
175     for (i = 0; i < n; i++)
176       {
177       func->Parameters[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
178       vtkParse_CopyValue(func->Parameters[i], orig->Parameters[i]);
179       }
180     }
181
182   func->ReturnValue = NULL;
183   if (orig->ReturnValue)
184     {
185     func->ReturnValue = (ValueInfo *)malloc(sizeof(ValueInfo));
186     vtkParse_CopyValue(func->ReturnValue, orig->ReturnValue);
187     }
188
189   func->Macro = orig->Macro;
190   func->SizeHint = orig->SizeHint;
191   func->IsStatic = orig->IsStatic;
192   func->IsVirtual = orig->IsVirtual;
193   func->IsPureVirtual = orig->IsPureVirtual;
194   func->IsOperator = orig->IsOperator;
195   func->IsVariadic = orig->IsVariadic;
196   func->IsConst = orig->IsConst;
197   func->IsExplicit = orig->IsExplicit;
198   func->IsLegacy = orig->IsLegacy;
199
200 #ifndef VTK_PARSE_LEGACY_REMOVE
201   /* everything below here is legacy information, *
202    * maintained only for backwards compatibility  */
203   func->NumberOfArguments = orig->NumberOfArguments;
204   func->ReturnType = orig->ReturnType;
205   func->ReturnClass = orig->ReturnClass;
206   func->HaveHint = orig->HaveHint;
207   func->HintSize = orig->HintSize;
208   func->ArrayFailure = orig->ArrayFailure;
209   func->IsPublic = orig->IsPublic;
210   func->IsProtected = orig->IsProtected;
211
212   for (i = 0; i < MAX_ARGS; i++)
213     {
214     func->ArgTypes[i] = orig->ArgTypes[i];
215     func->ArgClasses[i] = orig->ArgClasses[i];
216     func->ArgCounts[i] = orig->ArgCounts[i];
217     }
218 #endif
219 }
220
221 /* Free a Function struct */
222 void vtkParse_FreeFunction(FunctionInfo *function_info)
223 {
224   int j, m;
225
226   if (function_info->Template)
227     {
228     vtkParse_FreeTemplate(function_info->Template);
229     }
230
231   m = function_info->NumberOfParameters;
232   for (j = 0; j < m; j++) { vtkParse_FreeValue(function_info->Parameters[j]); }
233   if (m > 0) { free(function_info->Parameters); }
234
235   if (function_info->ReturnValue)
236     {
237     vtkParse_FreeValue(function_info->ReturnValue);
238     }
239
240   free(function_info);
241 }
242
243
244 /* Initialize a Value struct */
245 void vtkParse_InitValue(ValueInfo *val)
246 {
247   val->ItemType = VTK_VARIABLE_INFO;
248   val->Access = VTK_ACCESS_PUBLIC;
249   val->Name = NULL;
250   val->Comment = NULL;
251   val->Value = NULL;
252   val->Type = 0;
253   val->Class = NULL;
254   val->Count = 0;
255   val->CountHint = NULL;
256   val->NumberOfDimensions = 0;
257   val->Dimensions = NULL;
258   val->Function = NULL;
259   val->Template = NULL;
260   val->IsStatic = 0;
261   val->IsEnum = 0;
262 }
263
264 /* Copy a Value struct */
265 void vtkParse_CopyValue(ValueInfo *val, const ValueInfo *orig)
266 {
267   int i, n;
268
269   val->ItemType = orig->ItemType;
270   val->Access = orig->Access;
271   val->Name = orig->Name;
272   val->Comment = orig->Comment;
273   val->Value = orig->Value;
274   val->Type = orig->Type;
275   val->Class = orig->Class;
276   val->Count = orig->Count;
277   val->CountHint = orig->CountHint;
278
279   n = orig->NumberOfDimensions;
280   val->NumberOfDimensions = n;
281   if (n)
282     {
283     val->Dimensions = (const char **)malloc(n*sizeof(char *));
284     for (i = 0; i < n; i++)
285       {
286       val->Dimensions[i] = orig->Dimensions[i];
287       }
288     }
289
290   val->Function = NULL;
291   if (orig->Function)
292     {
293     val->Function = (FunctionInfo *)malloc(sizeof(FunctionInfo));
294     vtkParse_CopyFunction(val->Function, orig->Function);
295     }
296
297   val->Template = NULL;
298   if (orig->Template)
299     {
300     val->Template = (TemplateInfo *)malloc(sizeof(TemplateInfo));
301     vtkParse_CopyTemplate(val->Template, orig->Template);
302     }
303
304   val->IsStatic = orig->IsStatic;
305   val->IsEnum = orig->IsEnum;
306 }
307
308 /* Free a Value struct */
309 void vtkParse_FreeValue(ValueInfo *value_info)
310 {
311   if (value_info->NumberOfDimensions)
312     {
313     free((char **)value_info->Dimensions);
314     }
315   if (value_info->Function)
316     {
317     vtkParse_FreeFunction(value_info->Function);
318     }
319   if (value_info->Template)
320     {
321     vtkParse_FreeTemplate(value_info->Template);
322     }
323
324   free(value_info);
325 }
326
327
328 /* Initialize an Enum struct */
329 void vtkParse_InitEnum(EnumInfo *item)
330 {
331   item->ItemType = VTK_ENUM_INFO;
332   item->Access = VTK_ACCESS_PUBLIC;
333   item->Name = NULL;
334   item->Comment = NULL;
335 }
336
337 /* Copy an Enum struct */
338 void vtkParse_CopyEnum(EnumInfo *item, const EnumInfo *orig)
339 {
340   item->ItemType = orig->ItemType;
341   item->Access = orig->Access;
342   item->Name = orig->Name;
343   item->Comment = orig->Comment;
344 }
345
346 /* Free an Enum struct */
347 void vtkParse_FreeEnum(EnumInfo *enum_info)
348 {
349   free(enum_info);
350 }
351
352
353 /* Initialize a Using struct */
354 void vtkParse_InitUsing(UsingInfo *item)
355 {
356   item->ItemType = VTK_USING_INFO;
357   item->Access = VTK_ACCESS_PUBLIC;
358   item->Name = NULL;
359   item->Comment = NULL;
360   item->Scope = NULL;
361 }
362
363 /* Copy a Using struct */
364 void vtkParse_CopyUsing(UsingInfo *item, const UsingInfo *orig)
365 {
366   item->ItemType = orig->ItemType;
367   item->Access = orig->Access;
368   item->Name = orig->Name;
369   item->Comment = orig->Comment;
370   item->Scope = orig->Scope;
371 }
372
373 /* Free a Using struct */
374 void vtkParse_FreeUsing(UsingInfo *using_info)
375 {
376   free(using_info);
377 }
378
379
380 /* Initialize a Class struct */
381 void vtkParse_InitClass(ClassInfo *cls)
382 {
383   cls->ItemType = VTK_CLASS_INFO;
384   cls->Access = VTK_ACCESS_PUBLIC;
385   cls->Name = NULL;
386   cls->Comment = NULL;
387   cls->Template = NULL;
388   cls->NumberOfSuperClasses = 0;
389   cls->SuperClasses = NULL;
390   cls->NumberOfItems = 0;
391   cls->Items = NULL;
392   cls->NumberOfClasses = 0;
393   cls->Classes = NULL;
394   cls->NumberOfFunctions = 0;
395   cls->Functions = NULL;
396   cls->NumberOfConstants = 0;
397   cls->Constants = NULL;
398   cls->NumberOfVariables = 0;
399   cls->Variables = NULL;
400   cls->NumberOfEnums = 0;
401   cls->Enums = NULL;
402   cls->NumberOfTypedefs = 0;
403   cls->Typedefs = NULL;
404   cls->NumberOfUsings = 0;
405   cls->Usings = NULL;
406   cls->NumberOfNamespaces = 0;
407   cls->Namespaces = NULL;
408   cls->IsAbstract = 0;
409   cls->HasDelete = 0;
410 }
411
412 /* Copy a Class struct */
413 void vtkParse_CopyClass(ClassInfo *cls, const ClassInfo *orig)
414 {
415   int i, n;
416
417   cls->ItemType = orig->ItemType;
418   cls->Access = orig->Access;
419   cls->Name = orig->Name;
420   cls->Comment = orig->Comment;
421   cls->Template = NULL;
422
423   if (orig->Template)
424     {
425     cls->Template = (TemplateInfo *)malloc(sizeof(TemplateInfo));
426     vtkParse_CopyTemplate(cls->Template, orig->Template);
427     }
428
429   n = orig->NumberOfSuperClasses;
430   cls->NumberOfSuperClasses = n;
431   if (n)
432     {
433     cls->SuperClasses = (const char **)malloc(n*sizeof(char *));
434     for (i = 0; i < n; i++)
435       {
436       cls->SuperClasses[i] = orig->SuperClasses[i];
437       }
438     }
439
440   n = orig->NumberOfItems;
441   cls->NumberOfItems = n;
442   if (n)
443     {
444     cls->Items = (ItemInfo *)malloc(n*sizeof(ItemInfo));
445     for (i = 0; i < n; i++)
446       {
447       cls->Items[i].Type = orig->Items[i].Type;
448       cls->Items[i].Index = orig->Items[i].Index;
449       }
450     }
451
452   n = orig->NumberOfClasses;
453   cls->NumberOfClasses = n;
454   if (n)
455     {
456     cls->Classes = (ClassInfo **)malloc(n*sizeof(ClassInfo *));
457     for (i = 0; i < n; i++)
458       {
459       cls->Classes[i] = (ClassInfo *)malloc(sizeof(ClassInfo));
460       vtkParse_CopyClass(cls->Classes[i], orig->Classes[i]);
461       }
462     }
463
464   n = orig->NumberOfFunctions;
465   cls->NumberOfFunctions = n;
466   if (n)
467     {
468     cls->Functions = (FunctionInfo **)malloc(n*sizeof(FunctionInfo *));
469     for (i = 0; i < n; i++)
470       {
471       cls->Functions[i] = (FunctionInfo *)malloc(sizeof(FunctionInfo));
472       vtkParse_CopyFunction(cls->Functions[i], orig->Functions[i]);
473       }
474     }
475
476   n = orig->NumberOfConstants;
477   cls->NumberOfConstants = n;
478   if (n)
479     {
480     cls->Constants = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
481     for (i = 0; i < n; i++)
482       {
483       cls->Constants[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
484       vtkParse_CopyValue(cls->Constants[i], orig->Constants[i]);
485       }
486     }
487
488   n = orig->NumberOfVariables;
489   cls->NumberOfVariables = n;
490   if (n)
491     {
492     cls->Variables = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
493     for (i = 0; i < n; i++)
494       {
495       cls->Variables[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
496       vtkParse_CopyValue(cls->Variables[i], orig->Variables[i]);
497       }
498     }
499
500   n = orig->NumberOfEnums;
501   cls->NumberOfEnums = n;
502   if (n)
503     {
504     cls->Enums = (EnumInfo **)malloc(n*sizeof(EnumInfo *));
505     for (i = 0; i < n; i++)
506       {
507       cls->Enums[i] = (EnumInfo *)malloc(sizeof(EnumInfo));
508       vtkParse_CopyEnum(cls->Enums[i], orig->Enums[i]);
509       }
510     }
511
512   n = orig->NumberOfTypedefs;
513   cls->NumberOfTypedefs = n;
514   if (n)
515     {
516     cls->Typedefs = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
517     for (i = 0; i < n; i++)
518       {
519       cls->Typedefs[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
520       vtkParse_CopyValue(cls->Typedefs[i], orig->Typedefs[i]);
521       }
522     }
523
524   n = orig->NumberOfUsings;
525   cls->NumberOfUsings = n;
526   if (n)
527     {
528     cls->Usings = (UsingInfo **)malloc(n*sizeof(UsingInfo *));
529     for (i = 0; i < n; i++)
530       {
531       cls->Usings[i] = (UsingInfo *)malloc(sizeof(UsingInfo));
532       vtkParse_CopyUsing(cls->Usings[i], orig->Usings[i]);
533       }
534     }
535
536   n = orig->NumberOfNamespaces;
537   cls->NumberOfNamespaces = n;
538   if (n)
539     {
540     cls->Namespaces = (NamespaceInfo **)malloc(n*sizeof(NamespaceInfo *));
541     for (i = 0; i < n; i++)
542       {
543       cls->Namespaces[i] = (NamespaceInfo *)malloc(sizeof(NamespaceInfo));
544       vtkParse_CopyNamespace(cls->Namespaces[i], orig->Namespaces[i]);
545       }
546     }
547
548   cls->IsAbstract = orig->IsAbstract;
549   cls->HasDelete = orig->HasDelete;
550 }
551
552 /* Free a Class struct */
553 void vtkParse_FreeClass(ClassInfo *class_info)
554 {
555   int j, m;
556
557   if (class_info->Template) { vtkParse_FreeTemplate(class_info->Template); }
558
559   m = class_info->NumberOfSuperClasses;
560   if (m > 0) { free((char **)class_info->SuperClasses); }
561
562   m = class_info->NumberOfClasses;
563   for (j = 0; j < m; j++) { vtkParse_FreeClass(class_info->Classes[j]); }
564   if (m > 0) { free(class_info->Classes); }
565
566   m = class_info->NumberOfFunctions;
567   for (j = 0; j < m; j++) { vtkParse_FreeFunction(class_info->Functions[j]); }
568   if (m > 0) { free(class_info->Functions); }
569
570   m = class_info->NumberOfConstants;
571   for (j = 0; j < m; j++) { vtkParse_FreeValue(class_info->Constants[j]); }
572   if (m > 0) { free(class_info->Constants); }
573
574   m = class_info->NumberOfVariables;
575   for (j = 0; j < m; j++) { vtkParse_FreeValue(class_info->Variables[j]); }
576   if (m > 0) { free(class_info->Variables); }
577
578   m = class_info->NumberOfEnums;
579   for (j = 0; j < m; j++) { vtkParse_FreeEnum(class_info->Enums[j]); }
580   if (m > 0) { free(class_info->Enums); }
581
582   m = class_info->NumberOfTypedefs;
583   for (j = 0; j < m; j++) { vtkParse_FreeValue(class_info->Typedefs[j]); }
584   if (m > 0) { free(class_info->Typedefs); }
585
586   m = class_info->NumberOfUsings;
587   for (j = 0; j < m; j++) { vtkParse_FreeUsing(class_info->Usings[j]); }
588   if (m > 0) { free(class_info->Usings); }
589
590   m = class_info->NumberOfNamespaces;
591   for (j = 0; j < m; j++) { vtkParse_FreeNamespace(class_info->Namespaces[j]); }
592   if (m > 0) { free(class_info->Namespaces); }
593
594   if (class_info->NumberOfItems > 0) { free(class_info->Items); }
595
596   free(class_info);
597 }
598
599
600 /* Initialize a Namespace struct */
601 void vtkParse_InitNamespace(NamespaceInfo *name_info)
602 {
603   vtkParse_InitClass(name_info);
604   name_info->ItemType = VTK_NAMESPACE_INFO;
605 }
606
607 /* Copy a Namespace struct */
608 void vtkParse_CopyNamespace(NamespaceInfo *ninfo, const NamespaceInfo *orig)
609 {
610   vtkParse_CopyClass(ninfo, orig);
611 }
612
613 /* Free a Namespace struct */
614 void vtkParse_FreeNamespace(NamespaceInfo *namespace_info)
615 {
616   vtkParse_FreeClass(namespace_info);
617 }
618
619
620 /* This method is used for extending dynamic arrays in a progression of
621  * powers of two.  If "n" reaches a power of two, then the array size is
622  * doubled so that "n" can be safely incremented. */
623 static void *array_size_check(
624   void *arraymem, size_t size, int n)
625 {
626   /* if empty, alloc for the first time */
627   if (n == 0)
628     {
629     return malloc(size);
630     }
631   /* if count is power of two, reallocate with double size */
632   else if ((n & (n-1)) == 0)
633     {
634     return realloc(arraymem, (n << 1)*size);
635     }
636
637   /* no reallocation, just return the original array */
638   return arraymem;
639 }
640
641
642 /* Utility method to add an included file to a FileInfo */
643 void vtkParse_AddIncludeToFile(
644   FileInfo *file_info, FileInfo *include_file)
645 {
646   file_info->Includes = (FileInfo **)array_size_check(
647     (FileInfo **)file_info->Includes, sizeof(FileInfo *),
648     file_info->NumberOfIncludes);
649
650   file_info->Includes[file_info->NumberOfIncludes++] = include_file;
651
652   if (!include_file->Strings)
653     {
654     include_file->Strings = file_info->Strings;
655     }
656 }
657
658 /* Utility method to add a const char pointer to an array */
659 void vtkParse_AddStringToArray(
660   const char ***valueArray, int *count, const char *value)
661 {
662   *valueArray = (const char **)array_size_check(
663     (char **)*valueArray, sizeof(const char *), *count);
664
665   (*valueArray)[(*count)++] = value;
666 }
667
668 /* Utility method to add an item to an array */
669 void vtkParse_AddItemToArray(
670   ItemInfo **valueArray, int *count, parse_item_t type, int idx)
671 {
672   int n = *count;
673   ItemInfo *values = *valueArray;
674
675   values = (ItemInfo *)array_size_check(values, sizeof(ItemInfo), n);
676
677   values[n].Type = type;
678   values[n].Index = idx;
679   *count = n+1;
680   *valueArray = values;
681 }
682
683 /* Add a ClassInfo to a ClassInfo */
684 void vtkParse_AddClassToClass(ClassInfo *info, ClassInfo *item)
685 {
686   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
687     item->ItemType, info->NumberOfClasses);
688   info->Classes = (ClassInfo **)array_size_check(
689     info->Classes, sizeof(ClassInfo *), info->NumberOfClasses);
690   info->Classes[info->NumberOfClasses++] = item;
691 }
692
693 /* Add a FunctionInfo to a ClassInfo */
694 void vtkParse_AddFunctionToClass(ClassInfo *info, FunctionInfo *item)
695 {
696   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
697     item->ItemType, info->NumberOfFunctions);
698   info->Functions = (FunctionInfo **)array_size_check(
699     info->Functions, sizeof(FunctionInfo *), info->NumberOfFunctions);
700   info->Functions[info->NumberOfFunctions++] = item;
701 }
702
703 /* Add a EnumInfo to a ClassInfo */
704 void vtkParse_AddEnumToClass(ClassInfo *info, EnumInfo *item)
705 {
706   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
707     item->ItemType, info->NumberOfEnums);
708   info->Enums = (EnumInfo **)array_size_check(
709     info->Enums, sizeof(EnumInfo *), info->NumberOfEnums);
710   info->Enums[info->NumberOfEnums++] = item;
711 }
712
713 /* Add a Constant ValueInfo to a ClassInfo */
714 void vtkParse_AddConstantToClass(ClassInfo *info, ValueInfo *item)
715 {
716   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
717     item->ItemType, info->NumberOfConstants);
718   info->Constants = (ValueInfo **)array_size_check(
719     info->Constants, sizeof(ValueInfo *), info->NumberOfConstants);
720   info->Constants[info->NumberOfConstants++] = item;
721 }
722
723 /* Add a Variable ValueInfo to a ClassInfo */
724 void vtkParse_AddVariableToClass(ClassInfo *info, ValueInfo *item)
725 {
726   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
727     item->ItemType, info->NumberOfVariables);
728   info->Variables = (ValueInfo **)array_size_check(
729     info->Variables, sizeof(ValueInfo *), info->NumberOfVariables);
730   info->Variables[info->NumberOfVariables++] = item;
731 }
732
733 /* Add a Typedef ValueInfo to a ClassInfo */
734 void vtkParse_AddTypedefToClass(ClassInfo *info, ValueInfo *item)
735 {
736   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
737     item->ItemType, info->NumberOfTypedefs);
738   info->Typedefs = (ValueInfo **)array_size_check(
739     info->Typedefs, sizeof(ValueInfo *), info->NumberOfTypedefs);
740   info->Typedefs[info->NumberOfTypedefs++] = item;
741 }
742
743 /* Add a UsingInfo to a ClassInfo */
744 void vtkParse_AddUsingToClass(ClassInfo *info, UsingInfo *item)
745 {
746   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
747     item->ItemType, info->NumberOfUsings);
748   info->Usings = (UsingInfo **)array_size_check(
749     info->Usings, sizeof(UsingInfo *), info->NumberOfUsings);
750   info->Usings[info->NumberOfUsings++] = item;
751 }
752
753
754 /* Add a NamespaceInfo to a NamespaceInfo */
755 void vtkParse_AddNamespaceToNamespace(NamespaceInfo *info, NamespaceInfo *item)
756 {
757   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
758     item->ItemType, info->NumberOfNamespaces);
759   info->Namespaces = (NamespaceInfo **)array_size_check(
760     info->Namespaces, sizeof(NamespaceInfo *), info->NumberOfNamespaces);
761   info->Namespaces[info->NumberOfNamespaces++] = item;
762 }
763
764 /* Add a ClassInfo to a NamespaceInfo */
765 void vtkParse_AddClassToNamespace(NamespaceInfo *info, ClassInfo *item)
766 {
767   vtkParse_AddClassToClass(info, item);
768 }
769
770 /* Add a FunctionInfo to a NamespaceInfo */
771 void vtkParse_AddFunctionToNamespace(NamespaceInfo *info, FunctionInfo *item)
772 {
773   vtkParse_AddFunctionToClass(info, item);
774 }
775
776 /* Add a EnumInfo to a NamespaceInfo */
777 void vtkParse_AddEnumToNamespace(NamespaceInfo *info, EnumInfo *item)
778 {
779   vtkParse_AddEnumToClass(info, item);
780 }
781
782 /* Add a Constant ValueInfo to a NamespaceInfo */
783 void vtkParse_AddConstantToNamespace(NamespaceInfo *info, ValueInfo *item)
784 {
785   vtkParse_AddConstantToClass(info, item);
786 }
787
788 /* Add a Variable ValueInfo to a NamespaceInfo */
789 void vtkParse_AddVariableToNamespace(NamespaceInfo *info, ValueInfo *item)
790 {
791   vtkParse_AddVariableToClass(info, item);
792 }
793
794 /* Add a Typedef ValueInfo to a NamespaceInfo */
795 void vtkParse_AddTypedefToNamespace(NamespaceInfo *info, ValueInfo *item)
796 {
797   vtkParse_AddTypedefToClass(info, item);
798 }
799
800 /* Add a UsingInfo to a NamespaceInfo */
801 void vtkParse_AddUsingToNamespace(NamespaceInfo *info, UsingInfo *item)
802 {
803   vtkParse_AddUsingToClass(info, item);
804 }
805
806
807 /* Add a ValueInfo parameter to a FunctionInfo */
808 void vtkParse_AddParameterToFunction(FunctionInfo *info, ValueInfo *item)
809 {
810   info->Parameters = (ValueInfo **)array_size_check(
811     info->Parameters, sizeof(ValueInfo *), info->NumberOfParameters);
812   info->Parameters[info->NumberOfParameters++] = item;
813 }
814
815
816 /* Add a ValueInfo to a TemplateInfo */
817 void vtkParse_AddParameterToTemplate(TemplateInfo *info, ValueInfo *item)
818 {
819   info->Parameters = (ValueInfo **)array_size_check(
820     info->Parameters, sizeof(ValueInfo *), info->NumberOfParameters);
821   info->Parameters[info->NumberOfParameters++] = item;
822 }
823
824
825 /* Add default constructors if they do not already exist */
826 void vtkParse_AddDefaultConstructors(ClassInfo *cls, StringCache *cache)
827 {
828   FunctionInfo *func;
829   ValueInfo *param;
830   size_t k, l;
831   int i, n;
832   int default_constructor = 1;
833   int copy_constructor = 1;
834   char *tname;
835   const char *ccname;
836
837   if (cls == NULL || cls->Name == NULL)
838     {
839     return;
840     }
841
842   n = cls->NumberOfFunctions;
843   for (i = 0; i < n; i++)
844     {
845     func = cls->Functions[i];
846     if (func->Name && strcmp(func->Name, cls->Name) == 0)
847       {
848       default_constructor = 0;
849
850       if (func->NumberOfParameters == 1)
851         {
852         param = func->Parameters[0];
853         if (param->Class &&
854             strcmp(param->Class, cls->Name) == 0 &&
855             (param->Type & VTK_PARSE_POINTER_MASK) == 0)
856           {
857           copy_constructor = 0;
858           }
859         }
860       }
861     }
862
863   if (default_constructor)
864     {
865     func = (FunctionInfo *)malloc(sizeof(FunctionInfo));
866     vtkParse_InitFunction(func);
867     func->Class = cls->Name;
868     func->Name = cls->Name;
869     k = strlen(cls->Name);
870     tname = vtkParse_NewString(cache, k + 2);
871     strcpy(tname, cls->Name);
872     strcpy(&tname[k], "()");
873     func->Signature = tname;
874     vtkParse_AddFunctionToClass(cls, func);
875     }
876
877   if (copy_constructor)
878     {
879     ccname = cls->Name;
880
881     if (cls->Template)
882       {
883       /* specialize the name */
884       n = cls->Template->NumberOfParameters;
885
886       k = strlen(cls->Name) + 2;
887       for (i = 0; i < n; i++)
888         {
889         if (cls->Template->Parameters[i]->Name)
890           {
891           k += strlen(cls->Template->Parameters[i]->Name) + 2;
892           }
893         }
894       tname = vtkParse_NewString(cache, k);
895       strcpy(tname, cls->Name);
896       k = strlen(tname);
897       tname[k++] = '<';
898       for (i = 0; i < n; i++)
899         {
900         if (cls->Template->Parameters[i]->Name)
901           {
902           strcpy(&tname[k], cls->Template->Parameters[i]->Name);
903           k += strlen(cls->Template->Parameters[i]->Name);
904           }
905         if (i+1 < n)
906           {
907           tname[k++] = ',';
908           tname[k++] = ' ';
909           }
910         }
911       tname[k++] = '>';
912       tname[k] = '\0';
913       ccname = tname;
914       }
915
916     func = (FunctionInfo *)malloc(sizeof(FunctionInfo));
917     vtkParse_InitFunction(func);
918     func->Class = cls->Name;
919     func->Name = cls->Name;
920     k = strlen(cls->Name);
921     l = strlen(ccname);
922     tname = vtkParse_NewString(cache, k + l + 9);
923     strcpy(tname, cls->Name);
924     strcpy(&tname[k], "(const &");
925     strcpy(&tname[k+8], ccname);
926     strcpy(&tname[k+8+l], ")");
927     func->Signature = tname;
928     param = (ValueInfo *)malloc(sizeof(ValueInfo));
929     vtkParse_InitValue(param);
930     param->Type = (VTK_PARSE_OBJECT_REF | VTK_PARSE_CONST);
931     param->Class = ccname;
932     vtkParse_AddParameterToFunction(func, param);
933     vtkParse_AddFunctionToClass(cls, func);
934     }
935 }