36 setRootNode(rootNode);
57 sprintf(rootNode,
"%s", node);
61 sprintf(rootNode,
"%s",
"");
67 bool okay = doc.LoadFile(cfgFile);
82 const char* value = getString(str,
"");
83 if (strcmp(value,
"") == 0)
85 else return strtoul(value, NULL, 10);
90 const char* value = getAttributeString(node,str,
"");
91 if (strcmp(value,
"") == 0)
93 else return strtoul(value, NULL, 10);
98 doc.SaveFile(cfgFile);
103 TiXmlElement* iter = doc.FirstChildElement( rootNode );
105 return findNode(name, iter);
110 TiXmlElement* iter = start;
112 if (name == NULL || strcasecmp(name,
"") == 0)
117 strcpy(sBuffer, name);
119 pch = strtok(sBuffer,
".");
121 while (iter && (pch != NULL))
123 iter = iter->FirstChildElement(pch);
124 pch = strtok(NULL,
".");
127 if ((pch == NULL) && (iter))
134 std::vector<std::string>& tokens,
135 const std::string& delimiters)
138 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
140 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
142 while (std::string::npos != pos || std::string::npos != lastPos)
145 tokens.push_back(str.substr(lastPos, pos - lastPos));
147 lastPos = str.find_first_not_of(delimiters, pos);
149 pos = str.find_first_of(delimiters, lastPos);
155 TiXmlElement* iter = doc.FirstChildElement( rootNode );
157 findNodes(name, result, iter, 0);
162 std::string str = name;
163 std::vector<std::string> tokens;
166 if (level + 1 > tokens.size())
172 TiXmlElement* iter = start->FirstChildElement();
175 if (strcasecmp(iter->Value(), tokens[level].c_str()) == 0)
177 if (level + 1 == tokens.size())
178 result.push_back(iter);
180 findNodes(name, result, iter, level + 1);
182 iter = iter->NextSiblingElement();
188 findNodes(name, result, start, 0);
221 const char* value = getAttributeString(node,str,
"");
222 if (strcmp(value,
"") == 0)
224 else return atof(value);
230 const char* value = getAttributeString(node,str,
"");
231 if (strcmp(value,
"") == 0)
233 else return atof(value);
239 const char* tmpstr = node->Attribute(str);
248 const char* value = getAttributeString(node,str,
"");
249 if (strcmp(value,
"") == 0)
251 else return atoi(value);
257 const char* value = getAttributeString(node,str,
"");
258 if (strcmp(value,
"") == 0)
260 else if (strcasecmp(value,
"true") == 0)
262 else if (strcasecmp(value,
"false") == 0)
276 sprintf(buffer,
"%f", value);
277 node->SetAttribute(str, buffer);
284 sprintf(buffer,
"%f", value);
285 node->SetAttribute(str, buffer);
291 node->SetAttribute(str, value);
298 sprintf(buffer,
"%d", value);
299 node->SetAttribute(str, buffer);
306 node->SetAttribute(str,
"true");
308 node->SetAttribute(str,
"false");
316 sprintf(buffer,
"%f", value);
317 setString(str, buffer);
323 sprintf(buffer,
"%f", value);
324 setString(str, buffer);
329 TiXmlElement* result = findNode(str);
333 TiXmlText* text = result->FirstChild()->ToText();
334 text->SetValue(value);
341 sprintf(buffer,
"%d", value);
342 setString(str, buffer);
348 setString(str,
"true");
350 setString(str,
"false");
356 return node->GetText();
363 TiXmlElement* result = findNode(str);
365 if (result != NULL && result->GetText() != NULL)
366 return (
const char*)result->GetText();
373 return (
float) getDouble(str, (
double)def);
378 const char* value = getString(str,
"");
379 if (strcmp(value,
"") == 0)
381 else return atof(value);
386 const char* value = getString(str,
"");
387 if (strcmp(value,
"") == 0)
389 else return atoi(value);
394 const char* value = getString(str,
"");
395 if (strcmp(value,
"") == 0)
397 else if (strcasecmp(value,
"true") == 0)
399 else if (strcasecmp(value,
"false") == 0)
407 TiXmlElement* result = findNode(str, start);
409 if (result != NULL && result->GetText() != NULL)
410 return (
const char*)result->GetText();
417 return (
float) getDouble(str, start, (
double)def);
422 const char* value = getString(str, start,
"");
423 if (strcmp(value,
"") == 0)
425 else return atof(value);
430 const char* value = getString(str, start,
"");
431 if (strcmp(value,
"") == 0)
433 else return atoi(value);
438 const char* value = getString(str, start,
"");
439 if (strcmp(value,
"") == 0)
441 else if (strcasecmp(value,
"true") == 0)
443 else if (strcasecmp(value,
"false") == 0)
450 return new TiXmlElement( name );
458 doc.LinkEndChild( element );
468 return addNode(element);
470 parent->LinkEndChild( element );
479 if (afterThis == NULL)
482 doc.InsertAfterChild((TiXmlNode*)afterThis, *(TiXmlNode*)node);
491 if (afterThis == NULL)
495 return insertNode(node, afterThis);
497 parent->InsertAfterChild(afterThis, *node);
507 return removeNode(element);
509 return parent->RemoveChild(element);
517 return doc.RemoveChild(element);
525 element->RemoveAttribute(name);
TiXmlElement * getNode(const char *name)
void setString(const char *str, const char *value)
void setInteger(const char *str, int value)
static void setAttributeDouble(TiXmlElement *node, const char *str, double value)
static const char * getAttributeString(TiXmlElement *node, const char *str, const char *def="")
bool insertNode(TiXmlElement *node, TiXmlElement *afterThis)
void setFloat(const char *str, float value)
bool removeAttribute(TiXmlElement *element, const char *name)
unsigned long getUnsignedLong(const char *str, unsigned long def=0)
static void setAttributeBoolean(TiXmlElement *node, const char *str, bool value)
bool addNode(TiXmlElement *node)
float getFloat(const char *str, float def=0.0)
bool removeNode(TiXmlElement *element)
static float getAttributeFloat(TiXmlElement *node, const char *str, float def=0.0)
static unsigned long getAttributeUnsignedLong(TiXmlElement *node, const char *str, unsigned long def=0)
TiXmlElement * findNode(const char *name)
static void setAttributeString(TiXmlElement *node, const char *str, const char *value)
bool load(const char *cfgFile)
static std::string getText(TiXmlElement *node)
void setDouble(const char *str, double value)
static void setAttributeInteger(TiXmlElement *node, const char *str, int value)
bool getBoolean(const char *str, bool def=false)
bool parse(const char *str)
static void setAttributeFloat(TiXmlElement *node, const char *str, float value)
void tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters)
virtual ~CConfiguration()
void save(const char *cfgFile)
int getInteger(const char *str, int def=0)
double getDouble(const char *str, double def=0.0)
TiXmlDocument & getDocument()
void findNodes(const char *name, std::vector< TiXmlElement * > &result, TiXmlElement *start, unsigned int level)
void setRootNode(const char *node)
static bool getAttributeBoolean(TiXmlElement *node, const char *str, bool def=false)
static int getAttributeInteger(TiXmlElement *node, const char *str, int def=0)
const char * getString(const char *str, const char *def="")
static double getAttributeDouble(TiXmlElement *node, const char *str, double def=0.0)
void setBoolean(const char *str, bool value)