PhoenixFileParser  1.0.0
Set of tools to ease file parsing
Loading...
Searching...
No Matches
DicoValue Class Reference

Dictionnary of values. More...

#include <DicoValue.h>

Public Member Functions

 DicoValue ()
 Constructor of class DicoValue.
 
 DicoValue (const DicoValue &other)
 Copy Constructor of class DicoValue.
 
bool fromString (const PString &content)
 Create a DicoValue from a PString.
 
const DicoValuegetElementInVecWhere (const PString &key, const PString &value) const
 Get the element of a vector of children of the current DicoValue which has 'key'.value = value.
 
PString & getKey ()
 Gets the key of the DicoValue.
 
const PString & getKey () const
 Gets the key of the DicoValue.
 
DicoValuegetMap (const PString &key)
 Get a DicoValue in the map of the current one.
 
const DicoValuegetMap (const PString &key) const
 Get a DicoValue in the map of the current one.
 
const DicoValuegetMap (const PVecString &vecKey) const
 Get a nested DicoValue in the map of the current one.
 
std::map< PString, DicoValue > & getMapChild ()
 Gets the mapChild of the DicoValue.
 
const std::map< PString, DicoValue > & getMapChild () const
 Gets the mapChild of the DicoValue.
 
PString getString () const
 Get a string value without the first and/or last quote or double quote in there are some.
 
PString & getValue ()
 Gets the value of the DicoValue.
 
template<typename T>
getValue () const
 Convert the value of the current DicoValue into a type.
 
const PString & getValue () const
 Gets the value of the DicoValue.
 
std::vector< DicoValue > & getVecChild ()
 Gets the vecChild of the DicoValue.
 
const std::vector< DicoValue > & getVecChild () const
 Gets the vecChild of the DicoValue.
 
bool hasKey () const
 Say if the DicoValue has a key.
 
bool hasMap () const
 Say if the DicoValue has a map of children.
 
bool hasVec () const
 Say if the DicoValue has a vector of children.
 
bool isKeyExist (const PString &key) const
 Say if the given key exists in the map of children.
 
bool load (const PPath &fileName)
 Load the DicoValue with a text file.
 
DicoValueoperator= (const DicoValue &other)
 Operator = of class DicoValue.
 
void print () const
 Print the DicoValue.
 
bool save (const PPath &fileName, const PString &valueDecorator="", PString baseIndentation="\t", PString baseNewLine="\n") const
 Save the DicoValue with a text file.
 
void setKey (const PString &key)
 Sets the key of the DicoValue.
 
void setMapChild (const std::map< PString, DicoValue > &mapChild)
 Sets the mapChild of the DicoValue.
 
void setValue (const PString &value)
 Sets the value of the DicoValue.
 
void setVecChild (const std::vector< DicoValue > &vecChild)
 Sets the vecChild of the DicoValue.
 
PString toString (const PString &valueDecorator="", PString baseIndentation="\t", PString baseNewLine="\n") const
 Convert the DicoValue into a string.
 
virtual ~DicoValue ()
 Destructor of class DicoValue.
 

Protected Member Functions

void copyDicoValue (const DicoValue &other)
 Copy Function of class DicoValue.
 

Private Member Functions

bool errorAt (PFileParser &parser, bool &isRunning, const PString &errorMsg)
 Print the parsing error.
 
bool loadParser (PFileParser &parser)
 Load the DicoValue with a parser.
 
bool parseDicoValue (PFileParser &parser, bool &isRunning)
 Parse a DicoValue with a text file.
 
bool parseList (PFileParser &parser, bool &isRunning)
 Parse a list or a map.
 
bool parseListOrMap (PFileParser &parser, bool &isRunning)
 Parse a list or a map.
 
bool parseString (PString &parsedString, PFileParser &parser)
 Parse a string.
 
PString saveRecurse (const PString &indentation, const PString &valueDecorator, PString baseIndentation, PString baseNewLine, bool isInList=false) const
 Save the DicoValue with a text file.
 

Private Attributes

PString p_key
 Key of the current entry.
 
std::map< PString, DicoValuep_mapChild
 Map of sub DicoValue.
 
PString p_value
 Value of the current entry.
 
std::vector< DicoValuep_vecChild
 Vector of sub DicoValue.
 

Detailed Description

Dictionnary of values.

Definition at line 17 of file DicoValue.h.

Constructor & Destructor Documentation

◆ DicoValue() [1/2]

DicoValue::DicoValue ( )

Constructor of class DicoValue.

Definition at line 11 of file DicoValue.cpp.

11 {
12
13}

Referenced by copyDicoValue(), DicoValue(), getElementInVecWhere(), getMap(), getMap(), getMap(), operator=(), parseList(), and parseListOrMap().

+ Here is the caller graph for this function:

◆ DicoValue() [2/2]

DicoValue::DicoValue ( const DicoValue & other)

Copy Constructor of class DicoValue.

Parameters
other: DicoValue we want ot copy

Definition at line 18 of file DicoValue.cpp.

18 {
19 copyDicoValue(other);
20}
void copyDicoValue(const DicoValue &other)
Copy Function of class DicoValue.

References copyDicoValue(), and DicoValue().

+ Here is the call graph for this function:

◆ ~DicoValue()

DicoValue::~DicoValue ( )
virtual

Destructor of class DicoValue.

Definition at line 23 of file DicoValue.cpp.

23 {
24
25}

Member Function Documentation

◆ copyDicoValue()

void DicoValue::copyDicoValue ( const DicoValue & other)
protected

Copy Function of class DicoValue.

Parameters
other: DicoValue we want ot copy

Definition at line 278 of file DicoValue.cpp.

278 {
279 p_value = other.p_value;
280 p_key = other.p_key;
281 p_vecChild = other.p_vecChild;
282 p_mapChild = other.p_mapChild;
283}
PString p_value
Value of the current entry.
Definition DicoValue.h:70
PString p_key
Key of the current entry.
Definition DicoValue.h:72
std::map< PString, DicoValue > p_mapChild
Map of sub DicoValue.
Definition DicoValue.h:76
std::vector< DicoValue > p_vecChild
Vector of sub DicoValue.
Definition DicoValue.h:74

References DicoValue(), p_key, p_mapChild, p_value, and p_vecChild.

Referenced by DicoValue(), and operator=().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ errorAt()

bool DicoValue::errorAt ( PFileParser & parser,
bool & isRunning,
const PString & errorMsg )
private

Print the parsing error.

Parameters
[out]parser: parser to be used
[out]isRunning: true to continue the parsing, false to stop it
errorMsg: error message
Returns
true and stop the parsing with isRunning

Definition at line 419 of file DicoValue.cpp.

419 {
420 isRunning = false;
421 std::cerr << "DicoValue::errorAt : " << parser.getLocation() << std::endl;
422 std::cerr << "\t" << errorMsg << std::endl;
423 std::cerr << "Wrong token : '"<<parser.getNextToken()<<"'" << std::endl;
424 return true;
425}
PString getNextToken()
Get the next token.
PLocation getLocation() const
Fonction qui renvoie la PLocation du PFileParser.

References PFileParser::getLocation(), and PFileParser::getNextToken().

Referenced by loadParser(), parseDicoValue(), parseList(), and parseListOrMap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromString()

bool DicoValue::fromString ( const PString & content)

Create a DicoValue from a PString.

Parameters
content: content to be parsed
Returns
true on success, false otherwise

Definition at line 62 of file DicoValue.cpp.

62 {
63 PFileParser parser;
64 parser.setEscapeChar('\\');
65 parser.setFileContent(content);
66 return loadParser(parser);
67}
bool loadParser(PFileParser &parser)
Load the DicoValue with a parser.
void setEscapeChar(char escapeChar)
Sets the escape character of the PFileParser.
void setFileContent(const PString &fileContent)
Set the file content.

References loadParser(), PFileParser::setEscapeChar(), and PFileParser::setFileContent().

+ Here is the call graph for this function:

◆ getElementInVecWhere()

const DicoValue * DicoValue::getElementInVecWhere ( const PString & key,
const PString & value ) const

Get the element of a vector of children of the current DicoValue which has 'key'.value = value.

