/* print the parsed structures */ int main(int argc, char *argv[]) { OptionInfo *options; FileInfo *file_info; ClassInfo *data; FILE *fp; int i; /* get command-line args and parse the header file */ file_info = vtkParse_Main(argc, argv); /* get the command-line options */ options = vtkParse_GetCommandLineOptions(); /* get the output file */ fp = fopen(options->OutputFileName, "w"); if (!fp) { fprintf(stderr, "Error opening output file %s\n", options->OutputFileName); exit(1); } /* get the main class */ if ((data = file_info->MainClass) == NULL) { fclose(fp); exit(0); } /* get the hierarchy info for accurate typing */ if (options->HierarchyFileName) { hierarchyInfo = vtkParseHierarchy_ReadFile(options->HierarchyFileName); } fprintf(fp,"// java wrapper for %s object\n//\n",data->Name); fprintf(fp,"\npackage vtk;\n"); if (strcmp("vtkObjectBase",data->Name)) { fprintf(fp,"import vtk.*;\n"); } fprintf(fp,"\npublic class %s",data->Name); if (strcmp("vtkObjectBase",data->Name)) { if (data->NumberOfSuperClasses) { fprintf(fp," extends %s",data->SuperClasses[0]); } } fprintf(fp,"\n{\n"); /* insert function handling code here */ for (i = 0; i < data->NumberOfFunctions; i++) { currentFunction = data->Functions[i]; outputFunction(fp, data); } HandleDataArray(fp, data); if (!data->NumberOfSuperClasses) { if (!data->IsAbstract) { fprintf(fp,"\n public %s() {", data->Name); fprintf(fp,"\n this.vtkId = this.VTKInit();"); fprintf(fp,"\n vtkObject.JAVA_OBJECT_MANAGER.registerJavaObject(this.vtkId, this);"); fprintf(fp,"\n }\n"); } else { fprintf(fp,"\n public %s() { super(); }\n",data->Name); } fprintf(fp,"\n public %s(long id) {", data->Name); fprintf(fp,"\n super();"); fprintf(fp,"\n this.vtkId = id;"); fprintf(fp,"\n this.VTKRegister();"); fprintf(fp,"\n vtkObject.JAVA_OBJECT_MANAGER.registerJavaObject(this.vtkId, this);"); fprintf(fp,"\n }\n"); fprintf(fp,"\n protected long vtkId;\n"); fprintf(fp,"\n public long GetVTKId() { return this.vtkId; }"); /* if we are a base class and have a delete method */ if (data->HasDelete) { fprintf(fp,"\n public static native void VTKDeleteReference(long id);"); fprintf(fp,"\n public static native String VTKGetClassNameFromReference(long id);"); fprintf(fp,"\n protected native void VTKDelete();"); fprintf(fp,"\n protected native void VTKRegister();"); fprintf(fp,"\n public void Delete() {"); fprintf(fp,"\n vtkObject.JAVA_OBJECT_MANAGER.unRegisterJavaObject(this.vtkId);"); fprintf(fp,"\n this.vtkId = 0;"); fprintf(fp,"\n }"); } } /* Special case for vtkObject */ else if ( strcmp("vtkObject",data->Name) == 0 ) { fprintf(fp,"\n public static vtk.vtkJavaMemoryManager JAVA_OBJECT_MANAGER = new vtk.vtkJavaMemoryManagerImpl();"); fprintf(fp,"\n public %s() {", data->Name); fprintf(fp,"\n super();"); fprintf(fp,"\n this.vtkId = this.VTKInit();"); fprintf(fp,"\n vtkObject.JAVA_OBJECT_MANAGER.registerJavaObject(this.vtkId, this);"); fprintf(fp,"\n }\n"); fprintf(fp,"\n public %s(long id) { super(id); }\n",data->Name); } else { fprintf(fp,"\n public %s() { super(); }\n",data->Name); fprintf(fp,"\n public %s(long id) { super(id); }\n",data->Name); } if (!data->IsAbstract) { fprintf(fp," public native long VTKInit();\n"); } /* fprintf(fp," protected native void VTKCastInit();\n"); */ if (!strcmp("vtkObject",data->Name)) { /* Add the Print method to vtkObject. */ fprintf(fp," public native String Print();\n"); #ifndef VTK_LEGACY_REMOVE /* Add the PrintRevisions method to vtkObject. */ fprintf(fp," public native String PrintRevisions();\n"); #endif /* Add the default toString from java object */ fprintf(fp," public String toString() { return Print(); }\n"); } if (!strcmp("vtkObject",data->Name)) { fprintf(fp," public native int AddObserver(String id0, Object id1, String id2);\n"); } fprintf(fp,"\n}\n"); { size_t cc; size_t len; char *dir; char *fname; /*const */char javaDone[] = "VTKJavaWrapped"; FILE* tfp; fname = options->OutputFileName; dir = (char*)malloc(strlen(fname) + strlen(javaDone) + 2); sprintf(dir, "%s", fname); len = strlen(dir); for ( cc = len-1; cc > 0; cc -- ) { if ( dir[cc] == '/' || dir[cc] == '\\' ) { dir[cc+1] = 0; break; } } strcat(dir, javaDone); tfp = fopen(dir, "w"); if ( tfp ) { fprintf(tfp, "File: %s\n", fname); fclose(tfp); } free(dir); } vtkParse_Free(file_info); return 0; }
/* print the parsed structures */ int main(int argc, char *argv[]) { OptionInfo *options; FileInfo *file_info; ClassInfo *data; FILE *fp; int i; /* pre-define a macro to identify the language */ vtkParse_DefineMacro("__VTK_WRAP_JAVA__", 0); /* get command-line args and parse the header file */ file_info = vtkParse_Main(argc, argv); /* some utility functions require the string cache */ stringCache = file_info->Strings; /* get the command-line options */ options = vtkParse_GetCommandLineOptions(); /* get the output file */ fp = fopen(options->OutputFileName, "w"); if (!fp) { fprintf(stderr, "Error opening output file %s\n", options->OutputFileName); exit(1); } /* get the main class */ if ((data = file_info->MainClass) == NULL) { fclose(fp); exit(1); } /* get the hierarchy info for accurate typing */ if (options->HierarchyFileNames) { hierarchyInfo = vtkParseHierarchy_ReadFiles( options->NumberOfHierarchyFileNames, options->HierarchyFileNames); if (hierarchyInfo) { /* resolve using declarations within the header files */ vtkWrap_ApplyUsingDeclarations(data, file_info, hierarchyInfo); /* expand typedefs */ vtkWrap_ExpandTypedefs(data, file_info, hierarchyInfo); } } fprintf(fp,"// java wrapper for %s object\n//\n",data->Name); fprintf(fp,"#define VTK_WRAPPING_CXX\n"); if (strcmp("vtkObjectBase",data->Name) != 0) { /* Block inclusion of full streams. */ fprintf(fp,"#define VTK_STREAMS_FWD_ONLY\n"); } fprintf(fp,"#include \"vtkSystemIncludes.h\"\n"); fprintf(fp,"#include \"%s.h\"\n",data->Name); fprintf(fp,"#include \"vtkJavaUtil.h\"\n\n"); fprintf(fp,"#include \"vtkStdString.h\"\n\n"); fprintf(fp,"#include <sstream>\n"); for (i = 0; i < data->NumberOfSuperClasses; i++) { char *safe_name = vtkWrap_SafeSuperclassName(data->SuperClasses[i]); const char *safe_superclass = safe_name ? safe_name : data->SuperClasses[i]; /* if a template class is detected add a typedef */ if (safe_name) { fprintf(fp,"typedef %s %s;\n", data->SuperClasses[i], safe_name); } fprintf(fp,"extern \"C\" JNIEXPORT void* %s_Typecast(void *op,char *dType);\n", safe_superclass); free(safe_name); } fprintf(fp,"\nextern \"C\" JNIEXPORT void* %s_Typecast(void *me,char *dType)\n{\n",data->Name); if (data->NumberOfSuperClasses > 0) { fprintf(fp," void* res;\n"); } fprintf(fp," if (!strcmp(\"%s\",dType)) { return me; }\n", data->Name); /* check our superclasses */ for (i = 0; i < data->NumberOfSuperClasses; i++) { char *safe_name = vtkWrap_SafeSuperclassName(data->SuperClasses[i]); const char *safe_superclass = safe_name ? safe_name : data->SuperClasses[i]; fprintf(fp," if ((res= %s_Typecast(me,dType)) != NULL)", safe_superclass); fprintf(fp," { return res; }\n"); free(safe_name); } fprintf(fp," return NULL;\n"); fprintf(fp,"}\n\n"); HandleDataArray(fp, data); /* insert function handling code here */ for (i = 0; i < data->NumberOfFunctions; i++) { currentFunction = data->Functions[i]; outputFunction(fp, data); } if ((!data->NumberOfSuperClasses)&&(data->HasDelete)) { fprintf(fp,"\nextern \"C\" JNIEXPORT void JNICALL Java_vtk_%s_VTKDeleteReference(JNIEnv *,jclass,jlong id)\n", data->Name); fprintf(fp,"{\n %s *op;\n",data->Name); fprintf(fp," op = reinterpret_cast<%s*>(id);\n", data->Name); fprintf(fp," op->Delete();\n"); fprintf(fp,"}\n"); fprintf(fp,"\nextern \"C\" JNIEXPORT jstring JNICALL Java_vtk_%s_VTKGetClassNameFromReference(JNIEnv *env,jclass,jlong id)\n", data->Name); fprintf(fp,"{\n"); fprintf(fp," const char* name = \"\";\n"); fprintf(fp," %s *op;\n", data->Name); fprintf(fp," if(id != 0)\n"); fprintf(fp," {\n"); fprintf(fp," op = reinterpret_cast<%s*>(id);\n", data->Name); //fprintf(fp," std::cout << \"cast pointer \" << id << std::endl;\n"); fprintf(fp," name = op->GetClassName();\n"); fprintf(fp," }\n"); fprintf(fp," return vtkJavaMakeJavaString(env,name);\n"); fprintf(fp,"}\n"); fprintf(fp,"\nextern \"C\" JNIEXPORT void JNICALL Java_vtk_%s_VTKDelete(JNIEnv *env,jobject obj)\n", data->Name); fprintf(fp,"{\n %s *op;\n",data->Name); fprintf(fp," op = (%s *)vtkJavaGetPointerFromObject(env,obj);\n", data->Name); fprintf(fp," op->Delete();\n"); fprintf(fp,"}\n"); fprintf(fp,"\nextern \"C\" JNIEXPORT void JNICALL Java_vtk_%s_VTKRegister(JNIEnv *env,jobject obj)\n", data->Name); fprintf(fp,"{\n %s *op;\n",data->Name); fprintf(fp," op = (%s *)vtkJavaGetPointerFromObject(env,obj);\n", data->Name); fprintf(fp," op->Register(op);\n"); fprintf(fp,"}\n"); } if (!data->IsAbstract) { fprintf(fp,"\nextern \"C\" JNIEXPORT jlong JNICALL Java_vtk_%s_VTKInit(JNIEnv *, jobject)", data->Name); fprintf(fp,"\n{"); fprintf(fp,"\n %s *aNewOne = %s::New();",data->Name, data->Name); fprintf(fp,"\n return (jlong)(size_t)(void*)aNewOne;"); fprintf(fp,"\n}\n"); } /* for vtkRenderWindow we want to add a special method to support * native AWT rendering * * Including vtkJavaAwt.h provides inline implementations of * Java_vtk_vtkPanel_RenderCreate, Java_vtk_vtkPanel_Lock and * Java_vtk_vtkPanel_UnLock. */ if (!strcmp("vtkRenderWindow",data->Name)) { fprintf(fp,"\n#include \"vtkJavaAwt.h\"\n\n"); } if (!strcmp("vtkObject",data->Name)) { /* Add the Print method to vtkObjectBase. */ fprintf(fp,"\nextern \"C\" JNIEXPORT jstring JNICALL Java_vtk_vtkObjectBase_Print(JNIEnv *env,jobject obj)\n"); fprintf(fp,"{\n vtkObjectBase *op;\n"); fprintf(fp," jstring tmp;\n\n"); fprintf(fp," op = (vtkObjectBase *)vtkJavaGetPointerFromObject(env,obj);\n"); fprintf(fp," std::ostringstream vtkmsg_with_warning_C4701;\n"); fprintf(fp," op->Print(vtkmsg_with_warning_C4701);\n"); fprintf(fp," vtkmsg_with_warning_C4701.put('\\0');\n"); fprintf(fp," tmp = vtkJavaMakeJavaString(env,vtkmsg_with_warning_C4701.str().c_str());\n"); fprintf(fp," return tmp;\n"); fprintf(fp,"}\n"); fprintf(fp,"\nextern \"C\" JNIEXPORT jint JNICALL Java_vtk_vtkObject_AddObserver(JNIEnv *env,jobject obj, jstring id0, jobject id1, jstring id2)\n"); fprintf(fp,"{\n vtkObject *op;\n"); fprintf(fp," vtkJavaCommand *cbc = vtkJavaCommand::New();\n"); fprintf(fp," cbc->AssignJavaVM(env);\n"); fprintf(fp," cbc->SetGlobalRef(env->NewGlobalRef(id1));\n"); fprintf(fp," char *temp2;\n"); fprintf(fp," temp2 = vtkJavaUTFToChar(env,id2);\n"); fprintf(fp," cbc->SetMethodID(env->GetMethodID(env->GetObjectClass(id1),temp2,\"()V\"));\n"); fprintf(fp," char *temp0;\n"); fprintf(fp," temp0 = vtkJavaUTFToChar(env,id0);\n"); fprintf(fp," op = (vtkObject *)vtkJavaGetPointerFromObject(env,obj);\n"); fprintf(fp," unsigned long temp20;\n"); fprintf(fp," temp20 = op->AddObserver(temp0,cbc);\n"); fprintf(fp," delete[] temp0;\n"); fprintf(fp," delete[] temp2;\n"); fprintf(fp," cbc->Delete();\n"); fprintf(fp," return temp20;\n}\n"); } vtkParse_Free(file_info); fclose(fp); return 0; }
/* print the parsed structures */ int main(int argc, char *argv[]) { OptionInfo *options; FileInfo *fileInfo; ClassInfo *data; NamespaceInfo *ns; char nsname[1024]; struct { NamespaceInfo *ns; size_t nsnamepos; int n; } nsstack[32]; size_t nspos; FILE *fp; NewClassInfo *classData; int i; /* get command-line args and parse the header file */ fileInfo = vtkParse_Main(argc, argv); /* get the command-line options */ options = vtkParse_GetCommandLineOptions(); /* get the output file */ fp = fopen(options->OutputFileName, "w"); if (!fp) { fprintf(stderr, "Error opening output file %s\n", options->OutputFileName); exit(1); } data = fileInfo->MainClass; /* Set up the stack. */ nspos = 0; nsstack[nspos].ns = fileInfo->Contents; nsstack[nspos].nsnamepos = 0; nsstack[nspos].n = 0; nsname[nsstack[nspos].nsnamepos] = '\0'; ns = nsstack[nspos].ns; while (!data && ns) { if (ns->Name) { size_t namelen = strlen(nsname); snprintf(nsname + namelen, sizeof(nsname) - namelen, "::%s", ns->Name); } if (ns->NumberOfClasses > 0) { data = ns->Classes[0]; break; } if (ns->NumberOfNamespaces > nsstack[nspos].n) { /* Use the next namespace. */ ns = ns->Namespaces[nsstack[nspos].n]; nsstack[nspos].n++; /* Go deeper. */ nspos++; nsstack[nspos].ns = ns; nsstack[nspos].nsnamepos = strlen(nsname); nsstack[nspos].n = 0; } else { if (nspos) { --nspos; /* Reset the namespace name. */ nsname[nsstack[nspos].nsnamepos] = '\0'; /* Go back up the stack. */ ns = nsstack[nspos].ns; } else { /* Nothing left to search. */ ns = NULL; } } } if(!data) { fclose(fp); exit(1); } /* get the hierarchy info for accurate typing */ if (options->HierarchyFileName) { hierarchyInfo = vtkParseHierarchy_ReadFile(options->HierarchyFileName); if (hierarchyInfo) { /* resolve using declarations within the header files */ vtkWrap_ApplyUsingDeclarations(data, fileInfo, hierarchyInfo); } } fprintf(fp,"// ClientServer wrapper for %s object\n//\n",data->Name); fprintf(fp,"#define VTK_WRAPPING_CXX\n"); if(strcmp("vtkObjectBase", data->Name) != 0) { /* Block inclusion of full streams. */ fprintf(fp,"#define VTK_STREAMS_FWD_ONLY\n"); } fprintf(fp,"#include \"%s.h\"\n",data->Name); fprintf(fp,"#include \"vtkSystemIncludes.h\"\n"); if (classUsesStdString(data)) { fprintf(fp,"#include \"vtkStdString.h\"\n"); } fprintf(fp,"#include \"vtkClientServerInterpreter.h\"\n"); fprintf(fp,"#include \"vtkClientServerStream.h\"\n\n"); #if 0 if (!strcmp("vtkObject",data->Name)) { fprintf(fp,"#include \"vtkClientServerProgressObserver.h\"\n\n"); } #endif if (!strcmp("vtkObjectBase",data->Name)) { fprintf(fp,"#include <sstream>\n"); } if (*nsname) { fprintf(fp,"using namespace %s;\n", nsname); } if (!data->IsAbstract) { fprintf(fp,"\nvtkObjectBase *%sClientServerNewCommand(void* /*ctx*/)\n{\n",data->Name); fprintf(fp," return %s::New();\n}\n\n",data->Name); } fprintf(fp, "\n" "int VTK_EXPORT" " %sCommand(vtkClientServerInterpreter *arlu, vtkObjectBase *ob," " const char *method, const vtkClientServerStream& msg," " vtkClientServerStream& resultStream, void* /*ctx*/)\n" "{\n", data->Name); if(strcmp(data->Name, "vtkObjectBase") == 0) { fprintf(fp," %s *op = ob;\n", data->Name); } else { fprintf(fp," %s *op = %s::SafeDownCast(ob);\n", data->Name, data->Name); fprintf(fp, " if(!op)\n" " {\n" " vtkOStrStreamWrapper vtkmsg;\n" " vtkmsg << \"Cannot cast \" << ob->GetClassName() << \" object to %s. \"\n" " << \"This probably means the class specifies the incorrect superclass in vtkTypeMacro.\";\n" " resultStream.Reset();\n" " resultStream << vtkClientServerStream::Error\n" " << vtkmsg.str() << 0 << vtkClientServerStream::End;\n" " return 0;\n" " }\n", data->Name); } fprintf(fp, " (void)arlu;\n"); /*fprintf(fp," vtkClientServerStream resultStream;\n");*/ /* insert function handling code here */ for (i = 0; i < data->NumberOfFunctions; i++) { currentFunction = data->Functions[i]; outputFunction(fp, data); } /* try superclasses */ for (i = 0; i < data->NumberOfSuperClasses; i++) { fprintf(fp, "\n" " {\n" " const char* commandName = \"%s\";\n" " if (arlu->HasCommandFunction(commandName) &&\n" " arlu->CallCommandFunction(commandName, op, method, msg, resultStream)) { return 1; }\n" " }\n", data->SuperClasses[i]); } /* Add the Print method to vtkObjectBase. */ if (!strcmp("vtkObjectBase",data->Name)) { fprintf(fp, " if (!strcmp(\"Print\",method) && msg.GetNumberOfArguments(0) == 2)\n" " {\n" " std::ostringstream buf_with_warning_C4701;\n" " op->Print(buf_with_warning_C4701);\n" " resultStream.Reset();\n" " resultStream << vtkClientServerStream::Reply\n" " << buf_with_warning_C4701.str().c_str()\n" " << vtkClientServerStream::End;\n" " return 1;\n" " }\n"); } /* Add the special form of AddObserver to vtkObject. */ if (!strcmp("vtkObject",data->Name)) { fprintf(fp, " if (!strcmp(\"AddObserver\",method) && msg.GetNumberOfArguments(0) == 4)\n" " {\n" " const char* event;\n" " vtkClientServerStream css;\n" " if(msg.GetArgument(0, 2, &event) && msg.GetArgument(0, 3, &css))\n" " {\n" " return arlu->NewObserver(op, event, css);\n" " }\n" " }\n"); } fprintf(fp, " if(resultStream.GetNumberOfMessages() > 0 &&\n" " resultStream.GetCommand(0) == vtkClientServerStream::Error &&\n" " resultStream.GetNumberOfArguments(0) > 1)\n" " {\n" " /* A superclass wrapper prepared a special message. */\n" " return 0;\n" " }\n" " vtkOStrStreamWrapper vtkmsg;\n" " vtkmsg << \"Object type: %s, could not find requested method: \\\"\"\n" " << method << \"\\\"\\nor the method was called with incorrect arguments.\\n\";\n" " resultStream.Reset();\n" " resultStream << vtkClientServerStream::Error\n" " << vtkmsg.str() << vtkClientServerStream::End;\n" " vtkmsg.rdbuf()->freeze(0);\n", data->Name); fprintf(fp, " return 0;\n" "}\n"); classData = (NewClassInfo*)malloc(sizeof(NewClassInfo)); getClassInfo(fileInfo,data,classData); output_InitFunction(fp,classData); free(classData); vtkParse_Free(fileInfo); fclose(fp); return 0; }
/* print the parsed structures */ int main(int argc, char *argv[]) { OptionInfo *options; FileInfo *fileInfo; ClassInfo *data; FILE *fp; NewClassInfo *classData; int i; /* get command-line args and parse the header file */ fileInfo = vtkParse_Main(argc, argv); /* get the command-line options */ options = vtkParse_GetCommandLineOptions(); /* get the output file */ fp = fopen(options->OutputFileName, "w"); if (!fp) { fprintf(stderr, "Error opening output file %s\n", options->OutputFileName); exit(1); } data = fileInfo->MainClass; if(!data) { fclose(fp); exit(0); } fprintf(fp,"// ClientServer wrapper for %s object\n//\n",data->Name); fprintf(fp,"#define VTK_WRAPPING_CXX\n"); if(strcmp("vtkObjectBase", data->Name) != 0) { /* Block inclusion of full streams. */ fprintf(fp,"#define VTK_STREAMS_FWD_ONLY\n"); } fprintf(fp,"#include \"vtkSystemIncludes.h\"\n"); fprintf(fp,"#include \"%s.h\"\n",data->Name); if (classUsesStdString(data)) { fprintf(fp,"#include \"vtkStdString.h\"\n"); } fprintf(fp,"#include \"vtkClientServerInterpreter.h\"\n"); fprintf(fp,"#include \"vtkClientServerStream.h\"\n\n"); #if 0 if (!strcmp("vtkObject",data->Name)) { fprintf(fp,"#include \"vtkClientServerProgressObserver.h\"\n\n"); } #endif if (!strcmp("vtkObjectBase",data->Name)) { fprintf(fp,"#include <vtksys/ios/sstream>\n"); } if (!data->IsAbstract) { fprintf(fp,"\nvtkObjectBase *%sClientServerNewCommand()\n{\n",data->Name); fprintf(fp," return %s::New();\n}\n\n",data->Name); } fprintf(fp, "\n" "int VTK_EXPORT" " %sCommand(vtkClientServerInterpreter *arlu, vtkObjectBase *ob," " const char *method, const vtkClientServerStream& msg," " vtkClientServerStream& resultStream)\n" "{\n", data->Name); if(strcmp(data->Name, "vtkObjectBase") == 0) { fprintf(fp," %s *op = ob;\n", data->Name); } else { fprintf(fp," %s *op = %s::SafeDownCast(ob);\n", data->Name, data->Name); fprintf(fp, " if(!op)\n" " {\n" " vtkOStrStreamWrapper vtkmsg;\n" " vtkmsg << \"Cannot cast \" << ob->GetClassName() << \" object to %s. \"\n" " << \"This probably means the class specifies the incorrect superclass in vtkTypeMacro.\";\n" " resultStream.Reset();\n" " resultStream << vtkClientServerStream::Error\n" " << vtkmsg.str() << 0 << vtkClientServerStream::End;\n" " return 0;\n" " }\n", data->Name); } fprintf(fp, " (void)arlu;\n"); /*fprintf(fp," vtkClientServerStream resultStream;\n");*/ /* insert function handling code here */ for (i = 0; i < data->NumberOfFunctions; i++) { currentFunction = data->Functions[i]; outputFunction(fp, data); } /* try superclasses */ for (i = 0; i < data->NumberOfSuperClasses; i++) { fprintf(fp, "\n" " {\n" " vtkClientServerCommandFunction fn = arlu->GetCommandFunction(\"%s\");\n" " if (fn && fn(arlu, op, method, msg, resultStream)) { return 1; }\n" " }\n", data->SuperClasses[i]); } /* Add the Print method to vtkObjectBase. */ if (!strcmp("vtkObjectBase",data->Name)) { fprintf(fp, " if (!strcmp(\"Print\",method) && msg.GetNumberOfArguments(0) == 2)\n" " {\n" " vtksys_ios::ostringstream buf_with_warning_C4701;\n" " op->Print(buf_with_warning_C4701);\n" " resultStream.Reset();\n" " resultStream << vtkClientServerStream::Reply\n" " << buf_with_warning_C4701.str().c_str()\n" " << vtkClientServerStream::End;\n" " return 1;\n" " }\n"); } /* Add the special form of AddObserver to vtkObject. */ if (!strcmp("vtkObject",data->Name)) { fprintf(fp, " if (!strcmp(\"AddObserver\",method) && msg.GetNumberOfArguments(0) == 4)\n" " {\n" " const char* event;\n" " vtkClientServerStream css;\n" " if(msg.GetArgument(0, 2, &event) && msg.GetArgument(0, 3, &css))\n" " {\n" " return arlu->NewObserver(op, event, css);\n" " }\n" " }\n"); } fprintf(fp, " if(resultStream.GetNumberOfMessages() > 0 &&\n" " resultStream.GetCommand(0) == vtkClientServerStream::Error &&\n" " resultStream.GetNumberOfArguments(0) > 1)\n" " {\n" " /* A superclass wrapper prepared a special message. */\n" " return 0;\n" " }\n" " vtkOStrStreamWrapper vtkmsg;\n" " vtkmsg << \"Object type: %s, could not find requested method: \\\"\"\n" " << method << \"\\\"\\nor the method was called with incorrect arguments.\\n\";\n" " resultStream.Reset();\n" " resultStream << vtkClientServerStream::Error\n" " << vtkmsg.str() << vtkClientServerStream::End;\n" " vtkmsg.rdbuf()->freeze(0);\n", data->Name); fprintf(fp, " return 0;\n" "}\n"); classData = (NewClassInfo*)malloc(sizeof(NewClassInfo)); getClassInfo(fileInfo,data,classData); output_InitFunction(fp,classData); free(classData); vtkParse_Free(fileInfo); return 0; }
/* print the parsed structures */ int main(int argc, char *argv[]) { OptionInfo *options; FileInfo *file_info; ClassInfo *data; FILE *fp; int i; /* pre-define a macro to identify the language */ vtkParse_DefineMacro("__VTK_WRAP_JAVA__", 0); /* get command-line args and parse the header file */ file_info = vtkParse_Main(argc, argv); /* some utility functions require the string cache */ stringCache = file_info->Strings; /* get the command-line options */ options = vtkParse_GetCommandLineOptions(); /* get the hierarchy info for accurate typing */ if (options->HierarchyFileNames) { hierarchyInfo = vtkParseHierarchy_ReadFiles( options->NumberOfHierarchyFileNames, options->HierarchyFileNames); } /* get the output file */ fp = fopen(options->OutputFileName, "w"); if (!fp) { fprintf(stderr, "Error opening output file %s\n", options->OutputFileName); exit(1); } /* get the main class */ data = file_info->MainClass; if (data == NULL || data->IsExcluded) { fclose(fp); exit(0); } if (data->Template) { fclose(fp); exit(0); } for (i = 0; i < data->NumberOfSuperClasses; ++i) { if (strchr(data->SuperClasses[i], '<')) { fclose(fp); exit(0); } } if (hierarchyInfo) { if (!vtkWrap_IsTypeOf(hierarchyInfo, data->Name, "vtkObjectBase")) { fclose(fp); exit(0); } /* resolve using declarations within the header files */ vtkWrap_ApplyUsingDeclarations(data, file_info, hierarchyInfo); /* expand typedefs */ vtkWrap_ExpandTypedefs(data, file_info, hierarchyInfo); } fprintf(fp,"// java wrapper for %s object\n//\n",data->Name); fprintf(fp,"\npackage vtk;\n"); if (strcmp("vtkObjectBase",data->Name)) { fprintf(fp,"import vtk.*;\n"); } fprintf(fp,"\npublic class %s",data->Name); if (strcmp("vtkObjectBase",data->Name)) { if (data->NumberOfSuperClasses) { fprintf(fp," extends %s",data->SuperClasses[0]); } } fprintf(fp,"\n{\n"); /* insert function handling code here */ for (i = 0; i < data->NumberOfFunctions; i++) { currentFunction = data->Functions[i]; outputFunction(fp, data); } HandleDataArray(fp, data); if (!data->NumberOfSuperClasses) { if ( strcmp("vtkObjectBase",data->Name) == 0 ) { fprintf(fp,"\n public static vtk.vtkJavaMemoryManager JAVA_OBJECT_MANAGER = new vtk.vtkJavaMemoryManagerImpl();"); } if (!data->IsAbstract) { fprintf(fp,"\n public %s() {", data->Name); fprintf(fp,"\n this.vtkId = this.VTKInit();"); fprintf(fp,"\n vtkObjectBase.JAVA_OBJECT_MANAGER.registerJavaObject(this.vtkId, this);"); fprintf(fp,"\n}\n"); } else { fprintf(fp,"\n public %s() { super(); }\n",data->Name); } fprintf(fp,"\n public %s(long id) {", data->Name); fprintf(fp,"\n super();"); fprintf(fp,"\n this.vtkId = id;"); fprintf(fp,"\n this.VTKRegister();"); fprintf(fp,"\n vtkObjectBase.JAVA_OBJECT_MANAGER.registerJavaObject(this.vtkId, this);"); fprintf(fp,"\n}\n"); fprintf(fp,"\n protected long vtkId;\n"); fprintf(fp,"\n public long GetVTKId() { return this.vtkId; }"); /* if we are a base class and have a delete method */ if (data->HasDelete) { fprintf(fp,"\n public static native void VTKDeleteReference(long id);"); fprintf(fp,"\n public static native String VTKGetClassNameFromReference(long id);"); fprintf(fp,"\n protected native void VTKDelete();"); fprintf(fp,"\n protected native void VTKRegister();"); fprintf(fp,"\n public void Delete() {"); fprintf(fp,"\n vtkObjectBase.JAVA_OBJECT_MANAGER.unRegisterJavaObject(this.vtkId);"); fprintf(fp,"\n this.vtkId = 0;"); fprintf(fp,"\n }"); } } else { fprintf(fp,"\n public %s() { super(); }\n",data->Name); fprintf(fp,"\n public %s(long id) { super(id); }\n",data->Name); } if (!data->IsAbstract) { fprintf(fp," public native long VTKInit();\n"); } /* fprintf(fp," protected native void VTKCastInit();\n"); */ if (!strcmp("vtkObjectBase",data->Name)) { /* Add the Print method to vtkObjectBase. */ fprintf(fp," public native String Print();\n"); /* Add the default toString from java object */ fprintf(fp," public String toString() { return Print(); }\n"); } if (!strcmp("vtkObject",data->Name)) { fprintf(fp," public native int AddObserver(String id0, Object id1, String id2);\n"); } fprintf(fp,"\n}\n"); fclose(fp); { size_t cc; size_t len; char *dir; char *fname; /*const */char javaDone[] = "VTKJavaWrapped"; FILE* tfp; fname = options->OutputFileName; dir = (char*)malloc(strlen(fname) + strlen(javaDone) + 2); sprintf(dir, "%s", fname); len = strlen(dir); for ( cc = len-1; cc > 0; cc -- ) { if ( dir[cc] == '/' || dir[cc] == '\\' ) { dir[cc+1] = 0; break; } } strcat(dir, javaDone); tfp = fopen(dir, "w"); if ( tfp ) { fprintf(tfp, "File: %s\n", fname); fclose(tfp); } free(dir); } vtkParse_Free(file_info); return 0; }
int main(int argc, char *argv[]) { ClassInfo *wrappedClasses[MAX_WRAPPED_CLASSES]; unsigned char wrapAsVTKObject[MAX_WRAPPED_CLASSES]; ClassInfo *data = NULL; NamespaceInfo *contents; OptionInfo *options; HierarchyInfo *hinfo = NULL; FileInfo *file_info; FILE *fp; const char *module = "vtkCommonCore"; const char *name; char *name_from_file = NULL; int numberOfWrappedClasses = 0; int numberOfWrappedNamespaces = 0; int wrapped_anything = 0; int i, j; size_t k, m; int is_vtkobject; /* pre-define a macro to identify the language */ vtkParse_DefineMacro("__VTK_WRAP_PYTHON__", 0); /* get command-line args and parse the header file */ file_info = vtkParse_Main(argc, argv); /* get the command-line options */ options = vtkParse_GetCommandLineOptions(); /* get the output file */ fp = fopen(options->OutputFileName, "w"); if (!fp) { fprintf(stderr, "Error opening output file %s\n", options->OutputFileName); exit(1); } /* get the hierarchy info for accurate typing */ if (options->HierarchyFileNames) { hinfo = vtkParseHierarchy_ReadFiles( options->NumberOfHierarchyFileNames, options->HierarchyFileNames); } /* get the filename without the extension */ name = file_info->FileName; m = strlen(name); for (k = m; k > 0; k--) { if (name[k] == '.') { break; } } if (k > 0) { m = k; } for (k = m; k > 0; k--) { if (!((name[k-1] >= 'a' && name[k-1] <= 'z') || (name[k-1] >= 'A' && name[k-1] <= 'Z') || (name[k-1] >= '0' && name[k-1] <= '9') || name[k-1] == '_')) { break; } } name_from_file = (char *)malloc(m - k + 1); strncpy(name_from_file, &name[k], m - k); name_from_file[m-k] = '\0'; name = name_from_file; /* get the global namespace */ contents = file_info->Contents; /* use the hierarchy file to expand typedefs */ if (hinfo) { for (i = 0; i < contents->NumberOfClasses; i++) { vtkWrap_ApplyUsingDeclarations(contents->Classes[i], file_info, hinfo); } for (i = 0; i < contents->NumberOfClasses; i++) { vtkWrap_ExpandTypedefs(contents->Classes[i], file_info, hinfo); } } /* the VTK_WRAPPING_CXX tells header files where they're included from */ fprintf(fp, "// python wrapper for %s\n//\n" "#define VTK_WRAPPING_CXX\n", name); /* unless this is vtkObjectBase.h, define VTK_STREAMS_FWD_ONLY */ if (strcmp("vtkObjectBase", name) != 0) { /* Block inclusion of full streams. */ fprintf(fp, "#define VTK_STREAMS_FWD_ONLY\n"); } /* lots of important utility functions are defined in vtkPythonArgs.h */ fprintf(fp, "#include \"vtkPythonArgs.h\"\n" "#include \"vtkPythonOverload.h\"\n" "#include \"vtkConfigure.h\"\n" "#include <cstddef>\n" "#include <sstream>\n"); /* vtkPythonCommand is needed to wrap vtkObject.h */ if (strcmp("vtkObject", name) == 0) { fprintf(fp, "#include \"vtkPythonCommand.h\"\n"); } /* generate includes for any special types that are used */ vtkWrapPython_GenerateSpecialHeaders(fp, file_info, hinfo); /* the header file for the wrapped class */ fprintf(fp, "#include \"%s.h\"\n\n", name); /* do the export of the main entry point */ fprintf(fp, "extern \"C\" { %s void PyVTKAddFile_%s(PyObject *); }\n", "VTK_ABI_EXPORT", name); /* get the module that is being wrapped */ data = file_info->MainClass; if (!data && file_info->Contents->NumberOfClasses > 0) { data = file_info->Contents->Classes[0]; } if (data && hinfo) { module = vtkWrapPython_ClassModule(hinfo, data->Name); } /* Identify all enum types that are used by methods */ vtkWrapPython_MarkAllEnums(file_info->Contents, hinfo); /* Wrap any enum types defined in the global namespace */ for (i = 0; i < contents->NumberOfEnums; i++) { vtkWrapPython_GenerateEnumType(fp, module, NULL, contents->Enums[i]); } /* Wrap any namespaces */ for (i = 0; i < contents->NumberOfNamespaces; i++) { if (contents->Namespaces[i]->NumberOfConstants > 0) { vtkWrapPython_WrapNamespace(fp, module, contents->Namespaces[i]); numberOfWrappedNamespaces++; } } /* Check for all special classes before any classes are wrapped */ for (i = 0; i < contents->NumberOfClasses; i++) { data = contents->Classes[i]; /* guess whether type is a vtkobject */ is_vtkobject = (data == file_info->MainClass ? 1 : 0); if (hinfo) { is_vtkobject = vtkWrap_IsTypeOf(hinfo, data->Name, "vtkObjectBase"); } if (!is_vtkobject) { /* mark class as abstract only if it has pure virtual methods */ /* (does not check for inherited pure virtual methods) */ data->IsAbstract = 0; for (j = 0; j < data->NumberOfFunctions; j++) { FunctionInfo *func = data->Functions[j]; if (func && func->IsPureVirtual) { data->IsAbstract = 1; break; } } } wrapAsVTKObject[i] = (is_vtkobject ? 1 : 0); } /* Wrap all of the classes in the file */ for (i = 0; i < contents->NumberOfClasses; i++) { data = contents->Classes[i]; is_vtkobject = wrapAsVTKObject[i]; /* if "hinfo" is present, wrap everything, else just the main class */ if (hinfo || data == file_info->MainClass) { if (vtkWrapPython_WrapOneClass( fp, module, data->Name, data, file_info, hinfo, is_vtkobject)) { /* re-index wrapAsVTKObject for wrapped classes */ wrapAsVTKObject[numberOfWrappedClasses] = (is_vtkobject ? 1 : 0); wrappedClasses[numberOfWrappedClasses++] = data; } } } /* The function for adding everything to the module dict */ wrapped_anything = (numberOfWrappedClasses || numberOfWrappedNamespaces || contents->NumberOfConstants); fprintf(fp, "void PyVTKAddFile_%s(\n" " PyObject *%s)\n" "{\n" "%s", name, (wrapped_anything ? "dict" : ""), (wrapped_anything ? " PyObject *o;\n" : "")); /* Add all of the namespaces */ for (j = 0; j < contents->NumberOfNamespaces; j++) { if (contents->Namespaces[j]->NumberOfConstants > 0) { fprintf(fp, " o = PyVTKNamespace_%s();\n" " if (o && PyDict_SetItemString(dict, \"%s\", o) != 0)\n" " {\n" " Py_DECREF(o);\n" " }\n" "\n", contents->Namespaces[j]->Name, contents->Namespaces[j]->Name); } } /* Add all of the classes that have been wrapped */ for (i = 0; i < numberOfWrappedClasses; i++) { data = wrappedClasses[i]; is_vtkobject = wrapAsVTKObject[i]; if (data->Template) { /* Template generator */ fprintf(fp, " o = Py%s_TemplateNew();\n" "\n", data->Name); /* Add template specializations to dict */ fprintf(fp, " if (o)\n" " {\n" " PyObject *l = PyObject_CallMethod(o, (char *)\"values\", 0);\n" " Py_ssize_t n = PyList_GET_SIZE(l);\n" " for (Py_ssize_t i = 0; i < n; i++)\n" " {\n" " PyObject *ot = PyList_GET_ITEM(l, i);\n" " const char *nt = NULL;\n" " if (PyType_Check(ot))\n" " {\n" " nt = ((PyTypeObject *)ot)->tp_name;\n" " }\n" " else if (PyCFunction_Check(ot))\n" " {\n" " nt = ((PyCFunctionObject *)ot)->m_ml->ml_name;\n" " }\n" " if (nt)\n" " {\n" " PyDict_SetItemString(dict, nt, ot);\n" " }\n" " }\n" " Py_DECREF(l);\n" " }\n" "\n"); } else if (is_vtkobject) { /* Class is derived from vtkObjectBase */ fprintf(fp, " o = Py%s_ClassNew();\n" "\n", data->Name); } else { /* Classes that are not derived from vtkObjectBase */ fprintf(fp, " o = Py%s_TypeNew();\n" "\n", data->Name); } fprintf(fp, " if (o && PyDict_SetItemString(dict, \"%s\", o) != 0)\n" " {\n" " Py_DECREF(o);\n" " }\n" "\n", data->Name); } /* add any enum types defined in the file */ vtkWrapPython_AddPublicEnumTypes(fp, " ", "dict", "o", contents); /* add any constants defined in the file */ vtkWrapPython_AddPublicConstants(fp, " ", "dict", "o", contents); /* close the AddFile function */ fprintf(fp, "}\n\n"); free(name_from_file); vtkParse_Free(file_info); return 0; }
int main(int argc, char *argv[]) { int argi; int has_options = 0; FILE *ifile; FILE *ofile; FILE *hfile = 0; const char *cp; char *classname; size_t i; FileInfo *data; argi = check_options(argc, argv); if (argi > 1 && argc - argi == 2) { has_options = 1; } else if (argi < 0 || argc < 3 || argc > 5) { fprintf(stderr, "Usage: %s [options] input_file output_file\n" " --concrete force concrete class\n" " --abstract force abstract class\n" " --vtkobject vtkObjectBase-derived class\n" " --special non-vtkObjectBase class\n" " --hints <file> hints file\n" " --types <file> type hierarchy file\n" " -I <dir> add an include directory\n" " -D <macro> define a preprocessor macro\n", argv[0]); exit(1); } options.InputFileName = argv[argi++]; if (!(ifile = fopen(options.InputFileName, "r"))) { fprintf(stderr,"Error opening input file %s\n", options.InputFileName); exit(1); } if (!has_options) { if (argc == 5) { options.HintFileName = argv[argi++]; } if (argc >= 4) { options.IsConcrete = atoi(argv[argi++]); options.IsAbstract = !options.IsConcrete; } } if (options.HintFileName && options.HintFileName[0] != '\0') { if (!(hfile = fopen(options.HintFileName, "r"))) { fprintf(stderr, "Error opening hint file %s\n", options.HintFileName); fclose(ifile); exit(1); } } options.OutputFileName = argv[argi++]; ofile = fopen(options.OutputFileName, "w"); if (!ofile) { fprintf(stderr, "Error opening output file %s\n", options.OutputFileName); fclose(ifile); if (hfile) { fclose(hfile); } exit(1); } if (options.IsConcrete) { cp = options.InputFileName; i = strlen(cp); classname = (char *)malloc(i+1); while (i > 0 && cp[i-1] != '/' && cp[i-1] != '\\' && cp[i-1] != ':') { i--; } strcpy(classname, &cp[i]); i = 0; while (classname[i] != '\0' && classname[i] != '.') { i++; } classname[i] = '\0'; vtkParse_SetClassProperty(classname, "concrete"); } vtkParse_SetIgnoreBTX(0); if (options.HierarchyFileName) { vtkParse_SetIgnoreBTX(1); } data = vtkParse_ParseFile(options.InputFileName, ifile, stderr); if (!data) { fclose(ifile); fclose(ofile); if (hfile) { fclose(hfile); } exit(1); } if (hfile) { vtkParse_ReadHints(data, hfile, stderr); } if (options.IsConcrete && data->MainClass) { data->MainClass->IsAbstract = 0; } else if (options.IsAbstract && data->MainClass) { data->MainClass->IsAbstract = 1; } vtkParseOutput(ofile, data); fclose(ofile); vtkParse_Free(data); return 0; }
/* print the parsed structures */ int main(int argc, char *argv[]) { OptionInfo *options; FileInfo *file_info; ClassInfo *data; FILE *fp; int i,j,k; /* get command-line args and parse the header file */ file_info = vtkParse_Main(argc, argv); /* get the command-line options */ options = vtkParse_GetCommandLineOptions(); /* get the output file */ fp = fopen(options->OutputFileName, "w"); if (!fp) { fprintf(stderr, "Error opening output file %s\n", options->OutputFileName); exit(1); } /* get the main class */ if ((data = file_info->MainClass) == NULL) { fclose(fp); exit(0); } /* get the hierarchy info for accurate typing */ if (options->HierarchyFileName) { hierarchyInfo = vtkParseHierarchy_ReadFile(options->HierarchyFileName); } fprintf(fp,"// tcl wrapper for %s object\n//\n",data->Name); fprintf(fp,"#define VTK_WRAPPING_CXX\n"); if (strcmp("vtkObjectBase",data->Name) != 0) { /* Block inclusion of full streams. */ fprintf(fp,"#define VTK_STREAMS_FWD_ONLY\n"); } fprintf(fp,"#include \"vtkSystemIncludes.h\"\n"); fprintf(fp,"#include \"%s.h\"\n\n",data->Name); fprintf(fp,"#include \"vtkTclUtil.h\"\n"); fprintf(fp,"#include \"vtkStdString.h\"\n"); fprintf(fp,"#include <stdexcept>\n"); fprintf(fp,"#include <vtksys/ios/sstream>\n"); if (!data->IsAbstract) { if (strcmp(data->Name, "vtkRenderWindowInteractor") == 0) { fprintf(fp,"#include \"vtkToolkits.h\"\n"); fprintf(fp,"#if defined( VTK_USE_X ) && defined( VTK_USE_TK )\n"); fprintf(fp,"# include \"vtkXRenderWindowTclInteractor.h\"\n"); fprintf(fp,"#endif\n"); fprintf(fp,"\nClientData %sNewCommand()\n{\n",data->Name); fprintf(fp,"#if defined( VTK_USE_X ) && defined( VTK_USE_TK )\n"); fprintf(fp," %s *temp = vtkXRenderWindowTclInteractor::New();\n", data->Name); fprintf(fp,"#else\n"); fprintf(fp," %s *temp = %s::New();\n",data->Name,data->Name); fprintf(fp,"#endif\n"); fprintf(fp," return static_cast<ClientData>(temp);\n}\n\n"); } else { fprintf(fp,"\nClientData %sNewCommand()\n{\n",data->Name); fprintf(fp," %s *temp = %s::New();\n",data->Name,data->Name); fprintf(fp," return static_cast<ClientData>(temp);\n}\n\n"); } } for (i = 0; i < data->NumberOfSuperClasses; i++) { fprintf(fp,"int %sCppCommand(%s *op, Tcl_Interp *interp,\n int argc, char *argv[]);\n",data->SuperClasses[i],data->SuperClasses[i]); } fprintf(fp,"int VTKTCL_EXPORT %sCppCommand(%s *op, Tcl_Interp *interp,\n int argc, char *argv[]);\n",data->Name,data->Name); fprintf(fp,"\nint VTKTCL_EXPORT %sCommand(ClientData cd, Tcl_Interp *interp,\n int argc, char *argv[])\n{\n",data->Name); fprintf(fp," if ((argc == 2)&&(!strcmp(\"Delete\",argv[1]))&& !vtkTclInDelete(interp))\n {\n"); fprintf(fp," Tcl_DeleteCommand(interp,argv[0]);\n"); fprintf(fp," return TCL_OK;\n }\n"); fprintf(fp," return %sCppCommand(static_cast<%s *>(static_cast<vtkTclCommandArgStruct *>(cd)->Pointer),interp, argc, argv);\n}\n",data->Name,data->Name); fprintf(fp,"\nint VTKTCL_EXPORT %sCppCommand(%s *op, Tcl_Interp *interp,\n int argc, char *argv[])\n{\n",data->Name,data->Name); fprintf(fp," int tempi = 0; (void)tempi;\n"); fprintf(fp," double tempd = 0.0; (void)tempd;\n"); fprintf(fp," static char temps[80]; (void)temps;\n"); fprintf(fp," int error = 0; (void)error;\n"); fprintf(fp," temps[0] = 0;\n"); fprintf(fp,"\n"); fprintf(fp," if (argc < 2)\n {\n Tcl_SetResult(interp,const_cast<char *>(\"Could not find requested method.\"), TCL_VOLATILE);\n return TCL_ERROR;\n }\n"); /* stick in the typecasting and delete functionality here */ fprintf(fp," if (!interp)\n {\n"); fprintf(fp," if (!strcmp(\"DoTypecasting\",argv[0]))\n {\n"); fprintf(fp," if (!strcmp(\"%s\",argv[1]))\n {\n", data->Name); fprintf(fp," argv[2] = static_cast<char *>(static_cast<void *>(op));\n"); fprintf(fp," return TCL_OK;\n }\n"); /* check our superclasses */ for (i = 0; i < data->NumberOfSuperClasses; i++) { fprintf(fp," if (%sCppCommand(static_cast<%s *>(op),interp,argc,argv) == TCL_OK)\n {\n", data->SuperClasses[i],data->SuperClasses[i]); fprintf(fp," return TCL_OK;\n }\n"); } fprintf(fp," }\n return TCL_ERROR;\n }\n\n"); /* add the GetSuperClassName */ if (data->NumberOfSuperClasses) { fprintf(fp," if (!strcmp(\"GetSuperClassName\",argv[1]))\n"); fprintf(fp," {\n"); fprintf(fp," Tcl_SetResult(interp,const_cast<char *>(\"%s\"), TCL_VOLATILE);\n",data->SuperClasses[0]); fprintf(fp," return TCL_OK;\n"); fprintf(fp," }\n\n"); } fprintf(fp," try\n {\n"); /* insert function handling code here */ for (i = 0; i < data->NumberOfFunctions; i++) { currentFunction = data->Functions[i]; outputFunction(fp, data); } /* add the ListInstances method */ fprintf(fp,"\n if (!strcmp(\"ListInstances\",argv[1]))\n {\n"); fprintf(fp," vtkTclListInstances(interp,(ClientData)(%sCommand));\n",data->Name); fprintf(fp," return TCL_OK;\n }\n"); /* add the ListMethods method */ fprintf(fp,"\n if (!strcmp(\"ListMethods\",argv[1]))\n {\n"); /* recurse up the tree */ for (i = 0; i < data->NumberOfSuperClasses; i++) { fprintf(fp," %sCppCommand(op,interp,argc,argv);\n", data->SuperClasses[i]); } /* now list our methods */ fprintf(fp," Tcl_AppendResult(interp,\"Methods from %s:\\n\",NULL);\n",data->Name); fprintf(fp," Tcl_AppendResult(interp,\" GetSuperClassName\\n\",NULL);\n"); for (i = 0; i < numberOfWrappedFunctions; i++) { int numArgs = 0; currentFunction = wrappedFunctions[i]; if(currentFunction->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } /* calc the total required args */ for (j = 0; j < currentFunction->NumberOfArguments; j++) { numArgs = numArgs + (currentFunction->ArgCounts[j] ? currentFunction->ArgCounts[j] : 1); if (currentFunction->ArgTypes[j] == VTK_PARSE_FUNCTION) { break; } } if (numArgs > 1) { fprintf(fp," Tcl_AppendResult(interp,\" %s\\t with %i args\\n\",NULL);\n", currentFunction->Name, numArgs); } if (numArgs == 1) { fprintf(fp," Tcl_AppendResult(interp,\" %s\\t with 1 arg\\n\",NULL);\n", currentFunction->Name); } if (numArgs == 0) { fprintf(fp," Tcl_AppendResult(interp,\" %s\\n\",NULL);\n", currentFunction->Name); } if(currentFunction->IsLegacy) { fprintf(fp,"#endif\n"); } } fprintf(fp," return TCL_OK;\n }\n"); /* add the DescribeMethods method */ fprintf(fp,"\n if (!strcmp(\"DescribeMethods\",argv[1]))\n {\n"); fprintf(fp," if(argc>3) {\n" ); fprintf(fp," Tcl_SetResult ( interp, const_cast<char*>(\"Wrong number of arguments: object DescribeMethods <MethodName>\"), TCL_VOLATILE ); \n" ); fprintf(fp," return TCL_ERROR;\n }\n" ); fprintf(fp," if(argc==2) {\n" ); /* Return a list of methods */ fprintf(fp,"\n Tcl_DString dString, dStringParent;\n"); fprintf(fp,"\n Tcl_DStringInit ( &dString );\n" ); fprintf(fp,"\n Tcl_DStringInit ( &dStringParent );\n" ); /* recurse up the tree */ for (i = 0; i < data->NumberOfSuperClasses; i++) { fprintf(fp," %sCppCommand(op,interp,argc,argv);\n", data->SuperClasses[i]); /* append the result to our string */ fprintf(fp," Tcl_DStringGetResult ( interp, &dStringParent );\n" ); fprintf(fp," Tcl_DStringAppend ( &dString, Tcl_DStringValue ( &dStringParent ), -1 );\n" ); } for (k = 0; k < numberOfWrappedFunctions; k++) { currentFunction = wrappedFunctions[k]; if(currentFunction->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } fprintf(fp," Tcl_DStringAppendElement ( &dString, \"%s\" );\n", currentFunction->Name ); if(currentFunction->IsLegacy) { fprintf(fp,"#endif\n"); } } fprintf(fp," Tcl_DStringResult ( interp, &dString );\n" ); fprintf(fp," Tcl_DStringFree ( &dString );\n" ); fprintf(fp," Tcl_DStringFree ( &dStringParent );\n" ); fprintf(fp," return TCL_OK;\n }\n"); /* Now handle if we are asked for a specific function */ fprintf(fp," if(argc==3) {\n" ); fprintf(fp," Tcl_DString dString;\n"); if (data->NumberOfSuperClasses > 0) { fprintf(fp," int SuperClassStatus;\n" ); } /* recurse up the tree */ for (i = 0; i < data->NumberOfSuperClasses; i++) { fprintf(fp," SuperClassStatus = %sCppCommand(op,interp,argc,argv);\n", data->SuperClasses[i]); fprintf(fp," if ( SuperClassStatus == TCL_OK ) { return TCL_OK; }\n" ); } /* Now we handle it ourselves */ for (k = 0; k < numberOfWrappedFunctions; k++) { currentFunction = wrappedFunctions[k]; if(currentFunction->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } fprintf(fp," /* Starting function: %s */\n", currentFunction->Name ); fprintf(fp," if ( strcmp ( argv[2], \"%s\" ) == 0 ) {\n", currentFunction->Name ); fprintf(fp," Tcl_DStringInit ( &dString );\n" ); fprintf(fp," Tcl_DStringAppendElement ( &dString, \"%s\" );\n", currentFunction->Name ); /* calc the total required args */ fprintf(fp," /* Arguments */\n" ); fprintf(fp," Tcl_DStringStartSublist ( &dString );\n" ); for (i = 0; i < currentFunction->NumberOfArguments; i++) { unsigned int argtype; if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { fprintf(fp," Tcl_DStringAppendElement ( &dString, \"function\" );\n" ); break; } argtype = (currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE); switch (argtype) { case VTK_PARSE_FLOAT_PTR: case VTK_PARSE_DOUBLE_PTR: /* Vector */ fprintf(fp," Tcl_DStringStartSublist ( &dString );\n" ); for (j = 0; j < currentFunction->ArgCounts[i]; j++) { fprintf(fp," Tcl_DStringAppendElement ( &dString, \"float\" );\n" ); } fprintf(fp," Tcl_DStringEndSublist ( &dString );\n" ); break; case VTK_PARSE_INT_PTR: /* Vector */ fprintf(fp," Tcl_DStringStartSublist ( &dString );\n" ); for (j = 0; j < currentFunction->ArgCounts[i]; j++) { fprintf(fp," Tcl_DStringAppendElement ( &dString, \"int\" );\n" ); } fprintf(fp," Tcl_DStringEndSublist ( &dString );\n" ); break; case VTK_PARSE_ID_TYPE_PTR: /* Vector */ fprintf(fp," Tcl_DStringStartSublist ( &dString );\n" ); for (j = 0; j < currentFunction->ArgCounts[i]; j++) { fprintf(fp," Tcl_DStringAppendElement ( &dString, \"int\" );\n" ); } fprintf(fp," Tcl_DStringEndSublist ( &dString );\n" ); break; case VTK_PARSE_LONG_LONG_PTR: case VTK_PARSE___INT64_PTR: /* Vector */ fprintf(fp," Tcl_DStringStartSublist ( &dString );\n" ); for (j = 0; j < currentFunction->ArgCounts[i]; j++) { fprintf(fp," Tcl_DStringAppendElement ( &dString, \"int\" );\n" ); } fprintf(fp," Tcl_DStringEndSublist ( &dString );\n" ); break; case VTK_PARSE_OBJECT_PTR: fprintf(fp," Tcl_DStringAppendElement ( &dString, \"%s\" );\n", currentFunction->ArgClasses[i] ); break; case VTK_PARSE_VOID_PTR: case VTK_PARSE_CHAR_PTR: case VTK_PARSE_STRING: case VTK_PARSE_STRING_REF: fprintf(fp," Tcl_DStringAppendElement ( &dString, \"string\" );\n" ); break; case VTK_PARSE_FLOAT: case VTK_PARSE_DOUBLE: fprintf(fp," Tcl_DStringAppendElement ( &dString, \"float\" );\n" ); break; case VTK_PARSE_SIGNED_CHAR: case VTK_PARSE_ID_TYPE: case VTK_PARSE_UNSIGNED_LONG_LONG: case VTK_PARSE_LONG_LONG: case VTK_PARSE_UNSIGNED___INT64: case VTK_PARSE___INT64: case VTK_PARSE_UNSIGNED_INT: case VTK_PARSE_INT: case VTK_PARSE_UNSIGNED_SHORT: case VTK_PARSE_SHORT: case VTK_PARSE_UNSIGNED_LONG: case VTK_PARSE_LONG: fprintf(fp," Tcl_DStringAppendElement ( &dString, \"int\" );\n" ); break; case VTK_PARSE_CHAR: fprintf(fp," Tcl_DStringAppendElement ( &dString, \"char\" );\n" ); break; case VTK_PARSE_UNSIGNED_CHAR: fprintf(fp," Tcl_DStringAppendElement ( &dString, \"int\" );\n" ); break; case VTK_PARSE_BOOL: fprintf(fp," Tcl_DStringAppendElement ( &dString, \"bool\" );\n" ); break; } } fprintf(fp," Tcl_DStringEndSublist ( &dString );\n" ); /* Documentation */ fprintf(fp," /* Documentation for %s */\n", currentFunction->Name ); fprintf(fp," Tcl_DStringAppendElement ( &dString, \"%s\" );\n", quote_string ( currentFunction->Comment, 500 ) ); fprintf(fp," Tcl_DStringAppendElement ( &dString, \"%s\" );\n", quote_string ( currentFunction->Signature, 500 ) ); fprintf(fp," Tcl_DStringAppendElement ( &dString, \"%s\" );\n", quote_string ( data->Name, 500 ) ); fprintf(fp," /* Closing for %s */\n\n", currentFunction->Name ); fprintf(fp," Tcl_DStringResult ( interp, &dString );\n" ); fprintf(fp," Tcl_DStringFree ( &dString );\n" ); fprintf(fp," return TCL_OK;\n }\n"); if(currentFunction->IsLegacy) { fprintf(fp,"#endif\n"); } } /* Didn't find anything, return an error */ fprintf(fp," Tcl_SetResult ( interp, const_cast<char*>(\"Could not find method\"), TCL_VOLATILE ); \n" ); fprintf(fp," return TCL_ERROR;\n" ); fprintf(fp," }\n" ); fprintf(fp," }\n" ); /* try superclasses */ for (i = 0; i < data->NumberOfSuperClasses; i++) { fprintf(fp,"\n if (%sCppCommand(static_cast<%s *>(op),interp,argc,argv) == TCL_OK)\n", data->SuperClasses[i], data->SuperClasses[i]); fprintf(fp," {\n return TCL_OK;\n }\n"); } /* Add the Print method to vtkObjectBase. */ if (!strcmp("vtkObjectBase",data->Name)) { fprintf(fp," if ((!strcmp(\"Print\",argv[1]))&&(argc == 2))\n {\n"); fprintf(fp," vtksys_ios::ostringstream buf_with_warning_C4701;\n"); fprintf(fp," op->Print(buf_with_warning_C4701);\n"); fprintf(fp," buf_with_warning_C4701.put('\\0');\n"); fprintf(fp," Tcl_SetResult(interp,const_cast<char *>(buf_with_warning_C4701.str().c_str()),\n"); fprintf(fp," TCL_VOLATILE);\n"); fprintf(fp," return TCL_OK;\n }\n"); #ifndef VTK_LEGACY_REMOVE /* Add the PrintRevisions method to vtkObjectBase. */ fprintf(fp," if ((!strcmp(\"PrintRevisions\",argv[1]))&&(argc == 2))\n {\n"); fprintf(fp," vtksys_ios::ostringstream buf_with_warning_C4701;\n"); fprintf(fp," op->PrintRevisions(buf_with_warning_C4701);\n"); fprintf(fp," buf_with_warning_C4701.put('\\0');\n"); fprintf(fp," Tcl_SetResult(interp,const_cast<char *>(buf_with_warning_C4701.str().c_str()),\n"); fprintf(fp," TCL_VOLATILE);\n"); fprintf(fp," return TCL_OK;\n }\n"); #endif } /* Add the AddObserver method to vtkObject. */ if (!strcmp("vtkObject",data->Name)) { fprintf(fp," if ((!strcmp(\"AddObserver\",argv[1]))&&(argc >= 4))\n {\n"); fprintf(fp," error = 0;\n"); fprintf(fp," if (argc > 4 && Tcl_GetDouble(interp,argv[4],&tempd) != TCL_OK) error = 1;\n"); fprintf(fp," if (!error)\n {\n"); fprintf(fp," vtkTclCommand *cbc = vtkTclCommand::New();\n"); fprintf(fp," cbc->SetInterp(interp);\n"); fprintf(fp," cbc->SetStringCommand(argv[3]);\n"); fprintf(fp," unsigned long temp20;\n"); fprintf(fp," if (argc > 4)\n {\n"); fprintf(fp," temp20 = op->AddObserver(argv[2],cbc,tempd);\n"); fprintf(fp," }\n else\n {\n"); fprintf(fp," temp20 = op->AddObserver(argv[2],cbc);\n"); fprintf(fp," }\n"); fprintf(fp," cbc->Delete();\n"); fprintf(fp," char tempResult[1024];\n"); fprintf(fp," sprintf(tempResult,\"%%li\",temp20);\n"); fprintf(fp," Tcl_SetResult(interp,tempResult,TCL_VOLATILE);\n"); fprintf(fp," return TCL_OK;\n }\n"); fprintf(fp," }\n"); } /* i.e. If this is vtkObjectBase (or whatever the top of the class hierarchy will be) */ /* then report the error */ if (data->NumberOfSuperClasses == 0) { fprintf(fp,"\n if (argc >= 2)\n {\n"); fprintf(fp," char temps2[256];\n sprintf(temps2,\"Object named: %%s, could not find requested method: %%s\\nor the method was called with incorrect arguments.\\n\",argv[0],argv[1]);\n Tcl_SetResult(interp,temps2,TCL_VOLATILE);\n return TCL_ERROR;\n }\n"); } fprintf(fp," }\n"); fprintf(fp," catch (std::exception &e)\n"); fprintf(fp," {\n"); fprintf(fp," Tcl_AppendResult(interp, \"Uncaught exception: \", e.what(), \"\\n\", NULL);\n"); fprintf(fp," return TCL_ERROR;\n"); fprintf(fp," }\n"); fprintf(fp," return TCL_ERROR;\n}\n"); vtkParse_Free(file_info); return 0; }