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 {
15 public:
16  typedef XERCES_CPP_NAMESPACE::DOMDocument DOMDocument;
17  typedef XERCES_CPP_NAMESPACE::DOMElement DOMElement;
18  typedef XERCES_CPP_NAMESPACE::DOMNode DOMNode;
19  typedef XERCES_CPP_NAMESPACE::HandlerBase HandlerBase;
20  typedef XERCES_CPP_NAMESPACE::XercesDOMParser XercesDOMParser;
21  typedef XERCES_CPP_NAMESPACE::XMLPlatformUtils XMLPlatformUtils;
22  typedef XERCES_CPP_NAMESPACE::XMLString XMLString;
23 
26 
30  void openFile(const std::string & xmlFileName);
31 
35  void saveFile(const std::string & xmlFileName);
36 
37 
38  void closeFile()
39  {
40  delete errHandler;
42  errHandler=0;
43  parser=0;
44  }
48  DOMElement * calibrationDOM() { return m_calibrationDOM;}
49 
50 
51 //Static function to make everything easier, less transcode and type conversion
55  template <class T> static void writeAttribute(DOMElement *dom, const std::string & name, const T & value)
56  {
57  std::ostringstream buffer;
58  buffer << value;
59  XMLCh * nameStr = XMLString::transcode(name.c_str());
60  XMLCh * valueStr = XMLString::transcode(buffer.str().c_str());
61  dom->setAttribute(nameStr, valueStr );
62  XMLString::release(&nameStr);
63  XMLString::release(&valueStr);
64  }
65 
69  template <class T> static T readAttribute(DOMElement *dom, const std::string & name)
70  {
71  XMLCh* nameStr = XMLString::transcode(name.c_str());
72  char * valueStr = XMLString::transcode(dom->getAttribute(nameStr));
73  std::istringstream buffer(valueStr);
74  T value;
75  buffer >> value;
76  XMLString::release(&nameStr);
77  XMLString::release(&valueStr);
78  return value;
79  }
80 
84  static DOMElement * addChild(DOMNode *dom,const std::string & name);
85 
86 private:
88  DOMElement * m_calibrationDOM;
89  DOMDocument* doc;
90  HandlerBase* errHandler;
91  XercesDOMParser *parser;
92 };
93 #endif
94 
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