CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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>
11 
13 {
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 
37  void closeFile()
38  {
39  if(errHandler) delete errHandler;
40  if(parser) { delete parser; XMLPlatformUtils::Terminate(); }
41  errHandler=0;
42  parser=0;
43  }
48 
49 
50 //Static function to make everything easier, less transcode and type conversion
54  template <class T> static void writeAttribute(DOMElement *dom, const std::string & name, const T & value)
55  {
56  std::ostringstream buffer;
57  buffer << value;
58  XMLCh * nameStr = XMLString::transcode(name.c_str());
59  XMLCh * valueStr = XMLString::transcode(buffer.str().c_str());
60  dom->setAttribute(nameStr, valueStr );
61  XMLString::release(&nameStr);
62  XMLString::release(&valueStr);
63  }
64 
68  template <class T> static T readAttribute(DOMElement *dom, const std::string & name)
69  {
70  XMLCh* nameStr = XMLString::transcode(name.c_str());
71  char * valueStr = XMLString::transcode(dom->getAttribute(nameStr));
72  std::istringstream buffer(valueStr);
73  T value;
74  buffer >> value;
75  XMLString::release(&nameStr);
76  XMLString::release(&valueStr);
77  return value;
78  }
79 
83  static DOMElement * addChild(DOMNode *dom,const std::string & name);
84 
85 private:
86  std::string m_xmlFileName;
91 };
92 #endif
93 
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
XERCES_CPP_NAMESPACE::XMLString XMLString
XERCES_CPP_NAMESPACE::DOMDocument DOMDocument
DOMElement * calibrationDOM()
XERCES_CPP_NAMESPACE::XMLPlatformUtils XMLPlatformUtils
XERCES_CPP_NAMESPACE::DOMNode DOMNode
HandlerBase * errHandler
void openFile(const std::string &xmlFileName)
std::string m_xmlFileName
XercesDOMParser * parser
XERCES_CPP_NAMESPACE::DOMElement DOMElement
void saveFile(const std::string &xmlFileName)
XERCES_CPP_NAMESPACE::XercesDOMParser XercesDOMParser