/*************************************** Auteur : Pierre Aubert Mail : aubertp7@gmail.com Licence : CeCILL-C ****************************************/ #include "string_utils.h" #include "backend.h" ///Get the licence in string /** @return licence in string */ std::string ph5_licenceSaveStr(){ std::string body(""); body += "/***************************************\n"; body += "\tAuteur : Pierre Aubert\n"; body += "\tMail : aubertp7@gmail.com\n"; body += "\tLicence : CeCILL-C\n"; body += "****************************************/\n\n\n"; body += "//Warning : this file has been generated automatically by the phoenix_hdf5 program\n"; body += "//Do NOT modify it\n\n\n"; return body; } ///Save the header of the given PTable /** @param table : PTable to be used * @return corresponding string */ std::string ph5_backendTableHeaderCompType(const PTable & table){ std::string body("\t\tstatic H5::CompType getTypeAll();\n"); const PVecAttribute & vecAttriute = table.getVecAttribute(); for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){ body += "\t\tstatic H5::CompType getType" + firstToUpper(it->getName()) + "();\n"; } return body; } ///Save the header of the given PTable /** @param table : PTable to be used * @return corresponding string */ std::string ph5_backendTableHeaderAttribute(const PTable & table){ std::string body(""); const PVecAttribute & vecAttriute = table.getVecAttribute(); for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){ if(it->getDocString() != ""){ body += "\t\t///" + it->getDocString() + "\n"; } body += "\t\t"+it->getType()+" * p_"+it->getName()+";\n"; } return body; } ///Save the header of the given PTable /** @param table : PTable to be used * @return corresponding string */ std::string ph5_backendTableHeader(const PTable & table){ std::string body(""); if(table.getDocString() != ""){ body += "///" + table.getDocString() + "\n"; } std::string name(table.getName()); body += "class " + name + "{\n"; body += "\tpublic:\n"; body += "\t\t" + name + "();\n"; body += "\t\tvirtual ~" + name + "();\n"; body += "\t\tvoid resize(size_t nbRow);\n"; body += "\t\tvoid clear();\n\n"; body += "\t\tvoid read(const H5::H5File & file);\n"; body += "\t\tvoid read(const H5::Group & group);\n\n"; body += "\t\tvoid write(H5::H5File & file) const;\n"; body += "\t\tvoid write(H5::Group & group) const;\n\n"; body += ph5_backendTableHeaderCompType(table); body += "\tprivate:\n"; body += "\t\t///Number of rows in the table "+name+"\n"; body += "\t\tsize_t p_nbRow;\n"; body += ph5_backendTableHeaderAttribute(table); body += "};\n\n"; return body; } ///Save the header of the given PSource /** @param source : PSource to be used * @return corresponding string */ std::string ph5_backendHeader(const PSource & source){ std::string body(ph5_licenceSaveStr()); std::string baseMacro("__" + strToUpper(source.getName()) + "_H__"); body += "#ifndef " + baseMacro + "\n"; body += "#define " + baseMacro + "\n\n"; body += "#include \"H5Cpp.h\"\n\n"; const PVecTable & vecTable = source.getVecTable(); for(PVecTable::const_iterator it(vecTable.begin()); it != vecTable.end(); ++it){ body += ph5_backendTableHeader(*it); } body += "#endif\n\n"; return body; } ///Save the source of the given PTable /** @param table : PTable to be used * @return corresponding string */ std::string ph5_backendTableSource(const PTable & table){ std::string body(""), name(table.getName()); body += "///Constructor of the class " + name + "\n"; body += name + "::" + name + "(){\n"; body += "\tp_nbRow = 0lu;\n"; body += "}\n\n"; body += "///Destructor of the class " + name + "\n"; body += name + "::~" + name + "(){\n"; body += "\t\n"; body += "}\n\n"; return body; } ///Save the source of the given PSource /** @param source : PSource to be used * @return corresponding string */ std::string ph5_backendSource(const PSource & source){ std::string body(ph5_licenceSaveStr()); body += "#include \""+source.getName()+".h\"\n\n"; const PVecTable & vecTable = source.getVecTable(); for(PVecTable::const_iterator it(vecTable.begin()); it != vecTable.end(); ++it){ body += ph5_backendTableSource(*it); } return body; } ///Save a vector of PSource in the output directory /** @param source : source to be saved * @param outputDir : output directory where to save PSource * @return true on success, false otherwise */ bool ph5_backend(const PSource & source, const std::string & outputDir){ std::string headerSrc(ph5_backendHeader(source)); std::string sourceSrc(ph5_backendSource(source)); std::string outputHeaderFile(outputDir + "/" + source.getName() + ".h"); std::string outputSourceFile(outputDir + "/" + source.getName() + ".cpp"); if(saveFileContent(outputHeaderFile, headerSrc)){ std::cerr << "ph5_backend : cannot save header file '"<