Parameters
key: key to be found in a child of the current DicoValue
value: expected value of the child
Returns
pointer to the found child, NULL otherwise

Definition at line 149 of file DicoValue.cpp.

149 {
150 if(!hasVec()){return NULL;}
151 for(VecDicoValue::const_iterator it(p_vecChild.begin()); it != p_vecChild.end(); ++it){
152 const DicoValue * element = it->getMap(key);
153 if(element != NULL){
154 if(element->getString() == value){
155 return &(*it);
156 }
157 }else if(it->p_mapChild.size() == 1lu){
158 const DicoValue & mapElement = it->p_mapChild.begin()->second;
159 const DicoValue * elMap = mapElement.getMap(key);
160 if(elMap != NULL){
161 if(elMap->getString() == value){
162 return &mapElement;
163 }
164 }
165 }
166 }
167 return NULL;
168}
const DicoValue * getMap(const PString &key) const
Get a DicoValue in the map of the current one.
DicoValue()
Constructor of class DicoValue.
Definition DicoValue.cpp:11
PString getString() const
Get a string value without the first and/or last quote or double quote in there are some.
bool hasVec() const
Say if the DicoValue has a vector of children.

References DicoValue(), getMap(), getString(), hasVec(), and p_vecChild.

+ Here is the call graph for this function:

◆ getKey() [1/2]

PString & DicoValue::getKey ( )

Gets the key of the DicoValue.

Returns
key of the DicoValue

Definition at line 243 of file DicoValue.cpp.

243 {
244 return p_key;
245}

References p_key.

◆ getKey() [2/2]

const PString & DicoValue::getKey ( ) const

Gets the key of the DicoValue.

Returns
key of the DicoValue

Definition at line 236 of file DicoValue.cpp.

236 {
237 return p_key;
238}

References p_key.

Referenced by dico_find_all_var().

+ Here is the caller graph for this function:

◆ getMap() [1/3]

DicoValue * DicoValue::getMap ( const PString & key)

Get a DicoValue in the map of the current one.

Parameters
key: name of the DicoValue to get
Returns
pointer to the found DicoValue if it exists, NULL otherwise

Definition at line 175 of file DicoValue.cpp.

175 {
176 std::map<PString, DicoValue>::const_iterator it(p_mapChild.find(key));
177 if(it != p_mapChild.end()){
178 return (DicoValue *)&(it->second);
179 }else{
180 return NULL;
181 }
182}

References DicoValue(), and p_mapChild.

+ Here is the call graph for this function:

◆ getMap() [2/3]

const DicoValue * DicoValue::getMap ( const PString & key) const

Get a DicoValue in the map of the current one.

Parameters
key: name of the DicoValue to get
Returns
pointer to the found DicoValue if it exists, NULL otherwise

Definition at line 117 of file DicoValue.cpp.

117 {
118 std::map<PString, DicoValue>::const_iterator it(p_mapChild.find(key));
119 if(it != p_mapChild.end()){
120 return &(it->second);
121 }else{
122 return NULL;
123 }
124}

References DicoValue(), and p_mapChild.

Referenced by getElementInVecWhere(), getMap(), phoenix_get_nested_string(), phoenix_get_string(), phoenix_get_string(), phoenix_get_vecstring(), phoenix_load_value_from_config(), phoenix_load_value_from_config< bool >(), phoenix_load_value_from_dico(), phoenix_load_value_from_dico< bool >(), and phoenix_load_vecValue_from_config().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMap() [3/3]

const DicoValue * DicoValue::getMap ( const PVecString & vecKey) const

Get a nested DicoValue in the map of the current one.

Parameters
vecKey: full address name of the DicoValue to get
Returns
pointer to the found DicoValue if it exists, NULL otherwise

Definition at line 130 of file DicoValue.cpp.

130 {
131 if(vecKey.size() == 0lu){return NULL;}
132 const DicoValue * tmpDico = this;
133 for(PVecString::const_iterator itAddress(vecKey.begin()); itAddress != vecKey.end() && tmpDico != NULL; ++itAddress){
134 if(tmpDico->hasMap()){
135 const DicoValue * key = tmpDico->getMap(*itAddress);
136 tmpDico = key;
137 }else{
138 tmpDico = NULL;
139 }
140 }
141 return tmpDico;
142}
bool hasMap() const
Say if the DicoValue has a map of children.
Definition DicoValue.cpp:97

