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 "../mlParserSystem.h"
21#include "mlBase.h"
22#include "mlTreeNode.h"
23#include "mlXMLParserSystem.h"
24
25#include <mlTypeDefs.h>
26#include <xercesc/util/XercesVersion.hpp>
27
29{
30
31 class DOMElement;
32 class DOMNode;
33 class XercesDOMParser;
34} // namespace XERCES_CPP_NAMESPACE
35
36using namespace XERCES_CPP_NAMESPACE;
37
38
39ML_START_NAMESPACE
40
42enum {
48
49 ,
51 ,
52 TNE_XML_COUNT = static_cast<int>(TNE_XML_LAST_MESSAGE_IDX) - TNE_COUNT
53};
54
58{
59
60public:
62 XMLTreeNodeException(int errorCode = 0, const char* msg = nullptr);
63
65
67 const char* getMessage() const override;
68
69private:
70 std::string _message;
71
73 static const char* _stdErrorMsg[];
74
78};
79
80
85{
86public:
88
99 XMLTreeNode(TreeNode::ConstructionMode mode = TreeNode::CM_writerRoot);
100
102
104 ~XMLTreeNode() override;
105
108
110 void writeToFile(const char* fileName) override;
111
112public:
113 void writeToString(std::string& str) override;
115
118
120 void readFromFile(const char* fileName) override;
121
122 void readFromString(const std::string& str) override;
123
125
138
139 // virtual void addChild (bool val, const char* tagName);
140 void addChild(unsigned long val, const char* tagName) override;
141 void addChild(long val, const char* tagName) override;
142 void addChild(MLuint64 val, const char* tagName) override;
143 void addChild(MLint64 val, const char* tagName) override;
144 void addChild(long double val, const char* tagName) override;
145 void addChild(const Vector2& vec, const char* tagName) override;
146 void addChild(const Vector3& vec, const char* tagName) override;
147 void addChild(const Vector4& vec, const char* tagName) override;
148 void addChild(const Vector6& vec, const char* tagName) override;
149 void addChild(const ImageVector& vec, const char* tagName) override;
150 void addChild(const Matrix3& mat, const char* tagName) override;
151 void addChild(const Matrix4& mat, const char* tagName) override;
152 void addChild(const SubImageBox& box, const char* tagName) override;
153 void addChild(const SubImageBoxd& box, const char* tagName) override;
154
155public:
156 void addChild(const std::string& str, const char* tagName) override;
157 void addChild(const void* const ptr, size_t noBytes, const char* tagName) override;
158
159
162
167 void addChild(const Base* const obj, const char* tagName, bool generic = true) override;
168
171 TreeNode* addChild(const char* tagName) override;
172
173
175
188
193 bool hasChild(const char* tagName = nullptr) override;
194
195 // virtual void readChild (bool& val, const char* tagName = NULL);
196 void readChild(unsigned long& val, const char* tagName = nullptr) override;
197 void readChild(long& val, const char* tagName = nullptr) override;
198 void readChild(MLuint64& val, const char* tagName = nullptr) override;
199 void readChild(MLint64& val, const char* tagName = nullptr) override;
200 void readChild(long double& val, const char* tagName = nullptr) override;
201 void readChild(Vector2& val, const char* tagName = nullptr) override;
202 void readChild(Vector3& val, const char* tagName = nullptr) override;
203 void readChild(Vector4& val, const char* tagName = nullptr) override;
204 void readChild(Vector6& val, const char* tagName = nullptr) override;
205 void readChild(ImageVector& val, const char* tagName = nullptr) override;
206 void readChild(Matrix3& val, const char* tagName = nullptr) override;
207 void readChild(Matrix4& val, const char* tagName = nullptr) override;
208 void readChild(SubImageBox& val, const char* tagName = nullptr) override;
209 void readChild(SubImageBoxd& val, const char* tagName = nullptr) override;
210
212 void readChild(void*& ptr, unsigned long& noBytes, const char* tagName = nullptr) override;
213
214
215public:
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:
233
236
238 void deleteMemory(void* ptr) override;
239
241 void setVersion(const char* className, int version) override;
242
244 int getVersion(const char* /*className*/) override;
245
247
249 const char* getLastReadChildName() const override;
250
254 static std::string normalizeFileName(const char* fileName);
255
258
259 static void initXMLSystem();
260 static void terminateXMLSystem();
261
263
264protected:
265 //------------------------------------------------
268 //------------------------------------------------
269
272 XMLTreeNode(DOMElement* parent);
273
275 static char* _getTextNodeString(DOMElement* parentNode);
276
279 DOMElement* _findElemByTagName(const char* tagName, DOMNode* prevNode = nullptr);
280
282 XMLTreeNode* _addTreeNodeChild(DOMElement* child);
283
285 DOMElement* _parentDOMNode;
286
287 // count the number of active root instances, so we can correctly
288 // terminate the XML framework after deleting the last one
290
293
295
296private:
297 // above code hides overloaded virtual function and causes a lot of compiler warnings.
298 // This using silence the warning while keeping the old public interface. Still, it doesn't fix the real problem.
299 using TreeNode::addChild;
300 using TreeNode::readChild;
301
303 void _initFromParser(XercesDOMParser& parser);
304
306 DOMNode* _lastNode;
307
309 DOMNode* _lastNodeRead;
310
312 mutable StringX _lastName;
313
317
318}; // class XMLTreeNode
319
320ML_END_NAMESPACE
321
322#endif
Class for easy (though not terribly efficient) transcoding of XMLCh data to local code page for displ...
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:59
SubImageBoxd - SubImageBox with coordinates of float data type.
The class TreeNodeException is the base class for all exceptions thrown by the class TreeNode and all...
Definition mlTreeNode.h:95
The class TreeNode is the abstract base class for the import/export of ML objects.
Definition mlTreeNode.h:154
ConstructionMode
TreeNode construction modes.
Definition mlTreeNode.h:197
The XMLTreeNodeException class extends the exceptions already provided by class TreeNodeException.
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).
The class XMLTreeNode implements the abstract class TreeNode to allow export and import of ML objects...
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()
static std::string normalizeFileName(const char *fileName)
normalizes the given filename so that it can be used by Xerces to read or write a file with the given...
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
The type of the object here is read from the XML file.
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
Opposed to the readChild(Base*& ...) method, you have to create the object yourself BEFORE calling th...
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)
Starting from the element after node (or the first element, if node is NULL), returns the first DOM e...
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
Adds an child representing an object whose class is derived from base and thus implements the addStat...
void writeToFile(const char *fileName) override
Writes the complete tree to a file. Throws TNE_WritingFile.
TreeNode * addChild(const char *tagName) override
Adds a group or container node with the specified tag name.
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
returns true when a child of the given tagName exists.
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
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
Definiert systemspezifische Macros, die f"ur diese DLL gelten sollen.
#define ML_CLASS_HEADER(className)
Same like ML_CLASS_HEADER_EXPORTED with a non-existing export symbol.
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
Custom deleters around Xerces resources with std::unique_ptr.
@ TNE_COUNT
Definition mlTreeNode.h:79
@ 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