00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef SML_H
00019 #define SML_H
00020
00026 #include <iostream>
00027 #include <string>
00028
00029
00030 #define SML_TAG( n ) \
00031 virtual const char* getStartTag() \
00032 { return (std::string("<") + std::string(#n) + std::string(">")).c_str(); }\
00033 static const char* startTag() \
00034 { return (std::string("<") + std::string(#n) + std::string(">")).c_str(); }\
00035 virtual const char* getEndTag() \
00036 { return (std::string("</") + std::string(#n) + std::string(">")).c_str(); }\
00037 static const char* endTag() \
00038 { return (std::string("</") + std::string(#n) + std::string(">")).c_str(); }\
00039 virtual const char* getType() \
00040 { return #n; }\
00041 virtual void loadFromStream(std::istream&); \
00042 virtual void saveToStream(std::ostream&);
00043
00044
00045 #ifndef NO_SML_NAME
00046
00047 #define SML_LOAD_INIT( _class ) \
00048 void _class::loadFromStream(std::istream& in) \
00049 { \
00050 std::string tag; \
00051 char delim; \
00052 \
00053 while(1) \
00054 { \
00055 \
00056 in>>tag; \
00057 \
00058 if(tag.compare(getEndTag()) == 0) \
00059 return; \
00060 else \
00061 if(tag.compare("name") == 0) \
00062 { \
00063 in>>delim; \
00064 char _nameBuff[100]; \
00065 in.getline(_nameBuff, 100); \
00066 int __buff_counter = 0; \
00067 while( _nameBuff[__buff_counter] == ' ' && __buff_counter < 100) \
00068 ++__buff_counter; \
00069 SMLName = (_nameBuff + __buff_counter); \
00070 }
00071
00072 #else
00073
00074 #define SML_LOAD_INIT( _class ) \
00075 void _class::loadFromStream(std::istream& in) \
00076 { \
00077 std::string tag; \
00078 char delim; \
00079 \
00080 while(1) \
00081 { \
00082 \
00083 in>>tag; \
00084 \
00085 if(tag.compare(getEndTag()) == 0) \
00086 return; \
00087
00088 #endif
00089
00090
00091 #define SML_LOAD_END \
00092 };\
00093 }
00094
00095 #define SML_LOAD_OPTION_INIT_FOREIGN_CLASS( _class ) \
00096 else \
00097 if(tag.compare(_class::startTag()) == 0) \
00098 { \
00099
00100
00101 #define SML_LOAD_FOREIGN_SUB_SML( _class ) \
00102 _class* _ptr = new _class; \
00103 _ptr->loadFromStream(in); \
00104
00105 #define SML_LOAD_OPTION_END \
00106 }
00107
00108
00109
00110 #ifndef NO_SML_NAME
00111
00112 #define SML_SAVE_INIT( _class ) \
00113 void _class::saveToStream(std::ostream& out) \
00114 { \
00115 out<<getStartTag()<<std::endl; \
00116 \
00117 out<<" "<<"name = "<<SMLName<<std::endl;
00118
00119 #else
00120
00121 #define SML_SAVE_INIT( _class ) \
00122 void _class::saveToStream(std::ostream& out) \
00123 { \
00124 out<<getStartTag()<<std::endl;
00125
00126 #endif
00127
00128 #define SML_SAVE_END \
00129 out<<getEndTag()<<std::endl; \
00130 }
00131
00132 class SML
00133 {
00134 protected:
00135 #ifndef NO_SML_NAME
00136 std::string SMLName;
00137 #endif
00138 public:
00139 SML(){};
00140 virtual ~SML(){};
00141
00142 virtual const char* getStartTag() = 0;
00143 virtual const char* getEndTag() = 0;
00144
00145 virtual const char* getType() = 0;
00146
00147 #ifndef NO_SML_NAME
00148 virtual const char* getName() { return SMLName.c_str(); }
00149 virtual void setName(const char* n) { SMLName = n; }
00150 #else
00151 virtual const char* getName() { return ""; }
00152 virtual void setName(const char* n) { return; }
00153 #endif
00154
00155 virtual void loadFromStream(std::istream&) = 0;
00156 virtual void saveToStream(std::ostream&) = 0;
00157 };
00158
00159
00160 #endif