Commit 01c08c19 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add get Type/CompType/Offset

parent 4ae8277c
......@@ -23,16 +23,40 @@ 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_backendTableHeaderOffset(const PTable & table){
std::string body("\t\t");
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "\t\tstatic size_t getOffset" + 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_backendTableHeaderCompType(const PTable & table){
std::string body("\t\tstatic H5::CompType getTypeAll();\n");
std::string body("\t\tstatic H5::CompType getCompTypeAll();\n");
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "\t\tstatic H5::CompType getCompType" + 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_backendTableHeaderDataType(const PTable & table){
std::string body("");
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";
body += "\t\tstatic H5::DataType getType" + firstToUpper(it->getName()) + "();\n";
}
return body;
}
......@@ -77,7 +101,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_backendTableHeaderOffset(table);
body += ph5_backendTableHeaderCompType(table);
body += ph5_backendTableHeaderDataType(table);
body += "\tprivate:\n";
body += "\t\tvoid allocate(size_t nbRow);\n";
......@@ -143,6 +169,136 @@ std::string ph5_backendTableSourceClear(const PTable & table){
return body;
}
///Get the size of a column
/** @param attr : PAttribute to be used
* @return corresponding string
*/
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);
}
return body;
}
///Save the header of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableSourceOffset(const PTable & table){
std::string body(""), name(table.getName()), prevAttribute(""), prevAttributeSize("");
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "///Get the offset of the attribute " + it->getName() + "\n";
body += "/**\t@return offset of the attribute in bytes\n";
body += "*/\n";
body += "size_t " + name + "::getOffset" + firstToUpper(it->getName()) + "(){\n" ;
if(prevAttribute == "" && prevAttributeSize == ""){
body += "\treturn 0lu;\n";
}else{
body += "\treturn " + name + "::getOffset" + firstToUpper(prevAttribute) + "() + " + prevAttributeSize + ";\n";
}
body += "}\n\n";
prevAttribute = it->getName();
prevAttributeSize = ph5_getSizeOfCol(*it);
}
return body;
}
///Save the header of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableSourceCompType(const PTable & table){
std::string body(""), name(table.getName());
const PVecAttribute & vecAttriute = table.getVecAttribute();
body += "H5::CompType "+name+"::getCompTypeAll(){\n";
body += "\tsize_t sizeAll(";
bool addPlus(false);
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
if(addPlus){body += " + ";}
body += ph5_getSizeOfCol(*it);
}
body += ");\n";
body += "\tH5::CompType typeCol(sizeAll);\n";
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "\ttypeCol.insertMember(\""+it->getColName()+"\", " + name + "::getOffset" + firstToUpper(it->getName()) + "(),"+
name+"::getType" + firstToUpper(it->getName()) + "());\n";
}
body += "\treturn typeCol;\n";
body += "}\n\n";
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "///Get DataType of attribute "+it->getName() +" (column " + it->getColName() + ")\n";
body += "/**\t@return DataType of the attribute "+it->getName() +"\n";
body += "*/\n";
body += "H5::CompType "+name+"::getCompType" + firstToUpper(it->getName()) + "(){\n";
body += "\tH5::CompType typeCol("+ph5_getSizeOfCol(*it)+");\n";
body += "\tdatasetTypeX.insertMember(\""+it->getColName()+"\", 0, "+name+"::getType" + firstToUpper(it->getName()) + "());\n";
body += "\treturn typeCol;\n";
body += "}\n\n";
}
return body;
}
///Convert a C type into an HDF5 type
/** @param type : C type to be converted
* @return HDF5 type
*/
std::string ph5_cTypeToHDF5(const std::string & type){
if(type == "char"){return "H5::PredType::NATIVE_INT8";}
else if(type == "unsinged char"){return "H5::PredType::NATIVE_UINT8";}
else if(type == "short"){return "H5::PredType::NATIVE_INT16";}
else if(type == "unsigned short"){return "H5::PredType::NATIVE_UINT16";}
else if(type == "int"){return "H5::PredType::NATIVE_INT";}
else if(type == "unsigned int"){return "H5::PredType::NATIVE_UINT";}
else if(type == "float"){return "H5::PredType::NATIVE_FLOAT";}
else if(type == "double"){return "H5::PredType::NATIVE_DOUBLE";}
return "";
}
///Get the corresponding HDF5 type of the given PAttribute
/** @param attr : PAttribute to be used
* @return corresponding HDF5 type
*/
std::string ph5_getTypeHDF5(const PAttribute & attr){
std::string body("");
if(ph5_attributeIsTensor(attr)){
const PVecDim & vecDim = attr.getVecDim();
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 += "H5::ArrayType arrayType("+ph5_cTypeToHDF5(attr.getType())+", "+convertToString(vecDim.size())+", dims);\n";
body += "return arrayType;";
}else{
body += "return " + ph5_cTypeToHDF5(attr.getType());
}
return body;
}
///Save the header of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableSourceDataType(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){
body += "///Get DataType of attribute "+it->getName() +" (column " + it->getColName() + ")\n";
body += "/**\t@return DataType of the attribute "+it->getName() +"\n";
body += "*/\n";
body += "H5::DataType "+name+"::getType" + firstToUpper(it->getName()) + "(){\n";
body += ph5_getTypeHDF5(*it);
body += "}\n\n";
}
return body;
}
///Save the source of the given PTable
/** @param table : PTable to be used
* @return corresponding string
......@@ -184,6 +340,9 @@ std::string ph5_backendTableSource(const PTable & table){
body += ph5_backendTableSourceResize(table);
body += ph5_backendTableSourceClear(table);
body += ph5_backendTableSourceOffset(table);
body += ph5_backendTableSourceCompType(table);
body += ph5_backendTableSourceDataType(table);
body += ph5_backendTableSourceAllocate(table);
return body;
......
......@@ -13,10 +13,16 @@
*/
std::string ph5_dimentionToStr(const PDimention & dim){
if(dim.getIsValue()){
return convertToString(dim.getValue());
return convertToString(dim.getValue()) + "lu";
}else{
return dim.getName();
}
}
///Say if the given PAttribute is a tensor or not
/** @return true if the given PAttribute is a tensor, false if not
*/
bool ph5_attributeIsTensor(const PAttribute & attr){
return attr.getVecDim().size() != 0lu;
}
......@@ -15,5 +15,6 @@ typedef std::vector<PTable> PVecTable;
typedef std::vector<PSource> PVecSource;
std::string ph5_dimentionToStr(const PDimention & dim);
bool ph5_attributeIsTensor(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