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
Docker-in-Docker (DinD) capabilities of public runners deactivated.
More info
Open sidebar
CTA-LAPP
PHOENIX_LIBS
PhoenixHDF5
Commits
1c3d359d
Commit
1c3d359d
authored
Nov 25, 2020
by
Pierre Aubert
Browse files
Add test with type
parent
6020c644
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
156 additions
and
26 deletions
+156
-26
TESTS/CMakeLists.txt
TESTS/CMakeLists.txt
+1
-0
TESTS/TEST_TYPE/CMakeLists.txt
TESTS/TEST_TYPE/CMakeLists.txt
+14
-0
TESTS/TEST_TYPE/configType.ph5
TESTS/TEST_TYPE/configType.ph5
+20
-0
TESTS/TEST_TYPE/main.cpp
TESTS/TEST_TYPE/main.cpp
+79
-0
src/BackEnd/backend.cpp
src/BackEnd/backend.cpp
+28
-24
src/FrontEnd/ConfigParser.cpp
src/FrontEnd/ConfigParser.cpp
+13
-2
src/FrontEnd/ConfigParser.h
src/FrontEnd/ConfigParser.h
+1
-0
No files found.
TESTS/CMakeLists.txt
View file @
1c3d359d
...
...
@@ -10,4 +10,5 @@ message(STATUS "HDF5_CXX_LIBRARIES = ${HDF5_CXX_LIBRARIES}")
include
(
callGenerator.cmake
)
add_subdirectory
(
TEST_BASE_CONFIG
)
add_subdirectory
(
TEST_TYPE
)
TESTS/TEST_TYPE/CMakeLists.txt
0 → 100644
View file @
1c3d359d
project
(
Phoenix
)
cmake_minimum_required
(
VERSION 2.8
)
include_directories
(
${
CMAKE_CURRENT_BINARY_DIR
}
)
call_generator
(
test_type_lib configType.ph5
)
add_executable
(
test_type main.cpp
)
target_link_libraries
(
test_type test_type_lib
${
HDF5_CXX_LIBRARIES
}
)
add_test
(
NAME TestType
COMMAND
${
CMAKE_CURRENT_BINARY_DIR
}
/test_type
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
)
TESTS/TEST_TYPE/configType.ph5
0 → 100644
View file @
1c3d359d
///Table of types
TableType{
///Float value
float valFloat;
///Double value
float valDouble;
///In value
int valInt;
///Short value
short valShort;
///Char value
char valChar;
///unsigned int value
unsigned int valUInt;
}
TESTS/TEST_TYPE/main.cpp
0 → 100644
View file @
1c3d359d
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include "configType.h"
///Test to write data
/** @param fileName : name of the file to be written
* @return true on success, false otherwise
*/
bool
testWriteData
(
const
std
::
string
&
fileName
){
TableType
table
;
size_t
nbRow
(
10lu
);
table
.
resize
(
nbRow
);
//Let's set some values in the Table
for
(
size_t
i
(
0lu
);
i
<
nbRow
;
++
i
){
table
.
setValFloat
(
i
,
i
);
table
.
setValDouble
(
i
,
2lu
*
i
);
table
.
setValInt
(
i
,
3lu
*
i
);
table
.
setValShort
(
i
,
4lu
*
i
);
table
.
setValUInt
(
i
,
5lu
*
i
);
table
.
setValChar
(
i
,
i
);
}
//Now let's open a file
H5
::
H5File
file
(
fileName
,
H5F_ACC_TRUNC
);
//And write our table directly in it
table
.
write
(
file
);
//We can also explicitly cloase the file, otherwise it will do it automatically
file
.
close
();
return
true
;
}
///Test to read data
/** @param fileName : name of the file to be read
* @return true on success, false otherwise
*/
bool
testReadData
(
const
std
::
string
&
fileName
){
//First let's open a file in read only mode (better for concurencial access)
H5
::
H5File
file
(
fileName
,
H5F_ACC_RDONLY
);
//Let's create our table
TableType
table
;
//Add read the file
table
.
read
(
file
);
//Now we can close the file and use the Table directly
file
.
close
();
//Get the number of rows and number of columns
size_t
nbRow
=
table
.
getNbRow
();
bool
b
(
true
);
for
(
size_t
i
(
0lu
);
i
<
nbRow
;
++
i
){
b
&=
table
.
getValFloat
(
i
)
==
i
;
b
&=
table
.
getValDouble
(
i
)
==
2lu
*
i
;
b
&=
table
.
getValInt
(
i
)
==
(
int
)(
3lu
*
i
);
b
&=
table
.
getValShort
(
i
)
==
(
short
)(
4lu
*
i
);
b
&=
table
.
getValUInt
(
i
)
==
5lu
*
i
;
b
&=
table
.
getValChar
(
i
)
==
(
char
)
i
;
}
return
b
;
}
int
main
(
int
argc
,
char
**
argv
){
std
::
string
fileName
(
"configType.h5"
);
if
(
!
testWriteData
(
fileName
)){
std
::
cerr
<<
"Cannot write file '"
<<
fileName
<<
"'"
<<
std
::
endl
;
return
-
1
;
}
if
(
!
testReadData
(
fileName
)){
std
::
cerr
<<
"Cannot read file '"
<<
fileName
<<
"'"
<<
std
::
endl
;
return
-
1
;
}
return
0
;
}
src/BackEnd/backend.cpp
View file @
1c3d359d
...
...
@@ -164,20 +164,22 @@ std::string ph5_backendTableHeader(const PTable & table){
body
+=
ph5_backendTableHeaderCompType
(
table
);
body
+=
ph5_backendTableHeaderDataType
(
table
);
body
+=
"
\n\t\t
void 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\t
void set"
+
firstToUpper
(
*
it
)
+
"(size_t val);
\n
"
;
body
+=
"
\t\t
size_t get"
+
firstToUpper
(
*
it
)
+
"() const;
\n
"
;
if
(
vecDimVar
.
size
()
!=
0lu
){
body
+=
"
\n\t\t
void 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\t
void set"
+
firstToUpper
(
*
it
)
+
"(size_t val);
\n
"
;
body
+=
"
\t\t
size_t get"
+
firstToUpper
(
*
it
)
+
"() const;
\n
"
;
}
body
+=
"
\n
"
;
}
body
+=
"
\t
private:
\n
"
;
body
+=
"
\t\t
void readDataSet(const H5::DataSet & dataset);
\n
"
;
body
+=
"
\t\t
void writeDataSet(H5::DataSet & dataset) const;
\n
"
;
...
...
@@ -188,11 +190,13 @@ std::string ph5_backendTableHeader(const PTable & table){
body
+=
"
\t\t
///Number of rows in the table "
+
name
+
"
\n
"
;
body
+=
"
\t\t
size_t p__nbRow;
\n\n
"
;
for
(
PVecStr
::
iterator
it
(
vecDimVar
.
begin
());
it
!=
vecDimVar
.
end
();
++
it
){
body
+=
"
\t\t
///Tensor dimension "
+
(
*
it
)
+
"
\n
"
;
body
+=
"
\t\t
size_t p_"
+
(
*
it
)
+
";
\n
"
;
if
(
vecDimVar
.
size
()
!=
0lu
){
for
(
PVecStr
::
iterator
it
(
vecDimVar
.
begin
());
it
!=
vecDimVar
.
end
();
++
it
){
body
+=
"
\t\t
///Tensor dimension "
+
(
*
it
)
+
"
\n
"
;
body
+=
"
\t\t
size_t p_"
+
(
*
it
)
+
";
\n
"
;
}
body
+=
"
\n
"
;
}
body
+=
"
\n
"
;
body
+=
ph5_backendTableHeaderAttribute
(
table
);
body
+=
"};
\n\n
"
;
...
...
@@ -388,7 +392,7 @@ std::string ph5_backendTableSourceGetter(const PTable & table){
std
::
string
ph5_backendTableSourceDimGetterSetter
(
const
PTable
&
table
){
std
::
string
body
(
""
),
name
(
table
.
getName
());
PVecStr
vecDimVar
=
ph5_getDimName
(
table
);
if
(
vecDimVar
.
size
()
==
0lu
){
return
""
;}
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
){
...
...
@@ -504,12 +508,12 @@ std::string ph5_backendTableSourceCompType(const PTable & table){
* @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"
;}
if
(
type
==
"char"
||
type
==
"int8_t"
){
return
"H5::PredType::NATIVE_INT8"
;}
else
if
(
type
==
"unsinged char"
||
type
==
"int8_t"
){
return
"H5::PredType::NATIVE_UINT8"
;}
else
if
(
type
==
"short"
||
type
==
"int16_t"
){
return
"H5::PredType::NATIVE_INT16"
;}
else
if
(
type
==
"unsigned short"
||
type
==
"uint16_t"
){
return
"H5::PredType::NATIVE_UINT16"
;}
else
if
(
type
==
"int"
||
type
==
"int32_t"
){
return
"H5::PredType::NATIVE_INT
32
"
;}
else
if
(
type
==
"unsigned int"
||
type
==
"uint32_t"
){
return
"H5::PredType::NATIVE_UINT
32
"
;}
else
if
(
type
==
"float"
){
return
"H5::PredType::NATIVE_FLOAT"
;}
else
if
(
type
==
"double"
){
return
"H5::PredType::NATIVE_DOUBLE"
;}
return
""
;
...
...
src/FrontEnd/ConfigParser.cpp
View file @
1c3d359d
...
...
@@ -153,7 +153,8 @@ bool ConfigParser::parseAttribute(PAttribute & attr){
std
::
cerr
<<
"ConfigParser::parseAttribute : expect '(' after token 'Tensor'"
<<
std
::
endl
;
return
true
;
}
type
=
p_parser
->
getNextToken
();
parseType
(
type
);
if
(
!
p_parser
->
isMatch
(
","
)){
errorAt
();
std
::
cerr
<<
"ConfigParser::parseAttribute : expect ',' after type '"
<<
type
<<
"'"
<<
std
::
endl
;
...
...
@@ -175,7 +176,7 @@ bool ConfigParser::parseAttribute(PAttribute & attr){
}
}
}
else
{
type
=
p_parser
->
getNextToken
(
);
parseType
(
type
);
}
std
::
string
varName
(
p_parser
->
getNextToken
());
std
::
string
colName
(
varName
);
...
...
@@ -210,5 +211,15 @@ bool ConfigParser::parseDimention(PDimention & dim){
return
true
;
}
///Parse a data type
/** @param[out] type : type to be parsed
*/
void
ConfigParser
::
parseType
(
std
::
string
&
type
){
type
=
p_parser
->
getNextToken
();
if
(
type
==
"unsigned"
){
type
+=
" "
+
p_parser
->
getNextToken
();
}
}
src/FrontEnd/ConfigParser.h
View file @
1c3d359d
...
...
@@ -34,6 +34,7 @@ class ConfigParser : public PMultiFileParser{
bool
parseTable
(
PTable
&
table
);
bool
parseAttribute
(
PAttribute
&
attr
);
bool
parseDimention
(
PDimention
&
dim
);
void
parseType
(
std
::
string
&
type
);
///Last documentation string
std
::
string
p_lastDocString
;
...
...
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