XMLConfiguration.h
Go to the documentation of this file.
00001 #ifndef XMLCONFIGURATION_H_
00002 #define XMLCONFIGURATION_H_
00003 
00004 #include <string>
00005 //#include <map>
00006 
00007 //#include <utilities/TextFile.hpp>
00008 #include "Configuration.h"
00009 #include <tinyxml.h>
00010 #include <vector>
00011 
00012 // Forward declaration
00013 class IXMLConfigProperty;
00014 
00015 class IXMLConfigSection: public IConfigSection
00016 {
00017                 friend class CConfigSection;
00018 
00019         private:
00020                 TiXmlElement*           mPElement;
00021                 bool                            isSection(TiXmlElement* pElement) const;
00022                 bool                            isProperty(TiXmlElement* pElement) const;
00023 
00024         protected:
00025                 // Make the interface protected so that noone will accidentally use this class
00026                 std::string                     name() const;
00027                 bool                            hasSection(const std::string& section) const;
00028 
00029                 // Make sure that every function that returns an IConfigSection*,
00030                 // this pointer is added to mPendingInterfaces for later cleanup.
00031                 IConfigSection*         parent();
00032                 IConfigSection*         section(const std::string& section);
00033                 IConfigSection*         firstSection();
00034                 IConfigSection*         nextSection();
00035                 IConfigSection*         nextSimilarSection();
00036                 bool                            has(const std::string& property) const;
00037 
00038                 //bool                          isNull() const;
00039                 IConfigProperty*        get(const std::string& property);
00040                 IConfigProperty*        firstProperty();
00041 
00042         public:
00043                                                         IXMLConfigSection(TiXmlElement* pElement);
00044                 virtual                         ~IXMLConfigSection();
00045 };
00046 
00047 class IXMLConfigProperty: public IConfigProperty
00048 {
00049         friend class CConfigSection;
00050         private:
00051                 TiXmlElement*           mPElement;
00052                 bool                            isProperty(TiXmlElement* pElement) const;
00053 
00054         public:
00055                                                         IXMLConfigProperty(TiXmlElement* pElement);
00056                 virtual                         ~IXMLConfigProperty();
00057         protected:
00058                 std::string                     name() const;
00059                 std::string             toString() const;
00060                 void                            set(const std::string& value);
00061                 IConfigProperty*        nextProperty();
00062                 bool                            isVerbose() const;
00063 };
00064 
00065 
00072 typedef std::vector<TiXmlElement*>      TiXmlElementList;
00073 
00074 class CXMLConfiguration: public CConfiguration
00075 {
00076         protected:
00078                 TiXmlDocument                   mXMLDocument;
00079                 IXMLConfigSection               *mPRootConfigSection;
00080 
00082                 std::string                             mFilename;
00083                 // findXmlNode() searches for the XML nodes that fall into the nodePath (can contain wildcards, slashes, etc).
00084                 // Currently, only two types of paths are supported:
00085                 // 1) subnode/subnode2          (returns subnode2)
00086                 // 2) subnode/subnode2/         (returns all nodes *inside* subnode2)
00087                 bool                                    findXmlNode(TiXmlElement* rootElement, const std::string& nodePath, TiXmlElementList* resultList);
00088 
00089                 void                                    processIncludes(TiXmlElement* rootNode, TiXmlElement* node, const std::string& filePath);       // Processes <include> nodes
00090         public:
00091                                                                 CXMLConfiguration();
00092                 virtual                                 ~CXMLConfiguration();
00093 
00094                 virtual bool                    loadFile(const std::string& filename);
00095                 virtual bool                    saveFile(const std::string& filename = "");
00096                 virtual bool                    reload();
00097                 virtual std::string             errorStr();
00098                 virtual void                    clear();
00099                 virtual CConfigSection  root();
00100 
00101                 // DEBUGGING FUNCTIONS
00102                 void print();
00103 
00104         private:
00105                 /* Deny copying this class. Users should copy CConfigSections
00106                  * instead. */
00107                 CXMLConfiguration(CXMLConfiguration &other) : CConfiguration(other) { }
00108                 CXMLConfiguration &operator=(const CXMLConfiguration &other) { return *this; }
00109 };
00110 
00111 #endif /*XMLCONFIGURATION_H_*/


threemxl
Author(s):
autogenerated on Thu Jun 6 2019 21:10:52