summaryrefslogtreecommitdiffstats
path: root/include/astra/XMLNode.h
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2015-05-13 11:56:24 +0200
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2015-05-13 11:56:24 +0200
commitde30f7538a865a2ee7acb7dd8294fb6cdc4f98be (patch)
treeba11189e6e83e83e73167518b45641fc287c8eda /include/astra/XMLNode.h
parent6504cffdbe74d9b671222a7ec24b26fbb4f871f0 (diff)
parent86ad56f005d9d3871f654390739459d5634dd5d5 (diff)
downloadastra-de30f7538a865a2ee7acb7dd8294fb6cdc4f98be.tar.gz
astra-de30f7538a865a2ee7acb7dd8294fb6cdc4f98be.tar.bz2
astra-de30f7538a865a2ee7acb7dd8294fb6cdc4f98be.tar.xz
astra-de30f7538a865a2ee7acb7dd8294fb6cdc4f98be.zip
Merge branch 'master'
Diffstat (limited to 'include/astra/XMLNode.h')
-rw-r--r--include/astra/XMLNode.h92
1 files changed, 57 insertions, 35 deletions
diff --git a/include/astra/XMLNode.h b/include/astra/XMLNode.h
index eceffe1..4d29d5c 100644
--- a/include/astra/XMLNode.h
+++ b/include/astra/XMLNode.h
@@ -64,71 +64,68 @@ 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();
-
- /** 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);
+ vector<string> getContentArray() const;
/** Get the content of the XML node as a stl container of float32 data.
+ * NB: A 2D matrix is returned as a linear list
*
* @return node content
*/
- vector<float32> getContentNumericalArray();
- vector<double> getContentNumericalArrayDouble();
+ vector<float32> getContentNumericalArray() const;
+ vector<double> getContentNumericalArrayDouble() const;
@@ -137,7 +134,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 +142,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 +150,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 +159,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 +169,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 +177,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 +185,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 +193,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 +211,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:
* &lt;...&gt;&lt;_sNodeName&gt;_sValue&lt;/_sNodeName>&lt;/...&gt;
@@ -223,7 +220,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:
* &lt;...&gt;&lt;_sNodeName&gt;_sValue&lt;/_sNodeName>&lt;/...&gt;
@@ -232,7 +229,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:
* &lt;...&gt;&lt;_sNodeName&gt;_sValue&lt;/_sNodeName>&lt;/...&gt;
@@ -242,7 +239,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: &lt;...&gt;_sText&lt;/...&gt;
*
@@ -256,13 +253,38 @@ public:
*/
void setContent(float32 _fValue);
- /** Add a list of numerical data to the node: &lt;...&gt;_sText&lt;/...&gt;
+ /** Add a list of numerical data to the node
*
* @param _pfList data
* @param _iSize number of elements in the list
*/
void setContent(float32* _pfList, int _iSize);
+ /** Add a list of numerical data to the node
+ *
+ * @param _pfList data
+ * @param _iSize number of elements in the list
+ */
+ void setContent(double* _pfList, int _iSize);
+
+ /** Add a (2D) matrix of numerical data to the node
+ *
+ * @param _pfMatrix data
+ * @param _iWidth width of the matrix
+ * @param _iHeight height of the matrix
+ * @param transposed true is C order, false is Fortran order
+ */
+ void setContent(float32* _pfMatrix, int _iWidth, int _iHeight, bool transposed);
+
+ /** Add a (2D) matrix of numerical data to the node
+ *
+ * @param _pfMatrix data
+ * @param _iWidth width of the matrix
+ * @param _iHeight height of the matrix
+ * @param transposed true is C order, false is Fortran order
+ */
+ void setContent(double* _pfMatrix, int _iWidth, int _iHeight, bool transposed);
+
/** Add an attribute to this node: &lt;... _sName="_sValue"&gt;
*
* @param _sName name of the attribute
@@ -294,11 +316,11 @@ public:
/** Print to String
*/
- std::string toString();
+ std::string toString() const;
/** Print the node
*/
- void print();
+ void print() const;
protected: