PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
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  DicoValue * getMap(const PString & key);
40 
41  void setValue(const PString & value);
42  void setKey(const PString & key);
43  void setVecChild(const std::vector<DicoValue> & vecChild);
44  void setMapChild(const std::map<PString, DicoValue> & mapChild);
45  const PString & getValue() const;
46  PString & getValue();
47  PString getString() const;
48  const PString & getKey() const;
49  PString & getKey();
50  const std::vector<DicoValue> & getVecChild() const;
51  std::vector<DicoValue> & getVecChild();
52  const std::map<PString, DicoValue> & getMapChild() const;
53  std::map<PString, DicoValue> & getMapChild();
54 
55  protected:
56  void copyDicoValue(const DicoValue & other);
57  private:
58  bool loadParser(PFileParser & parser);
59  bool parseDicoValue(PFileParser & parser, bool & isRunning);
60  bool parseListOrMap(PFileParser & parser, bool & isRunning);
62  bool errorAt(PFileParser & parser, bool & isRunning, const PString & errorMsg);
63 
64  PString saveRecurse(const PString & indentation, const PString & valueDecorator, PString baseIndentation, PString baseNewLine) const;
65 
71  std::vector<DicoValue> p_vecChild;
73  std::map<PString, DicoValue> p_mapChild;
74 };
75 
77 typedef std::vector<DicoValue> VecDicoValue;
79 typedef std::map<PString, DicoValue> MapDicoValue;
80 
81 #include "DicoValue_impl.h"
82 
83 #endif
84 
std::map< PString, DicoValue > MapDicoValue
Vector of DicoValue.
Definition: DicoValue.h:79
std::vector< DicoValue > VecDicoValue
Vector of DicoValue.
Definition: DicoValue.h:77
Dictionnary of values.
Definition: DicoValue.h:17
void setVecChild(const std::vector< DicoValue > &vecChild)
Sets the vecChild of the DicoValue.
Definition: DicoValue.cpp:155
PString toString(const PString &valueDecorator="", PString baseIndentation="\t", PString baseNewLine="\n") const
Convert the DicoValue into a string.
Definition: DicoValue.cpp:74
const PString & getKey() const
Gets the key of the DicoValue.
Definition: DicoValue.cpp:190
bool isKeyExist(const PString &key) const
Say if the given key exists in the map of children.
Definition: DicoValue.cpp:107
PString p_value
Value of the current entry.
Definition: DicoValue.h:67
void copyDicoValue(const DicoValue &other)
Copy Function of class DicoValue.
Definition: DicoValue.cpp:232
void setKey(const PString &key)
Sets the key of the DicoValue.
Definition: DicoValue.cpp:148
bool parseListOrMap(PFileParser &parser, bool &isRunning)
Parse a list or a map.
Definition: DicoValue.cpp:293
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:91
const std::vector< DicoValue > & getVecChild() const
Gets the vecChild of the DicoValue.
Definition: DicoValue.cpp:204
PString saveRecurse(const PString &indentation, const PString &valueDecorator, PString baseIndentation, PString baseNewLine) const
Save the DicoValue with a text file.
Definition: DicoValue.cpp:351
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:116
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:141
bool hasMap() const
Say if the DicoValue has a map of children.
Definition: DicoValue.cpp:96
void print() const
Print the DicoValue.
Definition: DicoValue.cpp:82
PString p_key
Key of the current entry.
Definition: DicoValue.h:69
DicoValue()
Constructor of class DicoValue.
Definition: DicoValue.cpp:11
std::map< PString, DicoValue > p_mapChild
Map of sub DicoValue.
Definition: DicoValue.h:73
const std::map< PString, DicoValue > & getMapChild() const
Gets the mapChild of the DicoValue.
Definition: DicoValue.cpp:218
PString parseString(PFileParser &parser)
Parse a string.
Definition: DicoValue.cpp:322
std::vector< DicoValue > p_vecChild
Vector of sub DicoValue.
Definition: DicoValue.h:71
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:263
bool loadParser(PFileParser &parser)
Load the DicoValue with a parser.
Definition: DicoValue.cpp:243
bool errorAt(PFileParser &parser, bool &isRunning, const PString &errorMsg)
Print the parsing error.
Definition: DicoValue.cpp:337
PString getString() const
Get a string value without the first and/or last quote or double quote in there are some.
Definition: DicoValue.cpp:183
bool load(const PPath &fileName)
Load the DicoValue with a text file.
Definition: DicoValue.cpp:40
void setMapChild(const std::map< PString, DicoValue > &mapChild)
Sets the mapChild of the DicoValue.
Definition: DicoValue.cpp:162
bool hasVec() const
Say if the DicoValue has a vector of children.
Definition: DicoValue.cpp:101
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