CMS 3D CMS Logo

XMLDocument.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_MVATrainer_XMLDocument_h
2 #define PhysicsTools_MVATrainer_XMLDocument_h
3 
4 #include <string>
5 #include <memory>
6 #include <iosfwd>
7 
8 #include <xercesc/dom/DOM.hpp>
9 #include <xercesc/dom/DOMImplementation.hpp>
10 #include <xercesc/parsers/XercesDOMParser.hpp>
11 #include <xercesc/sax/HandlerBase.hpp>
12 #include <xercesc/sax/InputSource.hpp>
13 #include <xercesc/dom/DOMDocument.hpp>
14 
15 class XMLDocument {
16  public:
17  XMLDocument(const std::string &fileName, bool write = false);
19  ~XMLDocument();
20 
21  inline XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *
22  getDocument() const { return doc; }
23 
24  inline XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *
25  getRootNode() const { return rootNode; }
26 
27  XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *
29 
30  static bool hasAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem,
31  const char *name);
32  template<typename T>
33  static T readAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem,
34  const char *name);
35  template<typename T>
36  static T readAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem,
37  const char *name, const T &defValue);
38  template<typename T>
39  static void writeAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem,
40  const char *name, const T &value);
41 
42  template<typename T>
43  static T readContent(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node);
44  template<typename T>
45  static void writeContent(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node,
47  const T &value);
48 
49  private:
51  public:
54 
55  private:
56  // do not make any kind of copies
57  XercesPlatform(const XercesPlatform &orig);
59 
60  static unsigned int instances;
61  };
62 
63  void openForRead(std::unique_ptr<std::istream> &inputStream);
64  void openForWrite(const std::string &fileName);
65 
66  std::unique_ptr<XercesPlatform> platform;
67  std::unique_ptr<XERCES_CPP_NAMESPACE_QUALIFIER InputSource> inputSource;
68 
70  bool write;
71 
72  std::unique_ptr<XERCES_CPP_NAMESPACE_QUALIFIER XercesDOMParser> parser;
73  std::unique_ptr<XERCES_CPP_NAMESPACE_QUALIFIER HandlerBase> errHandler;
75 
78 };
79 
80 #include "PhysicsTools/MVATrainer/interface/XMLDocument.icc"
81 
82 #endif // PhysicsTools_MVATrainer_XMLDocument_h
static T readContent(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node)
XERCES_CPP_NAMESPACE_QUALIFIER DOMImplementation * impl
Definition: XMLDocument.h:74
std::unique_ptr< XercesPlatform > platform
Definition: XMLDocument.h:66
#define XERCES_CPP_NAMESPACE_QUALIFIER
Definition: LHERunInfo.h:16
XercesPlatform & operator=(const XercesPlatform &orig)
std::unique_ptr< XERCES_CPP_NAMESPACE_QUALIFIER InputSource > inputSource
Definition: XMLDocument.h:67
static bool hasAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem, const char *name)
Definition: XMLDocument.cc:305
XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * rootNode
Definition: XMLDocument.h:77
static T readAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem, const char *name)
static void writeContent(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node, XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc, const T &value)
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * doc
Definition: XMLDocument.h:76
Definition: value.py:1
void openForRead(std::unique_ptr< std::istream > &inputStream)
Definition: XMLDocument.cc:215
void openForWrite(const std::string &fileName)
Definition: XMLDocument.cc:261
static void writeAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem, const char *name, const T &value)
def elem(elemtype, innerHTML='', html_class='', kwargs)
Definition: HTMLExport.py:18
std::unique_ptr< XERCES_CPP_NAMESPACE_QUALIFIER HandlerBase > errHandler
Definition: XMLDocument.h:73
std::string fileName
Definition: XMLDocument.h:69
std::unique_ptr< XERCES_CPP_NAMESPACE_QUALIFIER XercesDOMParser > parser
Definition: XMLDocument.h:72
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * createDocument(const std::string &root)
Definition: XMLDocument.cc:268
list command
Definition: mps_check.py:23
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * getDocument() const
Definition: XMLDocument.h:22
XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * getRootNode() const
Definition: XMLDocument.h:25
static unsigned int instances
Definition: XMLDocument.h:60
long double T