Gazebo

XMLConfig.hh

00001 /*
00002  *  Gazebo - Outdoor Multi-Robot Simulator
00003  *  Copyright (C) 2003  
00004  *     Nate Koenig & Andrew Howard
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 /* Desc: XML config file
00022  * Author: Andrew Howard and Nate Koenig
00023  * Date: 3 Apr 2007
00024  * SVN: $Id: XMLConfig.hh 156 2007-11-26 20:26:57Z natepak $
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 
00039 namespace gazebo
00040 {
00041   
00042   // Forward declarations
00043   class XMLConfigNode;
00044   
00048   
00050   class XMLConfig
00051   {
00053     public: XMLConfig();
00054   
00056     public: ~XMLConfig();
00057   
00059     public: int Load( std::string filename );
00060   
00062     public: int LoadString( std::string str );
00063   
00066     public: int Save( std::string filename );
00067   
00069     public: XMLConfigNode *GetRootNode() const;
00070   
00072     private: XMLConfigNode *CreateNodes( XMLConfigNode *parent, 
00073                                          xmlNodePtr xmlNode );
00075     public: std::string filename;
00076     
00078     private: xmlDocPtr xmlDoc;
00079   
00081     private: XMLConfigNode *root;
00082   
00083     private: xmlXPathContextPtr xpathContex;
00084   };
00085   
00086   
00088   class XMLConfigNode
00089   {
00091     public: XMLConfigNode( XMLConfig *cfg, XMLConfigNode *parent, 
00092                           xmlNodePtr xmlNode, xmlDocPtr xmlDoc );
00093   
00095     public: ~XMLConfigNode();
00096   
00098     public: std::string GetName();
00099   
00101     public: std::string GetNSPrefix();
00102   
00104     public: XMLConfigNode *GetNext();
00105 
00107     public: XMLConfigNode *GetNext(std::string name);
00108 
00110     public: XMLConfigNode *GetNextByNSPrefix(std::string name);
00111   
00113     public: XMLConfigNode *GetChild();
00114   
00116     public: XMLConfigNode *GetChild( std::string name );
00117   
00119     public: XMLConfigNode *GetChildByNSPrefix( std::string prefix );
00120   
00122     public: XMLConfigNode *Rewind();
00123   
00125     public: void Print();
00126   
00128     public: std::string GetValue();
00129   
00131     public: std::string GetString( std::string key, std::string def, 
00132                                    int require = 0 );
00133   
00135     public: unsigned char GetChar( std::string key, char def, int require = 0 );
00136   
00140     public: std::string GetFilename( std::string key, std::string def, 
00141                                      int require = 0);
00142   
00144     public: int GetInt( std::string key, int def, int require = 0 );
00145   
00147     public: double GetDouble( std::string key, double def, int require = 0 );
00148   
00150     public: float GetFloat( std::string key, float def, int require = 0 );
00151   
00153     public: bool GetBool( std::string key, bool def, int require = 0 );
00154   
00156     public: double GetLength( std::string key, double def, int require = 0 );
00157   
00159     public: gazebo::Time GetTime( std::string key, double def, int require = 0 );
00160   
00162     public: Vector3 GetVector3( std::string key, Vector3 def );
00163   
00165     public: Vector2<double> GetVector2d( std::string key, Vector2<double> def );
00166 
00168     public: Vector2<int> GetVector2i( std::string key, Vector2<int> def );
00169   
00171     public: Quatern GetRotation( std::string key, Quatern def );
00172   
00174     public: std::string GetTupleString( std::string key, int index, 
00175                                         std::string def );
00176   
00178     public: int GetTupleInt( std::string key, int index, int def );
00179   
00181     public: double GetTupleDouble( std::string key, int index, double def );
00182   
00184     public: double GetTupleLength( std::string key, int index, double def );
00185   
00187     public: double GetTupleAngle( std::string key, int index, double def );
00188   
00190     protected: xmlChar* GetNodeValue( std::string key );
00191   
00193     private: XMLConfig *config;
00194     
00196     private: XMLConfigNode *parent;
00197     
00199     private: XMLConfigNode *next, *prev;
00200     
00202     private: XMLConfigNode *childFirst, *childLast;
00203   
00205     private: xmlNodePtr xmlNode;
00206   
00208     private: xmlDocPtr xmlDoc;
00209   };
00210   
00212 }
00213 
00214 #endif
00215 

Last updated Aug 04 2007