//Opens the output file. //Reads the syntax tree generated by the parser. Using the tree, C++ code is generated. void ClassBuilder::buildToFiles(const char *directory) { char fileName[MAX_PATH_LEN] = ""; //A temporary var to hold a string. char cppFileName[MAX_PATH_LEN] = ""; //Contains .cpp file name. char hFileName[MAX_PATH_LEN] = ""; //.h file name BigClassObject *classdata = NULL; //classData contains data for a class. while (true) { /*Each iteration of this loop generates one class.*/ classdata = PParser.parseClass (); //Get the next class. This method may need changing, in case you want to parse a different type of file. //classdata - PParser.parseProtegeFile(); //other type of parsing. if (classdata == NULL) break; //if there are no more classes, break out of loop. /*Get class name and it's parent's name.*/ char *className = classdata->getClassName (); //retrieve class name char *classIsA = classdata->getClassParent (); //retrive class parent //char *classIsA = "Organ"; //Cutoff point at "Organ"? May change later. (2/4/2008), commeneted on (2/13/2008) //bool singletonClass = classdata->getSingletonStatus (); //retrive class's singleton status (true or false) bool singletonClass = false; //make this FALSE if you don't want SINGLETON!! bool classIsRoot = false; //Is this class the root class? if (strcmp(classIsA,"USER") == 0) classIsRoot = true; //If the parent is "USER", then this class is the root. strncpy(fileName,directory,MAX_PATH_LEN); //Configure the file name using a series of string manips. strncat(fileName,"\\",MAX_PATH_LEN); strncat(fileName,className,MAX_PATH_LEN); strncpy(cppFileName,fileName,MAX_PATH_LEN); strncpy(hFileName,fileName,MAX_PATH_LEN); strncat(hFileName,".h",MAX_PATH_LEN); //create the directory and file name strncat(cppFileName,".cpp",MAX_PATH_LEN); // outHFile.open (hFileName); //opens the .h file outCppFile.open (cppFileName); //opens the .cpp file //begin writing to the HEADER file. /*Preprocessor. Headers, comments and macros.*/ outHFile << "//////////////////////////////////////////////////////" << endl; outHFile << "// " << className << endl; outHFile << "//////////////////////////////////////////////////////" << endl; outCppFile << "//////////////////////////////////////////////////////" << endl; outCppFile << "// Implementation of " << className << endl; outCppFile << "//////////////////////////////////////////////////////" << endl; outCppFile << "#include \"" << className << ".h\"" << endl; //Include the header file which contains class declaration. outHFile << "#ifndef CLASS_" << className << endl; //Macros to prevent redeclaration. outHFile << "#define CLASS_" << className << endl <<endl; //Include parent class. if (!classIsRoot) outHFile << "#include \"" << classIsA << ".h\"" << endl<<endl; if (classIsRoot) { /*Includes <cstring> library for the root class.*/ outHFile << "#include <cstring>" << endl; outHFile << "#include \"utilities.h\"" << endl; outHFile << "#include \"symbolDefs.h\"" << endl; } /*Begin class declaration in header*/ outHFile << "class " << className; if ( !classIsRoot ) { /*Defines inheritance, as long as the parent is a different class.*/ outHFile << ": public " << classdata->getClassParent (); } outHFile << "\n{\npublic:\n\t"; //print out public members. //This conditional decides if the class should be defined singleton or not. if (singletonClass == true) outHFile << "static " << className << " *getInstance();\n"; //singleton method else //public Constructor. outHFile << className << "();\n"; buildGetSetMethods(classdata); //writes out get/set methods in the H file and CPP file. outHFile << "protected:\n\t"; //print out protected members. if (singletonClass == true) { //protected constructor, if class is defined to be singleton. outHFile << className << "();\n"; //Singleton instance variable. outHFile << "\tstatic " << className << "* instance;\n"; } //Defines constructor in the .cpp file. outCppFile << className << "::" << className << "()\n{\n"; buildSlots(classdata); //print out private member slots. //also builds the constructor (this is done in the buildSlots function). outCppFile << "}\n\n"; //end constructor definition. outHFile << "};" << endl << endl; //print out end of class. outHFile << "#endif"; //WE are done with the header file at this point. //Singleton method definition in the .cpp file. if (singletonClass == true) { outCppFile << className << "*" << className << "::instance = NULL;\n\n"; outCppFile << className << "* " << className << "::getInstance()\n{\n\t"; outCppFile << "if (instance == NULL) \n \t\tinstance = new " << className << "();\n"; outCppFile << "\telse\n \t\treturn instance;\n}\n"; } cout << "Parsed to file: " << hFileName << endl; outHFile.close (); //close file outCppFile.close(); delete classdata; //deletes the BigClassObject data structure to free memory. /*I do this because each time I call parseClass(), a new BigClassObject is generated. The old one will still be somewhere in memory, unreferenced.*/ classdata = NULL; }//end while loop writeEnumDefs(directory); //write enum defs to file. PParser.closeFile(); //closes the protege file. cout << "Finished parsing all classes from the .pins file" << endl; }
Armature* BaseFactory::buildArmature(const std::string &armatureName, const std::string &skinName, const std::string &animationName, const std::string &dragonBonesName, const std::string &textureAtlasName) const { DragonBonesData *dragonBonesData = nullptr; ArmatureData *armatureData = nullptr; ArmatureData *animationArmatureData = nullptr; SkinData *skinData = nullptr; SkinData *skinDataCopy = nullptr; if (!dragonBonesName.empty()) { auto iterator = _dragonBonesDataMap.find(dragonBonesName); if (iterator != _dragonBonesDataMap.end()) { dragonBonesData = iterator->second; armatureData = dragonBonesData->getArmatureData(armatureName); _currentDragonBonesDataName = dragonBonesName; _currentTextureAtlasName = textureAtlasName.empty() ? _currentDragonBonesDataName : textureAtlasName; } } if (!armatureData) { AutoSearchType searchType = (dragonBonesName.empty() ? AutoSearchType::AST_ALL : (autoSearchDragonBonesData ? AutoSearchType::AST_AUTO : AutoSearchType::AST_NONE)); if (searchType != AutoSearchType::AST_NONE) { for (auto iterator = _dragonBonesDataMap.begin(); iterator != _dragonBonesDataMap.end(); ++iterator) { dragonBonesData = iterator->second; if (searchType == AutoSearchType::AST_ALL || dragonBonesData->autoSearch) { armatureData = dragonBonesData->getArmatureData(armatureName); if (armatureData) { _currentDragonBonesDataName = iterator->first; _currentTextureAtlasName = _currentDragonBonesDataName; break; } } } } } if (!armatureData) { return nullptr; } if (!animationName.empty() && animationName != armatureName) { animationArmatureData = dragonBonesData->getArmatureData(animationName); if (!animationArmatureData) { for (auto iterator = _dragonBonesDataMap.begin(); iterator != _dragonBonesDataMap.end(); ++iterator) { dragonBonesData = iterator->second; animationArmatureData = dragonBonesData->getArmatureData(animationName); if (animationArmatureData) { break; } } } if (animationArmatureData) { skinDataCopy = animationArmatureData->getSkinData(""); } } skinData = armatureData->getSkinData(skinName); Armature *armature = generateArmature(armatureData); armature->name = armatureName; if (animationArmatureData) { armature->getAnimation()->setAnimationDataList(animationArmatureData->animationDataList); } else { armature->getAnimation()->setAnimationDataList(armatureData->animationDataList); } // buildBones(armature, armatureData); // if (skinData) { buildSlots(armature, armatureData, skinData, skinDataCopy); } // update armature pose armature->getAnimation()->play(); armature->advanceTime(0); armature->getAnimation()->stop(); return armature; }