Developer documentation

polynomial_xml.hpp
Go to the documentation of this file.
1 #ifndef realroot_polynomial_xml_hpp
2 #define realroot_polynomial_xml_hpp
3 //====================================================================
4 #include <iostream>
5 #include <stdio.h>
7 
8 #define begin_polynomial "<polynomial"
9 #define end_polynomial "</polynomial>"
10 
11 //====================================================================
12 namespace mmx {
13 namespace xml {
14 
15 template<class OSTREAM, typename X>
16 OSTREAM& print(OSTREAM& os, const X& x, const char *tag)
17 {
18  os<<"<"<<tag<<">"<<x<<"</"<<tag<<">";
19  return os;
20 }
21 
22 template<class ISTREAM>
23 bool skip(ISTREAM& is, const char* s) {
24  char c=(*s); const char* t=s;
25  unsigned n= strlen(s),i=0;
26  while(c != EOF) {
27  for(i=0; i<n && (c !=EOF) && (c=is.get()) == (*t); i++,t++);
28  if(i==n) {
29  while((c=is.get()) != EOF && c != '>') ;
30  return true;
31  }
32  else
33  t=s;
34  }
35 
36  return false;
37 }
38 
40 template<class ISTREAM, typename C, typename R> bool
41 read(ISTREAM& is, polynomial<C,R>& p, variables& V) {
42  if(skip(is,begin_polynomial)) {
43  std::string s; char c;
44  while((c=is.get()) != EOF && c != '<') {
45  if(c != ' ' && c != '\n') s+=c;
46  }
47  s+='\0';
48  p = polynomial<C,R>(s.data(),V);
49  return true;
50  } else {
51  p=polynomial<C,R>(0); return false;
52  }
53 }
54 
56 template<class ISTREAM> bool
57 sread(ISTREAM& is, std::string& s) {
58  if(skip(is,begin_polynomial)) {
59  char c;
60  while((c=is.get()) != EOF && c != '<') {
61  if(c != ' ' && c != '\n') s+=c;
62  }
63  s+='\0';
64  return true;
65  } else {
66  return false;
67  }
68 }
69 
70 } //namespace xml
71 } //namespace mmx
72 //====================================================================
73 # undef begin_polynomial
74 # undef end_polynomial
75 #endif //realroot_polynomial_xml_hpp
#define begin_polynomial
Definition: polynomial_xml.hpp:8
bool read(ISTREAM &is, polynomial< C, R > &p, variables &V)
Read a polynomial, enclosed in polynomial tags.
Definition: polynomial_xml.hpp:41
TMPL X
Definition: polynomial_operators.hpp:148
bool sread(ISTREAM &is, std::string &s)
Read a polynomial as a string, enclosed in polynomial tags.
Definition: polynomial_xml.hpp:57
bool skip(ISTREAM &is, const char *s)
Definition: polynomial_xml.hpp:23
OSTREAM & print(OSTREAM &os, const X &x, const char *tag)
Definition: polynomial_xml.hpp:16
Definition: polynomial.hpp:37
const C & c
Definition: Interval_glue.hpp:45
Definition: array.hpp:12
Definition: variables.hpp:65
Home