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
c2bd6350
Commit
c2bd6350
authored
Nov 24, 2020
by
Pierre Aubert
Browse files
Add base of config parsing
parent
f7470962
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
156 additions
and
6 deletions
+156
-6
src/FrontEnd/ConfigParser.cpp
src/FrontEnd/ConfigParser.cpp
+133
-1
src/FrontEnd/ConfigParser.h
src/FrontEnd/ConfigParser.h
+10
-1
src/Representation/representation.cpp
src/Representation/representation.cpp
+12
-3
src/Representation/representation.h
src/Representation/representation.h
+1
-1
No files found.
src/FrontEnd/ConfigParser.cpp
View file @
c2bd6350
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
Licence : CeCILL-C
Licence : CeCILL-C
****************************************/
****************************************/
#include "string_utils.h"
#include "ConfigParser.h"
#include "ConfigParser.h"
///Default constructor of ConfigParser
///Default constructor of ConfigParser
...
@@ -47,12 +47,144 @@ void ConfigParser::copyConfigParser(const ConfigParser & other){
...
@@ -47,12 +47,144 @@ void ConfigParser::copyConfigParser(const ConfigParser & other){
p_vecSource
=
other
.
p_vecSource
;
p_vecSource
=
other
.
p_vecSource
;
}
}
///Parse the input file
/** @return true on success, false otherwise
*/
bool
ConfigParser
::
parseFile
(){
if
(
!
p_run
)
return
false
;
PSource
source
;
source
.
setName
(
getFileName
(
p_parser
->
getFileName
()));
//To parse the file we need to read char by char until we get something we know
while
(
!
p_parser
->
isEndOfFile
()
&&
p_run
){
//If we are not at the end of the file
PTable
table
;
if
(
parseTable
(
table
)){
source
.
getVecTable
().
push_back
(
table
);
}
else
{
errorAt
();
std
::
cerr
<<
"ConfigParser::parseFile : unexpected token '"
<<
p_parser
->
getNextToken
()
<<
"'"
<<
std
::
endl
;
}
}
p_vecSource
.
push_back
(
source
);
return
true
;
}
///Initialisation to be done just before loading a file
void
ConfigParser
::
preLoadFile
(){
//Save the current source
p_parser
->
setWhiteSpace
(
"
\t\n
"
);
p_parser
->
setSeparator
(
",;{}[]()"
);
}
///Initialisation to be done just after loading a file
void
ConfigParser
::
postLoadFile
(){
}
///Initialisation function of the class ConfigParser
///Initialisation function of the class ConfigParser
void
ConfigParser
::
initialisationConfigParser
(){
void
ConfigParser
::
initialisationConfigParser
(){
}
}
///Parse a PTable
/** @param[out] table : PTable to be parsed
* @return true on success, false otherwise
*/
bool
ConfigParser
::
parseTable
(
PTable
&
table
){
std
::
string
tableName
(
p_parser
->
getNextToken
());
std
::
string
dataSetName
(
tableName
);
if
(
p_parser
->
isMatch
(
"["
)){
dataSetName
=
p_parser
->
getUntilKeyWithoutPatern
(
"]"
);
}
if
(
!
p_parser
->
isMatch
(
"{"
)){
errorAt
();
std
::
cerr
<<
"ConfigParser::parseTable : expect '{' after table name '"
<<
tableName
<<
"'"
<<
std
::
endl
;
return
true
;
}
table
.
setName
(
tableName
);
table
.
setDataSetName
(
dataSetName
);
while
(
!
p_parser
->
isEndOfFile
()
&&
!
p_parser
->
isMatch
(
"}"
)
&&
p_run
){
PAttribute
attr
;
if
(
parseAttribute
(
attr
)){
table
.
getVecAttribute
().
push_back
(
attr
);
}
else
{
errorAt
();
std
::
cerr
<<
"ConfigParser::parseTable : cannot parse attribute"
<<
std
::
endl
;
return
true
;
}
}
return
true
;
}
///Parse a PAttribute
/** @param[out] attr : PAttribute to be parsed
* @return true on success, false otherwise
*/
bool
ConfigParser
::
parseAttribute
(
PAttribute
&
attr
){
if
(
p_parser
->
isMatchRewind
(
"}"
)){
return
true
;}
std
::
string
type
(
""
);
if
(
p_parser
->
isMatch
(
"Tensor"
)){
if
(
!
p_parser
->
isMatch
(
"("
)){
errorAt
();
std
::
cerr
<<
"ConfigParser::parseAttribute : expect '(' after token 'Tensor'"
<<
std
::
endl
;
return
true
;
}
type
=
p_parser
->
getNextToken
();
if
(
!
p_parser
->
isMatch
(
","
)){
errorAt
();
std
::
cerr
<<
"ConfigParser::parseAttribute : expect ',' after type '"
<<
type
<<
"'"
<<
std
::
endl
;
return
true
;
}
while
(
!
p_parser
->
isMatch
(
")"
)
&&
!
p_parser
->
isEndOfFile
()
&&
p_run
){
PDimention
dim
;
if
(
parseDimention
(
dim
)){
attr
.
getVecDim
().
push_back
(
dim
);
if
(
!
p_parser
->
isMatch
(
","
)
&&
!
p_parser
->
isMatchRewind
(
")"
)){
errorAt
();
std
::
cerr
<<
"ConfigParser::parseAttribute : expect ',' after dimention '"
<<
ph5_dimentionToStr
(
dim
)
<<
"'"
<<
std
::
endl
;
return
true
;
}
}
else
{
errorAt
();
std
::
cerr
<<
"ConfigParser::parseAttribute : cannot parse expected dimention"
<<
std
::
endl
;
return
true
;
}
}
}
else
{
type
=
p_parser
->
getNextToken
();
}
std
::
string
varName
(
p_parser
->
getNextToken
());
std
::
string
colName
(
varName
);
if
(
p_parser
->
isMatch
(
"["
)){
colName
=
p_parser
->
getUntilKeyWithoutPatern
(
"]"
);
}
if
(
!
p_parser
->
isMatch
(
";"
)){
errorAt
();
std
::
cerr
<<
"ConfigParser::parseAttribute : expect ';' at the end of the definition of the '"
<<
varName
<<
"' attribute"
<<
std
::
endl
;
return
true
;
}
attr
.
setName
(
varName
);
attr
.
setColName
(
colName
);
return
true
;
}
///Parse a PDimention
/** @param[out] dim : PDimention to be parsed
* @return true on success, false otherwise
*/
bool
ConfigParser
::
parseDimention
(
PDimention
&
dim
){
if
(
p_parser
->
isMatchRewind
(
")"
)){
return
true
;}
std
::
string
token
=
p_parser
->
getNextToken
();
bool
isNumber
=
isStrNumber
(
token
);
dim
.
setIsValue
(
isNumber
);
if
(
isNumber
){
dim
.
setValue
(
atol
(
token
.
c_str
()));
}
else
{
dim
.
setName
(
token
);
}
return
true
;
}
src/FrontEnd/ConfigParser.h
View file @
c2bd6350
...
@@ -7,10 +7,11 @@
...
@@ -7,10 +7,11 @@
#ifndef __CONFIGPARSER_H__
#ifndef __CONFIGPARSER_H__
#define __CONFIGPARSER_H__
#define __CONFIGPARSER_H__
#include "PMultiFileParser.h"
#include "Representation/representation.h"
#include "Representation/representation.h"
///@brief Parse the configuration a create the vector of sources
///@brief Parse the configuration a create the vector of sources
class
ConfigParser
{
class
ConfigParser
:
public
PMultiFileParser
{
public:
public:
ConfigParser
();
ConfigParser
();
ConfigParser
(
const
ConfigParser
&
other
);
ConfigParser
(
const
ConfigParser
&
other
);
...
@@ -22,9 +23,17 @@ class ConfigParser{
...
@@ -22,9 +23,17 @@ class ConfigParser{
protected:
protected:
void
copyConfigParser
(
const
ConfigParser
&
other
);
void
copyConfigParser
(
const
ConfigParser
&
other
);
virtual
bool
parseFile
();
virtual
void
preLoadFile
();
virtual
void
postLoadFile
();
private:
private:
void
initialisationConfigParser
();
void
initialisationConfigParser
();
bool
parseTable
(
PTable
&
table
);
bool
parseAttribute
(
PAttribute
&
attr
);
bool
parseDimention
(
PDimention
&
dim
);
///Vector of parsed PSource
///Vector of parsed PSource
PVecSource
p_vecSource
;
PVecSource
p_vecSource
;
};
};
...
...
src/Representation/representation.cpp
View file @
c2bd6350
...
@@ -4,10 +4,19 @@
...
@@ -4,10 +4,19 @@
Licence : CeCILL-C
Licence : CeCILL-C
****************************************/
****************************************/
#include "convertToString.h"
#include "representation.h"
#include "representation.h"
///Convert a PDimention into a string
/** @param dim : dimention to be converted
* @return corresponding string
*/
std
::
string
ph5_dimentionToStr
(
const
PDimention
&
dim
){
if
(
dim
.
getIsValue
()){
return
convertToString
(
dim
.
getValue
());
}
else
{
return
dim
.
getName
();
}
}
src/Representation/representation.h
View file @
c2bd6350
...
@@ -14,6 +14,6 @@ typedef std::vector<PAttribute> PVecAttribute;
...
@@ -14,6 +14,6 @@ typedef std::vector<PAttribute> PVecAttribute;
typedef
std
::
vector
<
PTable
>
PVecTable
;
typedef
std
::
vector
<
PTable
>
PVecTable
;
typedef
std
::
vector
<
PSource
>
PVecSource
;
typedef
std
::
vector
<
PSource
>
PVecSource
;
std
::
string
ph5_dimentionToStr
(
const
PDimention
&
dim
);
#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