PhoenixFileParser  1.5.1
Set of tools to ease file parsing
Loading...
Searching...
No Matches
ConfigNode Class Reference

Configuration of values. More...

#include <ConfigNode.h>

+ Collaboration diagram for ConfigNode:

Public Member Functions

ConfigNodeaddChild (const PString &name="")
 Add a child in the current ConfigNode.
 
ConfigNodeaddValue (const PString &value)
 Add a value in the ConfigNode.
 
void clear ()
 Clear the vector of children.
 
 ConfigNode ()
 Constructor of class ConfigNode.
 
ConfigNodegetChild (const PString &name)
 Get the child of the given name.
 
const ConfigNodegetChild (const PString &name) const
 Get the child of the given name.
 
const PPath & getFileName () const
 Get current file name.
 
PLocation getLocation () const
 Gets the location of the ConfigNode.
 
std::map< PString, ConfigNode * > & getMapChild ()
 Gets the mapChild of the ConfigNode.
 
const std::map< PString, ConfigNode * > & getMapChild () const
 Gets the mapChild of the ConfigNode.
 
PString & getName ()
 Gets the name of the ConfigNode.
 
const PString & getName () const
 Gets the name of the ConfigNode.
 
const ConfigNodegetParent () const
 Gets the parent of the ConfigNode.
 
PString getString () const
 Get string value without " or ' at the beginning of the end.
 
PString & getValue ()
 Gets the value of the ConfigNode.
 
const PString & getValue () const
 Gets the value of the ConfigNode.
 
std::vector< ConfigNode * > & getVecChild ()
 Gets the vecChild of the ConfigNode.
 
const std::vector< ConfigNode * > & getVecChild () const
 Gets the vecChild of the ConfigNode.
 
bool hasMapChild () const
 Say if the current ConfigNode has a map of children.
 
bool hasValue () const
 Say if the current ConfigNode has a value.
 
bool hasVecChild () const
 Say if the current ConfigNode has a vector of children.
 
ConfigNodeIter iter (std::ostream &out=std::cout) const
 Create an iterator of ConfigNode.
 
ConfigNodeIter iterWrite (std::ostream &out=std::cout)
 Create an iterator of ConfigNode.
 
void setFileName (const PPath &fileName)
 Set the fileName of the current ConfigNode.
 
void setLineCol (const PLocation &location)
 Set the line and the column of the current ConfigNode.
 
void setLocation (const PLocation &location)
 Sets the location of the ConfigNode.
 
void setMapChild (const std::map< PString, ConfigNode * > &mapChild)
 Sets the mapChild of the ConfigNode.
 
void setName (const PString &name)
 Sets the name of the ConfigNode.
 
void setValue (const PString &value)
 Sets the value of the ConfigNode.
 
void setVecChild (const std::vector< ConfigNode * > &vecChild)
 Sets the vecChild of the ConfigNode.
 
virtual ~ConfigNode ()
 Destructor of class ConfigNode.
 

Private Member Functions

void initialisationConfigNode ()
 Initialisation Function of class ConfigNode.
 
void setParent (const ConfigNode *parent)
 Sets the parent of the ConfigNode.
 

Private Attributes

PLocation p_location
 Location of the definition of the current ConfigNode.
 
std::map< PString, ConfigNode * > p_mapChild
 Map of sub ConfigNode.
 
PString p_name
 Name of the current entry.
 
const ConfigNodep_parent
 Parent of the current ConfigNode.
 
PString p_value
 Value of the current entry.
 
std::vector< ConfigNode * > p_vecChild
 Vector of sub ConfigNode.
 

Detailed Description

Configuration of values.

Definition at line 18 of file ConfigNode.h.

Constructor & Destructor Documentation

◆ ConfigNode()

ConfigNode::ConfigNode ( )

Constructor of class ConfigNode.

Definition at line 11 of file ConfigNode.cpp.

11 {
13}
void initialisationConfigNode()
Initialisation Function of class ConfigNode.

References initialisationConfigNode().

Referenced by addChild(), addValue(), getChild(), getChild(), getParent(), and setParent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ~ConfigNode()

ConfigNode::~ConfigNode ( )
virtual

Destructor of class ConfigNode.

Definition at line 16 of file ConfigNode.cpp.

16 {
17 clear();
18}
void clear()
Clear the vector of children.

References clear().

+ Here is the call graph for this function:

Member Function Documentation

◆ addChild()

ConfigNode * ConfigNode::addChild ( const PString & name = "")

Add a child in the current ConfigNode.

Parameters
name: name of the child
Returns
pointer to the created child, or NULL if the child with name already exist

