forked from TJKlein/3D_RFUltrasound_Reconstruction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XMLTools.h
155 lines (131 loc) · 5.35 KB
/
XMLTools.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#ifndef XMLTOOLS_H
#define XMLTOOLS_H
#include <xercesc/dom/DOMErrorHandler.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>
#include <xercesc/parsers/AbstractDOMParser.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
#include <xercesc/dom/DOMImplementationRegistry.hpp>
#include <xercesc/dom/DOMLSParser.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMError.hpp>
#include <xercesc/dom/DOMLocator.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp>
#include <xercesc/dom/DOMAttr.hpp>
#include <Eigen/Core>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <iostream>
USING_PART_OF_NAMESPACE_EIGEN
XERCES_CPP_NAMESPACE_USE
// ---------------------------------------------------------------------------
// Simple error handler deriviative to install on parser
// ---------------------------------------------------------------------------
class DOMCustomErrorHandler : public DOMErrorHandler
{
public:
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
DOMCustomErrorHandler();
~DOMCustomErrorHandler();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
bool getSawErrors() const;
// -----------------------------------------------------------------------
// Implementation of the DOM ErrorHandler interface
// -----------------------------------------------------------------------
bool handleError(const DOMError& domError);
void resetErrors();
private :
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMCustomErrorHandler(const DOMCustomErrorHandler&);
void operator=(const DOMCustomErrorHandler&);
// -----------------------------------------------------------------------
// Private data members
//
// fSawErrors
// This is set if we get any errors, and is queryable via a getter
// method. Its used by the main code to suppress output if there are
// errors.
// -----------------------------------------------------------------------
bool fSawErrors;
};
// ---------------------------------------------------------------------------
// This is a simple class that lets us do easy (though not terribly efficient)
// trancoding of XMLCh data to local code page for display.
// ---------------------------------------------------------------------------
class StrX
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
StrX(const XMLCh* const toTranscode)
{
// Call the private transcoding method
fLocalForm = XMLString::transcode(toTranscode);
}
~StrX()
{
XMLString::release(&fLocalForm);
}
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
const char* localForm() const
{
return fLocalForm;
}
private :
// -----------------------------------------------------------------------
// Private data members
//
// fLocalForm
// This is the local code page form of the string.
// -----------------------------------------------------------------------
char* fLocalForm;
};
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
{
target << toDump.localForm();
return target;
}
inline bool DOMCustomErrorHandler::getSawErrors() const
{
return fSawErrors;
}
class XMLTools
{
private:
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *m_doc;
DOMLSParser *m_parser;
public:
XMLTools();
~XMLTools();
bool loadFile(std::string filename);
bool createFile(std::string masterTag);
bool saveToFile(std::string filename);
void closeHandle() { m_doc->release(); }
bool handleData(bool write, std::string &data, std::string tagName, int itemId = 0);
bool handleData(int &data, const std::string &tagName, const std::string &attributeName, const int &itemId = 0);
bool handleData(float &data, const std::string &tagName, const std::string &attributeName, const int &itemId = 0);
bool handleData(bool write, std::string &data, const std::string &tagName, const std::string &attributeName, const int &itemId = 0);
int numberOfElements(std::string tagName);
bool handleData(Eigen::Matrix4f &matrix, std::string tagName, int itemId = 0);
/**
@brief Helper function that parses a string an outputs an Eigen Library matrix
**/
void string2matrix(Eigen::Matrix4f &matrix, std::string &str);
};
#endif