PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
DicoValue Class Reference

Dictionnary of values. More...

#include <DicoValue.h>

+ Collaboration diagram for DicoValue:

Public Member Functions

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

Protected Member Functions

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

Private Member Functions

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

Private Attributes

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

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 }

◆ 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.
Definition: DicoValue.cpp:278

References copyDicoValue().

+ 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 p_key, p_mapChild, p_value, and p_vecChild.

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

+ 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.
Definition: DicoValue.cpp:289
classe qui permet de parser des fichiers texte en renvoyant les tokens les uns après les autres
Definition: PFileParser.h:20
void setEscapeChar(char escapeChar)
Sets the escape character of the PFileParser.
Definition: PFileParser.cpp:58
void setFileContent(const PString &fileContent)
Set the file content.
Definition: PFileParser.cpp:50

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

Referenced by testFromJSonToJSon().

+ Here is the call graph for this function:
+ Here is the caller 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 }
Dictionnary of values.
Definition: DicoValue.h:17
const DicoValue * getMap(const PString &key) const
Get a DicoValue in the map of the current one.
Definition: DicoValue.cpp:117
PString getString() const
Get a string value without the first and/or last quote or double quote in there are some.
Definition: DicoValue.cpp:229
bool hasVec() const
Say if the DicoValue has a vector of children.
Definition: DicoValue.cpp:102

References getMap(), getString(), hasVec(), p_mapChild, 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(), and testDicoValue().

+ 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 p_mapChild.

◆ 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 p_mapChild.

Referenced by checkConstDicoValue(), getElementInVecWhere(), getMap(), phoenix_get_nested_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 >(), phoenix_load_vecValue_from_config(), testDicoDicoString(), testDicoDicoValueKeyPtr(), testDicoValue(), testDicoValue3(), testDicoVecString(), and testDicoVecValue().

+ 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 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 checkLoadFromConfig(), dico_find_all_var(), phoenix_save_value_to_dico(), testDicoDicoValueKeyPtr(), testDicoValue(), and testDicoValue2().

+ 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 }
PString eraseFirstLastChar(const PString &vecChar) const
Erase first and last char in a string.
Definition: PString.cpp:623

References PString::eraseFirstLastChar(), and p_value.

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

+ Here is the call graph for this function:
+ 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

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(), phoenix_load_value_from_dico(), testDicoValue(), testDicoValueKey(), and testDicoValueKeyPtr().

+ 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 checkLoadFromConfig(), dico_find_all_var(), phoenix_get_vecstring(), phoenix_load_vecValue_from_config(), testDicoValue(), and testDicoVecValueKeyPtr().

+ 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 checkLoadFromConfig(), and 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 checkLoadFromConfig(), 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 checkLoadFromConfig(), 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.

Referenced by testDicoValue2().

+ Here is the caller graph for this function:

◆ 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.
Definition: PFileParser.cpp:24

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

Referenced by testDicoBadParsing(), testDicoDicoString(), testDicoGoodParsing(), testDicoValue(), testDicoValue2(), testDicoValue3(), testDicoVecString(), testDicoVecValue(), and testFromJSonToJSon().

+ Here is the call graph for this function:
+ Here is the caller 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.
Definition: DicoValue.cpp:309
bool errorAt(PFileParser &parser, bool &isRunning, const PString &errorMsg)
Print the parsing error.
Definition: DicoValue.cpp:419
void setSeparator(const PString &separator)
Initialise la liste des caractères séparateurs.
Definition: PFileParser.cpp:43
void setWhiteSpace(const PString &whiteSpace)
Initialise la liste des caractères blancs.
Definition: PFileParser.cpp:35
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.
Definition: PFileParser.cpp:88

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().

+ 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.
Definition: DicoValue.cpp:341
bool parseString(PString &parsedString, PFileParser &parser)
Parse a string.
Definition: DicoValue.cpp:400
bool parseList(PFileParser &parser, bool &isRunning)
Parse a list or a map.
Definition: DicoValue.cpp:370
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.
Extends the std::string.
Definition: PString.h:16

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

Referenced by loadParser(), 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 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 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.
Definition: DicoValue.cpp:435

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
bool saveFileContent(const PString &content) const
Save a PString in a file.
Definition: PPath.cpp:394

References PPath::saveFileContent(), and toString().

Referenced by saveDico(), testDicoSaveParsing(), and testFromJSonToJSon().

+ Here is the call graph for this function:
+ Here is the caller 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 }
bool find(char ch) const
Find a char in a string.
Definition: PString.cpp:434

References PString::find(), p_key, p_mapChild, p_value, and p_vecChild.

Referenced by print(), and toString().

+ Here is the call graph for this function:
+ 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 checkLoadFromConfig(), and 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.

Referenced by testDicoValue().

+ Here is the caller graph for this function:

◆ 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 checkLoadFromConfig(), dico_update_all_nestedCall(), phoenix_save_value_to_dico(), and testDicoSaveParsing().

+ 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.

Referenced by testDicoValue().

+ Here is the caller graph for this function:

◆ 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(), and testFromJSonToJSon().

+ 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(), 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(), parseDicoValue(), saveRecurse(), and setValue().

◆ p_vecChild

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

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