References DicoValue(), getMap(), and hasMap().

+ Here is the call graph for this function:

◆ getMapChild() [1/2]

std::map< PString, DicoValue > & DicoValue::getMapChild ( )

Gets the mapChild of the DicoValue.

Returns
mapChild of the DicoValue

Definition at line 271 of file DicoValue.cpp.

271 {
272 return p_mapChild;
273}

References p_mapChild.

◆ getMapChild() [2/2]

const std::map< PString, DicoValue > & DicoValue::getMapChild ( ) const

Gets the mapChild of the DicoValue.

Returns
mapChild of the DicoValue

Definition at line 264 of file DicoValue.cpp.

264 {
265 return p_mapChild;
266}

References p_mapChild.

Referenced by dico_find_all_var(), and phoenix_save_value_to_dico().

+ Here is the caller graph for this function:

◆ getString()

PString DicoValue::getString ( ) const

Get a string value without the first and/or last quote or double quote in there are some.

Returns
value without the first and/or last quote or double quote in there are some

Definition at line 229 of file DicoValue.cpp.

229 {
230 return p_value.eraseFirstLastChar("\"\'");
231}

References p_value.

Referenced by dico_find_all_var(), getElementInVecWhere(), phoenix_get_nested_string(), phoenix_get_string(), phoenix_get_string(), phoenix_load_value_from_config< bool >(), and phoenix_load_value_from_dico< bool >().

+ Here is the caller graph for this function:

◆ getValue() [1/3]

PString & DicoValue::getValue ( )

Gets the value of the DicoValue.

Returns
value of the DicoValue

Definition at line 222 of file DicoValue.cpp.

222 {
223 return p_value;
224}

References p_value.

◆ getValue() [2/3]

template<typename T>
T DicoValue::getValue ( ) const

Convert the value of the current DicoValue into a type.

Returns
converted value of the current DicoValue

Definition at line 16 of file DicoValue_impl.h.

16 {
17 return stringToValue<T>(p_value);
18}

References p_value.

Referenced by dico_update_all_nestedCall(), phoenix_load_value_from_config(), and phoenix_load_value_from_dico().

+ Here is the caller graph for this function:

◆ getValue() [3/3]

const PString & DicoValue::getValue ( ) const

Gets the value of the DicoValue.

Returns
value of the DicoValue

Definition at line 215 of file DicoValue.cpp.

215 {
216 return p_value;
217}

References p_value.

◆ getVecChild() [1/2]

std::vector< DicoValue > & DicoValue::getVecChild ( )

Gets the vecChild of the DicoValue.

Returns
vecChild of the DicoValue

Definition at line 257 of file DicoValue.cpp.

257 {
258 return p_vecChild;
259}

References p_vecChild.

◆ getVecChild() [2/2]

const std::vector< DicoValue > & DicoValue::getVecChild ( ) const

Gets the vecChild of the DicoValue.

Returns
vecChild of the DicoValue

Definition at line 250 of file DicoValue.cpp.

250 {
251 return p_vecChild;
252}

References p_vecChild.

Referenced by dico_find_all_var(), phoenix_get_vecstring(), and phoenix_load_vecValue_from_config().

+ Here is the caller graph for this function:

◆ hasKey()

bool DicoValue::hasKey ( ) const

Say if the DicoValue has a key.

Returns
true if the DicoValue has a key, false otherwise

Definition at line 92 of file DicoValue.cpp.

92{return p_key != "";}

References p_key.

Referenced by dico_find_all_var().

+ Here is the caller graph for this function:

◆ hasMap()

bool DicoValue::hasMap ( ) const

Say if the DicoValue has a map of children.

Returns
true if the DicoValue has a map of children, false otherwise

Definition at line 97 of file DicoValue.cpp.

97{return p_mapChild.size() != 0lu;}

References p_mapChild.

Referenced by dico_find_all_var(), and getMap().

+ Here is the caller graph for this function:

◆ hasVec()

bool DicoValue::hasVec ( ) const

Say if the DicoValue has a vector of children.

Returns
true if the DicoValue has a vector of children, false otherwise

Definition at line 102 of file DicoValue.cpp.

102{return p_vecChild.size() != 0lu;}

References p_vecChild.

Referenced by dico_find_all_var(), and getElementInVecWhere().

+ Here is the caller graph for this function:

◆ isKeyExist()

bool DicoValue::isKeyExist ( const PString & key) const

Say if the given key exists in the map of children.

Parameters
key: key to be checked
Returns
true if the given key exists in the map of children, false otherwise

Definition at line 108 of file DicoValue.cpp.

108 {
109 std::map<PString, DicoValue>::const_iterator it(p_mapChild.find(key));
110 return it != p_mapChild.end();
111}

References p_mapChild.

◆ load()

bool DicoValue::load ( const PPath & fileName)

Load the DicoValue with a text file.

Parameters
fileName: name of the file to be loaded
Returns
true on success, false otherwise

Definition at line 40 of file DicoValue.cpp.

40 {
41 PFileParser parser;
42 if(!parser.open(fileName)){return false;}
43 return loadParser(parser);
44}
bool open(const PPath &fileName)
Fonction qui ouvre le fichier que l'on va parser.

References loadParser(), and PFileParser::open().

+ Here is the call graph for this function:

◆ loadParser()

bool DicoValue::loadParser ( PFileParser & parser)
private

Load the DicoValue with a parser.

Parameters
[out]parser: parser to be used
Returns
true on success, false otherwise

Definition at line 289 of file DicoValue.cpp.

289 {
290 parser.setEscapeChar('\\');
291 parser.setWhiteSpace(" \t\n");
292 parser.setSeparator(",:{}\"");
293 bool isRunning(true);
294 while(!parser.isEndOfFile() && isRunning){
295 if(parseDicoValue(parser, isRunning)){
296 parser.skipWhiteSpace();
297 }else{
298 errorAt(parser, isRunning, "Cannot parse dico value");
299 }
300 }
301 return isRunning;
302}
bool parseDicoValue(PFileParser &parser, bool &isRunning)
Parse a DicoValue with a text file.
bool errorAt(PFileParser &parser, bool &isRunning, const PString &errorMsg)
Print the parsing error.
void setSeparator(const PString &separator)
Initialise la liste des caractères séparateurs.
void setWhiteSpace(const PString &whiteSpace)
Initialise la liste des caractères blancs.
void skipWhiteSpace()
Skip the white space if there is at the current caracter position.
bool isEndOfFile() const
Dit si on est à la fin du fichier.

References errorAt(), PFileParser::isEndOfFile(), parseDicoValue(), PFileParser::setEscapeChar(), PFileParser::setSeparator(), PFileParser::setWhiteSpace(), and PFileParser::skipWhiteSpace().

Referenced by fromString(), and load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

DicoValue & DicoValue::operator= ( const DicoValue & other)

Operator = of class DicoValue.

Parameters
other: DicoValue we want ot copy
Returns
copied class DicoValue

Definition at line 31 of file DicoValue.cpp.

31 {
32 copyDicoValue(other);
33 return *this;
34}

References copyDicoValue(), and DicoValue().

+ Here is the call graph for this function:

◆ parseDicoValue()

bool DicoValue::parseDicoValue ( PFileParser & parser,
bool & isRunning )
private

Parse a DicoValue with a text file.

Parameters
[out]parser: parser to be used
[out]isRunning: true to continue the parsing, false to stop it
Returns
true on success, false otherwise

Definition at line 309 of file DicoValue.cpp.

309 {
310 if(parseListOrMap(parser, isRunning)){return true;}
311 else if(parseList(parser, isRunning)){return true;}
312 else{
313 PString nextKeyOrValue;
314 bool isParsingStrOk(parseString(nextKeyOrValue, parser));
315 if(nextKeyOrValue == ""){
316 nextKeyOrValue = parser.getStrComposedOf("abcdefghijklmnopqsrtuvwxyzABCDEFGHIJKLMNOPQSRTUVWXYZ0123456789._-+");
317 if(nextKeyOrValue == "" && !isParsingStrOk){
318 return errorAt(parser, isRunning,
319 "Expecting a string or a keywork composed of letters, number, underscore, slash or minus");
320 }
321 }
322 if(parser.isMatch(":")){ //It was a key for a dictionnary
323// std::cerr << "DicoValue::parseDicoValue : find key '"<<nextKeyOrValue<<"'" << std::endl;
324 p_key = nextKeyOrValue;
325 if(!parseDicoValue(parser, isRunning)){
326 return errorAt(parser, isRunning, "Cannot parse value");
327 }
328 }else{ //It was a value
329 p_value = nextKeyOrValue;
330 }
331 parser.skipWhiteSpace();
332 }
333 return true;
334}
bool parseListOrMap(PFileParser &parser, bool &isRunning)
Parse a list or a map.
bool parseString(PString &parsedString, PFileParser &parser)
Parse a string.
bool parseList(PFileParser &parser, bool &isRunning)
Parse a list or a map.
PString getStrComposedOf(const PString &charset)
Get string composed of the characters in the string charset.
bool isMatch(const PString &patern)
Says if the patern match with the current caracters of the PFileParser.

References errorAt(), PFileParser::getStrComposedOf(), PFileParser::isMatch(), p_key, p_value, parseDicoValue(), parseList(), parseListOrMap(), parseString(), and PFileParser::skipWhiteSpace().

Referenced by loadParser(), parseDicoValue(), parseList(), and parseListOrMap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseList()

bool DicoValue::parseList ( PFileParser & parser,
bool & isRunning )
private

Parse a list or a map.

Parameters
[out]parser: parser to be used
[out]isRunning: true to continue the parsing, false to stop it
Returns
true on success, false otherwise

Definition at line 370 of file DicoValue.cpp.

370 {
371 if(!parser.isMatch("[")){return false;} //If this is not a {, then it is not a list or a map
372
373 while(!parser.isEndOfFile() && !parser.isMatch("]") && isRunning){
374 DicoValue dv;
375 if(dv.parseDicoValue(parser, isRunning)){
376 if(dv.p_key != ""){ //It is a dico entry
377// std::cerr << "DicoValue::parseListOrMap : loadParser add DicoValue with key '"<<dv.p_key<<"'" << std::endl;
378 p_mapChild[dv.p_key] = dv;
379 }else{ //It is a value
380 p_vecChild.push_back(dv);
381 }
382 }else{
383 errorAt(parser, isRunning, "Cannot parse list value");
384 }
385 if(parser.isMatch(",")){}
386 else if(parser.isMatchRewind("]")){}
387 else{
388 return errorAt(parser, isRunning, "Expect ',' or ']' after value");
389 }
390 }
391
392 return true;
393}
bool isMatchRewind(const PString &patern)
Do a isMatch and then go back at the previous position.

References DicoValue(), errorAt(), PFileParser::isEndOfFile(), PFileParser::isMatch(), PFileParser::isMatchRewind(), p_key, p_mapChild, p_vecChild, and parseDicoValue().

Referenced by parseDicoValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseListOrMap()

bool DicoValue::parseListOrMap ( PFileParser & parser,
bool & isRunning )
private

Parse a list or a map.

Parameters
[out]parser: parser to be used
[out]isRunning: true to continue the parsing, false to stop it
Returns
true on success, false otherwise

Definition at line 341 of file DicoValue.cpp.

341 {
342 if(!parser.isMatch("{")){return false;} //If this is not a {, then it is not a list or a map
343 while(!parser.isEndOfFile() && !parser.isMatch("}") && isRunning){
344 DicoValue dv;
345 if(dv.parseDicoValue(parser, isRunning)){
346 if(dv.p_key != ""){ //It is a dico entry
347// std::cerr << "DicoValue::parseListOrMap : loadParser add DicoValue with key '"<<dv.p_key<<"'" << std::endl;
348 p_mapChild[dv.p_key] = dv;
349 }else{ //It is a value
350 p_vecChild.push_back(dv);
351 }
352 }else{
353 errorAt(parser, isRunning, "Cannot parse dico value");
354 }
355 if(parser.isMatch(",")){}
356 else if(parser.isMatchRewind("}")){}
357 else{
358 return errorAt(parser, isRunning, "Expect ',' or '}' after value");
359 }
360 }
361
362 return true;
363}

