realroot_doc 0.1.1
/Users/mourrain/Devel/mmx/realroot/include/realroot/polynomial_xml.hpp
Go to the documentation of this file.
00001 #ifndef realroot_polynomial_xml_hpp
00002 #define realroot_polynomial_xml_hpp
00003 //====================================================================
00004 #include <iostream>
00005 #include <stdio.h>
00006 #include <realroot/polynomial.hpp>
00007 
00008 #define begin_polynomial "<polynomial"
00009 #define end_polynomial "</polynomial>"
00010 
00011 //====================================================================
00012 namespace mmx {
00013   namespace xml {
00014 
00015     template<class OSTREAM, typename X>
00016     OSTREAM& print(OSTREAM& os, const X& x, const char *tag)
00017     {
00018       os<<"<"<<tag<<">"<<x<<"</"<<tag<<">";
00019       return os;
00020     }
00021 
00022     template<class ISTREAM>
00023     bool skip(ISTREAM& is, const char* s) {
00024       char c=(*s); const char* t=s;
00025       unsigned n= strlen(s),i=0;
00026       while(c != EOF) {
00027         for(i=0; i<n && (c !=EOF) && (c=is.get()) == (*t); i++,t++);
00028         if(i==n) {
00029           while((c=is.get()) != EOF && c != '>') ;
00030           return true;
00031         }
00032       else
00033         t=s;
00034       }
00035 
00036       return false;
00037     }
00038     
00040     template<class ISTREAM, typename C, typename R> bool 
00041     read(ISTREAM& is, polynomial<C,R>& p, variables& V) {
00042       if(skip(is,begin_polynomial)) {
00043         std::string s; char c;
00044         while((c=is.get()) != EOF && c != '<') {
00045           if(c != ' ' && c != '\n') s+=c;
00046         }
00047         s+='\0';
00048         p = polynomial<C,R>(s.data(),V);
00049         return true;
00050       } else {
00051         p=polynomial<C,R>(0); return false;
00052       }
00053     }
00054     
00056     template<class ISTREAM> bool 
00057     sread(ISTREAM& is, std::string& s) {
00058       if(skip(is,begin_polynomial)) {
00059         char c;
00060         while((c=is.get()) != EOF && c != '<') {
00061           if(c != ' ' && c != '\n') s+=c;
00062         }
00063         s+='\0';
00064         return true;
00065       } else {
00066         return false;
00067       }
00068     }
00069 
00070   } //namespace xml
00071 } //namespace mmx
00072 //====================================================================
00073 # undef begin_polynomial
00074 # undef end_polynomial
00075 #endif //realroot_polynomial_xml_hpp