Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
CTA-LAPP
PHOENIX_LIBS
PhoenixHDF5
Commits
01c08c19
Commit
01c08c19
authored
Nov 24, 2020
by
Pierre Aubert
Browse files
Add get Type/CompType/Offset
parent
4ae8277c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
170 additions
and
4 deletions
+170
-4
src/BackEnd/backend.cpp
src/BackEnd/backend.cpp
+162
-3
src/Representation/representation.cpp
src/Representation/representation.cpp
+7
-1
src/Representation/representation.h
src/Representation/representation.h
+1
-0
No files found.
src/BackEnd/backend.cpp
View file @
01c08c19
...
@@ -23,16 +23,40 @@ std::string ph5_licenceSaveStr(){
...
@@ -23,16 +23,40 @@ std::string ph5_licenceSaveStr(){
return
body
;
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\t
static size_t getOffset"
+
firstToUpper
(
it
->
getName
())
+
"();
\n
"
;
}
return
body
;
}
///Save the header of the given PTable
///Save the header of the given PTable
/** @param table : PTable to be used
/** @param table : PTable to be used
* @return corresponding string
* @return corresponding string
*/
*/
std
::
string
ph5_backendTableHeaderCompType
(
const
PTable
&
table
){
std
::
string
ph5_backendTableHeaderCompType
(
const
PTable
&
table
){
std
::
string
body
(
"
\t\t
static H5::CompType getTypeAll();
\n
"
);
std
::
string
body
(
"
\t\t
static H5::CompType get
Comp
TypeAll();
\n
"
);
const
PVecAttribute
&
vecAttriute
=
table
.
getVecAttribute
();
const
PVecAttribute
&
vecAttriute
=
table
.
getVecAttribute
();
for
(
PVecAttribute
::
const_iterator
it
(
vecAttriute
.
begin
());
it
!=
vecAttriute
.
end
();
++
it
){
for
(
PVecAttribute
::
const_iterator
it
(
vecAttriute
.
begin
());
it
!=
vecAttriute
.
end
();
++
it
){
body
+=
"
\t\t
static H5::CompType getType"
+
firstToUpper
(
it
->
getName
())
+
"();
\n
"
;
body
+=
"
\t\t
static 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\t
static H5::DataType getType"
+
firstToUpper
(
it
->
getName
())
+
"();
\n
"
;
}
}
return
body
;
return
body
;
}
}
...
@@ -77,7 +101,9 @@ std::string ph5_backendTableHeader(const PTable & table){
...
@@ -77,7 +101,9 @@ std::string ph5_backendTableHeader(const PTable & table){
body
+=
"
\t\t
void write(H5::H5File & file) const;
\n
"
;
body
+=
"
\t\t
void write(H5::H5File & file) const;
\n
"
;
body
+=
"
\t\t
void write(H5::Group & group) const;
\n\n
"
;
body
+=
"
\t\t
void write(H5::Group & group) const;
\n\n
"
;
body
+=
ph5_backendTableHeaderOffset
(
table
);
body
+=
ph5_backendTableHeaderCompType
(
table
);
body
+=
ph5_backendTableHeaderCompType
(
table
);
body
+=
ph5_backendTableHeaderDataType
(
table
);
body
+=
"
\t
private:
\n
"
;
body
+=
"
\t
private:
\n
"
;
body
+=
"
\t\t
void allocate(size_t nbRow);
\n
"
;
body
+=
"
\t\t
void allocate(size_t nbRow);
\n
"
;
...
@@ -143,6 +169,136 @@ std::string ph5_backendTableSourceClear(const PTable & table){
...
@@ -143,6 +169,136 @@ std::string ph5_backendTableSourceClear(const PTable & table){
return
body
;
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
+=
"
\t
return 0lu;
\n
"
;
}
else
{
body
+=
"
\t
return "
+
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
+=
"
\t
size_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
+=
"
\t
H5::CompType typeCol(sizeAll);
\n
"
;
for
(
PVecAttribute
::
const_iterator
it
(
vecAttriute
.
begin
());
it
!=
vecAttriute
.
end
();
++
it
){
body
+=
"
\t
typeCol.insertMember(
\"
"
+
it
->
getColName
()
+
"
\"
, "
+
name
+
"::getOffset"
+
firstToUpper
(
it
->
getName
())
+
"(),"
+
name
+
"::getType"
+
firstToUpper
(
it
->
getName
())
+
"());
\n
"
;
}
body
+=
"
\t
return 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
+=
"
\t
H5::CompType typeCol("
+
ph5_getSizeOfCol
(
*
it
)
+
");
\n
"
;
body
+=
"
\t
datasetTypeX.insertMember(
\"
"
+
it
->
getColName
()
+
"
\"
, 0, "
+
name
+
"::getType"
+
firstToUpper
(
it
->
getName
())
+
"());
\n
"
;
body
+=
"
\t
return 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
+=
"
\t
hsize_t dims["
+
convertToString
(
vecDim
.
size
())
+
"];
\n
"
;
size_t
i
(
0lu
);
for
(
PVecDim
::
const_iterator
it
(
vecDim
.
begin
());
it
!=
vecDim
.
end
();
++
it
){
body
+=
"
\t
dims["
+
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
///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
...
@@ -184,6 +340,9 @@ std::string ph5_backendTableSource(const PTable & table){
...
@@ -184,6 +340,9 @@ std::string ph5_backendTableSource(const PTable & table){
body
+=
ph5_backendTableSourceResize
(
table
);
body
+=
ph5_backendTableSourceResize
(
table
);
body
+=
ph5_backendTableSourceClear
(
table
);
body
+=
ph5_backendTableSourceClear
(
table
);
body
+=
ph5_backendTableSourceOffset
(
table
);
body
+=
ph5_backendTableSourceCompType
(
table
);
body
+=
ph5_backendTableSourceDataType
(
table
);
body
+=
ph5_backendTableSourceAllocate
(
table
);
body
+=
ph5_backendTableSourceAllocate
(
table
);
return
body
;
return
body
;
...
...
src/Representation/representation.cpp
View file @
01c08c19
...
@@ -13,10 +13,16 @@
...
@@ -13,10 +13,16 @@
*/
*/
std
::
string
ph5_dimentionToStr
(
const
PDimention
&
dim
){
std
::
string
ph5_dimentionToStr
(
const
PDimention
&
dim
){
if
(
dim
.
getIsValue
()){
if
(
dim
.
getIsValue
()){
return
convertToString
(
dim
.
getValue
());
return
convertToString
(
dim
.
getValue
())
+
"lu"
;
}
else
{
}
else
{
return
dim
.
getName
();
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
;
}
src/Representation/representation.h
View file @
01c08c19
...
@@ -15,5 +15,6 @@ typedef std::vector<PTable> PVecTable;
...
@@ -15,5 +15,6 @@ typedef std::vector<PTable> PVecTable;
typedef
std
::
vector
<
PSource
>
PVecSource
;
typedef
std
::
vector
<
PSource
>
PVecSource
;
std
::
string
ph5_dimentionToStr
(
const
PDimention
&
dim
);
std
::
string
ph5_dimentionToStr
(
const
PDimention
&
dim
);
bool
ph5_attributeIsTensor
(
const
PAttribute
&
attr
);
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment