00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef XMLCONFIG_HH
00028 #define XMLCONFIG_HH
00029
00030 #include <libxml/parser.h>
00031 #include <libxml/xpath.h>
00032 #include <string>
00033
00034 #include "Vector3.hh"
00035 #include "Vector2.hh"
00036 #include "Quatern.hh"
00037 #include "Time.hh"
00038 #include "StringValue.hh"
00039
00040 namespace gazebo
00041 {
00042
00043
00044 class XMLConfigNode;
00045
00049
00051 class XMLConfig
00052 {
00054 public: XMLConfig();
00055
00057 public: ~XMLConfig();
00058
00060 public: void Load(const std::string &filename );
00061
00063 public: void LoadString(const std::string &str );
00064
00067 public: int Save(const std::string &filename );
00068
00070 public: XMLConfigNode *GetRootNode() const;
00071
00073 private: XMLConfigNode *CreateNodes( XMLConfigNode *parent,
00074 xmlNodePtr xmlNode );
00076 public: std::string filename;
00077
00079 private: xmlDocPtr xmlDoc;
00080
00082 private: XMLConfigNode *root;
00083
00084 private: xmlXPathContextPtr xpathContex;
00085 };
00086
00087
00089 class XMLConfigNode
00090 {
00092 public: XMLConfigNode( XMLConfig *cfg, XMLConfigNode *parent,
00093 xmlNodePtr xmlNode, xmlDocPtr xmlDoc );
00094
00096 public: ~XMLConfigNode();
00097
00099 public: std::string GetName();
00100
00102 public: std::string GetNSPrefix();
00103
00105 public: XMLConfigNode *GetNext();
00106
00108 public: XMLConfigNode *GetNext(const std::string &name,const std::string &prefix=std::string());
00109
00111 public: XMLConfigNode *GetNextByNSPrefix(const std::string &prefix);
00112
00114 public: XMLConfigNode *GetChild();
00115
00117 public: XMLConfigNode *GetChild(const std::string &name, const std::string &prefix=std::string() );
00118
00120 public: XMLConfigNode *GetChildByNSPrefix(const std::string &prefix );
00121
00123 public: XMLConfigNode *Rewind();
00124
00126 public: void Print();
00127
00129 public: std::string GetValue();
00130
00132 public: std::string GetString( const std::string &key, const std::string &def,
00133 int require = 0 );
00134
00136 public: unsigned char GetChar( const std::string &key, char def, int require = 0 );
00137
00141 public: std::string GetFilename( const std::string &key, const std::string &def,
00142 int require = 0);
00143
00145 public: int GetInt( const std::string &key, int def, int require = 0 );
00146
00148 public: double GetDouble( const std::string &key, double def, int require = 0 );
00149
00151 public: float GetFloat( const std::string &key, float def, int require = 0 );
00152
00154 public: bool GetBool( const std::string &key, bool def, int require = 0 );
00155
00157 public: double GetLength( const std::string &key, double def, int require = 0 );
00158
00160 public: gazebo::Time GetTime( const std::string &key, double def, int require = 0 );
00161
00163 public: Vector3 GetVector3( const std::string &key, Vector3 def );
00164
00166 public: Vector2<double> GetVector2d( const std::string &key, Vector2<double> def );
00167
00169 public: Vector2<int> GetVector2i( const std::string &key, Vector2<int> def );
00170
00172 public: Quatern GetRotation( const std::string &key, Quatern def );
00173
00175 public: std::string GetTupleString( const std::string &key, int index,
00176 const std::string &def );
00177
00179 public: int GetTupleInt( const std::string &key, int index, int def );
00180
00182 public: double GetTupleDouble( const std::string &key, int index, double def );
00183
00185 public: double GetTupleLength( const std::string &key, int index, double def );
00186
00188 public: double GetTupleAngle( const std::string &key, int index, double def );
00189
00195 public: void SetValue(const std::string &key, const StringValue &data, int require =0, int type=0);
00196
00198 protected: xmlChar* GetNodeValue( const std::string &key );
00199
00201 protected: bool SetNodeValue(const std::string& key,const std::string& value);
00202
00204 protected: void NewNode(const char* key, const char* value, int type);
00205
00207 private: XMLConfig *config;
00208
00210 private: XMLConfigNode *parent;
00211
00213 private: XMLConfigNode *next, *prev;
00214
00216 private: XMLConfigNode *childFirst, *childLast;
00217
00219 private: xmlNodePtr xmlNode;
00220
00222 private: xmlDocPtr xmlDoc;
00223 };
00224
00225
00227 }
00228
00229 #endif
00230