1 // Copyright (C) 2006-2013 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.
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 #ifndef _PROCPARSER_HXX_
21 #define _PROCPARSER_HXX_
23 #include "blocParsers.hxx"
24 #include "typeParsers.hxx"
25 #include "containerParsers.hxx"
26 #include "componentinstanceParsers.hxx"
27 #include "nodeParsers.hxx"
30 #include "Container.hxx"
31 #include "TypeCode.hxx"
33 extern YACS::ENGINE::Proc* currentProc;
38 template <class T=YACS::ENGINE::Proc*>
39 struct proctypeParser: bloctypeParser<T>
42 static proctypeParser<T> procParser;
44 proctypeParser():bloctypeParser<T>()
46 this->_orders["type"]=1;
47 this->_orders["sequence"]=1;
48 this->_orders["objref"]=1;
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)
54 for (int i = 0; attr[i]; i += 2)
56 if(std::string(attr[i]) == "state")this->state(attr[i+1]);
57 if(std::string(attr[i]) == "name")name(attr[i+1]);
62 std::string name("proc");
63 currentProc=theRuntime->createProc(name);
64 this->_bloc=currentProc;
65 currentProc->names.push_back("");
68 virtual void name (const std::string& name)
70 currentProc->setName(name);
73 virtual void type (const mytype& t)
75 DEBTRACE( "type_set" );
76 YACS::ENGINE::TypeCode* tt=currentProc->createType(t._name,t._kind);
79 virtual void sequence (ENGINE::TypeCode* const& t)
81 DEBTRACE( "sequence_set" );
84 virtual void objref (ENGINE::TypeCode* const& t)
86 DEBTRACE( "objref_set" );
89 virtual void struct_ (ENGINE::TypeCode* const& t)
91 DEBTRACE( "struct_set" );
95 virtual void componentinstance (const mycomponentinstance& t)
97 DEBTRACE( "componentinstance: " << t._name );
98 YACS::ENGINE::ComponentInstance* inst=currentProc->createComponentInstance(t._component,t._name,t._kind);
100 // Set all properties for this component instance
101 std::map<std::string, std::string>::const_iterator pt;
102 for(pt=t._props.begin();pt!=t._props.end();pt++)
103 inst->setProperty((*pt).first,(*pt).second);
105 //associate a container to the component instance
106 if(currentProc->containerMap.count(t._container) != 0)
108 inst->setContainer(currentProc->containerMap[t._container]);
110 else if(t._container == "")
112 if(currentProc->containerMap.count("DefaultContainer") != 0)
114 //a default container is defined : use it if supported
117 currentProc->containerMap["DefaultContainer"]->checkCapabilityToDealWith(inst);
118 inst->setContainer(currentProc->containerMap["DefaultContainer"]);
120 catch(YACS::Exception){}
125 std::cerr << "WARNING: Unknown container " << t._container << " ignored" << std::endl;
131 virtual void container (const mycontainer& t)
133 DEBTRACE( "container_set: " << t._name )
134 std::vector<machine>::const_iterator iter;
135 for(iter=t._machs.begin();iter!=t._machs.end();iter++)
137 DEBTRACE( "machine name: " << (*iter)._name )
140 if(currentProc->containerMap.count(t._name) != 0 && t._name != "DefaultContainer")
142 std::cerr << "Warning: container " << t._name << " already defined. It will be ignored" << std::endl;
146 YACS::ENGINE::Container* cont=currentProc->createContainer(t._name);
147 // Set all properties for this container
148 std::map<std::string, std::string>::const_iterator pt;
149 for(pt=t._props.begin();pt!=t._props.end();pt++)
150 cont->setProperty((*pt).first,(*pt).second);
155 T post(){return this->_bloc;}
158 template <class T> proctypeParser<T> proctypeParser<T>::procParser;
165 void proctypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
167 DEBTRACE( "proctypeParser::onStart: " << el )
168 std::string element(el);
169 this->checkOrder(element);
170 parser* pp=&parser::main_parser;
171 if(element == "property")pp=&propertytypeParser::propertyParser;
172 else if(element == "type")pp=&typetypeParser::typeParser;
173 else if(element == "sequence")pp=&seqtypeParser::seqParser;
174 else if(element == "objref")pp=&objtypeParser::objParser;
175 else if(element == "struct")pp=&structtypeParser::structParser;
176 else if(element == "container")pp=&containertypeParser::containerParser;
177 else if(element == "componentinstance")pp=&componentinstancetypeParser::componentinstanceParser;
179 else if(element == "inline")pp=&inlinetypeParser<>::inlineParser;
180 else if(element == "sinline")pp=&sinlinetypeParser<>::sinlineParser;
181 else if(element == "service")pp=&servicetypeParser<>::serviceParser;
182 else if(element == "server")pp=&servertypeParser<>::serverParser;
183 else if(element == "remote")pp=&remotetypeParser<>::remoteParser;
184 else if(element == "node")pp=&nodetypeParser<>::nodeParser;
185 else if(element == "datanode")pp=&presettypeParser<>::presetParser;
186 else if(element == "outnode")pp=&outnodetypeParser<>::outnodeParser;
188 else if(element == "bloc")pp=&bloctypeParser<>::blocParser;
189 else if(element == "forloop")pp=&forlooptypeParser<>::forloopParser;
190 else if(element == "foreach")pp=&foreachlooptypeParser<>::foreachloopParser;
191 else if(element == "optimizer")pp=&optimizerlooptypeParser<>::optimizerloopParser;
192 else if(element == "while")pp=&whilelooptypeParser<>::whileloopParser;
193 else if(element == "switch")pp=&switchtypeParser::switchParser;
195 else if(element == "control")pp=&controltypeParser<>::controlParser;
196 else if(element == "datalink")pp=&linktypeParser<>::linkParser;
197 else if(element == "stream")pp=&streamtypeParser<>::streamParser;
198 else if(element == "parameter")pp=¶metertypeParser::parameterParser;
201 // OCC: san -- Allow external parsers for handling of unknown elements
202 // and attributes. This capability is used by YACS GUI to read
203 // graph presentation data
204 if ( this->_defaultParsersMap )
206 if((this->_defaultParsersMap)->count(element) != 0)
208 pp=(*(this->_defaultParsersMap))[element];
212 std::cerr << "There is no parser for this element type. It will be ignored! " << element << std::endl;
216 this->SetUserDataAndPush(pp);
223 void proctypeParser<T>::onEnd(const char *el,parser* child)
225 DEBTRACE( "proctypeParser::onEnd: " << el )
226 std::string element(el);
227 if(element == "property")this->property(((propertytypeParser*)child)->post());
228 else if(element == "type")type(((typetypeParser*)child)->post());
229 else if(element == "sequence")sequence(((seqtypeParser*)child)->post());
230 else if(element == "objref")objref(((objtypeParser*)child)->post());
231 else if(element == "struct")struct_(((structtypeParser*)child)->post());
232 else if(element == "container")container(((containertypeParser*)child)->post());
233 else if(element == "componentinstance")componentinstance(((componentinstancetypeParser*)child)->post());
235 else if(element == "inline")this->inline_(((inlinetypeParser<>*)child)->post());
236 else if(element == "sinline")this->sinline(((sinlinetypeParser<>*)child)->post());
237 else if(element == "service")this->service(((servicetypeParser<>*)child)->post());
238 else if(element == "server")this->server(((servertypeParser<>*)child)->post());
239 else if(element == "remote")this->remote(((remotetypeParser<>*)child)->post());
240 else if(element == "node")this->node(((nodetypeParser<>*)child)->post());
241 else if(element == "datanode")this->preset(((presettypeParser<>*)child)->post());
242 else if(element == "outnode")this->outnode(((outnodetypeParser<>*)child)->post());
244 else if(element == "bloc")this->bloc(((bloctypeParser<>*)child)->post());
245 else if(element == "forloop")this->forloop(((forlooptypeParser<>*)child)->post());
246 else if(element == "foreach")this->foreach(((foreachlooptypeParser<>*)child)->post());
247 else if(element == "optimizer")this->optimizer(((optimizerlooptypeParser<>*)child)->post());
248 else if(element == "while")this->while_(((whilelooptypeParser<>*)child)->post());
249 else if(element == "switch")this->switch_(((switchtypeParser*)child)->post());
251 else if(element == "control") this->control(((controltypeParser<>*)child)->post());
252 else if(element == "datalink") this->datalink(((linktypeParser<>*)child)->post());
253 else if(element == "stream") this->stream(((streamtypeParser<>*)child)->post());
254 else if(element == "parameter") this->parameter(((parametertypeParser*)child)->post());