Version: 9.15.0
presetParsers.hxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2025 CEA, EDF
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 #ifndef _PRESETPARSERS_HXX_
21 #define _PRESETPARSERS_HXX_
22 
23 #include "nodeParsers.hxx"
24 
25 #include "factory.hxx"
26 
27 #include "DataNode.hxx"
28 
29 namespace YACS
30 {
31 
44 {
46 
47  virtual void onStart(const XML_Char* el, const XML_Char** attr)
48  {
49  DEBTRACE("presetdatatypeParser::onStart");
50  std::string element(el);
51  this->maxcount("value",1,element);
53  if(element == "value")pp=&valuetypeParser::valueParser;
55  pp->init();
56  pp->pre();
57  pp->buildAttr(attr);
58  }
59  virtual void onEnd(const char *el,parser* child)
60  {
61  DEBTRACE("presetdatatypeParser::onEnd");
62  std::string element(el);
63  if(element == "value")value(((valuetypeParser*)child)->post());
64  }
65  virtual void buildAttr(const XML_Char** attr)
66  {
67  if (!attr)
68  return;
69  DEBTRACE("presetdatatypeParser::buildAttr");
70  required("name",attr);
71  required("type",attr);
72  for (int i = 0; attr[i]; i += 2)
73  {
74  if(std::string(attr[i]) == "name")name(attr[i+1]);
75  if(std::string(attr[i]) == "type")type(attr[i+1]);
76  if(std::string(attr[i]) == "ref")ref(attr[i+1]);
77  }
78  }
79  virtual void name (const std::string& name)
80  {
81  DEBTRACE("presetdatatypeParser::name");
83  _name=name;
84  }
85  virtual void type (const std::string& type)
86  {
87  DEBTRACE("presetdatatypeParser::type");
89  _type=type;
90  }
91 
92  virtual void ref (const std::string& ref)
93  {
94  _ref=ref;
95  }
96 
97  virtual void pre ()
98  {
99  DEBTRACE("presetdatatypeParser::pre");
100  _ref="undef";
101  _param.clear();
102  }
103  virtual void value (const std::string& value)
104  {
105  DEBTRACE("presetdatatypeParser::value " << value);
106  _param.setProperty("value",value);
107  }
108  virtual myoutport& post()
109  {
110  DEBTRACE("presetdatatypeParser::post");
111  //a parameter can have a ref attribute OR one value element
112  if(_ref == "undef")
113  mincount("value",1);
114  else
115  _param.setProperty("value",_ref);
116  return _param;
117  }
119  std::string _name;
120  std::string _type;
121  std::string _ref;
122 };
123 
134 template <class T=ENGINE::DataNode*>
136 {
138  virtual void onStart(const XML_Char* el, const XML_Char** attr);
139  virtual void onEnd(const char *el,parser* child);
140  virtual void buildAttr(const XML_Char** attr);
141  virtual void create ();
142  virtual void pre ();
143  virtual void name (const std::string& name);
144  virtual void kind (const std::string& kind);
145  virtual void parameter (myoutport& p);
146  std::string _name;
147  std::string _kind;
148 };
149 
151 
152 
153 template <class T>
154 void presettypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
155  {
156  DEBTRACE("presettypeParser::onStart");
157  std::string element(el);
159  if(element == "parameter")pp=&presetdatatypeParser::presetdataParser;
160  if(element == "property")pp=&propertytypeParser::propertyParser;
161  this->SetUserDataAndPush(pp);
162  pp->init();
163  pp->pre();
164  pp->buildAttr(attr);
165  }
166 
167 template <class T>
168 void presettypeParser<T>::onEnd(const char *el,parser* child)
169  {
170  DEBTRACE("presettypeParser::onEnd");
171  std::string element(el);
172  if(element == "parameter")parameter(((presetdatatypeParser*)child)->post());
173  if(element == "property")this->property(((propertytypeParser*)child)->post());
174  }
175 
176 template <class T>
178  {
179  if (!attr)
180  return;
181  DEBTRACE("presettypeParser::buildAttr");
182  this->required("name",attr);
183  for (int i = 0; attr[i]; i += 2)
184  {
185  if(std::string(attr[i]) == "name")name(attr[i+1]);
186  if(std::string(attr[i]) == "kind")kind(attr[i+1]);
187  }
188  create();
189  }
190 
191 template <class T>
193 {
194  _kind="";
195 }
196 
197 template <class T>
198 void presettypeParser<T>::name (const std::string& name)
199 {
200  _name=name;
201 }
202 
203 template <class T>
204 void presettypeParser<T>::kind (const std::string& kind)
205 {
206  _kind=kind;
207 }
208 
209 template <class T>
211 {
212  this->_node = theRuntime->createInDataNode(_kind,_name);
213 }
214 
215 template <class T>
217 {
218  DEBTRACE("presettypeParser::parameter");
219  if(currentProc->typeMap.count(p._type)==0)
220  {
221  //Check if the typecode is defined in the runtime
223  if(t==0)
224  {
225  std::string msg="Unknown Type: ";
226  msg=msg+p._type+" for node: "+this->_node->getName()+" port name: "+p._name;
227  this->logError(msg);
228  return;
229  }
230  else
231  {
232  currentProc->typeMap[p._type]=t;
233  t->incrRef();
234  }
235  }
236  ENGINE::OutputPort *port = this->_node->edAddOutputPort(p._name,currentProc->typeMap[p._type]);
237  this->_node->setData(port,p._props["value"]);
238 }
239 
240 }
241 #endif
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
YACS::ENGINE::Runtime * theRuntime
Definition: parsers.cxx:40
YACS::ENGINE::Proc * currentProc
Definition: parserBase.cxx:30
std::map< std::string, TypeCode * > typeMap
Definition: Proc.hxx:90
virtual TypeCode * getTypeCode(const std::string &name)
Get a typecode by its name from runtime catalogs.
Definition: Runtime.cxx:333
virtual DataNode * createInDataNode(const std::string &kind, const std::string &name)
Definition: Runtime.cxx:180
Base class for all type objects.
Definition: TypeCode.hxx:68
Proc * p
Definition: driver.cxx:216
char XML_Char
Definition: parserBase.hxx:37
Class for node parser.
Definition: nodeParsers.hxx:54
virtual void maxcount(std::string name, int max, std::string &el)
Definition: parserBase.cxx:122
virtual void init()
Definition: parserBase.cxx:86
virtual void pre()
Definition: parserBase.hxx:61
virtual void SetUserDataAndPush(parser *pp)
Definition: parserBase.cxx:55
virtual void mincount(std::string name, int min)
Definition: parserBase.cxx:134
virtual void required(const std::string &name, const XML_Char **attr)
Definition: parserBase.cxx:186
virtual void buildAttr(const XML_Char **attr)
Definition: parserBase.cxx:195
static parser main_parser
Definition: parserBase.hxx:41
Class for presetdata parser.
virtual void onEnd(const char *el, parser *child)
virtual void ref(const std::string &ref)
virtual void buildAttr(const XML_Char **attr)
virtual void type(const std::string &type)
virtual void value(const std::string &value)
virtual myoutport & post()
static presetdatatypeParser presetdataParser
virtual void onStart(const XML_Char *el, const XML_Char **attr)
virtual void name(const std::string &name)
Class for PresetNode parser.
virtual void onStart(const XML_Char *el, const XML_Char **attr)
virtual void parameter(myoutport &p)
virtual void kind(const std::string &kind)
virtual void onEnd(const char *el, parser *child)
virtual void name(const std::string &name)
static presettypeParser< T > presetParser
virtual void buildAttr(const XML_Char **attr)
Class for property parser.
static propertytypeParser propertyParser
Class for XML-RPC value parser.
static valuetypeParser valueParser
std::string _name
Definition: factory.hxx:80
std::string _type
Definition: factory.hxx:81
void setProperty(const std::string &name, const std::string &value)
Definition: factory.hxx:87
void clear()
Definition: factory.hxx:83