PhoenixFileParser  1.0.0
Set of tools to ease file parsing
Loading...
Searching...
No Matches
DicoValue.h
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#ifndef __DICOVALUE_H__
8#define __DICOVALUE_H__
9
10#include <vector>
11#include <map>
12#include "PPath.h"
13
14#include "PFileParser.h"
15
18 public:
19 DicoValue();
20 DicoValue(const DicoValue & other);
21 virtual ~DicoValue();
22 DicoValue & operator = (const DicoValue & other);
23
24 bool load(const PPath & fileName);
25 bool save(const PPath & fileName, const PString & valueDecorator = "", PString baseIndentation = "\t", PString baseNewLine = "\n") const;
26
27 bool fromString(const PString & content);
28 PString toString(const PString & valueDecorator = "", PString baseIndentation = "\t", PString baseNewLine = "\n") const;
29 void print() const;
30
31 template<typename T>
32 T getValue() const;
33
34 bool hasKey() const;
35 bool hasMap() const;
36 bool hasVec() const;
37 bool isKeyExist(const PString & key) const;
38 const DicoValue * getMap(const PString & key) const;
39 const DicoValue * getMap(const PVecString & vecKey) const;
40 DicoValue * getMap(const PString & key);
41 const DicoValue * getElementInVecWhere(const PString & key, const PString & value) const;
42
43 void setValue(const PString & value);
44 void setKey(const PString & key);
45 void setVecChild(const std::vector<DicoValue> & vecChild);
46 void setMapChild(const std::map<PString, DicoValue> & mapChild);
47 const PString & getValue() const;
48 PString & getValue();
49 PString getString() const;
50 const PString & getKey() const;
51 PString & getKey();
52 const std::vector<DicoValue> & getVecChild() const;
53 std::vector<DicoValue> & getVecChild();
54 const std::map<PString, DicoValue> & getMapChild() const;
55 std::map<PString, DicoValue> & getMapChild();
56
57 protected:
58 void copyDicoValue(const DicoValue & other);
59 private:
60 bool loadParser(PFileParser & parser);
61 bool parseDicoValue(PFileParser & parser, bool & isRunning);
62 bool parseListOrMap(PFileParser & parser, bool & isRunning);
63 bool parseList(PFileParser & parser, bool & isRunning);
64 bool parseString(PString & parsedString, PFileParser & parser);
65 bool errorAt(PFileParser & parser, bool & isRunning, const PString & errorMsg);
66
67 PString saveRecurse(const PString & indentation, const PString & valueDecorator, PString baseIndentation, PString baseNewLine, bool isInList = false) const;
68
70 PString p_value;
72 PString p_key;
74 std::vector<DicoValue> p_vecChild;
76 std::map<PString, DicoValue> p_mapChild;
77};
78
80typedef std::vector<DicoValue> VecDicoValue;
82typedef std::map<PString, DicoValue> MapDicoValue;
83
84#include "DicoValue_impl.h"
85
86#endif
87
std::map< PString, DicoValue > MapDicoValue
Vector of DicoValue.
Definition DicoValue.h:82
std::vector< DicoValue > VecDicoValue
Vector of DicoValue.
Definition DicoValue.h:80
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.
Definition DicoValue.cpp:75
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.
Definition DicoValue.h:70
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.
Definition DicoValue.cpp:62
bool hasKey() const
Say if the DicoValue has a key.
Definition DicoValue.cpp:92
const std::vector< DicoValue > & getVecChild() const
Gets the vecChild of the DicoValue.
DicoValue & operator=(const DicoValue &other)
Operator = of class DicoValue.
Definition DicoValue.cpp:31
virtual ~DicoValue()
Destructor of class DicoValue.
Definition DicoValue.cpp:23
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.
Definition DicoValue.cpp:53
void setValue(const PString &value)
Sets the value of the DicoValue.
bool hasMap() const
Say if the DicoValue has a map of children.
Definition DicoValue.cpp:97
void print() const
Print the DicoValue.
Definition DicoValue.cpp:83
PString p_key
Key of the current entry.
Definition DicoValue.h:72
DicoValue()
Constructor of class DicoValue.
Definition DicoValue.cpp:11
std::map< PString, DicoValue > p_mapChild
Map of sub DicoValue.
Definition DicoValue.h:76
const std::map< PString, DicoValue > & getMapChild() const
Gets the mapChild of the DicoValue.
std::vector< DicoValue > p_vecChild
Vector of sub DicoValue.
Definition DicoValue.h:74
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.
Definition DicoValue.cpp:40
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
Definition PFileParser.h:20