00001 #ifndef __XMLSERIALIZEABLE_H 00002 #define __XMLSERIALIZEABLE_H 00003 00004 #include "windows_defs.h" 00005 00006 #include <qdom.h> 00007 #include <qfile.h> 00008 #include <qdatetime.h> 00009 #include <string> 00010 #include <cstdlib> 00011 #include <fstream> 00012 #include <sstream> 00013 00014 00026 class GV_EXPORT XMLSerializeable { 00027 00028 protected: 00029 QDate mCurrentVersion; 00030 00031 virtual bool writeTextTag( 00032 QDomDocument &doc, 00033 QDomElement &elem, 00034 std::string tagName, 00035 std::string text, 00036 std::string id = "" ); 00037 00038 virtual bool writeIntTag( 00039 QDomDocument &doc, 00040 QDomElement &elem, 00041 std::string tagName, 00042 int val, 00043 std::string id = "" ) { 00044 char buf[128]; 00045 sprintf( buf, "%d", val ); 00046 return writeTextTag( doc, elem, tagName, buf, id ); 00047 } 00048 00049 virtual bool writeDoubleTag( 00050 QDomDocument &doc, 00051 QDomElement &elem, 00052 std::string tagName, 00053 double val, 00054 std::string id = "" ) { 00055 char buf[128]; 00056 sprintf( buf, "%10.5f", val ); 00057 return writeTextTag( doc, elem, tagName, buf, id ); 00058 } 00059 00060 virtual std::string readTextTag( 00061 QDomElement elem, 00062 std::string tagName = "", 00063 std::string id = "" ); 00064 00065 virtual int readIntTag( 00066 QDomElement elem, 00067 std::string tagName = "", 00068 std::string id = "" ) { 00069 return atoi( readTextTag( elem, tagName, id ).c_str() ); 00070 } 00071 00072 virtual double readDoubleTag( 00073 QDomElement elem, 00074 std::string tagName = "", 00075 std::string id = "" ) { 00076 return atof( readTextTag( elem, tagName, id ).c_str() ); 00077 } 00078 00079 virtual QDomElement createBaseTag( QDomDocument &doc, 00080 QDomElement &elem, 00081 std::string id, 00082 std::string tagName ) { 00083 QDomElement base = doc.createElement( tagName.c_str() ); 00084 if ( id != "" ) 00085 base.setAttribute( "id", id.c_str() ); 00086 elem.appendChild( base ); 00087 return base; 00088 } 00089 00090 virtual QDomElement getElemByTagName( QDomElement &elem, 00091 std::string name ); 00092 00093 00094 00095 // functions for storing and retreiving ISO-8601 compliant date/time strings 00096 virtual std::string qDateToString (const QDate * aQDate) ; 00097 virtual bool stringToQDate (const std::string aStrDate, QDate * aQDate) ; 00098 00099 virtual std::string qDateTimeToString (const QDateTime * aQDateTime) ; 00100 virtual bool stringToQDateTime (const std::string aStrDateTime, QDateTime * aQDateTime) ; 00101 00102 00103 public: 00104 virtual ~XMLSerializeable( ) { 00105 } 00106 00107 virtual bool toXML( QDomDocument &doc, 00108 QDomElement &elem, 00109 std::string id = "" ) = 0; 00110 virtual bool toXMLFile( std::string fname, std::string docname ); 00111 00112 virtual bool fromXML( QDomElement &elem ) = 0; 00113 virtual bool fromXMLFile( std::string fname, std::string docname ); 00114 00115 virtual void setCurrentVersion (std::string versionString) ; 00116 virtual void setCurrentVersion (QDate versionQDate) ; 00117 virtual QDate getCurrentVersion () ; 00118 virtual std::string getCurrentVersionStr () ; 00119 00120 }; 00121 00122 #endif 00123 00124 00125
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |