CMS 3D CMS Logo

CalibrationXML.h
Go to the documentation of this file.
1 #ifndef CALIBRATIONXML_H
2 #define CALIBRATIONXML_H
3 
4 #include <xercesc/util/XMLString.hpp>
5 #include <xercesc/dom/DOM.hpp>
6 #include <xercesc/dom/DOMElement.hpp>
7 #include <string>
8 #include <sstream>
9 #include <xercesc/sax/HandlerBase.hpp>
10 #include <xercesc/parsers/XercesDOMParser.hpp>
12 
14 public:
15  typedef XERCES_CPP_NAMESPACE::DOMDocument DOMDocument;
16  typedef XERCES_CPP_NAMESPACE::DOMElement DOMElement;
17  typedef XERCES_CPP_NAMESPACE::DOMNode DOMNode;
18  typedef XERCES_CPP_NAMESPACE::HandlerBase HandlerBase;
19  typedef XERCES_CPP_NAMESPACE::XercesDOMParser XercesDOMParser;
20  typedef XERCES_CPP_NAMESPACE::XMLPlatformUtils XMLPlatformUtils;
21  typedef XERCES_CPP_NAMESPACE::XMLString XMLString;
22 
25 
29  void openFile(const std::string &xmlFileName);
30 
34  void saveFile(const std::string &xmlFileName);
35 
36  void closeFile() {
37  delete errHandler;
38  delete parser;
40  errHandler = nullptr;
41  parser = nullptr;
42  }
47 
48  //Static function to make everything easier, less transcode and type conversion
52  template <class T>
53  static void writeAttribute(DOMElement *dom, const std::string &name, const T &value) {
54  std::ostringstream buffer;
55  buffer << value;
56  XMLCh *nameStr = XMLString::transcode(name.c_str());
57  XMLCh *valueStr = XMLString::transcode(buffer.str().c_str());
58  dom->setAttribute(nameStr, valueStr);
59  XMLString::release(&nameStr);
60  XMLString::release(&valueStr);
61  }
62 
66  template <class T>
68  XMLCh *nameStr = XMLString::transcode(name.c_str());
69  char *valueStr = XMLString::transcode(dom->getAttribute(nameStr));
70  std::istringstream buffer(valueStr);
71  T value;
72  buffer >> value;
73  XMLString::release(&nameStr);
74  XMLString::release(&valueStr);
75  return value;
76  }
77 
81  static DOMElement *addChild(DOMNode *dom, const std::string &name);
82 
83 private:
89 };
90 #endif
static T readAttribute(DOMElement *dom, const std::string &name)
static void writeAttribute(DOMElement *dom, const std::string &name, const T &value)
static DOMElement * addChild(DOMNode *dom, const std::string &name)
DOMDocument * doc
DOMElement * m_calibrationDOM
XERCES_CPP_NAMESPACE::HandlerBase HandlerBase
void xercesTerminate()
Definition: Xerces.cc:23
XERCES_CPP_NAMESPACE::XMLString XMLString
XERCES_CPP_NAMESPACE::DOMDocument DOMDocument
DOMElement * calibrationDOM()
XERCES_CPP_NAMESPACE::XMLPlatformUtils XMLPlatformUtils
XERCES_CPP_NAMESPACE::DOMNode DOMNode
HandlerBase * errHandler
Definition: value.py:1
void openFile(const std::string &xmlFileName)
std::string m_xmlFileName
XercesDOMParser * parser
long double T
XERCES_CPP_NAMESPACE::DOMElement DOMElement
void saveFile(const std::string &xmlFileName)
XERCES_CPP_NAMESPACE::XercesDOMParser XercesDOMParser