Definition at line 173 of file ConfigNode.cpp.

173 {
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}
ConfigNode()
Constructor of class 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
std::map< PString, ConfigNode * > p_mapChild
Map of sub ConfigNode.
Definition ConfigNode.h:67
ConfigNode * getChild(const PString &name)
Get the child of the given name.
void setName(const PString &name)
Sets the name of the ConfigNode.

References ConfigNode(), getChild(), p_mapChild, p_vecChild, setName(), and setParent().

Referenced by addValue(), parser_json_key(), and parser_json_list().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addValue()

ConfigNode * ConfigNode::addValue ( const PString & value)

Add a value in the ConfigNode.

Parameters
value: value to be added in the ConfigNode
Returns
pointer to the added value

Definition at line 220 of file ConfigNode.cpp.

220 {
221 ConfigNode * child = addChild("");
222 child->setValue(value);
223 return child;
224}
void setValue(const PString &value)
Sets the value of the ConfigNode.
ConfigNode * addChild(const PString &name="")
Add a child in the current ConfigNode.

References addChild(), ConfigNode(), and setValue().

+ Here is the call graph for this function:

◆ clear()

void ConfigNode::clear ( )

Clear the vector of children.

Definition at line 255 of file ConfigNode.cpp.

255 {
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}

References p_mapChild, and p_vecChild.

Referenced by ~ConfigNode().

+ Here is the caller graph for this function:

◆ getChild() [1/2]

ConfigNode * ConfigNode::getChild ( const PString & name)

Get the child of the given name.

Parameters
name: name of the child
Returns
pointer to the corresponding child, or NULL is it does not exist

Definition at line 194 of file ConfigNode.cpp.

194 {
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}

References ConfigNode(), and p_mapChild.

Referenced by addChild(), parser_json_key(), phoenix_get_string(), phoenix_get_string(), phoenix_get_value(), phoenix_get_value(), phoenix_get_vecstring(), and phoenix_load_vecValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChild() [2/2]

const ConfigNode * ConfigNode::getChild ( const PString & name) const

Get the child of the given name.

Parameters
name: name of the child
Returns
pointer to the corresponding child, or NULL is it does not exist

Definition at line 207 of file ConfigNode.cpp.

207 {
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}

References ConfigNode(), and p_mapChild.

+ Here is the call graph for this function:

◆ getFileName()

const PPath & ConfigNode::getFileName ( ) const

Get current file name.

Returns
current file name

Definition at line 150 of file ConfigNode.cpp.

150 {
151 if(p_location.getFileName() == ""){
152 if(p_parent != NULL){
153 return p_parent->getFileName();
154 }
155 }
156 return p_location.getFileName();
157}
const ConfigNode * p_parent
Parent of the current ConfigNode.
Definition ConfigNode.h:71
PLocation p_location
Location of the definition of the current ConfigNode.
Definition ConfigNode.h:69

References p_location, and p_parent.

Referenced by getLocation().

+ Here is the caller graph for this function:

◆ getLocation()

PLocation ConfigNode::getLocation ( ) const

Gets the location of the ConfigNode.

Returns
location of the ConfigNode

Definition at line 121 of file ConfigNode.cpp.

121 {
122 PLocation loc = p_location;
124 return loc;
125}
const PPath & getFileName() const
Get current file name.
void setFileName(const PPath &fileName)
fonction qui permet d'initialiser la ligne du PLocation
Definition PLocation.cpp:41

References getFileName(), p_location, and PLocation::setFileName().

Referenced by parser_json_key().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMapChild() [1/2]

std::map< PString, ConfigNode * > & ConfigNode::getMapChild ( )

Gets the mapChild of the ConfigNode.

Returns
mapChild of the ConfigNode

Definition at line 114 of file ConfigNode.cpp.

114 {
115 return p_mapChild;
116}

References p_mapChild.

◆ getMapChild() [2/2]

const std::map< PString, ConfigNode * > & ConfigNode::getMapChild ( ) const

Gets the mapChild of the ConfigNode.

Returns
mapChild of the ConfigNode

Definition at line 107 of file ConfigNode.cpp.

107 {
108 return p_mapChild;
109}

References p_mapChild.

Referenced by toJsonSaveRecurse().

+ Here is the caller graph for this function:

◆ getName() [1/2]

PString & ConfigNode::getName ( )

Gets the name of the ConfigNode.

Returns
name of the ConfigNode

Definition at line 86 of file ConfigNode.cpp.

86 {
87 return p_name;
88}
PString p_name
Name of the current entry.
Definition ConfigNode.h:63

