diff options
author | Willem Jan Palenstijn <wjp@usecode.org> | 2015-05-01 17:48:32 +0200 |
---|---|---|
committer | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2015-05-06 15:18:03 +0200 |
commit | 47fe3421585302f2101691a685ab99b0e1ad5cfc (patch) | |
tree | 5f7ff204c5d19f83313487a840748724e04ad8e5 /include/astra | |
parent | bf31003d74f538a9096ef5999b31b0daa58c38c9 (diff) | |
download | astra-47fe3421585302f2101691a685ab99b0e1ad5cfc.tar.gz astra-47fe3421585302f2101691a685ab99b0e1ad5cfc.tar.bz2 astra-47fe3421585302f2101691a685ab99b0e1ad5cfc.tar.xz astra-47fe3421585302f2101691a685ab99b0e1ad5cfc.zip |
Change XMLNode* to XMLNode
An XMLNode object is already simply a pointer, so no need to dynamically allocate XMLNodes.
Diffstat (limited to 'include/astra')
-rw-r--r-- | include/astra/AstraObjectFactory.h | 2 | ||||
-rw-r--r-- | include/astra/Config.h | 5 | ||||
-rw-r--r-- | include/astra/XMLDocument.h | 2 | ||||
-rw-r--r-- | include/astra/XMLNode.h | 59 |
4 files changed, 35 insertions, 33 deletions
diff --git a/include/astra/AstraObjectFactory.h b/include/astra/AstraObjectFactory.h index ba4ec11..1ed4955 100644 --- a/include/astra/AstraObjectFactory.h +++ b/include/astra/AstraObjectFactory.h @@ -110,7 +110,7 @@ template <typename T, typename TypeList> T* CAstraObjectFactory<T, TypeList>::create(const Config& _cfg) { functor_find<T> finder = functor_find<T>(); - finder.tofind = _cfg.self->getAttribute("type"); + finder.tofind = _cfg.self.getAttribute("type"); CreateObject<TypeList>::find(finder); if (finder.res == NULL) return NULL; if (finder.res->initialize(_cfg)) diff --git a/include/astra/Config.h b/include/astra/Config.h index 0230dbe..c10a16e 100644 --- a/include/astra/Config.h +++ b/include/astra/Config.h @@ -44,13 +44,12 @@ namespace astra { struct _AstraExport Config { Config(); - Config(XMLNode* _self); + Config(XMLNode _self); ~Config(); void initialize(std::string rootname); - XMLNode* self; - XMLNode* global; + XMLNode self; XMLDocument *_doc; }; diff --git a/include/astra/XMLDocument.h b/include/astra/XMLDocument.h index 869e1a3..eddd908 100644 --- a/include/astra/XMLDocument.h +++ b/include/astra/XMLDocument.h @@ -78,7 +78,7 @@ public: * * @return first XML node of the document */ - XMLNode* getRootNode(); + XMLNode getRootNode(); /** Save an XML DOM tree to an XML file * diff --git a/include/astra/XMLNode.h b/include/astra/XMLNode.h index eceffe1..f79c1a8 100644 --- a/include/astra/XMLNode.h +++ b/include/astra/XMLNode.h @@ -64,71 +64,74 @@ public: /** Deconstructor */ ~XMLNode(); - + + /** Check validity + */ + operator bool() const { return fDOMElement != 0; } /** Get a single child XML node. If there are more, the first one is returned * * @param _sName tagname of the requested child node * @return first child node with the correct tagname, null pointer if it doesn't exist */ - XMLNode* getSingleNode(string _sName); + XMLNode getSingleNode(string _sName) const; /** Get all child XML nodes that have the tagname name * * @param _sName tagname of the requested child nodes * @return list with all child nodes with the correct tagname */ - std::list<XMLNode*> getNodes(string _sName); + std::list<XMLNode> getNodes(string _sName) const; /** Get all child XML nodes * * @return list with all child nodes */ - std::list<XMLNode*> getNodes(); + std::list<XMLNode> getNodes() const; /** Get the name of this node * * @return name of node */ - std::string getName(); + std::string getName() const; /** Get the content of the XML node as a single string. * * @return node content */ - string getContent(); + string getContent() const; /** Get the content of the XML node as a numerical. * * @return node content */ - float32 getContentNumerical(); + float32 getContentNumerical() const; /** Get the content of the XML node as a boolean. * * @return node content */ - bool getContentBool(); + bool getContentBool() const; /** Get the content of the XML node as a vector of strings. * * @return node content */ - vector<string> getContentArray(); + vector<string> getContentArray() const; /** Get the content of the XML node as a c-array of float32 data. * * @param _pfData data array, shouldn't be initialized already. * @param _iSize number of elements stored in _pfData */ - void getContentNumericalArray(float32*& _pfData, int& _iSize); + void getContentNumericalArray(float32*& _pfData, int& _iSize) const; /** Get the content of the XML node as a stl container of float32 data. * * @return node content */ - vector<float32> getContentNumericalArray(); - vector<double> getContentNumericalArrayDouble(); + vector<float32> getContentNumericalArray() const; + vector<double> getContentNumericalArrayDouble() const; @@ -137,7 +140,7 @@ public: * @param _sName of the attribute. * @return attribute value, empty string if it doesn't exist. */ - bool hasAttribute(string _sName); + bool hasAttribute(string _sName) const; /** Get the value of an attribute. * @@ -145,7 +148,7 @@ public: * @param _sDefaultValue value to return if the attribute isn't found * @return attribute value, _sDefaultValue if it doesn't exist. */ - string getAttribute(string _sName, string _sDefaultValue = ""); + string getAttribute(string _sName, string _sDefaultValue = "") const; /** Get the value of a numerical attribute. * @@ -153,8 +156,8 @@ public: * @param _fDefaultValue value to return if the attribute isn't found * @return attribute value, _fDefaultValue if it doesn't exist. */ - float32 getAttributeNumerical(string _sName, float32 _fDefaultValue = 0); - double getAttributeNumericalDouble(string _sName, double _fDefaultValue = 0); + float32 getAttributeNumerical(string _sName, float32 _fDefaultValue = 0) const; + double getAttributeNumericalDouble(string _sName, double _fDefaultValue = 0) const; /** Get the value of a boolean attribute. * @@ -162,7 +165,7 @@ public: * @param _bDefaultValue value to return if the attribute isn't found * @return attribute value, _bDefaultValue if it doesn't exist. */ - bool getAttributeBool(string _sName, bool _bDefaultValue = false); + bool getAttributeBool(string _sName, bool _bDefaultValue = false) const; @@ -172,7 +175,7 @@ public: * @param _sKey option key * @return true if option does exist */ - bool hasOption(string _sKey); + bool hasOption(string _sKey) const; /** Get the value of an option within this XML Node * @@ -180,7 +183,7 @@ public: * @param _sDefaultValue value to return if key isn't found * @return option value, _sDefaultValue if the option doesn't exist */ - string getOption(string _sKey, string _sDefaultValue = ""); + string getOption(string _sKey, string _sDefaultValue = "") const; /** Get the value of an option within this XML Node * @@ -188,7 +191,7 @@ public: * @param _fDefaultValue value to return if key isn't found * @return option value, _fDefaultValue if the option doesn't exist */ - float32 getOptionNumerical(string _sKey, float32 _fDefaultValue = 0); + float32 getOptionNumerical(string _sKey, float32 _fDefaultValue = 0) const; /** Get the value of an option within this XML Node * @@ -196,14 +199,14 @@ public: * @param _bDefaultValue value to return if key isn't found * @return option value, _bDefaultValue if the option doesn't exist */ - bool getOptionBool(string _sKey, bool _bDefaultValue = false); + bool getOptionBool(string _sKey, bool _bDefaultValue = false) const; /** Get the value of an option within this XML Node * * @param _sKey option key * @return numerical array */ - vector<float32> getOptionNumericalArray(string _sKey); + vector<float32> getOptionNumericalArray(string _sKey) const; @@ -214,7 +217,7 @@ public: * @param _sNodeName the name of the new childnode * @return new child node */ - XMLNode* addChildNode(string _sNodeName); + XMLNode addChildNode(string _sNodeName); /** Create a new XML node as a child to this one, also add some content: * <...><_sNodeName>_sValue</_sNodeName></...> @@ -223,7 +226,7 @@ public: * @param _sValue some node content * @return new child node */ - XMLNode* addChildNode(string _sNodeName, string _sValue); + XMLNode addChildNode(string _sNodeName, string _sValue); /** Create a new XML node as a child to this one, also add some numerical content: * <...><_sNodeName>_sValue</_sNodeName></...> @@ -232,7 +235,7 @@ public: * @param _fValue some node content * @return new child node */ - XMLNode* addChildNode(string _sNodeName, float32 _fValue); + XMLNode addChildNode(string _sNodeName, float32 _fValue); /** Create a new XML node as a child to this one, also add a list of numerical content: * <...><_sNodeName>_sValue</_sNodeName></...> @@ -242,7 +245,7 @@ public: * @param _iSize number of elements in _pfList * @return new child node */ - XMLNode* addChildNode(string _sNodeName, float32* _pfList, int _iSize); + XMLNode addChildNode(string _sNodeName, float32* _pfList, int _iSize); /** Add some text to the node: <...>_sText</...> * @@ -294,11 +297,11 @@ public: /** Print to String */ - std::string toString(); + std::string toString() const; /** Print the node */ - void print(); + void print() const; protected: |