00001
00002
00003
00004
00005 #ifndef synaps_util_xml_H_
00006 #define synaps_util_xml_H_
00007
00008 #include <iostream>
00009 #include <complex>
00010 #include <synaps/init.h>
00011
00012 __BEGIN_NAMESPACE_SYNAPS
00013
00015 namespace xml {
00018 template<class ISTREAM>
00019 bool skip(ISTREAM& is, char* s)
00020 {
00021 char c=(*s)+1; char* t=s;
00022 unsigned n= strlen(s),i=0;
00023 while(c != EOF)
00024 {
00025 for(i=0; i<n && (c !=EOF) && (c=is.get()) == (*t); i++,t++);
00026 if(i==n)
00027 return true;
00028 else
00029 t=s;
00030 }
00031 return false;
00032 }
00033
00034 template<class OSTREAM, typename X>
00035 OSTREAM& print(OSTREAM& os, const X& x, char *tag)
00036 {
00037 os<<"<"<<tag<<">"<<x<<"</"<<tag<<">";
00038 return os;
00039 }
00040
00041
00042 #define begin_polynomial "<polynomial>"
00043 #define end_polynomial "</polynomial>"
00044
00046 template<class ISTREAM, typename T>
00047 bool read_pol(ISTREAM& is, T& p)
00048 {
00049 if(skip(is,begin_polynomial))
00050 {
00051 std::string s; char c;
00052 while((c=is.get()) != EOF && c != '<')
00053 {
00054 if(c != ' ' && c != '\n') s+=c;
00055 }
00056 s+='\0';
00057 p = T(s.data());
00058 return true;
00059 }
00060 else
00061 {
00062 p=T(0); return false;
00063 }
00064 }
00065
00067 template<class ISTREAM, typename T, class VAR>
00068 bool read_pol(ISTREAM& is, T& p, const VAR& V)
00069 {
00070 if(skip(is,begin_polynomial))
00071 {
00072 std::string s; char c;
00073 while((c=is.get()) != EOF && c != '<')
00074 {
00075 if(c != ' ' && c != '\n') s+=c;
00076 }
00077 s+='\0';
00078 p = T(s.data(),V);
00079 return true;
00080 }
00081 else
00082 {
00083 p=T(0); return false;
00084 }
00085 }
00086 }
00087
00088 __END_NAMESPACE_SYNAPS
00089
00090 #endif //synaps_util_xml_H_