PhoenixPresentation  2.0.0
Set of cmake function to automate presentation generation
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 
17 class DicoValue{
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 
74  std::vector<DicoValue> p_vecChild;
76  std::map<PString, DicoValue> p_mapChild;
77 };
78 
80 typedef std::vector<DicoValue> VecDicoValue;
82 typedef 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
std::vector< PString > PVecString
Definition: PString.h:99
Dictionnary of values.
Definition: DicoValue.h:17
void setVecChild(const std::vector< DicoValue > &vecChild)
Sets the vecChild of the DicoValue.
Definition: DicoValue.cpp:201
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.
Definition: DicoValue.cpp:236
bool isKeyExist(const PString &key) const
Say if the given key exists in the map of children.
Definition: DicoValue.cpp:108
PString p_value
Value of the current entry.
Definition: DicoValue.h:70
void copyDicoValue(const DicoValue &other)
Copy Function of class DicoValue.
Definition: DicoValue.cpp:278
void setKey(const PString &key)
Sets the key of the DicoValue.
Definition: DicoValue.cpp:194
bool parseListOrMap(PFileParser &parser, bool &isRunning)
Parse a list or a map.
Definition: DicoValue.cpp:341
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.
Definition: DicoValue.cpp:250
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.
Definition: DicoValue.cpp:117
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.
Definition: DicoValue.cpp:187
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.
Definition: DicoValue.cpp:264
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.
Definition: DicoValue.cpp:309
bool parseString(PString &parsedString, PFileParser &parser)
Parse a string.
Definition: DicoValue.cpp:400
bool loadParser(PFileParser &parser)
Load the DicoValue with a parser.
Definition: DicoValue.cpp:289
bool errorAt(PFileParser &parser, bool &isRunning, const PString &errorMsg)
Print the parsing error.
Definition: DicoValue.cpp:419
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
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
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.
Definition: DicoValue.cpp:149
void setMapChild(const std::map< PString, DicoValue > &mapChild)
Sets the mapChild of the DicoValue.
Definition: DicoValue.cpp:208
bool hasVec() const
Say if the DicoValue has a vector of children.
Definition: DicoValue.cpp:102
bool parseList(PFileParser &parser, bool &isRunning)
Parse a list or a map.
Definition: DicoValue.cpp:370
classe qui permet de parser des fichiers texte en renvoyant les tokens les uns après les autres
Definition: PFileParser.h:20
Path of a directory or a file.
Definition: PPath.h:17
Extends the std::string.
Definition: PString.h:16