Developer documentation

xml.hpp
Go to the documentation of this file.
1 /*********************************************************************
2 * This file is part of the source code of SYNAPS library. *
3 * Author(s): B. Mourrain, GALAAD, INRIA *
4 **********************************************************************/
5 #ifndef realroot_xml_hpp_
6 #define realroot_xml_hpp_
7 #include <string.h>
8 #include <string>
9 //--------------------------------------------------------------------
10 namespace mmx {
11 
12 //--------------------------------------------------------------------
14 namespace xml {
17  template<class ISTREAM>
18  bool skip(ISTREAM& is, const char* s)
19  {
20  char c=(*s); const char* t=s;
21  unsigned n= strlen(s),i=0;
22  while(c != EOF)
23  {
24  for(i=0; i<n && (c !=EOF) && (c=is.get()) == (*t); i++,t++);
25  if(i==n)
26  return true;
27  else
28  t=s;
29  }
30  return false;
31  }
32 
33  template<class OSTREAM, typename X>
34  OSTREAM& print(OSTREAM& os, const X& x, const char *tag)
35  {
36  os<<"<"<<tag<<">"<<x<<"</"<<tag<<">";
37  return os;
38  }
39 
40 
41  #define begin_polynomial "<polynomial>"
42  #define end_polynomial "</polynomial>"
43 
44 
46  template<class ISTREAM>
47  std::string read_tag(ISTREAM& is, const char* tag)
48  {
49  if(skip(is,tag))
50  {
51  std::string s; char c;
52  while((c=is.get()) != EOF && c != '<')
53  {
54  if(c != '\n') s+=c;
55  }
56  // s+='\0';
57  return s;
58  }
59  else
60  {
61  return std::string("");
62  }
63  }
65  template<class ISTREAM, typename T>
66  bool read_pol(ISTREAM& is, T& p)
67  {
68  if(skip(is,begin_polynomial))
69  {
70  ::std::string s; char c;
71  while((c=is.get()) != EOF && c != '<')
72  {
73  if(c != ' ' && c != '\n') s+=c;
74  }
75  s+='\0';
76  //PRINT_DEBUG(s.data());
77  p = T(s.data());
78  return true;
79  }
80  else
81  {
82  p=T(0); return false;
83  }
84  }
85 
87  template<class ISTREAM, typename T, class VAR>
88  bool read_pol(ISTREAM& is, T& p, const VAR& V)
89  {
90  if(skip(is,begin_polynomial))
91  {
92  std::string s; char c;
93  while((c=is.get()) != EOF && c != '<')
94  {
95  if(c != ' ' && c != '\n') s+=c;
96  }
97  s+='\0';
98  p = T(s.data(),V);
99  return true;
100  }
101  else
102  {
103  p=T(0); return false;
104  }
105  }
106 }
107 
108 //--------------------------------------------------------------------
109 template<typename C,typename R> struct upoldse;
110 //--------------------------------------------------------------------
111 namespace xml
112 {
113  // using namespace SYNAPS;
114 
116  template<class ISTREAM, typename T>
117  bool read_upol(ISTREAM& is, T& p)
118  {
119  if(skip(is,begin_polynomial))
120  {
121  std::string s; char c;
122  while((c=is.get()) != EOF && c != '<')
123  {
124  if(c != ' ' && c != '\n') s+=c;
125  }
126  s+='\0';
127  p = T(s.data());
128  return true;
129  }
130  else
131  {
132  p=T(0); return false;
133  }
134  }
135 
137  template<class ISTREAM, typename C,typename R>
138  bool read(ISTREAM& is, upoldse<C,R>& p)
139  {
140  return read_upol(is,p);
141  }
142 
144  template<class OSTREAM, typename C,typename R>
145  OSTREAM& print(OSTREAM& os, const upoldse<C,R>& p)
146  {
147  xml::print(os,p,"polynomial");
148  return os;
149  }
150 
151 }
152 //----------------------------------------------------------------------
153 } //namespace mmx
154 //----------------------------------------------------------------------
155 #endif //realroot_xml_hpp_
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
#define begin_polynomial
Definition: xml.hpp:41
bool skip(ISTREAM &is, const char *s)
Definition: polynomial_xml.hpp:23
Definition: xml.hpp:109
bool read_upol(ISTREAM &is, T &p)
Read a polynomial, enclosed in polynomial tags.
Definition: xml.hpp:117
OSTREAM & print(OSTREAM &os, const X &x, const char *tag)
Definition: polynomial_xml.hpp:16
std::string read_tag(ISTREAM &is, const char *tag)
Read between tag and "<" and build p from this string;.
Definition: xml.hpp:47
const C & c
Definition: Interval_glue.hpp:45
bool read_pol(ISTREAM &is, T &p)
Read a polynomial, enclosed in polynomial tags.
Definition: xml.hpp:66
Definition: array.hpp:12
Home