realroot_doc 0.1.1
|
00001 /********************************************************************* 00002 * This file is part of the source code of SYNAPS library. * 00003 * Author(s): B. Mourrain, GALAAD, INRIA * 00004 **********************************************************************/ 00005 #ifndef realroot_xml_hpp_ 00006 #define realroot_xml_hpp_ 00007 #include <string.h> 00008 #include <string> 00009 //-------------------------------------------------------------------- 00010 namespace mmx { 00011 00012 //-------------------------------------------------------------------- 00014 namespace xml { 00017 template<class ISTREAM> 00018 bool skip(ISTREAM& is, const char* s) 00019 { 00020 char c=(*s); const char* t=s; 00021 unsigned n= strlen(s),i=0; 00022 while(c != EOF) 00023 { 00024 for(i=0; i<n && (c !=EOF) && (c=is.get()) == (*t); i++,t++); 00025 if(i==n) 00026 return true; 00027 else 00028 t=s; 00029 } 00030 return false; 00031 } 00032 00033 template<class OSTREAM, typename X> 00034 OSTREAM& print(OSTREAM& os, const X& x, const char *tag) 00035 { 00036 os<<"<"<<tag<<">"<<x<<"</"<<tag<<">"; 00037 return os; 00038 } 00039 00040 00041 #define begin_polynomial "<polynomial>" 00042 #define end_polynomial "</polynomial>" 00043 00044 00046 template<class ISTREAM> 00047 std::string read_tag(ISTREAM& is, const char* tag) 00048 { 00049 if(skip(is,tag)) 00050 { 00051 std::string s; char c; 00052 while((c=is.get()) != EOF && c != '<') 00053 { 00054 if(c != '\n') s+=c; 00055 } 00056 // s+='\0'; 00057 return s; 00058 } 00059 else 00060 { 00061 return std::string(""); 00062 } 00063 } 00065 template<class ISTREAM, typename T> 00066 bool read_pol(ISTREAM& is, T& p) 00067 { 00068 if(skip(is,begin_polynomial)) 00069 { 00070 ::std::string s; char c; 00071 while((c=is.get()) != EOF && c != '<') 00072 { 00073 if(c != ' ' && c != '\n') s+=c; 00074 } 00075 s+='\0'; 00076 //PRINT_DEBUG(s.data()); 00077 p = T(s.data()); 00078 return true; 00079 } 00080 else 00081 { 00082 p=T(0); return false; 00083 } 00084 } 00085 00087 template<class ISTREAM, typename T, class VAR> 00088 bool read_pol(ISTREAM& is, T& p, const VAR& V) 00089 { 00090 if(skip(is,begin_polynomial)) 00091 { 00092 std::string s; char c; 00093 while((c=is.get()) != EOF && c != '<') 00094 { 00095 if(c != ' ' && c != '\n') s+=c; 00096 } 00097 s+='\0'; 00098 p = T(s.data(),V); 00099 return true; 00100 } 00101 else 00102 { 00103 p=T(0); return false; 00104 } 00105 } 00106 } 00107 00108 //-------------------------------------------------------------------- 00109 template<typename C,typename R> struct upoldse; 00110 //-------------------------------------------------------------------- 00111 namespace xml 00112 { 00113 // using namespace SYNAPS; 00114 00116 template<class ISTREAM, typename T> 00117 bool read_upol(ISTREAM& is, T& p) 00118 { 00119 if(skip(is,begin_polynomial)) 00120 { 00121 std::string s; char c; 00122 while((c=is.get()) != EOF && c != '<') 00123 { 00124 if(c != ' ' && c != '\n') s+=c; 00125 } 00126 s+='\0'; 00127 p = T(s.data()); 00128 return true; 00129 } 00130 else 00131 { 00132 p=T(0); return false; 00133 } 00134 } 00135 00137 template<class ISTREAM, typename C,typename R> 00138 bool read(ISTREAM& is, upoldse<C,R>& p) 00139 { 00140 return read_upol(is,p); 00141 } 00142 00144 template<class OSTREAM, typename C,typename R> 00145 OSTREAM& print(OSTREAM& os, const upoldse<C,R>& p) 00146 { 00147 xml::print(os,p,"polynomial"); 00148 return os; 00149 } 00150 00151 } 00152 //---------------------------------------------------------------------- 00153 } //namespace mmx 00154 //---------------------------------------------------------------------- 00155 #endif //realroot_xml_hpp_