00001 #ifndef CALIBRATIONXML_H 00002 #define CALIBRATIONXML_H 00003 00004 #include <xercesc/util/XMLString.hpp> 00005 #include <xercesc/dom/DOM.hpp> 00006 #include <xercesc/dom/DOMElement.hpp> 00007 #include <string> 00008 #include <sstream> 00009 #include <xercesc/sax/HandlerBase.hpp> 00010 #include <xercesc/parsers/XercesDOMParser.hpp> 00011 00012 using namespace XERCES_CPP_NAMESPACE; 00013 00014 class CalibrationXML 00015 { 00016 public: 00017 CalibrationXML(); 00018 ~CalibrationXML(); 00019 00023 void openFile(const std::string & xmlFileName); 00024 00028 void saveFile(const std::string & xmlFileName); 00029 00030 00031 void closeFile() 00032 { 00033 if(errHandler) delete errHandler; 00034 if(parser) { delete parser; XMLPlatformUtils::Terminate(); } 00035 errHandler=0; 00036 parser=0; 00037 } 00041 DOMElement * calibrationDOM() { return m_calibrationDOM;} 00042 00043 00044 //Static function to make everything easier, less transcode and type conversion 00048 template <class T> static void writeAttribute(DOMElement *dom, const std::string & name, const T & value) 00049 { 00050 std::ostringstream buffer; 00051 buffer << value; 00052 XMLCh * nameStr = XMLString::transcode(name.c_str()); 00053 XMLCh * valueStr = XMLString::transcode(buffer.str().c_str()); 00054 dom->setAttribute(nameStr, valueStr ); 00055 XMLString::release(&nameStr); 00056 XMLString::release(&valueStr); 00057 } 00058 00062 template <class T> static T readAttribute(DOMElement *dom, const std::string & name) 00063 { 00064 XMLCh* nameStr = XMLString::transcode(name.c_str()); 00065 char * valueStr = XMLString::transcode(dom->getAttribute(nameStr)); 00066 std::istringstream buffer(valueStr); 00067 T value; 00068 buffer >> value; 00069 XMLString::release(&nameStr); 00070 XMLString::release(&valueStr); 00071 return value; 00072 } 00073 00077 static DOMElement * addChild(DOMNode *dom,const std::string & name); 00078 00079 private: 00080 std::string m_xmlFileName; 00081 DOMElement * m_calibrationDOM; 00082 DOMDocument* doc; 00083 HandlerBase* errHandler; 00084 XercesDOMParser *parser; 00085 }; 00086 #endif 00087