void cdgClass::GenerateCode(std::ostream & outputStream) const { GenerateLineComment(outputStream); // if we need instantiation for mts proxy const std::string className = this->GetFieldValue("name"); const std::string classNamespace = this->GetFieldValue("namespace"); const std::string mtsProxy = this->GetFieldValue("mts-proxy"); if (mtsProxy == "true") { outputStream << std::endl << "// mts-proxy set to " << mtsProxy << std::endl; if (classNamespace != "") { outputStream << "CMN_IMPLEMENT_SERVICES_TEMPLATED(" << classNamespace << "_" << className << "Proxy);" << std::endl; } else { outputStream << "CMN_IMPLEMENT_SERVICES_TEMPLATED(" << className << "Proxy);" << std::endl; } outputStream << std::endl; } size_t index; GenerateConstructorsCode(outputStream); GenerateMethodSerializeRawCode(outputStream); GenerateMethodDeSerializeRawCode(outputStream); GenerateMethodToStreamCode(outputStream); GenerateMethodToStreamRawCode(outputStream); for (index = 0; index < Members.size(); index++) { Members[index]->GenerateCode(outputStream); } GenerateStandardFunctionsCode(outputStream); GenerateDataFunctionsCode(outputStream); }
void cdgClass::GenerateIncludes(std::ostream & outputStream) const { GenerateLineComment(outputStream); const std::string mtsProxy = this->GetFieldValue("mts-proxy"); // includes for mts proxy if (mtsProxy != "false") { outputStream << std::endl << "// mts-proxy set to " << mtsProxy << std::endl << "#include <cisstCommon/cmnClassServices.h>" << std::endl << "#include <cisstCommon/cmnClassRegisterMacros.h>" << std::endl << "#include <cisstMultiTask/mtsGenericObjectProxy.h>" << std::endl << std::endl; } }
void cdgEnum::GenerateHeader(std::ostream & outputStream) const { GenerateLineComment(outputStream); size_t index; const std::string enumName = this->GetFieldValue("name"); outputStream << "public:" << std::endl << " enum " << enumName << " {"; for (index = 0; index < Scopes.size(); index++) { outputStream << Scopes[index]->GetFieldValue("name"); if (Scopes[index]->GetFieldValue("value") != "") { outputStream << " = " << Scopes[index]->GetFieldValue("value"); } if (index != (Scopes.size() - 1)) { outputStream << ", "; } } outputStream << " };" << std::endl << " static std::string " << enumName << "ToString(const " << enumName << " & value) CISST_THROW(std::runtime_error);" << std::endl << " static " << enumName << " " << enumName << "FromString(const std::string & value) CISST_THROW(std::runtime_error);" << std::endl << " static const std::vector<int> & " << enumName << "VectorInt(void);" << std::endl << " static const std::vector<std::string> & " << enumName << "VectorString(void);" << std::endl; }
void cdgClass::GenerateHeader(std::ostream & outputStream) const { GenerateLineComment(outputStream); const std::string className = this->GetFieldValue("name"); const std::string classNamespace = this->GetFieldValue("namespace"); const std::string mtsProxy = this->GetFieldValue("mts-proxy"); size_t index; // class definition if (classNamespace != "") { outputStream << "namespace " << classNamespace << " {" << std::endl; } outputStream << "class " << this->GetFieldValue("attribute") << " " << className; if (BaseClasses.size() != 0) { outputStream << ": "; } for (index = 0; index < BaseClasses.size(); index++) { BaseClasses[index]->GenerateHeaderInheritance(outputStream); if (index != (BaseClasses.size() - 1)) { outputStream << ", "; } } outputStream << std::endl << "{" << std::endl; // constructors and destructor outputStream << " /* default constructors and destructors. */" << std::endl << " public:" << std::endl << " " << className << "(void);" << std::endl << " " << className << "(const " << this->GetFieldValue("name") << " & other);" << std::endl << " ~" << className << "();" << std::endl << std::endl; // generate code for all scopes for (index = 0; index < Scopes.size(); index++) { Scopes[index]->GenerateHeader(outputStream); } // create a constructor that requires all data members to be // initialized. Must appear after all scope code since this might // require some user defined enum and/or typedef if (this->GetFieldValue("ctor-all-members") == "true" && Members.size() > 0) { outputStream << std::endl << " public:" << std::endl << " /* ctor-all-member is set to: true */" << std::endl << " " << className << "("; std::string memberName, memberType; for (index = 0; index < Members.size(); index++) { memberName = Members[index]->GetFieldValue("name"); memberType = Members[index]->GetFieldValue("type"); outputStream << "const " << memberType << " & new" << memberName; if (index != (Members.size() - 1)) { outputStream << ", "; } } outputStream << ");" << std::endl; } // methods declaration GenerateStandardMethodsHeader(outputStream); GenerateDataMethodsHeader(outputStream); outputStream << "}; // " << className << std::endl; if (classNamespace != "") { outputStream << "}; // end of namespace " << classNamespace << std::endl; } // make sure mts proxy is registered, use namespace if any if (mtsProxy != "false") { outputStream << std::endl << "// mts-proxy set to " << mtsProxy << std::endl; if (classNamespace != "") { outputStream << "typedef mtsGenericObjectProxy<" << classNamespace << "::" << className << "> " << classNamespace << "_" << className << "Proxy;" << std::endl << "CMN_DECLARE_SERVICES_INSTANTIATION(" << classNamespace << "_" << className << "Proxy);" << std::endl; } else { outputStream << "typedef mtsGenericObjectProxy<" << className << "> " << className << "Proxy;" << std::endl << "CMN_DECLARE_SERVICES_INSTANTIATION(" << className << "Proxy);" << std::endl; } outputStream << std::endl; } // declaration of all global functions GenerateStandardFunctionsHeader(outputStream); GenerateDataFunctionsHeader(outputStream); // global functions for enums have to be declared after the enum is defined const std::string classWithNamespace = this->ClassWithNamespace(); for (index = 0; index < Enums.size(); ++index) { Enums[index]->GenerateDataFunctionsHeader(outputStream, classWithNamespace, this->GetFieldValue("attribute")); } }