References DicoValue(), errorAt(), PFileParser::isEndOfFile(), PFileParser::isMatch(), PFileParser::isMatchRewind(), p_key, p_mapChild, p_vecChild, and parseDicoValue().

Referenced by parseDicoValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseString()

bool DicoValue::parseString ( PString & parsedString,
PFileParser & parser )
private

Parse a string.

Parameters
[out]parsedString: parsed string
[out]parser: parser to be used
Returns
true on success, false otherwise

Definition at line 400 of file DicoValue.cpp.

400 {
401 if(parser.isMatch("\"")){
402 parsedString = parser.getUntilKeyWithoutPatern("\"");
403 return true;
404 }else if(parser.isMatch("'")){
405 parsedString = parser.getUntilKeyWithoutPatern("'");
406 return true;
407 }else{
408 parsedString = "";
409 return false;
410 }
411}
PString getUntilKeyWithoutPatern(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.

References PFileParser::getUntilKeyWithoutPatern(), and PFileParser::isMatch().

Referenced by parseDicoValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print()

void DicoValue::print ( ) const

Print the DicoValue.

Definition at line 83 of file DicoValue.cpp.

83 {
84 std::cout << "{" << std::endl;
85 std::cout << saveRecurse("\t", "\"", "\t", "\n") << std::endl;
86 std::cout << "{" << std::endl;
87}
PString saveRecurse(const PString &indentation, const PString &valueDecorator, PString baseIndentation, PString baseNewLine, bool isInList=false) const
Save the DicoValue with a text file.

References saveRecurse().

+ Here is the call graph for this function:

◆ save()

bool DicoValue::save ( const PPath & fileName,
const PString & valueDecorator = "",
PString baseIndentation = "\t",
PString baseNewLine = "\n" ) const

Save the DicoValue with a text file.

Parameters
fileName: name of the file to be saved
valueDecorator: string to add around keys and values ('"' for JSON)
baseIndentation: indentation character(s) to be used
baseNewLine: new line character(s) to be used
Returns
true on success, false otherwise

Definition at line 53 of file DicoValue.cpp.

53 {
54 PString out(toString(valueDecorator, baseIndentation, baseNewLine));
55 return fileName.saveFileContent(out);
56}
PString toString(const PString &valueDecorator="", PString baseIndentation="\t", PString baseNewLine="\n") const
Convert the DicoValue into a string.
Definition DicoValue.cpp:75

References toString().

+ Here is the call graph for this function:

◆ saveRecurse()

PString DicoValue::saveRecurse ( const PString & indentation,
const PString & valueDecorator,
PString baseIndentation,
PString baseNewLine,
bool isInList = false ) const
private

Save the DicoValue with a text file.

Parameters
indentation: indentation of the current DicoValue
valueDecorator: decorator to put around keys and values ('"' for JSON)
baseIndentation: indentation character(s) to be used
baseNewLine: new line character(s) to be used
isInList: true if the dico value is in a list
Returns
file content

Definition at line 435 of file DicoValue.cpp.

435 {
436 PString out(""), newIndentation(indentation);
437 if(p_key != "" || isInList){
438 newIndentation = indentation + baseIndentation;
439 }
440 if(p_mapChild.size() != 0lu){
441 if(p_key != ""){out += baseNewLine + indentation +valueDecorator + p_key + valueDecorator + ": {";}
442 else if(isInList){out += baseNewLine+indentation+"{";}
443 PString comma("");
444 for(MapDicoValue::const_iterator it(p_mapChild.begin()); it != p_mapChild.end(); ++it){
445 out += comma;
446 out += it->second.saveRecurse(newIndentation, valueDecorator, baseIndentation, baseNewLine);
447 comma = ",";
448 }
449 if(p_key != ""){out += baseNewLine+indentation+"}";}
450 else if(isInList){out += baseNewLine+indentation+"}";}
451 }else if(p_vecChild.size() != 0lu){
452 if(p_key != ""){out += baseNewLine + indentation + valueDecorator + p_key + valueDecorator + ": [";}
453 PString comma("");
454 for(VecDicoValue::const_iterator it(p_vecChild.begin()); it != p_vecChild.end(); ++it){
455 out += comma;
456 out += it->saveRecurse(newIndentation, valueDecorator, baseIndentation, baseNewLine, true);
457 comma = ", ";
458 }
459 if(p_key != ""){out += "]";}
460 }else{
461 PString valueToSave(p_value);
462 if(valueDecorator != ""){
463 valueToSave = valueDecorator + p_value + valueDecorator;
464 }else if(p_value.find(" \t\n':/")){
465 valueToSave = "\"" + p_value + "\"";
466 }
467 if(p_key != ""){out += baseNewLine + indentation + valueDecorator + p_key + valueDecorator + ": "+valueToSave;}
468 else{out += valueToSave;}
469 }
470 return out;
471}

References p_key, p_mapChild, p_value, and p_vecChild.

Referenced by print(), and toString().

+ Here is the caller graph for this function:

◆ setKey()

void DicoValue::setKey ( const PString & key)

Sets the key of the DicoValue.

Parameters
key: key of the DicoValue

Definition at line 194 of file DicoValue.cpp.

194 {
195 p_key = key;
196}

References p_key.

Referenced by phoenix_save_value_to_dico().

+ Here is the caller graph for this function:

◆ setMapChild()

void DicoValue::setMapChild ( const std::map< PString, DicoValue > & mapChild)

Sets the mapChild of the DicoValue.

Parameters
mapChild: mapChild of the DicoValue

Definition at line 208 of file DicoValue.cpp.

208 {
209 p_mapChild = mapChild;
210}

References p_mapChild.

◆ setValue()

void DicoValue::setValue ( const PString & value)

Sets the value of the DicoValue.

Parameters
value: value of the DicoValue

Definition at line 187 of file DicoValue.cpp.

187 {
188 p_value = value;
189}

References p_value.

Referenced by dico_update_all_nestedCall(), and phoenix_save_value_to_dico().

+ Here is the caller graph for this function:

◆ setVecChild()

void DicoValue::setVecChild ( const std::vector< DicoValue > & vecChild)

Sets the vecChild of the DicoValue.

Parameters
vecChild: vecChild of the DicoValue

Definition at line 201 of file DicoValue.cpp.

201 {
202 p_vecChild = vecChild;
203}

References p_vecChild.

◆ toString()

PString DicoValue::toString ( const PString & valueDecorator = "",
PString baseIndentation = "\t",
PString baseNewLine = "\n" ) const

Convert the DicoValue into a string.

Parameters
valueDecorator: string to add around keys and values ('"' for JSON)
baseIndentation: indentation character(s) to be used
baseNewLine: new line character(s) to be used
Returns
corresponding string

Definition at line 75 of file DicoValue.cpp.

75 {
76 PString out(baseNewLine+"{");
77 out += saveRecurse(baseIndentation, valueDecorator, baseIndentation, baseNewLine);
78 out += baseNewLine+"}"+baseNewLine;
79 return out;
80}

References saveRecurse().

Referenced by save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ p_key

PString DicoValue::p_key
private

Key of the current entry.

Definition at line 72 of file DicoValue.h.

Referenced by copyDicoValue(), getKey(), getKey(), hasKey(), parseDicoValue(), parseList(), parseListOrMap(), saveRecurse(), and setKey().

◆ p_mapChild

std::map<PString, DicoValue> DicoValue::p_mapChild
private

◆ p_value

PString DicoValue::p_value
private

Value of the current entry.

Definition at line 70 of file DicoValue.h.

Referenced by copyDicoValue(), getString(), getValue(), getValue(), parseDicoValue(), saveRecurse(), and setValue().

◆ p_vecChild

std::vector<DicoValue> DicoValue::p_vecChild
private

The documentation for this class was generated from the following files: