Go to the documentation of this file.
19 #ifndef __CONFIGURATION
21 #define __CONFIGURATION
23 #include <vector>
24 #include <string>
25 #include "tinyxml.h"
26 #include "utils.h"
35 {
36  protected:
37  TiXmlDocument doc;
38  char rootNode[255];
40  void findNodes(const char* name, std::vector<TiXmlElement*> &result, TiXmlElement* start, unsigned int level);
42  public:
43  CConfiguration(const char* rootNode);
46  virtual ~CConfiguration();
47  void findNodes(const char* name, std::vector<TiXmlElement*> &result);
48  void findNodes(const char* name, std::vector<TiXmlElement*> &result, TiXmlElement* start);
49  TiXmlElement* findNode(const char* name);
50  TiXmlElement* findNode(const char* name, TiXmlElement* start);
51  void setRootNode(const char* node);
53  bool load(const char* cfgFile);
54  bool parse(const char* str);
55  void save(const char* cfgFile);
56  void clear();
57  float getFloat(const char* str, float def = 0.0);
58  double getDouble(const char* str, double def = 0.0);
59  const char* getString(const char* str, const char* def = "");
60  int getInteger(const char* str, int def = 0);
61  unsigned long getUnsignedLong(const char* str, unsigned long def = 0);
62  bool getBoolean(const char* str, bool def = false);
64  static std::string getText(TiXmlElement* node);
66  float getFloat(const char* str, TiXmlElement* start, float def = 0.0);
67  double getDouble(const char* str, TiXmlElement* start, double def = 0.0);
68  const char* getString(const char* str, TiXmlElement* start, const char* def = "");
69  int getInteger(const char* str, TiXmlElement* start, int def = 0);
70  bool getBoolean(const char* str, TiXmlElement* start, bool def = false);
72  void setFloat(const char* str, float value);
73  void setDouble(const char* str, double value);
74  void setString(const char* str, const char* value);
75  void setInteger(const char* str, int value);
76  void setBoolean(const char* str, bool value);
78  static float getAttributeFloat(TiXmlElement* node, const char* str, float def = 0.0);
79  static unsigned long getAttributeUnsignedLong(TiXmlElement* node, const char* str, unsigned long def = 0);
80  static double getAttributeDouble(TiXmlElement* node, const char* str, double def = 0.0);
81  static const char* getAttributeString(TiXmlElement* node, const char* str, const char* def = "");
82  static int getAttributeInteger(TiXmlElement* node, const char* str, int def = 0);
83  static bool getAttributeBoolean(TiXmlElement* node, const char* str, bool def = false);
85  static void setAttributeFloat(TiXmlElement* node, const char* str, float value);
86  static void setAttributeDouble(TiXmlElement* node, const char* str, double value);
87  static void setAttributeString(TiXmlElement* node, const char* str, const char* value);
88  static void setAttributeInteger(TiXmlElement* node, const char* str, int value);
89  static void setAttributeBoolean(TiXmlElement* node, const char* str, bool value);
91  TiXmlDocument &getDocument();
93  TiXmlElement* getNode(const char* name);
94  bool addNode(TiXmlElement* node);
95  bool addNode(TiXmlElement* node, TiXmlElement* parent);
96  bool insertNode(TiXmlElement* node, TiXmlElement* afterThis);
97  bool insertNode(TiXmlElement* node, TiXmlElement* afterThis, TiXmlElement* parent);
99  bool removeNode(TiXmlElement* element);
100  bool removeNode(TiXmlElement* element, TiXmlElement* parent);
101  bool removeAttribute(TiXmlElement* element, const char* name);
102 };
104 #define XML_LOADER_INIT std::vector<std::string> xml_loader_strings;
105 #define XML_LOADER_ADD(Y,X) xml_loader_strings.push_back(robotLibPbD::printToString("<%s>%s</%s>", Y, X.c_str(), Y));
106 #define XML_LOADER_ADD_STRING(Y,X) xml_loader_strings.push_back(robotLibPbD::printToString("<%s>%s</%s>", Y, X.c_str(), Y));
107 #define XML_LOADER_ADD_INTEGER(Y,X) xml_loader_strings.push_back(robotLibPbD::printToString("<%s>%d</%s>", Y, X, Y));
108 #define XML_LOADER_ADD_DOUBLE(Y,X) xml_loader_strings.push_back(robotLibPbD::printToString("<%s>%g</%s>", Y, X, Y));
109 #define XML_LOADER_ADD_FLOAT(Y,X) xml_loader_strings.push_back(robotLibPbD::printToString("<%s>%g</%s>", Y, X, Y));
110 #define XML_LOADER_ADD_BOOLEAN(Y,X) xml_loader_strings.push_back(robotLibPbD::printToString("<%s>%s</%s>", Y, X ? "true" : "false", Y));
111 #define XML_LOADER_GET(Y) { \
112  for (unsigned int i=0; i<xml_loader_strings.size(); i++) \
113  { \
114  Y += xml_loader_strings[i] + "\n"; \
115  } \
116  }
119 {
120  public:
121  virtual bool writeAsXml(std::string &output, bool addBracket = true) { return false; };
122  virtual bool readFromXml(CConfiguration &configuration, TiXmlElement* xmlNode) { return false; };
123 };
125 void tokenize(const std::string& str,
126  std::vector<std::string>& tokens,
127  const std::string& delimiters);
129 #endif
TiXmlDocument doc
Definition: configuration.h:37
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="")
void tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters)
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)
char rootNode[255]
Definition: configuration.h:38
virtual ~CConfiguration()
void save(const char *cfgFile)
int getInteger(const char *str, int def=0)
double getDouble(const char *str, double def=0.0)
virtual bool writeAsXml(std::string &output, bool addBracket=true)
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)
virtual bool readFromXml(CConfiguration &configuration, TiXmlElement *xmlNode)
Configuration file wrapper.
Definition: configuration.h:34
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)

Author(s): Aumann Florian, Heller Florian, Jäkel Rainer, Wittenbeck Valerij
autogenerated on Mon Jun 10 2019 12:35:36