Back to index

salome-paravis  6.5.0
vtkWrap.c
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkWrap.c
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 
00016 #include "vtkWrap.h"
00017 #include "vtkParseInternal.h"
00018 #include "vtkParseExtras.h"
00019 #include <stdlib.h>
00020 #include <string.h>
00021 #include <ctype.h>
00022 
00023 /* -------------------------------------------------------------------- */
00024 /* Common types. */
00025 
00026 int vtkWrap_IsVoid(ValueInfo *val)
00027 {
00028   if (val == 0)
00029     {
00030     return 1;
00031     }
00032 
00033   return ((val->Type & VTK_PARSE_UNQUALIFIED_TYPE) == VTK_PARSE_VOID);
00034 }
00035 
00036 int vtkWrap_IsVoidFunction(ValueInfo *val)
00037 {
00038   unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
00039   return (t == VTK_PARSE_FUNCTION);
00040 }
00041 
00042 int vtkWrap_IsVoidPointer(ValueInfo *val)
00043 {
00044   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
00045   return (t == VTK_PARSE_VOID && vtkWrap_IsPointer(val));
00046 }
00047 
00048 int vtkWrap_IsCharPointer(ValueInfo *val)
00049 {
00050   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
00051   return (t == VTK_PARSE_CHAR && vtkWrap_IsPointer(val));
00052 }
00053 
00054 int vtkWrap_IsVTKObject(ValueInfo *val)
00055 {
00056   unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
00057   return (t == VTK_PARSE_OBJECT_PTR &&
00058           val->Class[0] == 'v' && strncmp(val->Class, "vtk", 3) == 0);
00059 }
00060 
00061 int vtkWrap_IsSpecialObject(ValueInfo *val)
00062 {
00063   unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
00064   return ((t == VTK_PARSE_OBJECT ||
00065            t == VTK_PARSE_OBJECT_REF) &&
00066           val->Class[0] == 'v' && strncmp(val->Class, "vtk", 3) == 0);
00067 }
00068 
00069 int vtkWrap_IsQtObject(ValueInfo *val)
00070 {
00071   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
00072   if (t == VTK_PARSE_QOBJECT &&
00073       val->Class[0] == 'Q' && isupper(val->Class[1]))
00074     {
00075     return 1;
00076     }
00077   return 0;
00078 }
00079 
00080 int vtkWrap_IsQtEnum(ValueInfo *val)
00081 {
00082   unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
00083   if ((t == VTK_PARSE_QOBJECT || t == VTK_PARSE_QOBJECT_REF) &&
00084       val->Class[0] == 'Q' && strncmp("Qt::", val->Class, 4) == 0)
00085     {
00086     return 1;
00087     }
00088   return 0;
00089 }
00090 
00091 
00092 /* -------------------------------------------------------------------- */
00093 /* The base types, all are mutually exclusive. */
00094 
00095 int vtkWrap_IsObject(ValueInfo *val)
00096 {
00097   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
00098   return (t == VTK_PARSE_OBJECT ||
00099           t == VTK_PARSE_QOBJECT);
00100 }
00101 
00102 int vtkWrap_IsFunction(ValueInfo *val)
00103 {
00104   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
00105   return (t == VTK_PARSE_FUNCTION);
00106 }
00107 
00108 int vtkWrap_IsStream(ValueInfo *val)
00109 {
00110   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
00111   return (t == VTK_PARSE_ISTREAM ||
00112           t == VTK_PARSE_OSTREAM);
00113 }
00114 
00115 int vtkWrap_IsNumeric(ValueInfo *val)
00116 {
00117   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
00118 
00119   t = (t & ~VTK_PARSE_UNSIGNED);
00120   switch (t)
00121     {
00122     case VTK_PARSE_FLOAT:
00123     case VTK_PARSE_DOUBLE:
00124     case VTK_PARSE_CHAR:
00125     case VTK_PARSE_SHORT:
00126     case VTK_PARSE_INT:
00127     case VTK_PARSE_LONG:
00128     case VTK_PARSE_ID_TYPE:
00129     case VTK_PARSE_LONG_LONG:
00130     case VTK_PARSE___INT64:
00131     case VTK_PARSE_SIGNED_CHAR:
00132     case VTK_PARSE_SSIZE_T:
00133     case VTK_PARSE_BOOL:
00134       return 1;
00135     }
00136 
00137   return 0;
00138 }
00139 
00140 int vtkWrap_IsString(ValueInfo *val)
00141 {
00142   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
00143   return (t == VTK_PARSE_STRING ||
00144           t == VTK_PARSE_UNICODE_STRING);
00145 }
00146 
00147 /* -------------------------------------------------------------------- */
00148 /* Subcategories */
00149 
00150 int vtkWrap_IsBool(ValueInfo *val)
00151 {
00152   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
00153   return (t == VTK_PARSE_BOOL);
00154 }
00155 
00156 int vtkWrap_IsChar(ValueInfo *val)
00157 {
00158   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
00159   return (t == VTK_PARSE_CHAR);
00160 }
00161 
00162 int vtkWrap_IsInteger(ValueInfo *val)
00163 {
00164   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
00165 
00166   if (t != VTK_PARSE_UNSIGNED_CHAR)
00167     {
00168     t = (t & ~VTK_PARSE_UNSIGNED);
00169     }
00170   switch (t)
00171     {
00172     case VTK_PARSE_SHORT:
00173     case VTK_PARSE_INT:
00174     case VTK_PARSE_LONG:
00175     case VTK_PARSE_ID_TYPE:
00176     case VTK_PARSE_LONG_LONG:
00177     case VTK_PARSE___INT64:
00178     case VTK_PARSE_UNSIGNED_CHAR:
00179     case VTK_PARSE_SIGNED_CHAR:
00180     case VTK_PARSE_SSIZE_T:
00181       return 1;
00182     }
00183 
00184   return 0;
00185 }
00186 
00187 int vtkWrap_IsRealNumber(ValueInfo *val)
00188 {
00189   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
00190   return (t == VTK_PARSE_FLOAT || t == VTK_PARSE_DOUBLE);
00191 }
00192 
00193 /* -------------------------------------------------------------------- */
00194 /* These are mutually exclusive, as well. */
00195 
00196 int vtkWrap_IsScalar(ValueInfo *val)
00197 {
00198   unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
00199   return (i == 0);
00200 }
00201 
00202 int vtkWrap_IsPointer(ValueInfo *val)
00203 {
00204   unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
00205   return (i == VTK_PARSE_POINTER && val->Count == 0 &&
00206           val->CountHint == 0 && val->NumberOfDimensions <= 1);
00207 }
00208 
00209 int vtkWrap_IsArray(ValueInfo *val)
00210 {
00211   unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
00212   return (i == VTK_PARSE_POINTER && val->NumberOfDimensions <= 1 &&
00213           (val->Count != 0 || val->CountHint != 0));
00214 }
00215 
00216 int vtkWrap_IsNArray(ValueInfo *val)
00217 {
00218   int j = 0;
00219   unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
00220   if (i != VTK_PARSE_ARRAY || val->NumberOfDimensions <= 1)
00221     {
00222     return 0;
00223     }
00224   for (j = 0; j < val->NumberOfDimensions; j++)
00225     {
00226     if (val->Dimensions[j] == NULL || val->Dimensions[j][0] == '\0')
00227       {
00228       return 0;
00229       }
00230     }
00231   return 1;
00232 }
00233 
00234 
00235 /* -------------------------------------------------------------------- */
00236 /* Other type properties, not mutually exclusive. */
00237 
00238 int vtkWrap_IsNonConstRef(ValueInfo *val)
00239 {
00240   return ((val->Type & VTK_PARSE_REF) != 0 &&
00241           (val->Type & VTK_PARSE_CONST) == 0);
00242 }
00243 
00244 int vtkWrap_IsConstRef(ValueInfo *val)
00245 {
00246   return ((val->Type & VTK_PARSE_REF) != 0 &&
00247           (val->Type & VTK_PARSE_CONST) != 0);
00248 }
00249 
00250 int vtkWrap_IsRef(ValueInfo *val)
00251 {
00252   return ((val->Type & VTK_PARSE_REF) != 0);
00253 }
00254 
00255 int vtkWrap_IsConst(ValueInfo *val)
00256 {
00257   return ((val->Type & VTK_PARSE_CONST) != 0);
00258 }
00259 
00260 /* -------------------------------------------------------------------- */
00261 /* Hints */
00262 
00263 int vtkWrap_IsNewInstance(ValueInfo *val)
00264 {
00265   return ((val->Type & VTK_PARSE_NEWINSTANCE) != 0);
00266 }
00267 
00268 /* -------------------------------------------------------------------- */
00269 /* Constructor/Destructor checks */
00270 
00271 int vtkWrap_IsConstructor(ClassInfo *c, FunctionInfo *f)
00272 
00273 {
00274   size_t i, m;
00275   const char *cp = c->Name;
00276 
00277   if (cp && f->Name && !vtkWrap_IsDestructor(c, f))
00278     {
00279     /* remove namespaces and template parameters from the name */
00280     m = vtkParse_UnscopedNameLength(cp);
00281     while (cp[m] == ':' && cp[m+1] == ':')
00282       {
00283       cp += m + 2;
00284       m = vtkParse_UnscopedNameLength(cp);
00285       }
00286     for (i = 0; i < m; i++)
00287       {
00288       if (cp[i] == '<')
00289         {
00290         break;
00291         }
00292       }
00293 
00294     return (i == strlen(f->Name) && strncmp(cp, f->Name, i) == 0);
00295     }
00296 
00297   return 0;
00298 }
00299 
00300 int vtkWrap_IsDestructor(ClassInfo *c, FunctionInfo *f)
00301 {
00302   size_t i;
00303   const char *cp;
00304 
00305   if (c->Name && f->Name)
00306     {
00307     cp = f->Signature;
00308     for (i = 0; cp[i] != '\0' && cp[i] != '('; i++)
00309       {
00310       if (cp[i] == '~')
00311         {
00312         return 1;
00313         }
00314       }
00315     }
00316 
00317   return 0;
00318 }
00319 
00320 int vtkWrap_IsSetVectorMethod(FunctionInfo *f)
00321 {
00322   if (f->Macro && strncmp(f->Macro, "vtkSetVector", 12) == 0)
00323     {
00324     return 1;
00325     }
00326 
00327   return 0;
00328 }
00329 
00330 int vtkWrap_IsGetVectorMethod(FunctionInfo *f)
00331 {
00332   if (f->Macro && strncmp(f->Macro, "vtkGetVector", 12) == 0)
00333     {
00334     return 1;
00335     }
00336 
00337   return 0;
00338 }
00339 
00340 /* -------------------------------------------------------------------- */
00341 /* Argument counting */
00342 
00343 int vtkWrap_CountWrappedArgs(FunctionInfo *f)
00344 {
00345   int totalArgs = f->NumberOfArguments;
00346 
00347   if (totalArgs > 0 &&
00348       (f->Arguments[0]->Type & VTK_PARSE_BASE_TYPE)
00349        == VTK_PARSE_FUNCTION)
00350     {
00351     totalArgs = 1;
00352     }
00353   else if (totalArgs == 1 &&
00354            (f->Arguments[0]->Type & VTK_PARSE_UNQUALIFIED_TYPE)
00355             == VTK_PARSE_VOID)
00356     {
00357     totalArgs = 0;
00358     }
00359 
00360   return totalArgs;
00361 }
00362 
00363 int vtkWrap_CountRequiredArgs(FunctionInfo *f)
00364 {
00365   int requiredArgs = 0;
00366   int totalArgs;
00367   int i;
00368 
00369   totalArgs = vtkWrap_CountWrappedArgs(f);
00370 
00371   for (i = 0; i < totalArgs; i++)
00372     {
00373     if (f->Arguments[i]->Value == NULL ||
00374         vtkWrap_IsArray(f->Arguments[i]) ||
00375         vtkWrap_IsNArray(f->Arguments[i]))
00376       {
00377       requiredArgs = i+1;
00378       }
00379     }
00380 
00381   return requiredArgs;
00382 }
00383 
00384 /* -------------------------------------------------------------------- */
00385 /* Check whether the class is derived from vtkObjectBase. */
00386 
00387 int vtkWrap_IsVTKObjectBaseType(
00388   HierarchyInfo *hinfo, const char *classname)
00389 {
00390   HierarchyEntry *entry;
00391 
00392   if (hinfo)
00393     {
00394     entry = vtkParseHierarchy_FindEntry(hinfo, classname);
00395     if (entry)
00396       {
00397       if (vtkParseHierarchy_IsTypeOf(hinfo, entry, "vtkObjectBase"))
00398         {
00399         return 1;
00400         }
00401       return 0;
00402       }
00403     }
00404 
00405   /* fallback if no HierarchyInfo */
00406   if (strncmp("vtk", classname, 3) == 0)
00407     {
00408     return 1;
00409     }
00410 
00411   return 0;
00412 }
00413 
00414 /* -------------------------------------------------------------------- */
00415 /* Check if the WRAP_SPECIAL flag is set for the class. */
00416 
00417 int vtkWrap_IsSpecialType(
00418   HierarchyInfo *hinfo, const char *classname)
00419 {
00420   HierarchyEntry *entry;
00421 
00422   if (hinfo)
00423     {
00424     entry = vtkParseHierarchy_FindEntry(hinfo, classname);
00425     if (entry && vtkParseHierarchy_GetProperty(entry, "WRAP_SPECIAL"))
00426       {
00427       return 1;
00428       }
00429     return 0;
00430     }
00431 
00432   /* fallback if no HierarchyInfo */
00433   if (strncmp("vtk", classname, 3) == 0)
00434     {
00435     return -1;
00436     }
00437 
00438   return 0;
00439 }
00440 
00441 /* -------------------------------------------------------------------- */
00442 /* Check if the class is derived from superclass */
00443 
00444 int vtkWrap_IsTypeOf(
00445   HierarchyInfo *hinfo, const char *classname, const char *superclass)
00446 {
00447   HierarchyEntry *entry;
00448 
00449   if (strcmp(classname, superclass) == 0)
00450     {
00451     return 1;
00452     }
00453 
00454   if (hinfo)
00455     {
00456     entry = vtkParseHierarchy_FindEntry(hinfo, classname);
00457     if (entry && vtkParseHierarchy_IsTypeOf(hinfo, entry, superclass))
00458       {
00459       return 1;
00460       }
00461     }
00462 
00463   return 0;
00464 }
00465 
00466 /* -------------------------------------------------------------------- */
00467 /* Make a guess about whether a class is wrapped */
00468 
00469 int vtkWrap_IsClassWrapped(
00470   HierarchyInfo *hinfo, const char *classname)
00471 {
00472   if (hinfo)
00473     {
00474     HierarchyEntry *entry;
00475     entry = vtkParseHierarchy_FindEntry(hinfo, classname);
00476 
00477     if (entry)
00478       {
00479       if (!vtkParseHierarchy_GetProperty(entry, "WRAP_EXCLUDE") ||
00480           vtkParseHierarchy_GetProperty(entry, "WRAP_SPECIAL"))
00481         {
00482         return 1;
00483         }
00484       }
00485     }
00486   else if (strncmp("vtk", classname, 3) == 0)
00487     {
00488     return 1;
00489     }
00490 
00491   return 0;
00492 }
00493 
00494 /* -------------------------------------------------------------------- */
00495 /* Check whether the destructor is public */
00496 int vtkWrap_HasPublicDestructor(ClassInfo *data)
00497 {
00498   FunctionInfo *func;
00499   int i;
00500 
00501   for (i = 0; i < data->NumberOfFunctions; i++)
00502     {
00503     func = data->Functions[i];
00504 
00505     if (vtkWrap_IsDestructor(data, func) &&
00506         func->Access != VTK_ACCESS_PUBLIC)
00507       {
00508       return 0;
00509       }
00510     }
00511 
00512   return 1;
00513 }
00514 
00515 /* -------------------------------------------------------------------- */
00516 /* Check whether the copy constructor is public */
00517 int vtkWrap_HasPublicCopyConstructor(ClassInfo *data)
00518 {
00519   FunctionInfo *func;
00520   int i;
00521 
00522   for (i = 0; i < data->NumberOfFunctions; i++)
00523     {
00524     func = data->Functions[i];
00525 
00526     if (vtkWrap_IsConstructor(data, func) &&
00527         func->NumberOfArguments == 1 &&
00528         func->Arguments[0]->Class &&
00529         strcmp(func->Arguments[0]->Class, data->Name) == 0 &&
00530         func->Access != VTK_ACCESS_PUBLIC)
00531       {
00532       return 0;
00533       }
00534     }
00535 
00536   return 1;
00537 }
00538 
00539 /* -------------------------------------------------------------------- */
00540 /* This sets the CountHint for vtkDataArray methods where the
00541  * tuple size is equal to GetNumberOfComponents. */
00542 void vtkWrap_FindCountHints(
00543   ClassInfo *data, HierarchyInfo *hinfo)
00544 {
00545   int i;
00546   const char *countMethod;
00547   const char *classname;
00548   FunctionInfo *theFunc;
00549   HierarchyEntry *entry;
00550   size_t m;
00551   char digit;
00552 
00553   /* add hints for array GetTuple methods */
00554   if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkDataArray"))
00555     {
00556     countMethod = "GetNumberOfComponents()";
00557 
00558     for (i = 0; i < data->NumberOfFunctions; i++)
00559       {
00560       theFunc = data->Functions[i];
00561 
00562       if ((strcmp(theFunc->Name, "GetTuple") == 0 ||
00563            strcmp(theFunc->Name, "GetTupleValue") == 0) &&
00564           theFunc->ReturnValue && theFunc->ReturnValue->Count == 0 &&
00565           theFunc->NumberOfArguments == 1 &&
00566           theFunc->Arguments[0]->Type == VTK_PARSE_ID_TYPE)
00567         {
00568         theFunc->ReturnValue->CountHint = countMethod;
00569         }
00570       else if ((strcmp(theFunc->Name, "SetTuple") == 0 ||
00571                 strcmp(theFunc->Name, "SetTupleValue") == 0 ||
00572                 strcmp(theFunc->Name, "GetTuple") == 0 ||
00573                 strcmp(theFunc->Name, "GetTupleValue") == 0 ||
00574                 strcmp(theFunc->Name, "InsertTuple") == 0 ||
00575                 strcmp(theFunc->Name, "InsertTupleValue") == 0) &&
00576                theFunc->NumberOfArguments == 2 &&
00577                theFunc->Arguments[0]->Type == VTK_PARSE_ID_TYPE &&
00578                theFunc->Arguments[1]->Count == 0)
00579         {
00580         theFunc->Arguments[1]->CountHint = countMethod;
00581         }
00582       else if ((strcmp(theFunc->Name, "InsertNextTuple") == 0 ||
00583                 strcmp(theFunc->Name, "InsertNextTupleValue") == 0) &&
00584                theFunc->NumberOfArguments == 1 &&
00585                theFunc->Arguments[0]->Count == 0)
00586         {
00587         theFunc->Arguments[0]->CountHint = countMethod;
00588         }
00589       }
00590     }
00591 
00592   /* add hints for interpolator Interpolate methods */
00593   if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkAbstractImageInterpolator"))
00594     {
00595     countMethod = "GetNumberOfComponents()";
00596 
00597     for (i = 0; i < data->NumberOfFunctions; i++)
00598       {
00599       theFunc = data->Functions[i];
00600 
00601       if (strcmp(theFunc->Name, "Interpolate") == 0 &&
00602            theFunc->NumberOfArguments == 2 &&
00603            theFunc->Arguments[0]->Type == (VTK_PARSE_DOUBLE_PTR|VTK_PARSE_CONST) &&
00604            theFunc->Arguments[0]->Count == 3 &&
00605            theFunc->Arguments[1]->Type == VTK_PARSE_DOUBLE_PTR &&
00606            theFunc->Arguments[1]->Count == 0)
00607         {
00608         theFunc->Arguments[1]->CountHint = countMethod;
00609         }
00610       }
00611     }
00612 
00613   for (i = 0; i < data->NumberOfFunctions; i++)
00614     {
00615     theFunc = data->Functions[i];
00616 
00617     /* hints for constructors that take arrays */
00618     if (vtkWrap_IsConstructor(data, theFunc) &&
00619         theFunc->NumberOfArguments == 1 &&
00620         vtkWrap_IsPointer(theFunc->Arguments[0]) &&
00621         vtkWrap_IsNumeric(theFunc->Arguments[0]) &&
00622         theFunc->Arguments[0]->Count == 0 &&
00623         hinfo)
00624       {
00625       entry = vtkParseHierarchy_FindEntry(hinfo, data->Name);
00626       if (entry && vtkParseHierarchy_IsTypeOfTemplated(
00627             hinfo, entry, data->Name, "vtkTuple", &classname))
00628         {
00629         /* attempt to get count from template parameter */
00630         if (classname)
00631           {
00632           m = strlen(classname);
00633           if (m > 2 && classname[m - 1] == '>' &&
00634               isdigit(classname[m-2]) && (classname[m-3] == ' ' ||
00635               classname[m-3] == ',' || classname[m-3] == '<'))
00636             {
00637             digit = classname[m-2];
00638             theFunc->Arguments[0]->Count = digit - '0';
00639             vtkParse_AddStringToArray(
00640               &theFunc->Arguments[0]->Dimensions,
00641               &theFunc->Arguments[0]->NumberOfDimensions,
00642               vtkParse_DuplicateString(&digit, 1));
00643             }
00644           free((char *)classname);
00645           }
00646         }
00647       }
00648 
00649     /* hints for operator[] index range */
00650     if (theFunc->IsOperator && theFunc->Name &&
00651         strcmp(theFunc->Name, "operator[]") == 0)
00652       {
00653       if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkTuple"))
00654         {
00655         theFunc->SizeHint = "GetSize()";
00656         }
00657       else if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayCoordinates") ||
00658                vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayExtents") ||
00659                vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArraySort"))
00660         {
00661         theFunc->SizeHint = "GetDimensions()";
00662         }
00663       else if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayExtentsList") ||
00664                vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayWeights"))
00665         {
00666         theFunc->SizeHint = "GetCount()";
00667         }
00668       }
00669     }
00670 }
00671 
00672 /* -------------------------------------------------------------------- */
00673 /* This sets the NewInstance hint for generator methods. */
00674 void vtkWrap_FindNewInstanceMethods(
00675   ClassInfo *data, HierarchyInfo *hinfo)
00676 {
00677   int i;
00678   FunctionInfo *theFunc;
00679 
00680   for (i = 0; i < data->NumberOfFunctions; i++)
00681     {
00682     theFunc = data->Functions[i];
00683     if (theFunc->Name && theFunc->ReturnValue &&
00684         vtkWrap_IsVTKObject(theFunc->ReturnValue) &&
00685         vtkWrap_IsVTKObjectBaseType(hinfo, theFunc->ReturnValue->Class))
00686       {
00687       if (strcmp(theFunc->Name, "NewInstance") == 0 ||
00688           strcmp(theFunc->Name, "CreateInstance") == 0 ||
00689           (strcmp(theFunc->Name, "CreateImageReader2") == 0 &&
00690            strcmp(data->Name, "vtkImageReader2Factory") == 0) ||
00691           (strcmp(theFunc->Name, "CreateDataArray") == 0 &&
00692            strcmp(data->Name, "vtkDataArray") == 0) ||
00693           (strcmp(theFunc->Name, "CreateArray") == 0 &&
00694            strcmp(data->Name, "vtkAbstractArray") == 0) ||
00695           (strcmp(theFunc->Name, "CreateArray") == 0 &&
00696            strcmp(data->Name, "vtkArray") == 0) ||
00697           (strcmp(theFunc->Name, "GetQueryInstance") == 0 &&
00698            strcmp(data->Name, "vtkSQLDatabase") == 0) ||
00699           (strcmp(theFunc->Name, "CreateFromURL") == 0 &&
00700            strcmp(data->Name, "vtkSQLDatabase") == 0) ||
00701           (strcmp(theFunc->Name, "MakeTransform") == 0 &&
00702            vtkWrap_IsTypeOf(hinfo, data->Name, "vtkAbstractTransform")))
00703         {
00704         theFunc->ReturnValue->Type |= VTK_PARSE_NEWINSTANCE;
00705         }
00706       }
00707     }
00708 }
00709 
00710 
00711 /* -------------------------------------------------------------------- */
00712 /* Expand all typedef types that are used in function arguments */
00713 void vtkWrap_ExpandTypedefs(ClassInfo *data, HierarchyInfo *hinfo)
00714 {
00715   int i, j, n;
00716   FunctionInfo *funcInfo;
00717   const char *newclass;
00718 
00719   n = data->NumberOfSuperClasses;
00720   for (i = 0; i < n; i++)
00721     {
00722     newclass = vtkParseHierarchy_ExpandTypedefsInName(
00723       hinfo, data->SuperClasses[i], NULL);
00724     if (newclass != data->SuperClasses[i])
00725       {
00726       data->SuperClasses[i] =
00727         vtkParse_DuplicateString(newclass, strlen(newclass));
00728       free((char *)newclass);
00729       }
00730     }
00731 
00732   n = data->NumberOfFunctions;
00733   for (i = 0; i < n; i++)
00734     {
00735     funcInfo = data->Functions[i];
00736     if (funcInfo->Access == VTK_ACCESS_PUBLIC)
00737       {
00738       for (j = 0; j < funcInfo->NumberOfArguments; j++)
00739         {
00740         vtkParseHierarchy_ExpandTypedefsInValue(
00741           hinfo, funcInfo->Arguments[j], data->Name);
00742         }
00743       if (funcInfo->ReturnValue)
00744         {
00745         vtkParseHierarchy_ExpandTypedefsInValue(
00746           hinfo, funcInfo->ReturnValue, data->Name);
00747         }
00748       }
00749     }
00750 }
00751 
00752 
00753 /* -------------------------------------------------------------------- */
00754 /* get the type name */
00755 
00756 const char *vtkWrap_GetTypeName(ValueInfo *val)
00757 {
00758   unsigned int aType = val->Type;
00759   const char *aClass = val->Class;
00760 
00761   /* print the type itself */
00762   switch (aType & VTK_PARSE_BASE_TYPE)
00763     {
00764     case VTK_PARSE_FLOAT:          return "float";
00765     case VTK_PARSE_DOUBLE:         return "double";
00766     case VTK_PARSE_INT:            return "int";
00767     case VTK_PARSE_SHORT:          return "short";
00768     case VTK_PARSE_LONG:           return "long";
00769     case VTK_PARSE_VOID:           return "void ";
00770     case VTK_PARSE_CHAR:           return "char";
00771     case VTK_PARSE_UNSIGNED_INT:   return "unsigned int";
00772     case VTK_PARSE_UNSIGNED_SHORT: return "unsigned short";
00773     case VTK_PARSE_UNSIGNED_LONG:  return "unsigned long";
00774     case VTK_PARSE_UNSIGNED_CHAR:  return "unsigned char";
00775     case VTK_PARSE_ID_TYPE:        return "vtkIdType";
00776     case VTK_PARSE_LONG_LONG:      return "long long";
00777     case VTK_PARSE___INT64:        return "__int64";
00778     case VTK_PARSE_UNSIGNED_LONG_LONG: return "unsigned long long";
00779     case VTK_PARSE_UNSIGNED___INT64:   return "unsigned __int64";
00780     case VTK_PARSE_SIGNED_CHAR:    return "signed char";
00781     case VTK_PARSE_BOOL:           return "bool";
00782     case VTK_PARSE_UNICODE_STRING: return "vtkUnicodeString";
00783     case VTK_PARSE_SSIZE_T:        return "ssize_t";
00784     case VTK_PARSE_SIZE_T:         return "size_t";
00785     }
00786 
00787   return aClass;
00788 }
00789 
00790 /* -------------------------------------------------------------------- */
00791 /* variable declarations */
00792 
00793 void vtkWrap_DeclareVariable(
00794   FILE *fp, ValueInfo *val, const char *name, int i, int flags)
00795 {
00796   unsigned int aType;
00797   int j;
00798 
00799   if (val == NULL)
00800     {
00801     return;
00802     }
00803 
00804   aType = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
00805 
00806   /* do nothing for void */
00807   if (aType == VTK_PARSE_VOID ||
00808       (aType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_FUNCTION)
00809     {
00810     return;
00811     }
00812 
00813   /* add a couple spaces */
00814   fprintf(fp,"  ");
00815 
00816   /* for const * return types, prepend with const */
00817   if ((flags & VTK_WRAP_RETURN) != 0)
00818     {
00819     if ((val->Type & VTK_PARSE_CONST) != 0 &&
00820         (aType & VTK_PARSE_INDIRECT) != 0)
00821       {
00822       fprintf(fp,"const ");
00823       }
00824     }
00825   /* do the same for "const char *" with initializer */
00826   else
00827     {
00828     if ((val->Type & VTK_PARSE_CONST) != 0 &&
00829         aType == VTK_PARSE_CHAR_PTR &&
00830         val->Value &&
00831         strcmp(val->Value, "0") != 0 &&
00832         strcmp(val->Value, "NULL") != 0)
00833       {
00834       fprintf(fp,"const ");
00835       }
00836     }
00837 
00838   /* print the type name */
00839   fprintf(fp, "%s ", vtkWrap_GetTypeName(val));
00840 
00841   /* indirection */
00842   if ((flags & VTK_WRAP_RETURN) != 0)
00843     {
00844     /* ref and pointer return values are stored as pointers */
00845     if ((aType & VTK_PARSE_INDIRECT) == VTK_PARSE_POINTER ||
00846         (aType & VTK_PARSE_INDIRECT) == VTK_PARSE_REF)
00847       {
00848       fprintf(fp, "*");
00849       }
00850     }
00851   else
00852     {
00853     /* objects refs and pointers are always handled via pointers,
00854      * other refs are passed by value */
00855     if (aType == VTK_PARSE_CHAR_PTR ||
00856         aType == VTK_PARSE_VOID_PTR ||
00857         aType == VTK_PARSE_OBJECT_PTR ||
00858         aType == VTK_PARSE_OBJECT_REF ||
00859         aType == VTK_PARSE_OBJECT ||
00860         vtkWrap_IsQtObject(val))
00861       {
00862       fprintf(fp, "*");
00863       }
00864     /* arrays of unknown size are handled via pointers */
00865     else if (val->CountHint)
00866       {
00867       fprintf(fp, "*");
00868       }
00869     }
00870 
00871   /* the variable name */
00872   if (i >= 0)
00873     {
00874     fprintf(fp,"%s%i", name, i);
00875     }
00876   else
00877     {
00878     fprintf(fp,"%s", name);
00879     }
00880 
00881   if ((flags & VTK_WRAP_ARG) != 0)
00882     {
00883     /* print the array decorators */
00884     if (((aType & VTK_PARSE_POINTER_MASK) != 0) &&
00885         aType != VTK_PARSE_CHAR_PTR &&
00886         aType != VTK_PARSE_VOID_PTR &&
00887         aType != VTK_PARSE_OBJECT_PTR &&
00888         !vtkWrap_IsQtObject(val) &&
00889         val->CountHint == NULL)
00890       {
00891       if (val->NumberOfDimensions == 1 && val->Count > 0)
00892         {
00893         fprintf(fp, "[%d]", val->Count);
00894         }
00895       else
00896         {
00897         for (j = 0; j < val->NumberOfDimensions; j++)
00898           {
00899           fprintf(fp, "[%s]", val->Dimensions[j]);
00900           }
00901         }
00902       }
00903 
00904     /* add a default value */
00905     else if (val->Value)
00906       {
00907       fprintf(fp, " = %s", val->Value);
00908       }
00909     else if (aType == VTK_PARSE_CHAR_PTR ||
00910              aType == VTK_PARSE_VOID_PTR ||
00911              aType == VTK_PARSE_OBJECT_PTR ||
00912              aType == VTK_PARSE_OBJECT_REF ||
00913              aType == VTK_PARSE_OBJECT ||
00914              vtkWrap_IsQtObject(val))
00915       {
00916       fprintf(fp, " = NULL");
00917       }
00918     else if (val->CountHint)
00919       {
00920       fprintf(fp, " = NULL");
00921       }
00922     else if (aType == VTK_PARSE_BOOL)
00923       {
00924       fprintf(fp, " = false");
00925       }
00926     }
00927 
00928   /* finish off with a semicolon */
00929   if ((flags & VTK_WRAP_NOSEMI) == 0)
00930     {
00931     fprintf(fp, ";\n");
00932     }
00933 }
00934 
00935 void vtkWrap_DeclareVariableSize(
00936   FILE *fp, ValueInfo *val, const char *name, int i)
00937 {
00938   char idx[32];
00939   int j;
00940 
00941   idx[0] = '\0';
00942   if (i >= 0)
00943     {
00944     sprintf(idx, "%d", i);
00945     }
00946 
00947   if (val->NumberOfDimensions > 1)
00948     {
00949     fprintf(fp,
00950             "  static int %s%s[%d] = ",
00951             name, idx, val->NumberOfDimensions);
00952 
00953     for (j = 0; j < val->NumberOfDimensions; j++)
00954       {
00955       fprintf(fp, "%c %s", ((j == 0) ? '{' : ','), val->Dimensions[j]);
00956       }
00957 
00958     fprintf(fp, " };\n");
00959     }
00960   else if (val->Count != 0 || val->CountHint)
00961     {
00962     fprintf(fp,
00963             "  %sint %s%s = %d;\n",
00964             (val->CountHint ? "" : "const "), name, idx,
00965             (val->CountHint ? 0 : val->Count));
00966     }
00967   else if (val->NumberOfDimensions == 1)
00968     {
00969     fprintf(fp,
00970             "  const int %s%s = %s;\n",
00971             name, idx, val->Dimensions[0]);
00972     }
00973 }