Version: 9.16.0
procParsers.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 _PROCPARSER_HXX_
21#define _PROCPARSER_HXX_
22
23#include "blocParsers.hxx"
24#include "typeParsers.hxx"
25#include "containerParsers.hxx"
27#include "nodeParsers.hxx"
28
29#include "Proc.hxx"
30#include "Container.hxx"
31#include "TypeCode.hxx"
32
34
35namespace YACS
36{
37
38template <class T=YACS::ENGINE::Proc*>
40{
41
43
45 {
46 this->_orders["type"]=1;
47 this->_orders["sequence"]=1;
48 this->_orders["objref"]=1;
49 }
50 void onStart(const XML_Char* el, const XML_Char** attr);
51 virtual void onEnd(const char *el,parser* child);
52 virtual void buildAttr(const XML_Char** attr)
53 {
54 if (!attr)
55 return;
56 for (int i = 0; attr[i]; i += 2)
57 {
58 if(std::string(attr[i]) == "state")
59 this->state(attr[i+1]);
60 if(std::string(attr[i]) == "name")
61 name(attr[i+1]);
62 }
63 }
64 virtual void pre()
65 {
66 std::string name("proc");
68 this->_bloc=currentProc;
69 currentProc->names.push_back("");
70 }
71
72 virtual void name(const std::string& name)
73 {
75 }
76
77 virtual void type(const mytype& t)
78 {
79 DEBTRACE( "type_set" );
81 tt->decrRef();
82 }
83 virtual void sequence(ENGINE::TypeCode* const& t)
84 {
85 DEBTRACE( "sequence_set" );
86 t->decrRef();
87 }
88 virtual void objref(ENGINE::TypeCode* const& t)
89 {
90 DEBTRACE( "objref_set" );
91 t->decrRef();
92 }
93 virtual void struct_(ENGINE::TypeCode* const& t)
94 {
95 DEBTRACE( "struct_set" );
96 t->decrRef();
97 }
98
100 {
101 DEBTRACE( "componentinstance: " << t._name );
103
104 // Set all properties for this component instance
105 std::map<std::string, std::string>::const_iterator pt;
106 for(pt=t._props.begin();pt!=t._props.end();pt++)
107 inst->setProperty((*pt).first,(*pt).second);
108
109 //associate a container to the component instance
110 if(currentProc->containerMap.count(t._container) != 0)
111 {
112 inst->setContainer(currentProc->containerMap[t._container]);
113 }
114 else if(t._container == "")
115 {
116 if(currentProc->containerMap.count("DefaultContainer") != 0)
117 {
118 //a default container is defined : use it if supported
119 try
120 {
121 currentProc->containerMap["DefaultContainer"]->checkCapabilityToDealWith(inst);
122 inst->setContainer(currentProc->containerMap["DefaultContainer"]);
123 }
124 catch(YACS::Exception){}
125 }
126 }
127 else
128 {
129 std::cerr << "WARNING: Unknown container " << t._container << " ignored" << std::endl;
130 }
131
132 inst->decrRef();
133 }
134
135 virtual void container(const mycontainer& t)
136 {
137 DEBTRACE( "container_set: " << t._name )
138 std::vector<machine>::const_iterator iter;
139 for(iter=t._machs.begin();iter!=t._machs.end();iter++)
140 {
141 DEBTRACE( "machine name: " << (*iter)._name )
142 }
143
144 if(currentProc->containerMap.count(t._name) != 0 && t._name != "DefaultContainer")
145 {
146 std::cerr << "Warning: container " << t._name << " already defined. It will be ignored" << std::endl;
147 }
148 else
149 {
150 // Set all properties for this container
151 std::string kindOfContainer;
152 std::map<std::string, std::string>::const_iterator pt(t._props.find(std::string(ENGINE::Container::KIND_ENTRY)));
153 if(pt!=t._props.end())
154 kindOfContainer=pt->second;
155 YACS::ENGINE::Container *cont(currentProc->createContainer(t._name,kindOfContainer));
156 for(pt=t._props.begin();pt!=t._props.end();pt++)
157 if((*pt).second!=ENGINE::Container::KIND_ENTRY)
158 cont->setProperty((*pt).first,(*pt).second);
159 cont->decrRef();
160 }
161 }
162
163 T post() { return this->_bloc; }
164};
165
166template <class T> proctypeParser<T> proctypeParser<T>::procParser;
167
168}
169
170namespace YACS
171{
172template <class T>
173void proctypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
174 {
175 DEBTRACE( "proctypeParser::onStart: " << el )
176 std::string element(el);
177 this->checkOrder(element);
179 if(element == "property")pp=&propertytypeParser::propertyParser;
180 else if(element == "type")pp=&typetypeParser::typeParser;
181 else if(element == "sequence")pp=&seqtypeParser::seqParser;
182 else if(element == "objref")pp=&objtypeParser::objParser;
183 else if(element == "struct")pp=&structtypeParser::structParser;
184 else if(element == "container")pp=&containertypeParser::containerParser;
185 else if(element == "componentinstance")pp=&componentinstancetypeParser::componentinstanceParser;
186
187 else if(element == "inline")pp=&inlinetypeParser<>::inlineParser;
188 else if(element == "sinline")pp=&sinlinetypeParser<>::sinlineParser;
189 else if(element == "service")pp=&servicetypeParser<>::serviceParser;
190 else if(element == "server")pp=&servertypeParser<>::serverParser;
191 else if(element == "remote")pp=&remotetypeParser<>::remoteParser;
192 else if(element == "node")pp=&nodetypeParser<>::nodeParser;
193 else if(element == "datanode")pp=&presettypeParser<>::presetParser;
194 else if(element == "outnode")pp=&outnodetypeParser<>::outnodeParser;
195
196 else if(element == "bloc")pp=&bloctypeParser<>::blocParser;
197 else if(element == "forloop")pp=&forlooptypeParser<>::forloopParser;
200 else if(element == "optimizer")pp=&optimizerlooptypeParser<>::optimizerloopParser;
201 else if(element == "while")pp=&whilelooptypeParser<>::whileloopParser;
202 else if(element == "switch")pp=&switchtypeParser::switchParser;
203
204 else if(element == "control")pp=&controltypeParser<>::controlParser;
205 else if(element == "datalink")pp=&linktypeParser<>::linkParser;
206 else if(element == "stream")pp=&streamtypeParser<>::streamParser;
207 else if(element == "parameter")pp=&parametertypeParser::parameterParser;
208 else
209 {
210 // OCC: san -- Allow external parsers for handling of unknown elements
211 // and attributes. This capability is used by YACS GUI to read
212 // graph presentation data
213 if ( this->_defaultParsersMap )
214 {
215 if((this->_defaultParsersMap)->count(element) != 0)
216 {
217 pp=(*(this->_defaultParsersMap))[element];
218 }
219 else
220 {
221 std::cerr << "There is no parser for this element type. It will be ignored! " << element << std::endl;
222 }
223 }
224 }
225 this->SetUserDataAndPush(pp);
226 pp->init();
227 pp->pre();
228 pp->buildAttr(attr);
229 }
230
231template <class T>
232void proctypeParser<T>::onEnd(const char *el,parser* child)
233 {
234 DEBTRACE( "proctypeParser::onEnd: " << el )
235 std::string element(el);
236 if(element == "property")this->property(((propertytypeParser*)child)->post());
237 else if(element == "type")type(((typetypeParser*)child)->post());
238 else if(element == "sequence")sequence(((seqtypeParser*)child)->post());
239 else if(element == "objref")objref(((objtypeParser*)child)->post());
240 else if(element == "struct")struct_(((structtypeParser*)child)->post());
241 else if(element == "container")container(((containertypeParser*)child)->post());
242 else if(element == "componentinstance")componentinstance(((componentinstancetypeParser*)child)->post());
243
244 else if(element == "inline")this->inline_(((inlinetypeParser<>*)child)->post());
245 else if(element == "sinline")this->sinline(((sinlinetypeParser<>*)child)->post());
246 else if(element == "service")this->service(((servicetypeParser<>*)child)->post());
247 else if(element == "server")this->server(((servertypeParser<>*)child)->post());
248 else if(element == "remote")this->remote(((remotetypeParser<>*)child)->post());
249 else if(element == "node")this->node(((nodetypeParser<>*)child)->post());
250 else if(element == "datanode")this->preset(((presettypeParser<>*)child)->post());
251 else if(element == "outnode")this->outnode(((outnodetypeParser<>*)child)->post());
252
253 else if(element == "bloc")this->bloc(((bloctypeParser<>*)child)->post());
254 else if(element == "forloop")this->forloop(((forlooptypeParser<>*)child)->post());
255 else if(element == "foreach")this->foreach(((foreachlooptypeParser<ENGINE::ForEachLoop *>*)child)->post());
256 else if(element == "foreachdyn")this->foreach(((foreachlooptypeParser<ENGINE::ForEachLoopDyn *>*)child)->post());
257 else if(element == "optimizer")this->optimizer(((optimizerlooptypeParser<>*)child)->post());
258 else if(element == "while")this->while_(((whilelooptypeParser<>*)child)->post());
259 else if(element == "switch")this->switch_(((switchtypeParser*)child)->post());
260
261 else if(element == "control") this->control(((controltypeParser<>*)child)->post());
262 else if(element == "datalink") this->datalink(((linktypeParser<>*)child)->post());
263 else if(element == "stream") this->stream(((streamtypeParser<>*)child)->post());
264 else if(element == "parameter") this->parameter(((parametertypeParser*)child)->post());
265 }
266
267}
268
269#endif
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
YACS::ENGINE::Runtime * theRuntime
Definition: parsers.cxx:40
Base class for all component instances.
virtual bool setContainer(Container *cont)
virtual void setProperty(const std::string &name, const std::string &value)=0
static const char KIND_ENTRY[]
Definition: Container.hxx:87
Base class for all schema objects.
Definition: Proc.hxx:44
virtual Container * createContainer(const std::string &name, const std::string &kind="")
Create a new Container and store it in containerMap.
Definition: Proc.cxx:506
virtual TypeCode * createType(const std::string &name, const std::string &kind)
Definition: Proc.cxx:103
std::vector< std::string > names
Definition: Proc.hxx:93
std::map< std::string, Container * > containerMap
Definition: Proc.hxx:91
void setName(const std::string &name)
Definition: Proc.cxx:204
virtual ComponentInstance * createComponentInstance(const std::string &componame, const std::string &name="", const std::string &kind="")
Create a new ComponentInstance and add it into componentInstanceMap.
Definition: Proc.cxx:599
virtual void setProperty(const std::string &name, const std::string &value)
virtual Proc * createProc(const std::string &name)
Definition: Runtime.cxx:226
Base class for all type objects.
Definition: TypeCode.hxx:68
char XML_Char
Definition: parserBase.hxx:37
YACS::ENGINE::Proc * currentProc
Definition: parserBase.cxx:30
virtual void state(const std::string &name)
Class for componentinstance parser.
static componentinstancetypeParser componentinstanceParser
Class for container parser.
static containertypeParser containerParser
Class for node parser.
Definition: nodeParsers.hxx:54
Class for objref parser.
Definition: typeParsers.hxx:99
static objtypeParser objParser
Class for OutNode parser.
static parametertypeParser parameterParser
virtual void init()
Definition: parserBase.cxx:86
virtual void pre()
Definition: parserBase.hxx:61
virtual void buildAttr(const XML_Char **attr)
Definition: parserBase.cxx:195
static parser main_parser
Definition: parserBase.hxx:41
std::map< std::string, int > _orders
Definition: parserBase.hxx:99
Class for PresetNode parser.
virtual void sequence(ENGINE::TypeCode *const &t)
Definition: procParsers.hxx:83
virtual void onEnd(const char *el, parser *child)
virtual void name(const std::string &name)
Definition: procParsers.hxx:72
virtual void buildAttr(const XML_Char **attr)
Definition: procParsers.hxx:52
void onStart(const XML_Char *el, const XML_Char **attr)
virtual void type(const mytype &t)
Definition: procParsers.hxx:77
virtual void componentinstance(const mycomponentinstance &t)
Definition: procParsers.hxx:99
virtual void pre()
Definition: procParsers.hxx:64
virtual void objref(ENGINE::TypeCode *const &t)
Definition: procParsers.hxx:88
virtual void container(const mycontainer &t)
virtual void struct_(ENGINE::TypeCode *const &t)
Definition: procParsers.hxx:93
static proctypeParser< T > procParser
Definition: procParsers.hxx:42
Class for property parser.
static propertytypeParser propertyParser
Class for sequence parser.
Definition: typeParsers.hxx:70
static seqtypeParser seqParser
Definition: typeParsers.hxx:71
Class for parsing ServiceInlineNode description.
Class for struct parser.
static structtypeParser structParser
static switchtypeParser switchParser
Class for type parser.
Definition: typeParsers.hxx:44
static typetypeParser typeParser
Definition: typeParsers.hxx:45