1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "xmlrpcParsers.hxx"
21 #include "dataParsers.hxx"
27 arraytypeParser arraytypeParser::arrayParser;
28 valuetypeParser valuetypeParser::valueParser;
29 parametertypeParser parametertypeParser::parameterParser;
30 datatypeParser datatypeParser::dataParser;
31 memberdatatypeParser memberdatatypeParser::memberdataParser;
32 structdatatypeParser structdatatypeParser::structdataParser;
34 static std::string t4[]={"string","objref","double","int","boolean","array","struct",""};
36 void valuetypeParser::pre (){ }
37 void valuetypeParser::int_ (const int& d)
39 std::ostringstream os;
40 os << "<int>" << d<< "</int>";
44 void valuetypeParser::boolean (const bool& d)
46 std::ostringstream os;
47 os << "<boolean>" << d<< "</boolean>";
51 void valuetypeParser::double_ (const double& d)
53 std::ostringstream os;
54 os << "<double>"<< std::setprecision(16) << d<< "</double>";
58 void valuetypeParser::string(const std::string& d)
60 _data="<string>"+ d+ "</string>";
63 void valuetypeParser::objref(const std::string& d)
65 _data="<objref>"+ d+ "</objref>";
68 void valuetypeParser::array (const std::string& d)
72 void valuetypeParser::struct_ (const std::string& d)
76 std::string valuetypeParser::post()
79 std::string value="<value>"+_v.back()+"</value>\n";
84 void datatypeParser::onStart(const XML_Char* el, const XML_Char** attr)
86 std::string element(el);
87 parser* pp=&parser::main_parser;
88 if(element == "value")pp=&valuetypeParser::valueParser;
89 SetUserDataAndPush(pp);
94 void datatypeParser::onEnd(const char *el,parser* child)
96 std::string element(el);
97 if(element == "value")value(((valuetypeParser*)child)->post());
99 void datatypeParser::pre ()
101 _datas.push_back(_data);
104 void datatypeParser::value (const std::string& v){
107 std::string datatypeParser::post()
109 std::string d="<data>\n"+_data+"</data>";
115 void memberdatatypeParser::onStart(const XML_Char* el, const XML_Char** attr)
117 std::string element(el);
118 parser* pp=&parser::main_parser;
119 if(element == "name")pp=&stringtypeParser::stringParser;
120 else if(element == "value")pp=&valuetypeParser::valueParser;
121 SetUserDataAndPush(pp);
126 void memberdatatypeParser::onEnd(const char *el,parser* child)
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());
134 void memberdatatypeParser::pre ()
136 _datas.push_back(_data);
139 void memberdatatypeParser::name (const std::string& v)
141 _data=_data+"<name>"+v+"</name>";
143 void memberdatatypeParser::value (const std::string& v)
147 std::string memberdatatypeParser::post()
151 std::string d="<member>\n"+_data+"</member>";
157 void structdatatypeParser::onStart(const XML_Char* el, const XML_Char** attr)
159 std::string element(el);
160 parser* pp=&parser::main_parser;
161 if(element == "member")pp=&memberdatatypeParser::memberdataParser;
162 SetUserDataAndPush(pp);
167 void structdatatypeParser::onEnd(const char *el,parser* child)
169 std::string element(el);
170 if(element == "member")member(((memberdatatypeParser*)child)->post());
172 void structdatatypeParser::pre ()
174 _membersStack.push_back(_members);
177 void structdatatypeParser::member (const std::string& d)
181 std::string structdatatypeParser::post()
183 std::string value="<struct>"+_members+"</struct>";
184 _members=_membersStack.back();
185 _membersStack.pop_back();
189 void arraytypeParser::onStart(const XML_Char* el, const XML_Char** attr)
191 std::string element(el);
192 this->maxcount("data",1,element);
193 parser* pp=&parser::main_parser;
194 if(element == "data")pp=&datatypeParser::dataParser;
195 SetUserDataAndPush(pp);
200 void arraytypeParser::onEnd(const char *el,parser* child)
202 std::string element(el);
203 if(element == "data")data(((datatypeParser*)child)->post());
205 void arraytypeParser::pre (){ }
206 void arraytypeParser::data (const std::string& d)
208 _arrays.push_back(d);
210 std::string arraytypeParser::post()
213 std::string value="<array>"+_arrays.back()+"</array>";
219 void valuetypeParser::onStart(const XML_Char* el, const XML_Char** attr)
221 std::string element(el);
222 parser* pp=&parser::main_parser;
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);
244 void valuetypeParser::onEnd(const char *el,parser* child)
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());
256 void parametertypeParser::onStart(const XML_Char* el, const XML_Char** attr)
258 std::string element(el);
259 this->maxcount("tonode",1,element);
260 this->maxcount("toport",1,element);
261 this->maxcount("value",1,element);
262 parser* pp=&parser::main_parser;
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);
271 void parametertypeParser::onEnd(const char *el,parser* child)
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());
278 void parametertypeParser::pre (){}
279 void parametertypeParser::tonode (const std::string& name){
282 void parametertypeParser::toport (const std::string& name){
285 void parametertypeParser::value (const std::string& name){
288 myparam& parametertypeParser::post(){
289 mincount("tonode",1);
290 mincount("toport",1);