42 if(!parser.
open(fileName)){
return false;}
76 out +=
saveRecurse(baseIndentation, valueDecorator, baseIndentation, baseNewLine);
77 out += baseNewLine+
"}"+baseNewLine;
83 std::cout <<
"{" << std::endl;
84 std::cout <<
saveRecurse(
"\t",
"\"",
"\t",
"\n") << std::endl;
85 std::cout <<
"{" << std::endl;
108 std::map<PString, DicoValue>::const_iterator it(
p_mapChild.find(key));
117 std::map<PString, DicoValue>::const_iterator it(
p_mapChild.find(key));
119 return &(it->second);
130 std::map<PString, DicoValue>::const_iterator it(
p_mapChild.find(key));
247 bool isRunning(
true);
252 errorAt(parser, isRunning,
"Cannot parse dico value");
267 if(nextKeyOrValue ==
""){
268 nextKeyOrValue = parser.
getStrComposedOf(
"abcdefghijklmnopqsrtuvwxyzABCDEFGHIJKLMNOPQSRTUVWXYZ0123456789._-+");
269 if(nextKeyOrValue ==
""){
270 return errorAt(parser, isRunning,
271 "Expecting a string or a keywork composed of letters, number, underscore, slash or minus");
276 p_key = nextKeyOrValue;
278 return errorAt(parser, isRunning,
"Cannot parse value");
294 if(!parser.
isMatch(
"{")){
return false;}
306 errorAt(parser, isRunning,
"Cannot parse dico value");
311 return errorAt(parser, isRunning,
"Expect ',' or '}' after value");
339 std::cerr <<
"DicoValue::errorAt : " << parser.
getLocation() << std::endl;
340 std::cerr <<
"\t" << errorMsg << std::endl;
352 PString out(
""), newIndentation(indentation);
354 newIndentation = indentation + baseIndentation;
357 if(
p_key !=
""){out += baseNewLine + indentation +valueDecorator +
p_key + valueDecorator +
": {";}
361 out += it->second.saveRecurse(newIndentation, valueDecorator, baseIndentation, baseNewLine);
364 if(
p_key !=
""){out += baseNewLine+indentation+
"}";}
366 if(
p_key !=
""){out += baseNewLine + indentation + valueDecorator +
p_key + valueDecorator +
": {";}
370 out += it->saveRecurse(newIndentation, valueDecorator, baseIndentation, baseNewLine);
373 if(
p_key !=
""){out +=
"}";}
376 if(valueDecorator !=
""){
377 valueToSave = valueDecorator +
p_value + valueDecorator;
379 valueToSave =
"\"" +
p_value +
"\"";
381 if(
p_key !=
""){out += baseNewLine + indentation + valueDecorator +
p_key + valueDecorator +
": "+valueToSave;}
382 else{out += valueToSave;}
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.
const PString & getKey() const
Gets the key of the DicoValue.
bool isKeyExist(const PString &key) const
Say if the given key exists in the map of children.
PString p_value
Value of the current entry.
void copyDicoValue(const DicoValue &other)
Copy Function of class DicoValue.
void setKey(const PString &key)
Sets the key of the DicoValue.
bool parseListOrMap(PFileParser &parser, bool &isRunning)
Parse a list or a map.
bool fromString(const PString &content)
Create a DicoValue from a PString.
bool hasKey() const
Say if the DicoValue has a key.
const std::vector< DicoValue > & getVecChild() const
Gets the vecChild of the DicoValue.
PString saveRecurse(const PString &indentation, const PString &valueDecorator, PString baseIndentation, PString baseNewLine) const
Save the DicoValue with a text file.
DicoValue & operator=(const DicoValue &other)
Operator = of class DicoValue.
virtual ~DicoValue()
Destructor of class DicoValue.
const DicoValue * getMap(const PString &key) const
Get a DicoValue in the map of the current one.
bool save(const PPath &fileName, const PString &valueDecorator="", PString baseIndentation="\t", PString baseNewLine="\n") const
Save the DicoValue with a text file.
void setValue(const PString &value)
Sets the value of the DicoValue.
bool hasMap() const
Say if the DicoValue has a map of children.
void print() const
Print the DicoValue.
PString p_key
Key of the current entry.
DicoValue()
Constructor of class DicoValue.
std::map< PString, DicoValue > p_mapChild
Map of sub DicoValue.
const std::map< PString, DicoValue > & getMapChild() const
Gets the mapChild of the DicoValue.
PString parseString(PFileParser &parser)
Parse a string.
std::vector< DicoValue > p_vecChild
Vector of sub DicoValue.
T getValue() const
Convert the value of the current DicoValue into a type.
bool parseDicoValue(PFileParser &parser, bool &isRunning)
Parse a DicoValue with a text file.
bool loadParser(PFileParser &parser)
Load the DicoValue with a parser.
bool errorAt(PFileParser &parser, bool &isRunning, const PString &errorMsg)
Print the parsing error.
PString getString() const
Get a string value without the first and/or last quote or double quote in there are some.
bool load(const PPath &fileName)
Load the DicoValue with a text file.
void setMapChild(const std::map< PString, DicoValue > &mapChild)
Sets the mapChild of the DicoValue.
bool hasVec() const
Say if the DicoValue has a vector of children.
classe qui permet de parser des fichiers texte en renvoyant les tokens les uns après les autres
void setSeparator(const PString &separator)
Initialise la liste des caractères séparateurs.
bool open(const PPath &fileName)
Fonction qui ouvre le fichier que l'on va parser.
PString getUntilKeyWithoutPatern(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.
void setEscapeChar(char escapeChar)
Sets the escape character of the PFileParser.
PString getStrComposedOf(const PString &charset)
Get string composed of the characters in the string charset.
void setWhiteSpace(const PString &whiteSpace)
Initialise la liste des caractères blancs.
bool isMatchRewind(const PString &patern)
Do a isMatch and then go back at the previous position.
bool isMatch(const PString &patern)
Says if the patern match with the current caracters of the PFileParser.
PLocation getLocation() const
Fonction qui renvoie la PLocation du PFileParser.
void skipWhiteSpace()
Skip the white space if there is at the current caracter position.
void setFileContent(const PString &fileContent)
Set the file content.
bool isEndOfFile() const
Dit si on est à la fin du fichier.
Path of a directory or a file.
bool saveFileContent(const PString &content) const
Save a PString in a file.
bool find(char ch) const
Find a char in a string.
PString eraseFirstLastChar(const PString &vecChar) const
Erase first and last char in a string.