Version: 9.16.0
outputParsers.hxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 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 _OUTPUTPARSERS_HXX_
21#define _OUTPUTPARSERS_HXX_
22
23#include "nodeParsers.hxx"
24
25#include "factory.hxx"
26
27#include "DataNode.hxx"
28
29namespace YACS
30{
31
44{
46
47 virtual void onStart(const XML_Char* el, const XML_Char** attr)
48 {
49 DEBTRACE("outputdatatypeParser::onStart");
50 std::string element(el);
53 pp->init();
54 pp->pre();
55 pp->buildAttr(attr);
56 }
57 virtual void onEnd(const char *el,parser* child)
58 {
59 }
60 virtual void buildAttr(const XML_Char** attr)
61 {
62 if (!attr)
63 return;
64 DEBTRACE("outputdatatypeParser::buildAttr");
65 required("name",attr);
66 required("type",attr);
67 for (int i = 0; attr[i]; i += 2)
68 {
69 if(std::string(attr[i]) == "name")name(attr[i+1]);
70 if(std::string(attr[i]) == "type")type(attr[i+1]);
71 if(std::string(attr[i]) == "ref")ref(attr[i+1]);
72 }
73 }
74 virtual void name (const std::string& name)
75 {
76 DEBTRACE("outputdatatypeParser::name");
78 }
79 virtual void type (const std::string& type)
80 {
81 DEBTRACE("outputdatatypeParser::type");
83 }
84 virtual void ref (const std::string& ref)
85 {
86 _param.setProperty("ref",ref);
87 }
88
89 virtual void pre ()
90 {
91 DEBTRACE("outputdatatypeParser::pre");
92 _param.clear();
93 }
94 virtual myoutport& post()
95 {
96 return _param;
97 }
99};
100
113template <class T=ENGINE::DataNode*>
115{
117 virtual void onStart(const XML_Char* el, const XML_Char** attr);
118 virtual void onEnd(const char *el,parser* child);
119 virtual void buildAttr(const XML_Char** attr);
120 virtual void pre ();
121 virtual void name (const std::string& name);
122 virtual void kind (const std::string& kind);
123 virtual void ref (const std::string& ref);
124 virtual void create ();
125 virtual void parameter (myoutport& p);
126 virtual T post();
127 std::string _name;
128 std::string _kind;
129 std::string _ref;
130};
131
133
134
135template <class T>
137 {
138 DEBTRACE("outnodetypeParser::onStart");
139 std::string element(el);
141 if(element == "parameter")pp=&outputdatatypeParser::outputdataParser;
142 if(element == "property")pp=&propertytypeParser::propertyParser;
143 this->SetUserDataAndPush(pp);
144 pp->init();
145 pp->pre();
146 pp->buildAttr(attr);
147 }
148
149template <class T>
150void outnodetypeParser<T>::onEnd(const char *el,parser* child)
151 {
152 DEBTRACE("outnodetypeParser::onEnd");
153 std::string element(el);
154 if(element == "parameter")parameter(((outputdatatypeParser*)child)->post());
155 if(element == "property")this->property(((propertytypeParser*)child)->post());
156 }
157
158template <class T>
160 {
161 if (!attr)
162 return;
163 DEBTRACE("outnodetypeParser::buildAttr");
164 this->required("name",attr);
165 for (int i = 0; attr[i]; i += 2)
166 {
167 if(std::string(attr[i]) == "name")name(attr[i+1]);
168 if(std::string(attr[i]) == "kind")kind(attr[i+1]);
169 if(std::string(attr[i]) == "ref")ref(attr[i+1]);
170 }
171 create();
172 }
173
174template <class T>
176{
177 this->_node=0;
178 _kind="";
179 _ref="";
180}
181
182template <class T>
183void outnodetypeParser<T>::name (const std::string& name)
184{
185 _name=name;
186}
187template <class T>
188void outnodetypeParser<T>::kind (const std::string& kind)
189{
190 _kind=kind;
191}
192template <class T>
193void outnodetypeParser<T>::ref (const std::string& ref)
194{
195 _ref=ref;
196}
197
198template <class T>
200{
201 this->_node = theRuntime->createOutDataNode(_kind,_name);
202}
203
204template <class T>
206{
207 DEBTRACE("outnodetypeParser::parameter");
208 if(currentProc->typeMap.count(p._type)==0)
209 {
210 //Check if the typecode is defined in the runtime
212 if(t==0)
213 {
214 std::string msg="Unknown Type: ";
215 msg=msg+p._type+" for node: "+this->_node->getName()+" port name: "+p._name;
216 this->logError(msg);
217 return;
218 }
219 else
220 {
221 currentProc->typeMap[p._type]=t;
222 t->incrRef();
223 }
224 }
225 ENGINE::InputPort *port = this->_node->edAddInputPort(p._name,currentProc->typeMap[p._type]);
226 this->_node->setData(port,p._props["ref"]);
227}
228
229template <class T>
231{
232 this->_node->setRef(_ref);
233 return this->_node;
234}
235
236}
237#endif
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
YACS::ENGINE::Runtime * theRuntime
Definition: parsers.cxx:40
YACS::ENGINE::Proc * currentProc
Definition: parserBase.cxx:30
Base class for Input Ports.
Definition: InputPort.hxx:44
std::map< std::string, TypeCode * > typeMap
Definition: Proc.hxx:90
virtual DataNode * createOutDataNode(const std::string &kind, const std::string &name)
Definition: Runtime.cxx:185
virtual TypeCode * getTypeCode(const std::string &name)
Get a typecode by its name from runtime catalogs.
Definition: Runtime.cxx:333
Base class for all type objects.
Definition: TypeCode.hxx:68
Proc * p
Definition: driver.cxx:216
char XML_Char
Definition: parserBase.hxx:37
def ref(target, callback=None)
Definition: CONNECTOR.py:120
Class for node parser.
Definition: nodeParsers.hxx:54
Class for OutNode parser.
virtual void onEnd(const char *el, parser *child)
virtual void name(const std::string &name)
virtual void onStart(const XML_Char *el, const XML_Char **attr)
virtual void kind(const std::string &kind)
static outnodetypeParser< T > outnodeParser
virtual void ref(const std::string &ref)
virtual void buildAttr(const XML_Char **attr)
virtual void parameter(myoutport &p)
Class for outputdata parser.
virtual void buildAttr(const XML_Char **attr)
static outputdatatypeParser outputdataParser
virtual myoutport & post()
virtual void onEnd(const char *el, parser *child)
virtual void onStart(const XML_Char *el, const XML_Char **attr)
virtual void name(const std::string &name)
virtual void type(const std::string &type)
virtual void ref(const std::string &ref)
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 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 property parser.
static propertytypeParser propertyParser
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