2 #ifndef _SWITCHPARSERS_HXX_
3 #define _SWITCHPARSERS_HXX_
5 #include "parserBase.hxx"
6 #include "propertyParsers.hxx"
7 #include "nodeParsers.hxx"
10 #include "ForLoop.hxx"
11 #include "ForEachLoop.hxx"
12 #include "WhileLoop.hxx"
16 #include "InlineNode.hxx"
17 #include "ServiceNode.hxx"
18 #include "ServiceInlineNode.hxx"
19 #include "Runtime.hxx"
21 #include "factory.hxx"
28 extern YACS::ENGINE::Proc* currentProc;
29 extern YACS::ENGINE::Runtime* theRuntime;
34 struct casetypeParser:parser
36 static casetypeParser caseParser;
37 void onStart(const XML_Char* el, const XML_Char** attr);
38 void onEnd(const char *el,parser* child);
39 virtual void buildAttr(const XML_Char** attr);
41 virtual void id (const int& n);
42 virtual void property (const myprop& prop);
43 virtual void inline_ (ENGINE::InlineNode* const& n);
44 virtual void sinline (ENGINE::ServiceInlineNode* const& n);
45 virtual void service (ENGINE::ServiceNode* const& n);
46 virtual void node (ENGINE::InlineNode* const& n);
47 virtual void forloop (ENGINE::ForLoop* const& n);
48 virtual void foreach (ENGINE::ForEachLoop* const& n);
49 virtual void while_ (ENGINE::WhileLoop* const& n);
50 virtual void switch_ (ENGINE::Switch* const& n);
51 virtual void bloc (ENGINE::Bloc* const& n);
52 virtual std::pair<int,ENGINE::Node*> post();
55 std::vector<int> _idStack;
58 struct defaultcasetypeParser:casetypeParser
60 static defaultcasetypeParser defaultcaseParser;
61 virtual void buildAttr(const XML_Char** attr);
65 struct switchtypeParser:parser
67 static switchtypeParser switchParser;
68 void onStart(const XML_Char* el, const XML_Char** attr);
69 void onEnd(const char *el,parser* child);
70 virtual void buildAttr(const XML_Char** attr);
72 virtual void case_ (const std::pair<int,ENGINE::Node*>& p);
73 virtual void default_ (const std::pair<int,ENGINE::Node*>& p);
74 virtual void name (const std::string& name);
75 virtual void state (const std::string& state);
76 virtual void select (const int& s);
77 virtual ENGINE::Switch* post ();
78 // stack to store switches in case of switch in switch
79 std::vector<ENGINE::Switch *> _cnodes;
85 #include "loopParsers.hxx"
90 static std::string switch_t3[]={"inline","sinline","service","node","forloop","foreach","while","switch","bloc",""};
92 void casetypeParser::buildAttr(const XML_Char** attr)
94 this->required("id",attr);
95 for (int i = 0; attr[i]; i += 2)
97 if(std::string(attr[i]) == "id")id(atoi(attr[i+1]));
100 void casetypeParser::pre ()
105 void casetypeParser::id (const int& n)
107 DEBTRACE( "case_id: " << n )
109 //store this level id
110 _idStack.push_back(_id);
111 //store this level name
112 std::stringstream temp;
113 if (_id <0) temp << "m" << -_id << "_";
114 else temp << "p" << _id << "_";
115 std::string fullname=currentProc->names.back()+temp.str();
116 DEBTRACE( "case_fullname: " << fullname )
117 currentProc->names.push_back(fullname);
119 void casetypeParser::property (const myprop& prop)
121 DEBTRACE( "property_set: " << prop._name << prop._value )
123 void casetypeParser::inline_ (ENGINE::InlineNode* const& n)
126 std::string fullname=currentProc->names.back()+ n->getName();
127 currentProc->nodeMap[fullname]=n;
128 currentProc->inlineMap[fullname]=n;
130 void casetypeParser::sinline (ENGINE::ServiceInlineNode* const& n)
133 std::string fullname=currentProc->names.back()+ n->getName();
134 currentProc->nodeMap[fullname]=n;
135 currentProc->serviceMap[fullname]=n;
137 void casetypeParser::service (ENGINE::ServiceNode* const& n)
140 std::string fullname=currentProc->names.back()+ n->getName();
141 currentProc->nodeMap[fullname]=n;
142 currentProc->serviceMap[fullname]=n;
144 void casetypeParser::node (ENGINE::InlineNode* const& n)
147 std::string fullname=currentProc->names.back()+ n->getName();
148 currentProc->nodeMap[fullname]=n;
149 currentProc->inlineMap[fullname]=n;
151 void casetypeParser::forloop (ENGINE::ForLoop* const& n)
154 std::string fullname=currentProc->names.back()+ n->getName();
155 currentProc->nodeMap[fullname]=n;
157 void casetypeParser::foreach (ENGINE::ForEachLoop* const& n)
160 std::string fullname=currentProc->names.back()+ n->getName();
161 currentProc->nodeMap[fullname]=n;
162 fullname += ".splitter";
163 currentProc->nodeMap[fullname]=n->getChildByShortName("splitter");
165 void casetypeParser::while_ (ENGINE::WhileLoop* const& n)
168 std::string fullname=currentProc->names.back()+ n->getName();
169 currentProc->nodeMap[fullname]=n;
171 void casetypeParser::switch_ (ENGINE::Switch* const& n)
174 std::string fullname=currentProc->names.back()+ n->getName();
175 currentProc->nodeMap[fullname]=n;
177 void casetypeParser::bloc (ENGINE::Bloc* const& n)
180 std::string fullname=currentProc->names.back()+ n->getName();
181 currentProc->nodeMap[fullname]=n;
183 std::pair<int,ENGINE::Node*> casetypeParser::post()
185 DEBTRACE( "case_post" )
186 minchoice(switch_t3,1);
187 //get back this level id
190 //pop back this level name
191 currentProc->names.pop_back();
192 return std::pair<int,ENGINE::Node*>(_id,_cnode);
195 void defaultcasetypeParser::buildAttr(const XML_Char** attr)
197 for (int i = 0; attr[i]; i += 2)
199 DEBTRACE( attr[i] << "=" << attr[i + 1] )
202 void defaultcasetypeParser::pre ()
206 //store this level id
207 _idStack.push_back(_id);
208 //store this level name
209 std::string fullname=currentProc->names.back()+"default_";
210 DEBTRACE( "case_fullname: " << fullname )
211 currentProc->names.push_back(fullname);
214 void switchtypeParser::buildAttr(const XML_Char** attr)
216 this->required("name",attr);
217 for (int i = 0; attr[i]; i += 2)
219 if(std::string(attr[i]) == "name")name(attr[i+1]);
220 if(std::string(attr[i]) == "state")state(attr[i+1]);
221 if(std::string(attr[i]) == "select")select(atoi(attr[i+1]));
224 void switchtypeParser::pre (){_state="";}
225 void switchtypeParser::case_ (const std::pair<int,ENGINE::Node*>& p)
227 ENGINE::Switch* s=_cnodes.back();
228 s->edSetNode(p.first,p.second);
230 void switchtypeParser::default_ (const std::pair<int,ENGINE::Node*>& p)
232 ENGINE::Switch* s=_cnodes.back();
233 s->edSetDefaultNode(p.second);
235 void switchtypeParser::name (const std::string& name)
238 std::string fullname=currentProc->names.back()+name;
239 DEBTRACE( "switch_fullname: " << fullname )
240 s=theRuntime->createSwitch(name);
241 _cnodes.push_back(s);
242 currentProc->names.push_back(fullname+'.');
244 void switchtypeParser::state (const std::string& state)
246 //state is an attribute (no order). It can be defined before name
248 ENGINE::Switch* s=_cnodes.back();
249 if(_state == "disabled")
251 DEBTRACE( "Switch disabled: " << s->getName())
252 s->exDisabledState();
255 void switchtypeParser::select (const int& s)
257 //select is an attribute
258 ENGINE::Switch* sw=_cnodes.back();
259 ENGINE::InputPort *p=sw->edGetConditionPort();
262 ENGINE::Switch* switchtypeParser::post ()
264 DEBTRACE( "switch_post: " )
265 ENGINE::Switch* sw=_cnodes.back();
266 //pop back current level name and node
268 currentProc->names.pop_back();
272 void switchtypeParser::onStart(const XML_Char* el, const XML_Char** attr)
274 DEBTRACE( "switchtypeParser::onStart: " << el )
275 std::string element(el);
276 this->maxcount("default",1,element);
277 parser* pp=&parser::main_parser;
278 if(element == "case")pp=&casetypeParser::caseParser;
279 else if(element == "default")pp=&defaultcasetypeParser::defaultcaseParser;
280 SetUserDataAndPush(pp);
286 void switchtypeParser::onEnd(const char *el,parser* child)
288 DEBTRACE( "switchtypeParser::onEnd: " << el )
289 std::string element(el);
290 if(element == "case")case_(((casetypeParser*)child)->post());
291 else if(element == "default")default_(((defaultcasetypeParser*)child)->post());
294 void casetypeParser::onStart(const XML_Char* el, const XML_Char** attr)
296 DEBTRACE( "casetypeParser::onStart: " << el )
297 std::string element(el);
298 this->maxcount("inline",1,element);
299 this->maxcount("sinline",1,element);
300 this->maxcount("service",1,element);
301 this->maxcount("node",1,element);
302 this->maxcount("forloop",1,element);
303 this->maxcount("foreach",1,element);
304 this->maxcount("while",1,element);
305 this->maxcount("switch",1,element);
306 this->maxcount("bloc",1,element);
307 this->maxchoice(switch_t3,1,element);
308 parser* pp=&parser::main_parser;
309 if(element == "property")pp=&propertytypeParser::propertyParser;
310 else if(element == "inline")pp=&inlinetypeParser<>::inlineParser;
311 else if(element == "sinline")pp=&sinlinetypeParser<>::sinlineParser;
312 else if(element == "service")pp=&servicetypeParser<>::serviceParser;
313 else if(element == "node")pp=&nodetypeParser<>::nodeParser;
314 else if(element == "forloop")pp=&forlooptypeParser<>::forloopParser;
315 else if(element == "foreach")pp=&foreachlooptypeParser<>::foreachloopParser;
316 else if(element == "while")pp=&whilelooptypeParser<>::whileloopParser;
317 else if(element == "switch")pp=&switchtypeParser::switchParser;
318 else if(element == "bloc")pp=&bloctypeParser<>::blocParser;
319 SetUserDataAndPush(pp);
325 void casetypeParser::onEnd(const char *el,parser* child)
327 DEBTRACE( "casetypeParser::onEnd: " << el )
328 std::string element(el);
329 if(element == "property")property(((propertytypeParser*)child)->post());
330 else if(element == "inline")inline_(((inlinetypeParser<>*)child)->post());
331 else if(element == "sinline")sinline(((sinlinetypeParser<>*)child)->post());
332 else if(element == "service")service(((servicetypeParser<>*)child)->post());
333 else if(element == "node")node(((nodetypeParser<>*)child)->post());
334 else if(element == "forloop")forloop(((forlooptypeParser<>*)child)->post());
335 else if(element == "foreach")foreach(((foreachlooptypeParser<>*)child)->post());
336 else if(element == "while")while_(((whilelooptypeParser<>*)child)->post());
337 else if(element == "switch")switch_(((switchtypeParser*)child)->post());
338 else if(element == "bloc")bloc(((bloctypeParser<>*)child)->post());