src/xml_types.h

См. документацию.
00001 //
00002 // C++ Interface: xml_types
00003 //
00004 // Description: 
00005 //
00006 //
00007 // Author: yessss <gennadiyesss@mail.ru>, (C) 2007
00008 //
00009 // Copyright: See COPYING file that comes with this distribution
00010 //
00011 //
00012 
00013 #include <vector>
00014 #include <string>
00015 #include <lstring.h>
00016 #include <xpath.h>
00017 #include <xpathresult.h>
00018 #include <xpathiterator.h>
00019 #include <to_xml.h>
00020 
00021 #ifndef XML_TYPES_H
00022 #define XML_TYPES_H
00023 
00024 template<typename T>
00025 inline void add_string(T&,const char* c, int len) {
00026      printf("add_string\n");
00027 }
00028 
00029 template<>
00030 inline void add_string<std::string>(std::string& s, const char* c, int len) {
00031 //   printf("string::add_string\n");
00032      s.append(c, len);
00033 }
00034 
00035 template<>
00036 inline void add_string<lstring>(lstring& s, const char* c, int len) {
00037 //   printf("lstring::add_string\n");
00038      s.append(c, len);
00039 }
00040 
00041 template<typename T>
00042 inline void applyXPath(T* obj, XPath::iterator xp, XPath::iterator ite, XPathResult& res){
00043 }
00044 
00045 template<typename T>
00046 inline T* instance(const char** args){
00047      return new T(args);
00048 }
00049 
00050 template<typename T>
00051 inline T* instance(){
00052      return new T();
00053 }
00054 
00055 #ifndef LIST
00056      #define LIST std::vector
00057 #endif
00058 
00059 #ifndef xstring
00060      #ifdef X_LIGHTER_STRINGS
00061           #define xstring lstring
00062           template<>
00063           inline const char* to_string<xstring>(const xstring& obj) {
00064                if(obj.value == NULL)
00065                     return "";
00066                return obj.value;
00067           }
00068           template<>
00069           inline xstring from_string<xstring>(const char* c) {
00070                lstring l(c);
00071                return l;
00072           }
00073           template<>
00074           inline lstring* instance(const char** args) {
00075                return new lstring();
00076           }
00077           template<>
00078           inline void to_xml(const xstring& obj, const char* name, std::ostream& out) {
00079 //             printf("to_xml lstring\n");
00080                if(obj.value == NULL)
00081                     return;
00082                std::string s("");
00083                for(const char* c = obj.value; *c != 0; c++) {
00084                     switch(*c) {
00085                          case '<':
00086                               s += "&lt;";
00087                               break;
00088                          case '>':
00089                               s += "&gt;";
00090                               break;
00091                          case '&':
00092                               s += "&amp;";
00093                               break;
00094                          case '\'':
00095                               s += "&apos;";
00096                               break;
00097                          case '\"':
00098                               s += "&quot;";
00099                               break;
00100                          default:
00101                               s += *c;
00102                     }
00103                }
00104                if(name)
00105                     out << '<' << name << '>';
00106                out << s;
00107                if(name)
00108                     out << "</" << name << '>';
00109           }
00110      #else
00111           #define xstring std::string
00112           template<>
00113           inline const char* to_string<xstring>(const xstring& obj) {
00114                return obj.c_str();
00115           }
00116           template<>
00117           inline xstring from_string<xstring>(const char* c) {
00118                return xstring(c);
00119           }
00120           template<>
00121           inline xstring* instance(const char** args){
00122                return new xstring();
00123           }
00124           template<>
00125           inline void to_xml(const xstring& obj, const char* name, std::ostream& out) {
00126                std::string s("");
00127                for(const char* c = obj.c_str(); *c != 0; c++) {
00128                     switch(*c) {
00129                          case '<':
00130                               s += "&lt;";
00131                               break;
00132                          case '>':
00133                               s += "&gt;";
00134                               break;
00135                          case '&':
00136                               s += "&amp;";
00137                               break;
00138                          case '\'':
00139                               s += "&apos;";
00140                               break;
00141                          case '\"':
00142                               s += "&quot;";
00143                               break;
00144                          default:
00145                               s += *c;
00146                     }
00147                }
00148                if(name)
00149                     out << '<' << name << '>';
00150                out << s;
00151                if(name)
00152                     out << "</" << name << '>';
00153           }
00154      #endif
00155 #endif
00156 
00157 #ifndef xdouble
00158      #define xdouble double
00159      template<>
00160      inline const char* to_string<xdouble>(const xdouble& obj) {
00161           char * c = (char*)malloc(16*sizeof(char));
00162           snprintf(c, 16, "%f", (float)obj);
00163           return c;
00164      }
00165      template<>
00166      inline xdouble from_string<xdouble>(const char* c) {
00167           float d = 0;
00168           sscanf(c, "%f", &d);
00169           return d;
00170      }
00171 #endif
00172 
00173 #ifndef xanyURI
00174      #define xanyURI xstring
00175 #endif
00176 
00177 #ifndef xbase64Binary
00178      #define xbase64Binary xstring
00179 #endif
00180 
00181 #ifndef xboolean
00182      #define xboolean bool
00183      template<>
00184      inline const char* to_string<xboolean>(const xboolean& obj) {
00185           if(obj)
00186                return "true";
00187           return "false";
00188      }
00189      template<>
00190      inline xboolean from_string<xboolean>(const char* c) {
00191           return (strncasecmp(c,"true", 4) == 0);
00192      }
00193 #endif
00194 
00195 #ifndef xbyte
00196      #define xbyte char
00197      template<>
00198      inline const char* to_string<xbyte>(const xbyte& obj) {
00199           char * c = (char*)malloc(5*sizeof(char));
00200           snprintf(c, 5, "%i", obj);
00201           return c;
00202      }
00203      template<>
00204      inline xbyte from_string<xbyte>(const char* c) {
00205           int d = 0;
00206           sscanf(c, "%i", &d);
00207           return d;
00208      }
00209 #endif
00210 
00211 #ifndef xdateTime
00212      #define xdateTime xstring
00213 #endif
00214 
00215 #ifndef xdecimal
00216      #define xdecimal xstring
00217 #endif
00218 
00219 #ifndef xduration
00220      #define xduration xstring
00221 #endif
00222 
00223 #ifndef xENTITY
00224      #define xENTITY xstring
00225 #endif
00226 
00227 #ifndef xENTITIES
00228      #ifdef X_SPLIT_ATTRIBUTES
00229           #define xENTITIES LIST<xENTITY>
00230           template<>
00231           inline const char* to_string<xENTITIES>(const xENTITIES& obj) {
00232                std::string s = "";
00233                LIST<xENTITY>::const_iterator it = obj.begin();
00234                LIST<xENTITY>::const_iterator ite = obj.end();
00235                for(int num = 0;it != ite;it++,num++) {
00236                     if(num != 0)
00237                          s += " ";
00238                     s += to_string<xENTITY>(*it);
00239                }
00240                return s.c_str();
00241           }
00242           template<>
00243           inline xENTITIES from_string<xENTITIES>(const char* c) {
00244                const char* i = c;
00245                LIST<xENTITY> v;
00246                for(;*i != 0;) {
00247                     std::string xe;
00248                     for(;*i != ' ' && *i != 0;)
00249                          xe += *(i++);
00250                     #ifdef X_LIGHTER_STRINGS
00251                          lstring l(xe.c_str());
00252                     #endif
00253                          if(xe.length() != 0 || *(i-1) != 0)
00254                               v.push_back(l);
00255                     for(;*i == ' ';)
00256                          i++;
00257                }
00258                return v;
00259           }
00260      #else
00261           #define xENTITIES xstring
00262      #endif
00263      
00264 #endif
00265 
00266 #ifndef xfloat
00267      #define xfloat xdouble
00268 #endif
00269 
00270 #ifndef xgDay
00271      #define xgDay xstring
00272 #endif
00273 
00274 #ifndef xgMonth
00275      #define xgMonth xstring
00276 #endif
00277 
00278 #ifndef xgMonthDay
00279      #define xgMonthDay xstring
00280 #endif
00281 
00282 #ifndef xgYear
00283      #define xgYear xstring
00284 #endif
00285 
00286 #ifndef xgYearMonth
00287      #define xgYearMonth xstring
00288 #endif
00289 
00290 #ifndef xhexBinary
00291      #define xhexBinary xstring
00292 #endif
00293 
00294 #ifndef xID
00295      #define xID xstring
00296 #endif
00297 
00298 #ifndef xIDREF
00299      #define xIDREF xstring
00300 #endif
00301 
00302 #ifndef xIDREFS
00303      //#define xIDREFS LIST<xIDREF>
00304      #define xIDREFS xENTITIES
00305 #endif
00306 
00307 #ifndef xint
00308      #define xint xstring
00309 #endif
00310 
00311 #ifndef xinteger
00312      #define xinteger xdouble
00313 #endif
00314 
00315 #ifndef xlanguage
00316      #define xlanguage xstring
00317 #endif
00318 
00319 #ifndef xlong
00320      #define xlong xstring
00321 #endif
00322 
00323 #ifndef xName
00324      #define xName xstring
00325 #endif
00326 
00327 #ifndef xNCName
00328      #define xNCName xstring
00329 #endif
00330 
00331 #ifndef xnegativeInteger
00332      #define xnegativeInteger xinteger
00333 #endif
00334 
00335 #ifndef xNMTOKEN
00336      #define xNMTOKEN xstring
00337 #endif
00338 
00339 #ifndef xNMTOKENS
00340      //#define xNMTOKENS LIST<xNMTOKEN>
00341      #define xNMTOKENS xENTITIES
00342 #endif
00343 
00344 #ifndef xnonNegativeInteger
00345      #define xnonNegativeInteger xinteger
00346 #endif
00347 
00348 #ifndef xnonPositiveInteger
00349      #define xnonPositiveInteger xinteger
00350 #endif
00351 
00352 #ifndef xnormalizedString
00353      #define xnormalizedString xstring
00354 #endif
00355 
00356 #ifndef xNOTATION
00357      #define xNOTATION xstring
00358 #endif
00359 
00360 #ifndef xpositiveInteger
00361      #define xpositiveInteger xinteger
00362 #endif
00363 
00364 #ifndef xQName
00365      #define xQName xstring
00366 #endif
00367 
00368 #ifndef xshort
00369      #define xshort xstring
00370 #endif
00371 
00372 #ifndef xtime
00373      #define xtime xstring
00374 #endif
00375 
00376 #ifndef xtoken
00377      #define xtoken xstring
00378 #endif
00379 
00380 #ifndef xunsignedByte
00381      #define xunsignedByte xbyte
00382 #endif
00383 
00384 #ifndef xunsignedInt
00385      #define xunsignedInt xint
00386 #endif
00387 
00388 #ifndef xunsignedLong
00389      #define xunsignedLong xlong
00390 #endif
00391 
00392 #ifndef xunsignedShort
00393      #define xunsignedShort xshort
00394 #endif
00395 
00396 #ifndef xdate
00397      #define xdate xstring
00398 #endif
00399 
00400 #endif //XML_TYPES_H

Документация по XDataServer. Последние изменения: Thu Jul 12 11:49:43 2007. Создано системой  doxygen 1.5.2