Version: 8.3.0
xmlrpcParsers.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #include "xmlrpcParsers.hxx"
21 #include "dataParsers.hxx"
22 #include <sstream>
23 #include <iomanip>
24 
25 namespace YACS
26 {
27  arraytypeParser arraytypeParser::arrayParser;
28  valuetypeParser valuetypeParser::valueParser;
29  parametertypeParser parametertypeParser::parameterParser;
30  datatypeParser datatypeParser::dataParser;
31  memberdatatypeParser memberdatatypeParser::memberdataParser;
32  structdatatypeParser structdatatypeParser::structdataParser;
33 
34 static std::string t4[]={"string","objref","double","int","boolean","array","struct",""};
35 
37  void valuetypeParser::int_ (const int& d)
38  {
39  std::ostringstream os;
40  os << "<int>" << d<< "</int>";
41  _data=os.str();
42  _v.push_back(_data);
43  }
44  void valuetypeParser::boolean (const bool& d)
45  {
46  std::ostringstream os;
47  os << "<boolean>" << d<< "</boolean>";
48  _data=os.str();
49  _v.push_back(_data);
50  }
51  void valuetypeParser::double_ (const double& d)
52  {
53  std::ostringstream os;
54  os << "<double>"<< std::setprecision(16) << d<< "</double>";
55  _data=os.str();
56  _v.push_back(_data);
57  }
58  void valuetypeParser::string(const std::string& d)
59  {
60  _data="<string>"+ d+ "</string>";
61  _v.push_back(_data);
62  }
63  void valuetypeParser::objref(const std::string& d)
64  {
65  _data="<objref>"+ d+ "</objref>";
66  _v.push_back(_data);
67  }
68  void valuetypeParser::array (const std::string& d)
69  {
70  _v.push_back(d);
71  }
72  void valuetypeParser::struct_ (const std::string& d)
73  {
74  _v.push_back(d);
75  }
76  std::string valuetypeParser::post()
77  {
78  minchoice(t4,1);
79  std::string value="<value>"+_v.back()+"</value>\n";
80  _v.pop_back();
81  return value;
82  }
83 
84  void datatypeParser::onStart(const XML_Char* el, const XML_Char** attr)
85  {
86  std::string element(el);
88  if(element == "value")pp=&valuetypeParser::valueParser;
90  pp->init();
91  pp->pre();
92  pp->buildAttr(attr);
93  }
94  void datatypeParser::onEnd(const char *el,parser* child)
95  {
96  std::string element(el);
97  if(element == "value")value(((valuetypeParser*)child)->post());
98  }
100  {
101  _datas.push_back(_data);
102  _data="";
103  }
104  void datatypeParser::value (const std::string& v){
105  _data=_data+v;
106  }
107  std::string datatypeParser::post()
108  {
109  std::string d="<data>\n"+_data+"</data>";
110  _data=_datas.back();
111  _datas.pop_back();
112  return d;
113  }
114 
115  void memberdatatypeParser::onStart(const XML_Char* el, const XML_Char** attr)
116  {
117  std::string element(el);
119  if(element == "name")pp=&stringtypeParser::stringParser;
120  else if(element == "value")pp=&valuetypeParser::valueParser;
121  SetUserDataAndPush(pp);
122  pp->init();
123  pp->pre();
124  pp->buildAttr(attr);
125  }
126  void memberdatatypeParser::onEnd(const char *el,parser* child)
127  {
128  std::string element(el);
129  this->maxcount("name",1,element);
130  this->maxcount("value",1,element);
131  if(element == "name")name(((stringtypeParser*)child)->post());
132  else if(element == "value")value(((valuetypeParser*)child)->post());
133  }
135  {
136  _datas.push_back(_data);
137  _data="";
138  }
139  void memberdatatypeParser::name (const std::string& v)
140  {
141  _data=_data+"<name>"+v+"</name>";
142  }
143  void memberdatatypeParser::value (const std::string& v)
144  {
145  _data=_data+v;
146  }
148  {
149  mincount("value",1);
150  mincount("name",1);
151  std::string d="<member>\n"+_data+"</member>";
152  _data=_datas.back();
153  _datas.pop_back();
154  return d;
155  }
156 
157  void structdatatypeParser::onStart(const XML_Char* el, const XML_Char** attr)
158  {
159  std::string element(el);
161  if(element == "member")pp=&memberdatatypeParser::memberdataParser;
162  SetUserDataAndPush(pp);
163  pp->init();
164  pp->pre();
165  pp->buildAttr(attr);
166  }
167  void structdatatypeParser::onEnd(const char *el,parser* child)
168  {
169  std::string element(el);
170  if(element == "member")member(((memberdatatypeParser*)child)->post());
171  }
173  {
174  _membersStack.push_back(_members);
175  _members="";
176  }
177  void structdatatypeParser::member (const std::string& d)
178  {
179  _members=_members+d;
180  }
182  {
183  std::string value="<struct>"+_members+"</struct>";
184  _members=_membersStack.back();
185  _membersStack.pop_back();
186  return value;
187  }
188 
189  void arraytypeParser::onStart(const XML_Char* el, const XML_Char** attr)
190  {
191  std::string element(el);
192  this->maxcount("data",1,element);
194  if(element == "data")pp=&datatypeParser::dataParser;
195  SetUserDataAndPush(pp);
196  pp->init();
197  pp->pre();
198  pp->buildAttr(attr);
199  }
200  void arraytypeParser::onEnd(const char *el,parser* child)
201  {
202  std::string element(el);
203  if(element == "data")data(((datatypeParser*)child)->post());
204  }
206  void arraytypeParser::data (const std::string& d)
207  {
208  _arrays.push_back(d);
209  }
210  std::string arraytypeParser::post()
211  {
212  mincount("data",1);
213  std::string value="<array>"+_arrays.back()+"</array>";
214  _arrays.pop_back();
215  return value;
216  }
217 
218 
219 void valuetypeParser::onStart(const XML_Char* el, const XML_Char** attr)
220 {
221  std::string element(el);
223  this->maxcount("string",1,element);
224  this->maxcount("objref",1,element);
225  this->maxcount("double",1,element);
226  this->maxcount("int",1,element);
227  this->maxcount("boolean",1,element);
228  this->maxcount("array",1,element);
229  this->maxcount("struct",1,element);
230  this->maxchoice(t4,1,element);
231  if(element == "string")pp=&stringtypeParser::stringParser;
232  else if(element == "objref")pp=&stringtypeParser::stringParser;
233  else if(element == "double")pp=&doubletypeParser::doubleParser;
234  else if(element == "int")pp=&inttypeParser::intParser;
235  else if(element == "boolean")pp=&booltypeParser::boolParser;
236  else if(element == "array")pp=&arraytypeParser::arrayParser;
237  else if(element == "struct")pp=&structdatatypeParser::structdataParser;
238  SetUserDataAndPush(pp);
239  pp->init();
240  pp->pre();
241  pp->buildAttr(attr);
242 }
243 
244 void valuetypeParser::onEnd(const char *el,parser* child)
245 {
246  std::string element(el);
247  if(element == "string")string(((stringtypeParser*)child)->post());
248  else if(element == "objref")objref(((stringtypeParser*)child)->post());
249  else if(element == "double")double_(((doubletypeParser*)child)->post());
250  else if(element == "int")int_(((inttypeParser*)child)->post());
251  else if(element == "boolean")boolean(((booltypeParser*)child)->post());
252  else if(element == "array")array(((arraytypeParser*)child)->post());
253  else if(element == "struct")struct_(((structdatatypeParser*)child)->post());
254 }
255 
256  void parametertypeParser::onStart(const XML_Char* el, const XML_Char** attr)
257  {
258  std::string element(el);
259  this->maxcount("tonode",1,element);
260  this->maxcount("toport",1,element);
261  this->maxcount("value",1,element);
263  if(element == "tonode")pp=&stringtypeParser::stringParser;
264  else if(element == "toport")pp=&stringtypeParser::stringParser;
265  else if(element == "value")pp=&valuetypeParser::valueParser;
266  SetUserDataAndPush(pp);
267  pp->init();
268  pp->pre();
269  pp->buildAttr(attr);
270  }
271  void parametertypeParser::onEnd(const char *el,parser* child)
272  {
273  std::string element(el);
274  if(element == "tonode")tonode(((stringtypeParser*)child)->post());
275  else if(element == "toport")toport(((stringtypeParser*)child)->post());
276  else if(element == "value")value(((valuetypeParser*)child)->post());
277  }
279  void parametertypeParser::tonode (const std::string& name){
280  _param._tonode=name;
281  }
282  void parametertypeParser::toport (const std::string& name){
283  _param._toport=name;
284  }
285  void parametertypeParser::value (const std::string& name){
286  _param._value=name;
287  }
289  mincount("tonode",1);
290  mincount("toport",1);
291  mincount("value",1);
292  return _param;
293  }
294 
295 }