Go to the documentation of this file.00001 #ifndef PhysicsTools_MVATrainer_XMLDocument_h
00002 #define PhysicsTools_MVATrainer_XMLDocument_h
00003
00004 #include <string>
00005 #include <memory>
00006 #include <iosfwd>
00007
00008 #include <xercesc/dom/DOM.hpp>
00009 #include <xercesc/dom/DOMImplementation.hpp>
00010 #include <xercesc/parsers/XercesDOMParser.hpp>
00011 #include <xercesc/sax/HandlerBase.hpp>
00012 #include <xercesc/sax/InputSource.hpp>
00013 #include <xercesc/dom/DOMDocument.hpp>
00014
00015 class XMLDocument {
00016 public:
00017 XMLDocument(const std::string &fileName, bool write = false);
00018 XMLDocument(const std::string &fileName, const std::string &command);
00019 ~XMLDocument();
00020
00021 inline XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *
00022 getDocument() const { return doc; }
00023
00024 inline XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *
00025 getRootNode() const { return rootNode; }
00026
00027 XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *
00028 createDocument(const std::string &root);
00029
00030 static bool hasAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem,
00031 const char *name);
00032 template<typename T>
00033 static T readAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem,
00034 const char *name);
00035 template<typename T>
00036 static T readAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem,
00037 const char *name, const T &defValue);
00038 template<typename T>
00039 static void writeAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem,
00040 const char *name, const T &value);
00041
00042 template<typename T>
00043 static T readContent(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node);
00044 template<typename T>
00045 static void writeContent(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node,
00046 XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc,
00047 const T &value);
00048
00049 private:
00050 class XercesPlatform {
00051 public:
00052 XercesPlatform();
00053 ~XercesPlatform();
00054
00055 private:
00056
00057 XercesPlatform(const XercesPlatform &orig);
00058 XercesPlatform &operator = (const XercesPlatform &orig);
00059
00060 static unsigned int instances;
00061 };
00062
00063 void openForRead(std::auto_ptr<std::istream> &inputStream);
00064 void openForWrite(const std::string &fileName);
00065
00066 std::auto_ptr<XercesPlatform> platform;
00067 std::auto_ptr<XERCES_CPP_NAMESPACE_QUALIFIER InputSource> inputSource;
00068
00069 std::string fileName;
00070 bool write;
00071
00072 std::auto_ptr<XERCES_CPP_NAMESPACE_QUALIFIER XercesDOMParser> parser;
00073 std::auto_ptr<XERCES_CPP_NAMESPACE_QUALIFIER HandlerBase> errHandler;
00074 XERCES_CPP_NAMESPACE_QUALIFIER DOMImplementation *impl;
00075
00076 XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc;
00077 XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *rootNode;
00078 };
00079
00080 #include "PhysicsTools/MVATrainer/interface/XMLDocument.icc"
00081
00082 #endif // PhysicsTools_MVATrainer_XMLDocument_h