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

Add getters and setters

parent d949871e
......@@ -23,6 +23,45 @@ std::string ph5_licenceSaveStr(){
return body;
}
///Save the header of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableHeaderSetter(const PTable & table){
std::string body("");
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
std::string type(it->getType());
if(ph5_attributeIsTensor(*it)){
body += "\t\tvoid set" + firstToUpper(it->getName()) + "(size_t i, const "+type+" * tabVal);\n";
}else{
body += "\t\tvoid set" + firstToUpper(it->getName()) + "(size_t i, "+type+" val);\n";
}
}
return body;
}
///Save the header of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableHeaderGetter(const PTable & table){
std::string body("");
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
std::string type(it->getType());
if(ph5_attributeIsTensor(*it)){
body += "\t\tconst "+type+" * get" + firstToUpper(it->getName()) + "(size_t i) const;\n";
body += "\t\t"+type+" * get" + firstToUpper(it->getName()) + "(size_t i);\n";
}else{
body += "\t\t"+type+" get" + firstToUpper(it->getName()) + "(size_t i) const;\n";
body += "\t\t"+type+" & get" + firstToUpper(it->getName()) + "(size_t i);\n";
}
}
return body;
}
///Save the header of the given PTable
/** @param table : PTable to be used
* @return corresponding string
......@@ -101,6 +140,9 @@ std::string ph5_backendTableHeader(const PTable & table){
body += "\t\tvoid write(H5::H5File & file) const;\n";
body += "\t\tvoid write(H5::Group & group) const;\n\n";
body += ph5_backendTableHeaderSetter(table);
body += ph5_backendTableHeaderGetter(table);
body += "\n";
body += ph5_backendTableHeaderOffset(table);
body += ph5_backendTableHeaderCompType(table);
body += ph5_backendTableHeaderDataType(table);
......@@ -225,6 +267,79 @@ std::string ph5_backendTableSourceWrite(const PTable & table){
return body;
}
///Save the header of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableSourceSetter(const PTable & table){
std::string body(""), name(table.getName());
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
std::string type(it->getType());
body += "///Set the attribute "+it->getName()+" (column "+it->getColName()+")\n";
if(ph5_attributeIsTensor(*it)){
body += "/**\t@param i : index of the row to be used\n";
body += " * \t@param tabVal : table of value to be copied\n";
body += "*/\n";
body += "void " + name + "::set" + firstToUpper(it->getName()) + "(size_t i, const "+type+" * tabVal){\n";
body += "\tsize_t sizeRow("+ph5_getFullAttributeElement(*it)+");\n";
body += "\tmemcpy(p_"+it->getName()+" + i*sizeRow, tabVal, sizeRow);\n";
body += "}\n\n";
}else{
body += "/**\t@param i : index of the row to be used\n";
body += " * \t@param val : value to be copied\n";
body += "*/\n";
body += "void " + name + "::set" + firstToUpper(it->getName()) + "(size_t i, "+type+" val){\n";
body += "\tp_"+it->getName()+"[i] = val;\n";
body += "}\n\n";
}
}
return body;
}
///Save the header of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableSourceGetter(const PTable & table){
std::string body(""), name(table.getName());
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
std::string type(it->getType());
if(ph5_attributeIsTensor(*it)){
std::string docString("");
docString += "///Get the tensor i of the attribute "+it->getName()+" (column "+it->getColName()+")\n";
docString += "/**\t@param i : index of the row to be used\n";
docString += " * \t@return pointer to the corresponding tensor\n";
docString += "*/\n";
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 += "}\n\n";
body += docString;
body += type+" * " + name + "::get" + firstToUpper(it->getName()) + "(size_t i){\n";
body += "return p_"+it->getName()+" + i**"+sizeElement+";\n";
body += "}\n\n";
}else{
std::string docString("");
docString += "///Get the value i of the attribute "+it->getName()+" (column "+it->getColName()+")\n";
docString += "/**\t@param i : index of the row to be used\n";
docString += " * \t@return corresponding value\n";
docString += "*/\n";
body += docString;
body += type+" " + name + "::get" + firstToUpper(it->getName()) + "(size_t i) const{\n";
body += "\treturn p_"+it->getName()+"[i];\n";
body += "}\n\n";
body += docString;
body += type+" & " + name + "::get" + firstToUpper(it->getName()) + "(size_t i){\n";
body += "\treturn p_"+it->getName()+"[i];\n";
body += "}\n\n";
}
}
return body;
}
///Get the size of a column
/** @param attr : PAttribute to be used
* @return corresponding string
......@@ -437,6 +552,9 @@ std::string ph5_backendTableSource(const PTable & table){
body += ph5_backendTableSourceRead(table);
body += ph5_backendTableSourceWrite(table);
body += ph5_backendTableSourceSetter(table);
body += ph5_backendTableSourceGetter(table);
body += ph5_backendTableSourceOffset(table);
body += ph5_backendTableSourceCompType(table);
body += ph5_backendTableSourceDataType(table);
......@@ -454,6 +572,7 @@ std::string ph5_backendTableSource(const PTable & table){
*/
std::string ph5_backendSource(const PSource & source){
std::string body(ph5_licenceSaveStr());
body += "#include <string.h>\n";
body += "#include \""+eraseExtension(source.getName())+".h\"\n\n";
const PVecTable & vecTable = source.getVecTable();
for(PVecTable::const_iterator it(vecTable.begin()); it != vecTable.end(); ++it){
......
......@@ -9,13 +9,14 @@
///Convert a PDimention into a string
/** @param dim : dimention to be converted
* @param prefix : variable prefix
* @return corresponding string
*/
std::string ph5_dimentionToStr(const PDimention & dim){
std::string ph5_dimentionToStr(const PDimention & dim, const std::string & prefix){
if(dim.getIsValue()){
return convertToString(dim.getValue()) + "lu";
}else{
return dim.getName();
return prefix + dim.getName();
}
}
......@@ -26,3 +27,19 @@ bool ph5_attributeIsTensor(const PAttribute & attr){
return attr.getVecDim().size() != 0lu;
}
///Get the number of elements of an attribute
/** @param attr : attribute to be used
* @return number of elements of the attribute
*/
std::string ph5_getFullAttributeElement(const PAttribute & attr){
std::string body("");
bool addMult(false);
const PVecDim & vecDim = attr.getVecDim();
for(PVecDim::const_iterator it(vecDim.begin()); it != vecDim.end(); ++it){
if(addMult){body += "*";}
body += ph5_dimentionToStr(*it, "p_");
addMult = true;
}
return body;
}
......@@ -14,7 +14,8 @@ typedef std::vector<PAttribute> PVecAttribute;
typedef std::vector<PTable> PVecTable;
typedef std::vector<PSource> PVecSource;
std::string ph5_dimentionToStr(const PDimention & dim);
std::string ph5_dimentionToStr(const PDimention & dim, const std::string & prefix = "");
bool ph5_attributeIsTensor(const PAttribute & attr);
std::string ph5_getFullAttributeElement(const PAttribute & attr);
#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