References p_name.

◆ getName() [2/2]

const PString & ConfigNode::getName ( ) const

Gets the name of the ConfigNode.

Returns
name of the ConfigNode

Definition at line 79 of file ConfigNode.cpp.

79 {
80 return p_name;
81}

References p_name.

Referenced by toJsonSaveRecurse().

+ Here is the caller graph for this function:

◆ getParent()

const ConfigNode * ConfigNode::getParent ( ) const

Gets the parent of the ConfigNode.

Returns
parent of the ConfigNode

Definition at line 130 of file ConfigNode.cpp.

130 {
131 return p_parent;
132}

References ConfigNode(), and p_parent.

+ Here is the call graph for this function:

◆ getString()

PString ConfigNode::getString ( ) const

Get string value without " or ' at the beginning of the end.

Returns
value without " or ' at the beginning of the end

Definition at line 229 of file ConfigNode.cpp.

229 {
230 return getValue().eraseFirstLastChar("\"'");
231}
const PString & getValue() const
Gets the value of the ConfigNode.

References getValue().

Referenced by phoenix_get_string(), phoenix_get_string(), phoenix_get_value(), and phoenix_get_value().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getValue() [1/2]

PString & ConfigNode::getValue ( )

Gets the value of the ConfigNode.

Returns
value of the ConfigNode

Definition at line 72 of file ConfigNode.cpp.

72 {
73 return p_value;
74}
PString p_value
Value of the current entry.
Definition ConfigNode.h:61

References p_value.

◆ getValue() [2/2]

const PString & ConfigNode::getValue ( ) const

Gets the value of the ConfigNode.

Returns
value of the ConfigNode

Definition at line 65 of file ConfigNode.cpp.

65 {
66 return p_value;
67}

References p_value.

Referenced by getString(), and toJsonSaveRecurse().

+ Here is the caller graph for this function:

◆ getVecChild() [1/2]

std::vector< ConfigNode * > & ConfigNode::getVecChild ( )

Gets the vecChild of the ConfigNode.

Returns
vecChild of the ConfigNode

Definition at line 100 of file ConfigNode.cpp.

100 {
101 return p_vecChild;
102}

References p_vecChild.

◆ getVecChild() [2/2]

const std::vector< ConfigNode * > & ConfigNode::getVecChild ( ) const

Gets the vecChild of the ConfigNode.

Returns
vecChild of the ConfigNode

Definition at line 93 of file ConfigNode.cpp.

93 {
94 return p_vecChild;
95}

References p_vecChild.

Referenced by phoenix_get_vecstring(), phoenix_load_vecValue(), and toJsonSaveRecurse().

+ Here is the caller graph for this function:

◆ hasMapChild()

bool ConfigNode::hasMapChild ( ) const

Say if the current ConfigNode has a map of children.

Returns
true if the current ConfigNode has a map of children

Definition at line 250 of file ConfigNode.cpp.

250 {
251 return p_vecChild.size() != 0lu && p_mapChild.size() != 0lu;
252}

References p_mapChild, and p_vecChild.

◆ hasValue()

bool ConfigNode::hasValue ( ) const

Say if the current ConfigNode has a value.

Returns
true if the current ConfigNode has a value

Definition at line 236 of file ConfigNode.cpp.

236 {
237 return p_vecChild.size() == 0lu && p_mapChild.size() == 0lu;
238}

References p_mapChild, and p_vecChild.

◆ hasVecChild()

bool ConfigNode::hasVecChild ( ) const

Say if the current ConfigNode has a vector of children.

Returns
true if the current ConfigNode has a vector of children

Definition at line 243 of file ConfigNode.cpp.

243 {
244 return p_vecChild.size() != 0lu && p_mapChild.size() == 0lu;
245}

References p_mapChild, and p_vecChild.

◆ initialisationConfigNode()

void ConfigNode::initialisationConfigNode ( )
private

Initialisation Function of class ConfigNode.

Definition at line 282 of file ConfigNode.cpp.

282 {
283 p_value = "";
284 p_name = "";
285 p_parent = NULL;
286}

References p_name, p_parent, and p_value.

Referenced by ConfigNode().

+ Here is the caller graph for this function:

◆ iter()

ConfigNodeIter ConfigNode::iter ( std::ostream & out = std::cout) const

Create an iterator of ConfigNode.

Parameters
[out]out: std::ostream to be used for the error messages
Returns
corresponding ConfigNodeIter

Definition at line 267 of file ConfigNode.cpp.

267 {
268 ConfigNodeIter it(this, &out, false);
269 return it;
270}

◆ iterWrite()

ConfigNodeIter ConfigNode::iterWrite ( std::ostream & out = std::cout)

Create an iterator of ConfigNode.

Parameters
[out]out: std::ostream to be used for the error messages
Returns
corresponding ConfigNodeIter

Definition at line 276 of file ConfigNode.cpp.

276 {
277 ConfigNodeIter it(this, &out, true);
278 return it;
279}

◆ setFileName()

void ConfigNode::setFileName ( const PPath & fileName)

Set the fileName of the current ConfigNode.

Parameters
fileName: file name of the current ConfigNode

Definition at line 137 of file ConfigNode.cpp.

137 {
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}

References p_location, and p_vecChild.

Referenced by parser_json().

+ Here is the caller graph for this function:

◆ setLineCol()

void ConfigNode::setLineCol ( const PLocation & location)

Set the line and the column of the current ConfigNode.

Parameters
location: PLocation which contains line and column of the current ConfigNode

Definition at line 162 of file ConfigNode.cpp.

162 {
163 if(p_location.getLine() == 0lu && p_location.getColumn() == 0lu){
164 p_location.setLine(location.getLine());
165 p_location.setColumn(location.getColumn());
166 }
167}
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

References PLocation::getColumn(), PLocation::getLine(), and p_location.

Referenced by parser_json_fileParser(), parser_json_key(), parser_json_list(), parser_json_map(), and parser_json_value().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLocation()

void ConfigNode::setLocation ( const PLocation & location)

Sets the location of the ConfigNode.

Parameters
location: location of the ConfigNode

Definition at line 51 of file ConfigNode.cpp.

51 {
52 p_location = location;
53}

References p_location.

◆ setMapChild()

void ConfigNode::setMapChild ( const std::map< PString, ConfigNode * > & mapChild)

Sets the mapChild of the ConfigNode.

Parameters
mapChild: mapChild of the ConfigNode

Definition at line 44 of file ConfigNode.cpp.

44 {
45 p_mapChild = mapChild;
46}

References p_mapChild.

◆ setName()

void ConfigNode::setName ( const PString & name)

Sets the name of the ConfigNode.

Parameters
name: name of the ConfigNode

Definition at line 30 of file ConfigNode.cpp.

30 {
31 p_name = name;
32}

References p_name.

Referenced by addChild().

+ Here is the caller graph for this function:

◆ setParent()

void ConfigNode::setParent ( const ConfigNode * parent)
private

Sets the parent of the ConfigNode.

Parameters
parent: parent of the ConfigNode

Definition at line 58 of file ConfigNode.cpp.

58 {
59 p_parent = parent;
60}

References ConfigNode(), and p_parent.

Referenced by addChild().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setValue()

void ConfigNode::setValue ( const PString & value)

Sets the value of the ConfigNode.

Parameters
value: value of the ConfigNode

Definition at line 23 of file ConfigNode.cpp.

23 {
24 p_value = value;
25}

References p_value.

Referenced by addValue(), parser_json_list(), and parser_json_value().

+ Here is the caller graph for this function:

◆ setVecChild()

void ConfigNode::setVecChild ( const std::vector< ConfigNode * > & vecChild)

Sets the vecChild of the ConfigNode.

Parameters
vecChild: vecChild of the ConfigNode

Definition at line 37 of file ConfigNode.cpp.

37 {
38 p_vecChild = vecChild;
39}

References p_vecChild.

Member Data Documentation

◆ p_location

PLocation ConfigNode::p_location
private

Location of the definition of the current ConfigNode.

Definition at line 69 of file ConfigNode.h.

Referenced by getFileName(), getLocation(), setFileName(), setLineCol(), and setLocation().

◆ p_mapChild

std::map<PString, ConfigNode*> ConfigNode::p_mapChild
private

◆ p_name

PString ConfigNode::p_name
private

Name of the current entry.

Definition at line 63 of file ConfigNode.h.

Referenced by getName(), getName(), initialisationConfigNode(), and setName().

◆ p_parent

const ConfigNode* ConfigNode::p_parent
private

Parent of the current ConfigNode.

Definition at line 71 of file ConfigNode.h.

Referenced by getFileName(), getParent(), initialisationConfigNode(), and setParent().

◆ p_value

PString ConfigNode::p_value
private

Value of the current entry.

Definition at line 61 of file ConfigNode.h.

Referenced by getValue(), getValue(), initialisationConfigNode(), and setValue().

◆ p_vecChild

std::vector<ConfigNode*> ConfigNode::p_vecChild
private

The documentation for this class was generated from the following files: