PhoenixFileParser  1.5.1
Set of tools to ease file parsing
Loading...
Searching...
No Matches
ConfigNode.cpp
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
8#include "ConfigNode.h"
9
14
19
21
23void ConfigNode::setValue(const PString & value){
24 p_value = value;
25}
26
28
30void ConfigNode::setName(const PString & name){
31 p_name = name;
32}
33
35
37void ConfigNode::setVecChild(const std::vector<ConfigNode*> & vecChild){
38 p_vecChild = vecChild;
39}
40
42
44void ConfigNode::setMapChild(const std::map<PString, ConfigNode*> & mapChild){
45 p_mapChild = mapChild;
46}
47
49
51void ConfigNode::setLocation(const PLocation & location){
52 p_location = location;
53}
54
56
59 p_parent = parent;
60}
61
63
65const PString & ConfigNode::getValue() const{
66 return p_value;
67}
68
70
73 return p_value;
74}
75
77
79const PString & ConfigNode::getName() const{
80 return p_name;
81}
82
84
87 return p_name;
88}
89
91
93const std::vector<ConfigNode*> & ConfigNode::getVecChild() const{
94 return p_vecChild;
95}
96
98
100std::vector<ConfigNode*> & ConfigNode::getVecChild(){
101 return p_vecChild;
102}
103
105
107const std::map<PString, ConfigNode*> & ConfigNode::getMapChild() const{
108 return p_mapChild;
109}
110
112
114std::map<PString, ConfigNode*> & ConfigNode::getMapChild(){
115 return p_mapChild;
116}
117
119
122 PLocation loc = p_location;
124 return loc;
125}
126
128
131 return p_parent;
132}
133
135
137void ConfigNode::setFileName(const PPath & fileName){
138 if(p_location.getFileName() == fileName){return;} //If we already have this file name, we return
139 if(p_location.getFileName() != ""){ //These is alread a file name, so we propagate it in the children and we set it after for the new comers
140 for(std::vector<ConfigNode*>::iterator it(p_vecChild.begin()); it != p_vecChild.end(); ++it){
141 (*it)->setFileName(fileName);
142 }
143 }
144 p_location.setFileName(fileName);
145}
146
148
150const PPath & ConfigNode::getFileName() const{
151 if(p_location.getFileName() == ""){
152 if(p_parent != NULL){
153 return p_parent->getFileName();
154 }
155 }
156 return p_location.getFileName();
157}
158
160
162void ConfigNode::setLineCol(const PLocation & location){
163 if(p_location.getLine() == 0lu && p_location.getColumn() == 0lu){
164 p_location.setLine(location.getLine());
165 p_location.setColumn(location.getColumn());
166 }
167}
168
170
173ConfigNode * ConfigNode::addChild(const PString & name){
174 PString childName = name.eraseFirstLastChar("\"'");
175 if(name != ""){
176 if(getChild(childName) != NULL){
177 return NULL;
178 }
179 }
180 ConfigNode* child = new ConfigNode;
181 child->setName(name);
182 child->setParent(this);
183 p_vecChild.push_back(child);
184 if(name != ""){
185 p_mapChild[childName] = child;
186 }
187 return child;
188}
189
191
194ConfigNode * ConfigNode::getChild(const PString & name){
195 std::map<PString, ConfigNode*>::iterator it(p_mapChild.find(name));
196 if(it != p_mapChild.end()){
197 return it->second;
198 }else{
199 return NULL;
200 }
201}
202
204
207const ConfigNode * ConfigNode::getChild(const PString & name) const{
208 std::map<PString, ConfigNode*>::const_iterator it(p_mapChild.find(name));
209 if(it != p_mapChild.end()){
210 return it->second;
211 }else{
212 return NULL;
213 }
214}
215
217
220ConfigNode * ConfigNode::addValue(const PString & value){
221 ConfigNode * child = addChild("");
222 child->setValue(value);
223 return child;
224}
225
227
229PString ConfigNode::getString() const{
230 return getValue().eraseFirstLastChar("\"'");
231}
232
234
237 return p_vecChild.size() == 0lu && p_mapChild.size() == 0lu;
238}
239
241
244 return p_vecChild.size() != 0lu && p_mapChild.size() == 0lu;
245}
246
248
251 return p_vecChild.size() != 0lu && p_mapChild.size() != 0lu;
252}
253
256 for(std::vector<ConfigNode*>::iterator it(p_vecChild.begin()); it != p_vecChild.end(); ++it){
257 delete *it;
258 }
259 p_vecChild.clear();
260 p_mapChild.clear();
261}
262
264
267ConfigNodeIter ConfigNode::iter(std::ostream & out) const{
268 ConfigNodeIter it(this, &out, false);
269 return it;
270}
271
273
277 ConfigNodeIter it(this, &out, true);
278 return it;
279}
280
283 p_value = "";
284 p_name = "";
285 p_parent = NULL;
286}
287
Iterator of the ConfigNode.
PString getString() const
Get string value without " or ' at the beginning of the end.
const PString & getValue() const
Gets the value of the ConfigNode.
void setValue(const PString &value)
Sets the value of the ConfigNode.
PLocation getLocation() const
Gets the location of the ConfigNode.
ConfigNode()
Constructor of class ConfigNode.
void setMapChild(const std::map< PString, ConfigNode * > &mapChild)
Sets the mapChild of the ConfigNode.
void setParent(const ConfigNode *parent)
Sets the parent of the ConfigNode.
std::vector< ConfigNode * > p_vecChild
Vector of sub ConfigNode.
Definition ConfigNode.h:65
const ConfigNode * p_parent
Parent of the current ConfigNode.
Definition ConfigNode.h:71
std::map< PString, ConfigNode * > p_mapChild
Map of sub ConfigNode.
Definition ConfigNode.h:67
void clear()
Clear the vector of children.
void setLineCol(const PLocation &location)
Set the line and the column of the current ConfigNode.
virtual ~ConfigNode()
Destructor of class ConfigNode.
bool hasMapChild() const
Say if the current ConfigNode has a map of children.
const PString & getName() const
Gets the name of the ConfigNode.
ConfigNodeIter iter(std::ostream &out=std::cout) const
Create an iterator of ConfigNode.
const std::vector< ConfigNode * > & getVecChild() const
Gets the vecChild of the ConfigNode.
ConfigNode * addValue(const PString &value)
Add a value in the ConfigNode.
ConfigNode * addChild(const PString &name="")
Add a child in the current ConfigNode.
PString p_value
Value of the current entry.
Definition ConfigNode.h:61
void setLocation(const PLocation &location)
Sets the location of the ConfigNode.
void initialisationConfigNode()
Initialisation Function of class ConfigNode.
ConfigNode * getChild(const PString &name)
Get the child of the given name.
void setVecChild(const std::vector< ConfigNode * > &vecChild)
Sets the vecChild of the ConfigNode.
bool hasVecChild() const
Say if the current ConfigNode has a vector of children.
const ConfigNode * getParent() const
Gets the parent of the ConfigNode.
void setName(const PString &name)
Sets the name of the ConfigNode.
const std::map< PString, ConfigNode * > & getMapChild() const
Gets the mapChild of the ConfigNode.
void setFileName(const PPath &fileName)
Set the fileName of the current ConfigNode.
const PPath & getFileName() const
Get current file name.
PString p_name
Name of the current entry.
Definition ConfigNode.h:63
bool hasValue() const
Say if the current ConfigNode has a value.
PLocation p_location
Location of the definition of the current ConfigNode.
Definition ConfigNode.h:69
ConfigNodeIter iterWrite(std::ostream &out=std::cout)
Create an iterator of ConfigNode.
Classe qui permet de décrire une localisation, avec un nom de fichier et une ligne.
Definition PLocation.h:15
void setFileName(const PPath &fileName)
fonction qui permet d'initialiser la ligne du PLocation
Definition PLocation.cpp:41
size_t getLine() const
renvoie la ligne du PLocation
Definition PLocation.cpp:67
size_t getColumn() const
renvoie la colonne du PLocation
Definition PLocation.cpp:74