Commit bcc079e6 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add base of backend

parent c2bd6350
...@@ -4,10 +4,174 @@ ...@@ -4,10 +4,174 @@
Licence : CeCILL-C Licence : CeCILL-C
****************************************/ ****************************************/
#include "string_utils.h"
#include "backend.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 '"<<outputHeaderFile<<"'" << std::endl;
return false;
}
if(saveFileContent(outputSourceFile, sourceSrc)){
std::cerr << "ph5_backend : cannot save source file '"<<outputSourceFile<<"'" << std::endl;
return false;
}
return true;
}
///Save a vector of PSource in the output directory
/** @param vecSource : vector of source
* @param outputDir : output directory where to save PSource
* @return true on success, false otherwise
*/
bool ph5_backend(const PVecSource & vecSource, const std::string & outputDir){
bool b(true);
for(PVecSource::const_iterator it(vecSource.begin()); it != vecSource.end(); ++it){
b &= ph5_backend(*it, outputDir);
}
return b;
}
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#ifndef __BACKEND_H__ #ifndef __BACKEND_H__
#define __BACKEND_H__ #define __BACKEND_H__
#include "Representation/representation.h"
bool ph5_backend(const PSource & source, const std::string & outputDir);
bool ph5_backend(const PVecSource & vecSource, const std::string & outputDir);
#endif #endif
...@@ -294,6 +294,13 @@ void PTable::setVarNbEntry(const std::string & varNbEntry){ ...@@ -294,6 +294,13 @@ void PTable::setVarNbEntry(const std::string & varNbEntry){
p_varNbEntry = varNbEntry; p_varNbEntry = varNbEntry;
} }
///Sets the docString of the PTable
/** @param docString : docString of the PTable
*/
void PTable::setDocString(const std::string & docString){
p_docString = docString;
}
///Sets the vecAttribute of the PTable ///Sets the vecAttribute of the PTable
/** @param vecAttribute : vecAttribute of the PTable /** @param vecAttribute : vecAttribute of the PTable
*/ */
...@@ -343,6 +350,20 @@ std::string & PTable::getVarNbEntry(){ ...@@ -343,6 +350,20 @@ std::string & PTable::getVarNbEntry(){
return p_varNbEntry; return p_varNbEntry;
} }
///Gets the docString of the PTable
/** @return docString of the PTable
*/
const std::string & PTable::getDocString() const{
return p_docString;
}
///Gets the docString of the PTable
/** @return docString of the PTable
*/
std::string & PTable::getDocString(){
return p_docString;
}
///Gets the vecAttribute of the PTable ///Gets the vecAttribute of the PTable
/** @return vecAttribute of the PTable /** @return vecAttribute of the PTable
*/ */
...@@ -364,6 +385,7 @@ void PTable::copyPTable(const PTable & other){ ...@@ -364,6 +385,7 @@ void PTable::copyPTable(const PTable & other){
p_name = other.p_name; p_name = other.p_name;
p_dataSetName = other.p_dataSetName; p_dataSetName = other.p_dataSetName;
p_varNbEntry = other.p_varNbEntry; p_varNbEntry = other.p_varNbEntry;
p_docString = other.p_docString;
p_vecAttribute = other.p_vecAttribute; p_vecAttribute = other.p_vecAttribute;
} }
......
...@@ -84,6 +84,7 @@ class PTable{ ...@@ -84,6 +84,7 @@ class PTable{
void setName(const std::string & name); void setName(const std::string & name);
void setDataSetName(const std::string & dataSetName); void setDataSetName(const std::string & dataSetName);
void setVarNbEntry(const std::string & varNbEntry); void setVarNbEntry(const std::string & varNbEntry);
void setDocString(const std::string & docString);
void setVecAttribute(const std::vector<PAttribute> & vecAttribute); void setVecAttribute(const std::vector<PAttribute> & vecAttribute);
const std::string & getName() const; const std::string & getName() const;
std::string & getName(); std::string & getName();
...@@ -91,6 +92,8 @@ class PTable{ ...@@ -91,6 +92,8 @@ class PTable{
std::string & getDataSetName(); std::string & getDataSetName();
const std::string & getVarNbEntry() const; const std::string & getVarNbEntry() const;
std::string & getVarNbEntry(); std::string & getVarNbEntry();
const std::string & getDocString() const;
std::string & getDocString();
const std::vector<PAttribute> & getVecAttribute() const; const std::vector<PAttribute> & getVecAttribute() const;
std::vector<PAttribute> & getVecAttribute(); std::vector<PAttribute> & getVecAttribute();
protected: protected:
...@@ -102,6 +105,8 @@ class PTable{ ...@@ -102,6 +105,8 @@ class PTable{
std::string p_dataSetName; std::string p_dataSetName;
///Name of the variable which describes the number of entries (or row) of the current PTable (or DataSet) ///Name of the variable which describes the number of entries (or row) of the current PTable (or DataSet)
std::string p_varNbEntry; std::string p_varNbEntry;
///Documentation string of the current PTable
std::string p_docString;
///Vector of all the attributes of the PTable ///Vector of all the attributes of the PTable
std::vector<PAttribute> p_vecAttribute; std::vector<PAttribute> p_vecAttribute;
}; };
......
...@@ -34,6 +34,8 @@ PTable{ ...@@ -34,6 +34,8 @@ PTable{
std::string dataSetName; std::string dataSetName;
///Name of the variable which describes the number of entries (or row) of the current PTable (or DataSet) ///Name of the variable which describes the number of entries (or row) of the current PTable (or DataSet)
std::string varNbEntry; std::string varNbEntry;
///Documentation string of the current PTable
std::string docString;
///Vector of all the attributes of the PTable ///Vector of all the attributes of the PTable
std::vector<PAttribute> vecAttribute; std::vector<PAttribute> vecAttribute;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment