Commit 4ae8277c authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add resize, clear and alocate

parent bcc079e6
...@@ -80,11 +80,11 @@ std::string ph5_backendTableHeader(const PTable & table){ ...@@ -80,11 +80,11 @@ std::string ph5_backendTableHeader(const PTable & table){
body += ph5_backendTableHeaderCompType(table); body += ph5_backendTableHeaderCompType(table);
body += "\tprivate:\n"; body += "\tprivate:\n";
body += "\t\tvoid allocate(size_t nbRow);\n";
body += "\t\t///Number of rows in the table "+name+"\n"; body += "\t\t///Number of rows in the table "+name+"\n";
body += "\t\tsize_t p_nbRow;\n"; body += "\t\tsize_t p_nbRow;\n";
body += ph5_backendTableHeaderAttribute(table); body += ph5_backendTableHeaderAttribute(table);
body += "};\n\n"; body += "};\n\n";
return body; return body;
} }
...@@ -108,6 +108,60 @@ std::string ph5_backendHeader(const PSource & source){ ...@@ -108,6 +108,60 @@ std::string ph5_backendHeader(const PSource & source){
return body; return body;
} }
///Save the source of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableSourceResize(const PTable & table){
std::string body(""), name(table.getName());
body += "///Resize the table " + name + "\n";
body += "/*\t@param nbRow : new number of rows of the Table\n";
body += "*/\n";
body += "void " + name + "::resize(size_t nbRow){\n";
body += "\tif(nbRow == p_nbRow){return;} //Nothing to do\n";
body += "\tclear()\n";
body += "\tallocate(nbRow);\n";
body += "}\n\n";
return body;
}
///Save the source of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableSourceClear(const PTable & table){
std::string body(""), name(table.getName());
body += "///Clear the table " + name + " (delete all column)\n";
body += "void " + name + "::clear(){\n";
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "\tif(p_"+it->getName()+" != NULL){delete [] p_"+it->getName()+";p_"+it->getName()+" = NULL;}\n";
}
body += "}\n\n";
return body;
}
///Save the source of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableSourceAllocate(const PTable & table){
std::string body(""), name(table.getName());
body += "///Allocate the table " + name + " (delete all column)\n";
body += "/*\t@param nbRow : new number of rows of the Table\n";
body += "*/\n";
body += "void " + name + "::allocate(size_t nbRow){\n";
body += "\tp_nbRow = nbRow;\n";
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "\tp_"+it->getName()+" = new "+it->getType()+"[p_nbRow];}\n";
}
body += "}\n\n";
return body;
}
///Save the source of the given PTable ///Save the source of the given PTable
/** @param table : PTable to be used /** @param table : PTable to be used
* @return corresponding string * @return corresponding string
...@@ -117,12 +171,21 @@ std::string ph5_backendTableSource(const PTable & table){ ...@@ -117,12 +171,21 @@ std::string ph5_backendTableSource(const PTable & table){
body += "///Constructor of the class " + name + "\n"; body += "///Constructor of the class " + name + "\n";
body += name + "::" + name + "(){\n"; body += name + "::" + name + "(){\n";
body += "\tp_nbRow = 0lu;\n"; body += "\tp_nbRow = 0lu;\n";
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "\tp_"+it->getName()+" = NULL;\n";
}
body += "}\n\n"; body += "}\n\n";
body += "///Destructor of the class " + name + "\n"; body += "///Destructor of the class " + name + "\n";
body += name + "::~" + name + "(){\n"; body += name + "::~" + name + "(){\n";
body += "\t\n"; body += "\tclear();\n";
body += "}\n\n"; body += "}\n\n";
body += ph5_backendTableSourceResize(table);
body += ph5_backendTableSourceClear(table);
body += ph5_backendTableSourceAllocate(table);
return body; return body;
} }
......
...@@ -52,12 +52,15 @@ void ConfigParser::copyConfigParser(const ConfigParser & other){ ...@@ -52,12 +52,15 @@ void ConfigParser::copyConfigParser(const ConfigParser & other){
*/ */
bool ConfigParser::parseFile(){ bool ConfigParser::parseFile(){
if(!p_run) return false; if(!p_run) return false;
p_lastDocString = "";
PSource source; PSource source;
source.setName(getFileName(p_parser->getFileName())); source.setName(getFileName(p_parser->getFileName()));
//To parse the file we need to read char by char until we get something we know //To parse the file we need to read char by char until we get something we know
while(!p_parser->isEndOfFile() && p_run){ //If we are not at the end of the file while(!p_parser->isEndOfFile() && p_run){ //If we are not at the end of the file
PTable table; PTable table;
if(parseTable(table)){ if(parseDocString()){}
else if(p_parser->isMatch("//")){p_parser->getUntilKeyWithoutPatern("\n");} //Skip comment
else if(parseTable(table)){
source.getVecTable().push_back(table); source.getVecTable().push_back(table);
}else{ }else{
errorAt(); errorAt();
...@@ -85,6 +88,16 @@ void ConfigParser::initialisationConfigParser(){ ...@@ -85,6 +88,16 @@ void ConfigParser::initialisationConfigParser(){
} }
///Parse a doc string
/** @return true on success, false otherwise
*/
bool ConfigParser::parseDocString(){
if(!p_parser->isMatch("///")){return false;}
p_lastDocString = p_parser->getUntilKeyWithoutPatern("\n");
return true;
}
///Parse a PTable ///Parse a PTable
/** @param[out] table : PTable to be parsed /** @param[out] table : PTable to be parsed
* @return true on success, false otherwise * @return true on success, false otherwise
...@@ -92,6 +105,8 @@ void ConfigParser::initialisationConfigParser(){ ...@@ -92,6 +105,8 @@ void ConfigParser::initialisationConfigParser(){
bool ConfigParser::parseTable(PTable & table){ bool ConfigParser::parseTable(PTable & table){
std::string tableName(p_parser->getNextToken()); std::string tableName(p_parser->getNextToken());
std::string dataSetName(tableName); std::string dataSetName(tableName);
table.setDocString(p_lastDocString);
p_lastDocString = "";
if(p_parser->isMatch("[")){ if(p_parser->isMatch("[")){
dataSetName = p_parser->getUntilKeyWithoutPatern("]"); dataSetName = p_parser->getUntilKeyWithoutPatern("]");
} }
...@@ -105,7 +120,9 @@ bool ConfigParser::parseTable(PTable & table){ ...@@ -105,7 +120,9 @@ bool ConfigParser::parseTable(PTable & table){
while(!p_parser->isEndOfFile() && !p_parser->isMatch("}") && p_run){ while(!p_parser->isEndOfFile() && !p_parser->isMatch("}") && p_run){
PAttribute attr; PAttribute attr;
if(parseAttribute(attr)){ if(parseDocString()){}
else if(p_parser->isMatch("//")){p_parser->getUntilKeyWithoutPatern("\n");} //Skip comment
else if(parseAttribute(attr)){
table.getVecAttribute().push_back(attr); table.getVecAttribute().push_back(attr);
}else{ }else{
errorAt(); errorAt();
...@@ -123,6 +140,8 @@ bool ConfigParser::parseTable(PTable & table){ ...@@ -123,6 +140,8 @@ bool ConfigParser::parseTable(PTable & table){
*/ */
bool ConfigParser::parseAttribute(PAttribute & attr){ bool ConfigParser::parseAttribute(PAttribute & attr){
if(p_parser->isMatchRewind("}")){return true;} if(p_parser->isMatchRewind("}")){return true;}
attr.setDocString(p_lastDocString);
p_lastDocString = "";
std::string type(""); std::string type("");
if(p_parser->isMatch("Tensor")){ if(p_parser->isMatch("Tensor")){
if(!p_parser->isMatch("(")){ if(!p_parser->isMatch("(")){
......
...@@ -30,10 +30,14 @@ class ConfigParser : public PMultiFileParser{ ...@@ -30,10 +30,14 @@ class ConfigParser : public PMultiFileParser{
private: private:
void initialisationConfigParser(); void initialisationConfigParser();
bool parseDocString();
bool parseTable(PTable & table); bool parseTable(PTable & table);
bool parseAttribute(PAttribute & attr); bool parseAttribute(PAttribute & attr);
bool parseDimention(PDimention & dim); bool parseDimention(PDimention & dim);
///Last documentation string
std::string p_lastDocString;
///Vector of parsed PSource ///Vector of parsed PSource
PVecSource p_vecSource; PVecSource p_vecSource;
}; };
......
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