1 // Copyright (C) 2006-2008 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
19 #ifndef _PROCPARSER_HXX_
20 #define _PROCPARSER_HXX_
22 #include "blocParsers.hxx"
23 #include "typeParsers.hxx"
24 #include "containerParsers.hxx"
25 #include "nodeParsers.hxx"
28 #include "Container.hxx"
29 #include "TypeCode.hxx"
31 extern YACS::ENGINE::Proc* currentProc;
36 template <class T=YACS::ENGINE::Proc*>
37 struct proctypeParser: bloctypeParser<T>
40 static proctypeParser<T> procParser;
42 proctypeParser():bloctypeParser<T>()
44 this->_orders["type"]=1;
45 this->_orders["sequence"]=1;
46 this->_orders["objref"]=1;
48 void onStart(const XML_Char* el, const XML_Char** attr);
49 virtual void onEnd(const char *el,parser* child);
50 virtual void buildAttr(const XML_Char** attr)
52 for (int i = 0; attr[i]; i += 2)
54 if(std::string(attr[i]) == "state")this->state(attr[i+1]);
59 std::string name("proc");
60 currentProc=theRuntime->createProc(name);
61 this->_bloc=currentProc;
62 currentProc->names.push_back("");
64 virtual void type (const mytype& t)
66 DEBTRACE( "type_set" );
67 YACS::ENGINE::TypeCode* tt=currentProc->createType(t._name,t._kind);
70 virtual void sequence (ENGINE::TypeCode* const& t)
72 DEBTRACE( "sequence_set" );
75 virtual void objref (ENGINE::TypeCode* const& t)
77 DEBTRACE( "objref_set" );
80 virtual void struct_ (ENGINE::TypeCode* const& t)
82 DEBTRACE( "struct_set" );
85 virtual void container (const mycontainer& t)
87 DEBTRACE( "container_set: " << t._name )
88 std::vector<machine>::const_iterator iter;
89 for(iter=t._machs.begin();iter!=t._machs.end();iter++)
91 DEBTRACE( "machine name: " << (*iter)._name )
94 if(currentProc->containerMap.count(t._name) == 0)
96 YACS::ENGINE::Container* cont=theRuntime->createContainer();
97 cont->setName(t._name);
98 // Set all properties for this container
99 std::map<std::string, std::string>::const_iterator pt;
100 for(pt=t._props.begin();pt!=t._props.end();pt++)
101 cont->setProperty((*pt).first,(*pt).second);
102 currentProc->containerMap[t._name]=cont;
106 std::cerr << "Warning: container " << t._name << " already defined. It will be ignored" << std::endl;
110 T post(){return this->_bloc;}
113 template <class T> proctypeParser<T> proctypeParser<T>::procParser;
120 void proctypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
122 DEBTRACE( "proctypeParser::onStart: " << el )
123 std::string element(el);
124 this->checkOrder(element);
125 parser* pp=&parser::main_parser;
126 if(element == "property")pp=&propertytypeParser::propertyParser;
127 else if(element == "type")pp=&typetypeParser::typeParser;
128 else if(element == "sequence")pp=&seqtypeParser::seqParser;
129 else if(element == "objref")pp=&objtypeParser::objParser;
130 else if(element == "struct")pp=&structtypeParser::structParser;
131 else if(element == "container")pp=&containertypeParser::containerParser;
133 else if(element == "inline")pp=&inlinetypeParser<>::inlineParser;
134 else if(element == "sinline")pp=&sinlinetypeParser<>::sinlineParser;
135 else if(element == "service")pp=&servicetypeParser<>::serviceParser;
136 else if(element == "node")pp=&nodetypeParser<>::nodeParser;
137 else if(element == "datanode")pp=&presettypeParser<>::presetParser;
138 else if(element == "outnode")pp=&outnodetypeParser<>::outnodeParser;
140 else if(element == "bloc")pp=&bloctypeParser<>::blocParser;
141 else if(element == "forloop")pp=&forlooptypeParser<>::forloopParser;
142 else if(element == "foreach")pp=&foreachlooptypeParser<>::foreachloopParser;
143 else if(element == "while")pp=&whilelooptypeParser<>::whileloopParser;
144 else if(element == "switch")pp=&switchtypeParser::switchParser;
146 else if(element == "control")pp=&controltypeParser<>::controlParser;
147 else if(element == "datalink")pp=&linktypeParser<>::linkParser;
148 else if(element == "stream")pp=&streamtypeParser<>::streamParser;
149 else if(element == "parameter")pp=¶metertypeParser::parameterParser;
152 // OCC: san -- Allow external parsers for handling of unknown elements
153 // and attributes. This capability is used by YACS GUI to read
154 // graph presentation data
155 if ( this->_defaultParsersMap )
157 if((this->_defaultParsersMap)->count(element) != 0)
159 pp=(*(this->_defaultParsersMap))[element];
163 std::cerr << "There is no parser for this element type. It will be ignored!" << std::endl;
167 this->SetUserDataAndPush(pp);
174 void proctypeParser<T>::onEnd(const char *el,parser* child)
176 DEBTRACE( "proctypeParser::onEnd: " << el )
177 std::string element(el);
178 if(element == "property")this->property(((propertytypeParser*)child)->post());
179 else if(element == "type")type(((typetypeParser*)child)->post());
180 else if(element == "sequence")sequence(((seqtypeParser*)child)->post());
181 else if(element == "objref")objref(((objtypeParser*)child)->post());
182 else if(element == "struct")struct_(((structtypeParser*)child)->post());
183 else if(element == "container")container(((containertypeParser*)child)->post());
185 else if(element == "inline")this->inline_(((inlinetypeParser<>*)child)->post());
186 else if(element == "sinline")this->sinline(((sinlinetypeParser<>*)child)->post());
187 else if(element == "service")this->service(((servicetypeParser<>*)child)->post());
188 else if(element == "node")this->node(((nodetypeParser<>*)child)->post());
189 else if(element == "datanode")this->preset(((presettypeParser<>*)child)->post());
190 else if(element == "outnode")this->outnode(((outnodetypeParser<>*)child)->post());
192 else if(element == "bloc")this->bloc(((bloctypeParser<>*)child)->post());
193 else if(element == "forloop")this->forloop(((forlooptypeParser<>*)child)->post());
194 else if(element == "foreach")this->foreach(((foreachlooptypeParser<>*)child)->post());
195 else if(element == "while")this->while_(((whilelooptypeParser<>*)child)->post());
196 else if(element == "switch")this->switch_(((switchtypeParser*)child)->post());
198 else if(element == "control") this->control(((controltypeParser<>*)child)->post());
199 else if(element == "datalink") this->datalink(((linktypeParser<>*)child)->post());
200 else if(element == "stream") this->stream(((streamtypeParser<>*)child)->post());
201 else if(element == "parameter") this->parameter(((parametertypeParser*)child)->post());