42 if(!parser.
open(fileName)){
return false;}
77 out +=
saveRecurse(baseIndentation, valueDecorator, baseIndentation, baseNewLine);
78 out += baseNewLine+
"}"+baseNewLine;
84 std::cout <<
"{" << std::endl;
85 std::cout <<
saveRecurse(
"\t",
"\"",
"\t",
"\n") << std::endl;
86 std::cout <<
"{" << std::endl;
109 std::map<PString, DicoValue>::const_iterator it(
p_mapChild.find(key));
118 std::map<PString, DicoValue>::const_iterator it(
p_mapChild.find(key));
120 return &(it->second);
131 if(vecKey.size() == 0lu){
return NULL;}
133 for(PVecString::const_iterator itAddress(vecKey.begin()); itAddress != vecKey.end() && tmpDico != NULL; ++itAddress){
150 if(!
hasVec()){
return NULL;}
157 }
else if(it->p_mapChild.size() == 1lu){
176 std::map<PString, DicoValue>::const_iterator it(
p_mapChild.find(key));
293 bool isRunning(
true);
298 errorAt(parser, isRunning,
"Cannot parse dico value");
311 else if(
parseList(parser, isRunning)){
return true;}
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");
324 p_key = nextKeyOrValue;
326 return errorAt(parser, isRunning,
"Cannot parse value");
342 if(!parser.
isMatch(
"{")){
return false;}
353 errorAt(parser, isRunning,
"Cannot parse dico value");
358 return errorAt(parser, isRunning,
"Expect ',' or '}' after value");
371 if(!parser.
isMatch(
"[")){
return false;}
383 errorAt(parser, isRunning,
"Cannot parse list value");
388 return errorAt(parser, isRunning,
"Expect ',' or ']' after value");
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;
436 PString out(
""), newIndentation(indentation);
437 if(
p_key !=
"" || isInList){
438 newIndentation = indentation + baseIndentation;
441 if(
p_key !=
""){out += baseNewLine + indentation +valueDecorator +
p_key + valueDecorator +
": {";}
442 else if(isInList){out += baseNewLine+indentation+
"{";}
446 out += it->second.saveRecurse(newIndentation, valueDecorator, baseIndentation, baseNewLine);
449 if(
p_key !=
""){out += baseNewLine+indentation+
"}";}
450 else if(isInList){out += baseNewLine+indentation+
"}";}
452 if(
p_key !=
""){out += baseNewLine + indentation + valueDecorator +
p_key + valueDecorator +
": [";}
456 out += it->saveRecurse(newIndentation, valueDecorator, baseIndentation, baseNewLine,
true);
459 if(
p_key !=
""){out +=
"]";}
462 if(valueDecorator !=
""){
463 valueToSave = valueDecorator +
p_value + valueDecorator;
465 valueToSave =
"\"" +
p_value +
"\"";
467 if(
p_key !=
""){out += baseNewLine + indentation + valueDecorator +
p_key + valueDecorator +
": "+valueToSave;}
468 else{out += valueToSave;}
std::vector< PString > PVecString
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.
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.
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 parseString(PString &parsedString, PFileParser &parser)
Parse a string.
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.
PString saveRecurse(const PString &indentation, const PString &valueDecorator, PString baseIndentation, PString baseNewLine, bool isInList=false) const
Save the DicoValue with a text file.
bool load(const PPath &fileName)
Load the DicoValue with a text file.
const 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.
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.
bool parseList(PFileParser &parser, bool &isRunning)
Parse a list or a map.
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 getNextToken()
Get the next token.
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.