ERRORCODE NodeSimCodeGenerator::GenerateHeaderFile(std::fstream& fileHeader, INsCodeGenHelper* codeGenHelper, ICluster* cluster) { //1. includes std::string headers; fileHeader << codeGenHelper->GetProtocolIncludesHeaderName(cluster) << std::endl; //2. cluster NameSpace; std::string clusterName = GetClusterName(cluster); fileHeader << defNameSpace << TAG_SPACE << clusterName << TAG_OPENFBRACE << std::endl; //3. Pdu namespace fileHeader << defNameSpace <<" " <<"PDU" << TAG_OPENFBRACE <<std::endl; //4. Pdu Decl char chTemp[256]; std::string pduName; std::map<UID_ELEMENT, IElement*> pduList; cluster->GetElementList(ePduElement, pduList); IPduCodeGenHelper* pduCodeGenHelper = codeGenHelper->GetPduCodeGenHelper(); PduProps pduProps; for ( auto itrPdu : pduList ) { IPdu* pdu = (IPdu*)(itrPdu.second); pdu->GetProperties(pduProps); fileHeader << pduCodeGenHelper->GetDecl(pdu) << std::endl; fileHeader << TAG_OPENFBRACE << std::endl; fileHeader << TAG_PUBLICSTART << std::endl; sprintf_s(chTemp, sizeof(chTemp), TAG_DATABYTEDECL, pduProps.m_unByteLength); fileHeader << chTemp; fileHeader << pduCodeGenHelper->GetBaseClassDecl(pdu) << std::endl; fileHeader << pduCodeGenHelper->GetSignalsDecl(pdu)<< std::endl; fileHeader << "};" << std::endl; pduName = pduCodeGenHelper->GetUniqueName(pdu); fileHeader << "typedef" << " " << "_" << pduName << " " << pduName <<TAG_SEMICOLON << std::endl; } //5. Endl Pdu namespace fileHeader << TAG_CLOSEFBRACE << std::endl; //6. Frame Namespace start fileHeader << defNameSpace <<" " <<"Frame" << TAG_OPENFBRACE <<std::endl; //7. Using namespace fileHeader <<"using namespace PDU;" << std::endl; //8. Class Decleration std::string frameName; std::map<UID_ELEMENT, IElement*> frameList; cluster->GetElementList(eFrameElement, frameList); IFrameCodeGenHelper* frameCodeGenHelper = codeGenHelper->GetFrameCodeGenHelper(); std::map<IPdu*, PduInstanse> pduMap; for ( auto itrPdu : frameList ) { IFrame* frame = (IFrame*)(itrPdu.second); fileHeader << frameCodeGenHelper->GetDecl(frame) << std::endl; fileHeader << TAG_OPENFBRACE << std::endl; fileHeader << TAG_PUBLICSTART << std::endl; fileHeader << frameCodeGenHelper->GetBaseClassDecl(frame) << std::endl; fileHeader << frameCodeGenHelper->GetPdusDecl(frame)<< std::endl; pduMap.clear(); frame->GetPduList(pduMap); if ( pduMap.size() == 0 ) { fileHeader << frameCodeGenHelper->GetSignalsDecl(frame)<< std::endl; } fileHeader << "};" << std::endl; } //9. Endl Frame namespace fileHeader << TAG_CLOSEFBRACE << std::endl; //10. Endl cluster namespace fileHeader << TAG_CLOSEFBRACE << std::endl; //11. using namespaces fileHeader << "using namespace" << " " <<clusterName << "::" << "Frame" <<TAG_SEMICOLON << std::endl; fileHeader << "using namespace" << " " <<clusterName << "::" << "PDU" <<TAG_SEMICOLON << std::endl; return EC_SUCCESS; }
ERRORCODE NodeSimCodeGenerator::GenerateCppFile(std::fstream& fileHeader, INsCodeGenHelper* codeGenHelper, ICluster* cluster) { //1. Header path std::string dbAppPath; GetBusMasterDBCachePath(dbAppPath); std::string strChkSum; std::string headerfilePath; cluster->GetDBFileChecksum(strChkSum); char headerFilePath[MAX_PATH*2]; headerfilePath = strChkSum + ".h"; PathCombine(headerFilePath, dbAppPath.c_str(), headerfilePath.c_str()); fileHeader <<"#include " << AddDoubleQuotes(headerFilePath) <<std::endl ; //2. namespace cluster std::string clusterName = GetClusterName(cluster); fileHeader <<defNameSpace <<" " << clusterName <<"{" <<std::endl ; //3. Cluster Id fileHeader << "unsigned long long g_strClusterPath = " <<"0x" << strChkSum <<TAG_SEMICOLON << std::endl ; //4. Pdu namespace fileHeader << defNameSpace <<" " <<"PDU" << TAG_OPENFBRACE <<std::endl; //5. pdu definition std::string pduName; std::map<UID_ELEMENT, IElement*> pduList; cluster->GetElementList(ePduElement, pduList); IPduCodeGenHelper* pduCodeGenHelper = codeGenHelper->GetPduCodeGenHelper(); PduProps pduProps; for ( auto itrPdu : pduList ) { IPdu* pdu = (IPdu*)(itrPdu.second); fileHeader << pduCodeGenHelper->GetConstructorDef(pdu) <<":" <<std::endl; fileHeader << pduCodeGenHelper->GetBaseClassConstructorDef(pdu) <<std::endl; fileHeader << pduCodeGenHelper->GetSignalsConstructorDef(pdu) << std::endl; fileHeader << TAG_OPENFBRACE << std::endl << TAG_CLOSEFBRACE <<std::endl; } //6. Endl Pdu namespace fileHeader << TAG_CLOSEFBRACE << std::endl; //7. Frame Namespace start fileHeader << defNameSpace <<" " <<"Frame" << TAG_OPENFBRACE <<std::endl; //8. Using namespace fileHeader <<"using namespace PDU;" << std::endl; //9. Frame definition std::string frameName; std::map<UID_ELEMENT, IElement*> frameList; std::map<IPdu*, PduInstanse> pduMap; cluster->GetElementList(eFrameElement, frameList); IFrameCodeGenHelper* frameCodeGenHelper = codeGenHelper->GetFrameCodeGenHelper(); for ( auto itrFrame : frameList ) { IFrame* frame = (IFrame*)(itrFrame.second); fileHeader << frameCodeGenHelper->GetConstructorDef(frame) <<":" <<std::endl; fileHeader << frameCodeGenHelper->GetBaseClassConstructorDef(frame) <<std::endl; fileHeader << frameCodeGenHelper->GetPdusConstructorDef(frame) << std::endl; pduMap.clear(); frame->GetPduList(pduMap); if ( pduMap.size() == 0 ) { fileHeader << frameCodeGenHelper->GetSignalsConstructorDef(frame) << std::endl; } fileHeader << TAG_OPENFBRACE << std::endl << TAG_CLOSEFBRACE <<std::endl; } //10. Endl Frame namespace fileHeader << TAG_CLOSEFBRACE << std::endl; //11. Cluster namespace fileHeader << TAG_CLOSEFBRACE << std::endl; return EC_SUCCESS; }