MeVisLab Toolbox Reference
mlXMLTreeNode.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_XMLTREE_NODE_H
14#define ML_XMLTREE_NODE_H
15
16
19
20#include "mlBase.h"
21#include "mlTreeNode.h"
22#include "../mlParserSystem.h"
23#include "mlXMLParserSystem.h"
24
25#include <mlTypeDefs.h>
26
27namespace XERCES_CPP_NAMESPACE {
28
29 class DOMElement;
30 class DOMNode;
31 class XercesDOMParser;
32}
33
34using namespace XERCES_CPP_NAMESPACE;
35
36
37ML_START_NAMESPACE
38
40 enum {
46
49 };
50
54
55 public:
56
58 XMLTreeNodeException(int errorCode = 0, const char* msg = nullptr);
59
61
63 const char* getMessage() const override;
64
65 private:
66
67 std::string _message;
68
70 static const char* _stdErrorMsg[];
71
75
76 };
77
78
83 {
84 public:
85
87
98
100
102 ~XMLTreeNode() override;
103
106
108 void writeToFile (const char* fileName) override;
109
110 public:
111 void writeToString(std::string& str) override;
113
116
118 void readFromFile (const char* fileName) override;
119
120 void readFromString(const std::string& str) override;
121
123
136
137 //virtual void addChild (bool val, const char* tagName);
138 void addChild (unsigned long val, const char* tagName) override;
139 void addChild (long val, const char* tagName) override;
140 void addChild (MLuint64 val, const char* tagName) override;
141 void addChild (MLint64 val, const char* tagName) override;
142 void addChild (long double val, const char* tagName) override;
143 void addChild (const Vector2& vec, const char* tagName) override;
144 void addChild (const Vector3& vec, const char* tagName) override;
145 void addChild (const Vector4& vec, const char* tagName) override;
146 void addChild (const Vector6& vec, const char* tagName) override;
147 void addChild (const ImageVector& vec, const char* tagName) override;
148 void addChild (const Matrix3& mat, const char* tagName) override;
149 void addChild (const Matrix4& mat, const char* tagName) override;
150 void addChild (const SubImageBox& box, const char* tagName) override;
151 void addChild (const SubImageBoxd& box, const char* tagName) override;
152
153 public:
154
155 void addChild(const std::string& str, const char* tagName) override;
156 void addChild (const void* const ptr, size_t noBytes, const char* tagName) override;
157
158
161
166 void addChild (const Base* const obj, const char* tagName, bool generic = true) override;
167
170 TreeNode* addChild ( const char* tagName) override;
171
172
174
187
192 bool hasChild (const char* tagName = nullptr) override;
193
194 //virtual void readChild (bool& val, const char* tagName = NULL);
195 void readChild (unsigned long& val, const char* tagName = nullptr) override;
196 void readChild (long& val, const char* tagName = nullptr) override;
197 void readChild (MLuint64& val, const char* tagName = nullptr) override;
198 void readChild (MLint64& val, const char* tagName = nullptr) override;
199 void readChild (long double& val, const char* tagName = nullptr) override;
200 void readChild (Vector2& val, const char* tagName = nullptr) override;
201 void readChild (Vector3& val, const char* tagName = nullptr) override;
202 void readChild (Vector4& val, const char* tagName = nullptr) override;
203 void readChild (Vector6& val, const char* tagName = nullptr) override;
204 void readChild (ImageVector& val, const char* tagName = nullptr) override;
205 void readChild (Matrix3& val, const char* tagName = nullptr) override;
206 void readChild (Matrix4& val, const char* tagName = nullptr) override;
207 void readChild (SubImageBox& val, const char* tagName = nullptr) override;
208 void readChild (SubImageBoxd& val, const char* tagName = nullptr) override;
209
211 void readChild(void*& ptr, unsigned long& noBytes, const char* tagName = nullptr) override;
212
213
214public:
215
216 void readChild(std::string& val, const char* tagName = nullptr) override;
217
221 void readChild (Base*& val, const char* tagName = nullptr) override;
222
226 void readChild (Base& val, const char* tagName = nullptr) override;
227
229 void readChild (TreeNode*& val, const char* tagName = nullptr) override;
230
231public:
232
233
235
238
240 void deleteMemory(void* ptr) override;
241
243 void setVersion(const char* className, int version) override;
244
246 int getVersion(const char* /*className*/) override;
247
249
251 const char* getLastReadChildName() const override;
252
257 static char* normalizeFileName(const char* fileName);
258
261
262 static void initXMLSystem();
263 static void terminateXMLSystem();
264
266
267 protected:
268
269 //------------------------------------------------
272 //------------------------------------------------
273
276 XMLTreeNode(DOMElement* parent);
277
279 static char* _getTextNodeString(DOMElement* parentNode);
280
283 DOMElement* _findElemByTagName(const char* tagName, DOMNode* prevNode = nullptr);
284
286 XMLTreeNode* _addTreeNodeChild(DOMElement* child);
287
289 DOMElement* _parentDOMNode;
290
291 // count the number of active root instances, so we can correctly
292 // terminate the XML framework after deleting the last one
294
297
299
300 private:
301 // above code hides overloaded virtual function and causes a lot of compiler warnings.
302 // This using silence the warning while keeping the old public interface. Still, it doesn't fix the real problem.
303 using TreeNode::addChild;
304 using TreeNode::readChild;
305
307 void _initFromParser(XercesDOMParser& parser);
308
310 DOMNode* _lastNode;
311
313 DOMNode* _lastNodeRead;
314
316 mutable StringX _lastName;
317
321
322 }; // class XMLTreeNode
323
324ML_END_NAMESPACE
325
326#endif
327
Defines library specific stuff, mostly for system independence.
TreeNodeException(int errorCode=0, const char *msg=nullptr)
ConstructionMode
TreeNode construction modes.
Definition mlTreeNode.h:197
@ CM_writerRoot
Construct as root node for writing.
Definition mlTreeNode.h:200
virtual void addChild(bool val, const char *name) ADD_ULONG_CHILD
Factory method for adding a child encapsulating a variable of type bool.
XMLTreeNodeException(int errorCode=0, const char *msg=nullptr)
Constructor.
const char * getMessage() const override
Returns an error message containing error code and message (if present).
void readFromString(const std::string &str) override
Reads the subtree represented by this node from a string.
void readChild(SubImageBox &val, const char *tagName=nullptr) override
void readChild(Matrix4 &val, const char *tagName=nullptr) override
void deleteMemory(void *ptr) override
frees memory obtained with readChild(void*& ...)
static void terminateXMLSystem()
void setVersion(const char *className, int version) override
Set version for current node. className is currently not used.
void addChild(const Matrix4 &mat, const char *tagName) override
void readChild(Base *&val, const char *tagName=nullptr) override
void addChild(const void *const ptr, size_t noBytes, const char *tagName) override
void readChild(Vector2 &val, const char *tagName=nullptr) override
void writeToString(std::string &str) override
Generates a string representation of the subtree represented by this node to a file.
static void initXMLSystem()
void addChild(const std::string &str, const char *tagName) override
void addChild(const SubImageBox &box, const char *tagName) override
void readChild(long double &val, const char *tagName=nullptr) override
XMLTreeNode(TreeNode::ConstructionMode mode=TreeNode::CM_writerRoot)
Constructor.
static char * _getTextNodeString(DOMElement *parentNode)
Returns the string contained by the TextNode child of parentNode.
void addChild(const Vector3 &vec, const char *tagName) override
void addChild(const Vector6 &vec, const char *tagName) override
void readChild(ImageVector &val, const char *tagName=nullptr) override
void addChild(unsigned long val, const char *tagName) override
Factory method for adding a child encapsulating a variable of type long.
XMLTreeNode * _addTreeNodeChild(DOMElement *child)
Adds a new node containing the given child.
void readChild(SubImageBoxd &val, const char *tagName=nullptr) override
void readChild(unsigned long &val, const char *tagName=nullptr) override
void readChild(Vector6 &val, const char *tagName=nullptr) override
void addChild(const Vector4 &vec, const char *tagName) override
static int _numActiveRootInstances
void addChild(const SubImageBoxd &box, const char *tagName) override
void readChild(Base &val, const char *tagName=nullptr) override
DOMElement * _parentDOMNode
pointer to the DOM node actually wrapped by this class
void readFromFile(const char *fileName) override
Generates a tree parsing a file. Throws TNE_FileNotFound, TNE_ReadingFile, TNE_XML_ParserError.
void readChild(Vector3 &val, const char *tagName=nullptr) override
void addChild(const Vector2 &vec, const char *tagName) override
void readChild(MLint64 &val, const char *tagName=nullptr) override
void addChild(const ImageVector &vec, const char *tagName) override
void readChild(long &val, const char *tagName=nullptr) override
XMLTreeNode(DOMElement *parent)
void readChild(Matrix3 &val, const char *tagName=nullptr) override
static bool _xercesInitialized
Indicates whether the Xerces XML SubSystem is already initialized.
~XMLTreeNode() override
Destructor.
DOMElement * _findElemByTagName(const char *tagName, DOMNode *prevNode=nullptr)
void readChild(Vector4 &val, const char *tagName=nullptr) override
void addChild(long double val, const char *tagName) override
Factory method for adding a child encapsulating a variable of type long double.
void addChild(MLuint64 val, const char *tagName) override
Factory method for adding a child encapsulating a variable of type MLuint64.
void addChild(long val, const char *tagName) override
Factory method for adding a child encapsulating a variable of type long.
void addChild(const Base *const obj, const char *tagName, bool generic=true) override
void writeToFile(const char *fileName) override
Writes the complete tree to a file. Throws TNE_WritingFile.
TreeNode * addChild(const char *tagName) override
void readChild(MLuint64 &val, const char *tagName=nullptr) override
void readChild(TreeNode *&val, const char *tagName=nullptr) override
Returns the group or container node with the specified tag name.
bool hasChild(const char *tagName=nullptr) override
const char * getLastReadChildName() const override
Returns the name of the child most recently read.
void readChild(void *&ptr, unsigned long &noBytes, const char *tagName=nullptr) override
The returned ptr (string) must be deleted later with deleteMemory(ptr).
void readChild(std::string &val, const char *tagName=nullptr) override
void addChild(const Matrix3 &mat, const char *tagName) override
static char * normalizeFileName(const char *fileName)
void addChild(MLint64 val, const char *tagName) override
Factory method for adding a child encapsulating a variable of type MLint64.
int getVersion(const char *) override
Get version of current node. className is currently not used.
#define PARSER_EXPORT
#define ML_CLASS_HEADER(className)
UINT64 MLuint64
Introduce platform-independent 64-bit unsigned integer type.
Definition mlTypeDefs.h:424
INT64 MLint64
Include 64-bit integer support for Windows or Unix.
Definition mlTypeDefs.h:411
Implement the AbstractPersistence(Input/Output)Stream classes with XML backend.
@ TNE_COUNT
Definition mlTreeNode.h:79
Tvec4< MLdouble > Vector4
A vector with four components of type double.
Definition mlVector4.h:162
Tmat4< MLdouble > Matrix4
The standard 4x4 matrix of type double.
Definition mlMatrix4.h:713
@ TNE_XML_Unknown
@ TNE_XML_SystemInit
@ TNE_XML_ParserError
@ TNE_XML_COUNT
@ TNE_XML_LAST_MESSAGE_IDX
Only for number calculations; do not use.
@ TNE_XML_ReadingRawDataSize
@ TNE_XML_Other
Tvec3< MLdouble > Vector3
A vector with three components of type double.
Definition mlVector3.h:286
Tvec6< MLdouble > Vector6
A vector with six components of type double.
Definition mlVector6.h:194
Tvec2< MLdouble > Vector2
A vector with two components of type double.
Definition mlVector2.h:159
Tmat3< MLdouble > Matrix3
The standard 3x3 matrix of type double.
Definition mlMatrix3.h:711
TSubImageBox< MLint > SubImageBox
Defines the standard SubImageBox type used in the ML. Its size varies with the size of the MLint type...
TImageVector< MLint > ImageVector
Defines the standard ImageVector type that is used by the ML for indexing and coordinates.