Commit 19c5e4cd authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add getter and setter for tensor dimention

parent bf087d72
......@@ -5,6 +5,8 @@ TableParameters{
float x;
///Position on the y axis
float y;
///Table of value
Tensor(float, nbCol) tabValue;
}
......
......@@ -121,6 +121,8 @@ std::string ph5_backendTableHeaderAttribute(const PTable & table){
* @return corresponding string
*/
std::string ph5_backendTableHeader(const PTable & table){
PVecStr vecDimVar = ph5_getDimName(table);
std::string body("");
if(table.getDocString() != ""){
body += "///" + table.getDocString() + "\n";
......@@ -147,12 +149,33 @@ std::string ph5_backendTableHeader(const PTable & table){
body += ph5_backendTableHeaderCompType(table);
body += ph5_backendTableHeaderDataType(table);
body += "\n\t\tvoid setAllDim(";
bool addComma(false);
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
if(addComma){body += ", ";}
body += "size_t " + (*it);
addComma = true;
}
body += ");\n";
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
body += "\t\tvoid set"+firstToUpper(*it)+"(size_t val);\n";
body += "\t\tsize_t get"+firstToUpper(*it)+"() const;\n";
}
body += "\tprivate:\n";
body += "\t\tvoid readDataSet(const H5::DataSet & dataset);\n";
body += "\t\tvoid writeDataSet(H5::DataSet & dataset) const;\n";
body += "\t\tvoid allocate(size_t nbRow);\n";
body += "\t\tvoid allocate(size_t nbRow);\n\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\n";
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
body += "\t\t///Tensor dimension "+(*it)+"\n";
body += "\t\tsize_t p_"+(*it)+";\n";
}
body += "\n";
body += ph5_backendTableHeaderAttribute(table);
body += "};\n\n";
......@@ -188,7 +211,7 @@ std::string ph5_backendTableSourceResize(const PTable & table){
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 += "\tif(nbRow == p__nbRow){return;} //Nothing to do\n";
body += "\tclear()\n";
body += "\tallocate(nbRow);\n";
body += "}\n\n";
......@@ -248,7 +271,7 @@ std::string ph5_backendTableSourceWrite(const PTable & table){
body += "*/\n";
body += "void " + name + "::write(const H5::H5File & file) const{\n";
body += "\thsize_t dim[1];\n";
body += "\tdim[0] = p_nbRow;\n";
body += "\tdim[0] = p__nbRow;\n";
body += "\tH5::DataSpace space(1, dim);\n";
body += "\tH5::DataSet dataset = file.createDataSet(\""+table.getDataSetName()+"\", " + name + "::getCompTypeAll(), space);\n";
body += "\twriteDataSet(dataset);\n";
......@@ -259,7 +282,7 @@ std::string ph5_backendTableSourceWrite(const PTable & table){
body += "*/\n";
body += "void " + name + "::write(const H5::Group & group) const{\n";
body += "\thsize_t dim[1];\n";
body += "\tdim[0] = p_nbRow;\n";
body += "\tdim[0] = p__nbRow;\n";
body += "\tH5::DataSpace space(1, dim);\n";
body += "\tH5::DataSet dataset = group.createDataSet(\""+table.getDataSetName()+"\", " + name + "::getCompTypeAll(), space);\n";
body += "\twriteDataSet(dataset);\n";
......@@ -315,11 +338,11 @@ std::string ph5_backendTableSourceGetter(const PTable & table){
body += docString;
std::string sizeElement(ph5_getFullAttributeElement(*it));
body += "const "+type+" * " + name + "::get" + firstToUpper(it->getName()) + "(size_t i) const{\n";
body += "return p_"+it->getName()+" + i*"+sizeElement+";\n";
body += "\treturn p_"+it->getName()+" + i*"+sizeElement+";\n";
body += "}\n\n";
body += docString;
body += type+" * " + name + "::get" + firstToUpper(it->getName()) + "(size_t i){\n";
body += "return p_"+it->getName()+" + i**"+sizeElement+";\n";
body += "\treturn p_"+it->getName()+" + i*"+sizeElement+";\n";
body += "}\n\n";
}else{
std::string docString("");
......@@ -340,6 +363,50 @@ std::string ph5_backendTableSourceGetter(const PTable & table){
return body;
}
///Create all the dimention getter and setters of the Table
/** @param table : PTable to be used
* @return C++ string
*/
std::string ph5_backendTableSourceDimGetterSetter(const PTable & table){
std::string body(""), name(table.getName());
PVecStr vecDimVar = ph5_getDimName(table);
body += "///Set all the dimentions of the Tensor in the table\n";
std::string docPrefix("/**");
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
body += docPrefix + "\t@param "+(*it)+" : set the tensor dimention "+(*it)+"\n";
docPrefix = " * ";
}
body += "*/\n";
body += "void " + name + "::setAllDim(";
bool addComma(false);
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
if(addComma){body += ", ";}
body += "size_t " + (*it);
addComma = true;
}
body += "){\n";
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
body += "\tset"+firstToUpper(*it)+"("+(*it)+");\n";
}
body += "}\n\n";
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
body += "///Set the Tensor dimention "+(*it)+"\n";
body += "/**\t@param val : set the tensor dimention "+(*it)+"\n";
body += "*/\n";
body += "void " + name + "::set"+firstToUpper(*it)+"(size_t val){\n";
body += "\t p_" + (*it) + " = val;\n";
body += "}\n\n";
body += "///Get the Tensor dimention "+(*it)+"\n";
body += "/**\t@return the tensor dimention "+(*it)+"\n";
body += "*/\n";
body += "size_t " + name + "::get"+firstToUpper(*it)+"() const{\n";
body += "\treturn p_" + (*it) + ";\n";
body += "}\n\n";
}
return body;
}
///Get the size of a column
/** @param attr : PAttribute to be used
* @return corresponding string
......@@ -348,7 +415,7 @@ std::string ph5_getSizeOfCol(const PAttribute & attr){
std::string body("sizeof("+attr.getType()+")");
const PVecDim & vecDim = attr.getVecDim();
for(PVecDim::const_iterator it(vecDim.begin()); it != vecDim.end(); ++it){
body += "*" + ph5_dimentionToStr(*it);
body += "*" + ph5_dimentionToStr(*it, "p_");
}
return body;
}
......@@ -441,7 +508,7 @@ std::string ph5_getTypeHDF5(const PAttribute & attr){
body += "\thsize_t dims["+convertToString(vecDim.size())+"];\n";
size_t i(0lu);
for(PVecDim::const_iterator it(vecDim.begin()); it != vecDim.end(); ++it){
body += "\tdims["+convertToString(i)+"] = "+ ph5_dimentionToStr(*it) +";\n";
body += "\tdims["+convertToString(i)+"] = "+ ph5_dimentionToStr(*it, "p_") +";\n";
}
body += "\tH5::ArrayType arrayType("+ph5_cTypeToHDF5(attr.getType())+", "+convertToString(vecDim.size())+", dims);\n";
body += "\treturn arrayType;\n";
......@@ -518,10 +585,15 @@ std::string ph5_backendTableSourceAllocate(const PTable & table){
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";
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";
if(ph5_attributeIsTensor(*it)){
body += "\tp_"+it->getName()+" = new "+it->getType()+"[p__nbRow*"+ph5_getFullAttributeElement(*it)+"];\n";
}else{
body += "\tp_"+it->getName()+" = new "+it->getType()+"[p__nbRow];\n";
}
}
body += "}\n\n";
return body;
......@@ -535,7 +607,11 @@ 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 += "\tp__nbRow = 0lu;\n";
PVecStr vecDimVar = ph5_getDimName(table);
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
body += "\tp_" + (*it) + " = 0lu;\n";
}
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "\tp_"+it->getName()+" = NULL;\n";
......@@ -555,6 +631,8 @@ std::string ph5_backendTableSource(const PTable & table){
body += ph5_backendTableSourceSetter(table);
body += ph5_backendTableSourceGetter(table);
body += ph5_backendTableSourceDimGetterSetter(table);
body += ph5_backendTableSourceOffset(table);
body += ph5_backendTableSourceCompType(table);
body += ph5_backendTableSourceDataType(table);
......
......@@ -4,6 +4,7 @@
Licence : CeCILL-C
****************************************/
#include <map>
#include "convertToString.h"
#include "representation.h"
......@@ -43,3 +44,25 @@ std::string ph5_getFullAttributeElement(const PAttribute & attr){
return body;
}
///Get all the variable which are a flexible dimention
/** @param table : PTable to be used
* @return vector of variables which are flexible dimention
*/
PVecStr ph5_getDimName(const PTable & table){
std::map<std::string, bool> mapStr;
const PVecAttribute & vecAttr = table.getVecAttribute();
for(PVecAttribute::const_iterator itAttr(vecAttr.begin()); itAttr != vecAttr.end(); ++itAttr){
if(!ph5_attributeIsTensor(*itAttr)){continue;}
const PVecDim & vecDim = itAttr->getVecDim();
for(PVecDim::const_iterator it(vecDim.begin()); it != vecDim.end(); ++it){
if(it->getIsValue()){continue;}
mapStr[it->getName()] = true;
}
}
PVecStr vecString;
for(std::map<std::string, bool>::iterator it(mapStr.begin()); it != mapStr.end(); ++it){
vecString.push_back(it->first);
}
return vecString;
}
......@@ -9,6 +9,7 @@
#include "PRepr.h"
typedef std::vector<std::string> PVecStr;
typedef std::vector<PDimention> PVecDim;
typedef std::vector<PAttribute> PVecAttribute;
typedef std::vector<PTable> PVecTable;
......@@ -18,4 +19,6 @@ std::string ph5_dimentionToStr(const PDimention & dim, const std::string & prefi
bool ph5_attributeIsTensor(const PAttribute & attr);
std::string ph5_getFullAttributeElement(const PAttribute & attr);
PVecStr ph5_getDimName(const PTable & table);
#endif
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