43 using namespace YACS::ENGINE;
70 _stackState.push(_state);
95 if (element ==
"graphState") parser =
new graphParser();
98 _what =
"expected <graphState>, got <" + element +
">";
104 _stackParser.push(parser);
105 XML_SetUserData(_xmlParser, parser);
114 _state = _stackState.top();
131 _stackState.push(_state);
132 if (p) getAttributes(p);
137 string element(elem);
139 if (element ==
"node") parser =
new nodeParser();
142 _what =
"expected <node>, got <" + element +
">";
148 _stackParser.push(parser);
149 XML_SetUserData(_xmlParser, parser);
150 parser->
init(p,
this);
157 std::map<std::string, YACS::StatesForNode>::const_iterator it;
158 for (it = _nodeStates.begin(); it != _nodeStates.end(); it++)
161 string nodeName = it->first;
162 DEBTRACE(
"nodeName = " << nodeName);
163 if(_p->getName() == nodeName)
170 for (list<OutGate*>::iterator io = backlinks.begin(); io != backlinks.end(); io++)
172 Node* fromNode = (*io)->getNode();
174 if (fromNode == _p) fromName = fromNode->
getName();
175 else fromName = _p->getChildName(fromNode);
178 DEBTRACE(
" fromNode = " << fromName);
196 YASSERT( dynamic_cast<nodeParser*> (father));
197 _stackState.push(_state);
198 if (p) getAttributes(p);
200 virtual void onStart (
const XML_Char* elem,
const xmlChar**
p)
203 string element(elem);
205 if (element ==
"name") parser =
new attrParser();
206 else if (element ==
"value") parser =
new valueParser();
209 _what =
"expected name or value, got <" + element +
">";
215 _stackParser.push(parser);
216 XML_SetUserData(_xmlParser, parser);
217 parser->
init(p,
this);
226 virtual void addData(std::string )
237 _loopSamples.clear();
240 _stackState.push(_state);
241 if (p) getAttributes(p);
247 DEBTRACE(
"nodeParser::onStart" << elem);
248 string element(elem);
250 if (element ==
"inputPort") parser =
new portParser();
251 else if (element ==
"name") parser =
new attrParser();
252 else if (element ==
"state") parser =
new attrParser();
253 else if (element ==
"nsteps") parser =
new attrParser();
254 else if (element ==
"nbdone") parser =
new attrParser();
255 else if (element ==
"condition") parser =
new attrParser();
256 else if (element ==
"outputPort") parser =
new outputParser();
257 else if (element ==
"loopOutputPort")
260 _loopSamples.push_back(sparser);
265 _what =
"expected name, state or inputPort, got <" + element +
">";
271 _stackParser.push(parser);
272 XML_SetUserData(_xmlParser, parser);
273 parser->
init(p,
this);
279 string nodeName = _mapAttrib[
"name"];
280 string nodeType = _mapAttrib[
"type"];
281 string nodeState = _mapAttrib[
"state"];
282 DEBTRACE(
"nodeName: " << nodeName <<
" nodeType: " << nodeType <<
" nodeState: " << nodeState );
285 _nodeStates[nodeName] = _nodeStateValue[nodeState];
287 if(_p->getName() == nodeName)
292 YASSERT(_nodeStateValue.find(nodeState) != _nodeStateValue.end());
295 if (nodeType ==
"forLoop")
297 if (_mapAttrib.find(
"nsteps") == _mapAttrib.end())
299 _what =
"no attribute nsteps in forLoop " + _mapAttrib[
"name"];
303 int nsteps = atoi(_mapAttrib[
"nsteps"].c_str());
305 if (_mapAttrib.find(
"nbdone") == _mapAttrib.end())
307 _what =
"no attribute nbdone in forLoop " + _mapAttrib[
"name"];
311 int nbdone = atoi(_mapAttrib[
"nbdone"].c_str());
312 DEBTRACE(
"nsteps = " << nsteps <<
", nbdone = " << nbdone);
317 _what =
"node is not a ForLoop: " + _mapAttrib[
"name"];
325 else if (nodeType ==
"whileLoop")
327 if (_mapAttrib.find(
"nbdone") == _mapAttrib.end())
329 _what =
"no attribute nbdone in forLoop " + _mapAttrib[
"name"];
333 int nbdone = atoi(_mapAttrib[
"nbdone"].c_str());
335 if (_mapAttrib.find(
"condition") == _mapAttrib.end())
337 _what =
"no attribute condition in forLoop " + _mapAttrib[
"name"];
341 bool condition = atoi(_mapAttrib[
"condition"].c_str());
342 DEBTRACE(
"condition = " << condition <<
", nbdone = " << nbdone);
347 _what =
"node is not a WhileLoop: " + _mapAttrib[
"name"];
355 else if (nodeType ==
"switch")
357 if (_mapAttrib.find(
"condition") == _mapAttrib.end())
359 _what =
"no attribute condition in switch " + _mapAttrib[
"name"];
363 int condition = atoi(_mapAttrib[
"condition"].c_str());
364 DEBTRACE(
"condition = " << condition);
369 _what =
"node is not a Switch: " + _mapAttrib[
"name"];
375 else if (nodeType ==
"forEachLoop")
380 _what =
"node is not a ForEachLoop: " + _mapAttrib[
"name"];
386 std::vector<unsigned int> passedIds;
387 std::vector<SequenceAny *> passedOutputs;
388 std::vector<std::string> nameOfOutputs;
389 bool firstPort =
true;
390 std::list<loopPortParser*>::const_iterator itPort;
391 for(itPort=_loopSamples.begin(); itPort!=_loopSamples.end(); itPort++)
393 const std::string& portName =(*itPort)->getPortName();
394 nameOfOutputs.push_back(portName);
398 _what =
"Impossible to find the type of the port " + portName;
403 unsigned int nbSamples = (*itPort)->getNbSamples();
405 passedOutputs.push_back(seqValues);
406 for(
unsigned int i = 0;
i < nbSamples;
i++)
408 unsigned int sampleId = (*itPort)->getSampleId(
i);
409 const std::string& sampleData = (*itPort)->getSampleData(
i);
410 Any* value = xmlToAny(sampleData, tc);
413 passedIds.push_back(sampleId);
418 unsigned int pos = 0;
419 while(pos < passedIds.size() && sampleId != passedIds[pos])
421 if(pos < passedIds.size())
425 _what =
"Inconsistent sample id in foreach node " + _mapAttrib[
"name"];
428 itPort=_loopSamples.end();
449 doc = xmlParseMemory(data.c_str(), data.length());
453 msg <<
"Problem in conversion: XML Document not parsed successfully ";
454 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
457 cur = xmlDocGetRootElement(doc);
462 msg <<
"Problem in conversion: empty XML Document";
463 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
468 if ((!xmlStrcmp(cur->name, (
const xmlChar *)
"value")))
479 msg <<
"Problem in conversion: incorrect XML value";
480 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
494 _stackState.push(_state);
495 if (p) getAttributes(p);
501 string element(elem);
502 _what =
"expected nothing, got <" + element +
">";
516 _father->setAttribute((
char*)name, _attrValue);
527 YASSERT( dynamic_cast<nodeParser*> (father));
528 _stackState.push(_state);
529 if (p) getAttributes(p);
535 DEBTRACE(
"portParser::onStart" << elem);
536 string element(elem);
538 if (element ==
"name") parser =
new attrParser();
539 else if (element ==
"value") parser =
new valueParser();
542 _what =
"expected name or value, got <" + element +
">";
548 _stackParser.push(parser);
549 XML_SetUserData(_xmlParser, parser);
550 parser->
init(p,
this);
561 DEBTRACE(
"portName: " << _mapAttrib[
"name"] <<
"value: " << _data );
562 string nodeName = _father->getAttribute(
"name");
563 string nodeType = _father->getAttribute(
"type");
565 if (nodeType ==
"elementaryNode")
571 port->
edInit(
"XML",_data.c_str());
573 else if (nodeType ==
"forLoop")
575 string what=
"no way to set a port value on port " + _mapAttrib[
"name"];
576 what +=
" in node " + nodeName +
" of type " + nodeType;
579 else if (nodeType ==
"whileLoop")
581 string what=
"no way to set a port value on port " + _mapAttrib[
"name"];
582 what +=
" in node " + nodeName +
" of type " + nodeType;
585 else if (nodeType ==
"switch")
587 string what=
"no way to set a port value on port " + _mapAttrib[
"name"];
588 what +=
" in node " + nodeName +
" of type " + nodeType;
591 else if (nodeType ==
"forEachLoop")
597 port->
edInit(
"XML",_data.c_str());
601 string what=
"no way to set a port value on port " + _mapAttrib[
"name"];
602 what +=
" in node " + nodeName +
" of type " + nodeType;
616 _stackState.push(_state);
617 if (p) getAttributes(p);
623 string element(elem);
624 DEBTRACE(
"value type " << element );
626 if (element ==
"data") parser =
new dataParser();
627 else if (element ==
"array") parser =
new arrayParser();
631 _stackParser.push(parser);
632 XML_SetUserData(_xmlParser, parser);
633 parser->
init(p,
this);
639 _data =
"<value>" + value +
"</value>";
645 _father->addData(_data);
646 string elem = (
char *) name;
659 _stackState.push(_state);
660 if (p) getAttributes(p);
666 string element(elem);
669 if (element ==
"data") parser =
new dataParser();
672 _what =
"expected data, got <" + element +
">";
678 _stackParser.push(parser);
679 XML_SetUserData(_xmlParser, parser);
680 parser->
init(p,
this);
686 string val =
"<array>" + value +
"</array>";
695 _father->addData(_data);
706 _stackState.push(_state);
707 if (p) getAttributes(p);
713 string element(elem);
716 if (element ==
"value") parser =
new valueParser();
719 _what =
"expected value, got <" + element +
">";
725 _stackParser.push(parser);
726 XML_SetUserData(_xmlParser, parser);
727 parser->
init(p,
this);
733 _dataList.push_back(value);
739 string val =
"<data>";
740 while (!_dataList.empty())
742 val += _dataList.front();
743 _dataList.pop_front();
747 _father->addData(val);
755 DEBTRACE(
"simpleTypeParser::init()");
758 _stackState.push(_state);
759 if (p) getAttributes(p);
764 string element(elem);
765 _what =
"expected nothing, got <" + element +
">";
772 string val = string(
"<") + (
char*) name +
">" + _data +
"</" + (
char*) name +
">";
774 _father->addData(val);
780 _data = _data + data;
790 _stackState.push(_state);
793 if (p) getAttributes(p);
798 DEBTRACE(
"loopPortParser::onStart" << elem);
799 string element(elem);
801 if (element ==
"name") parser =
new attrParser();
802 else if (element ==
"sample") parser =
new sampleParser(
this);
805 _what =
"expected name or sample, got <" + element +
">";
811 _stackParser.push(parser);
812 XML_SetUserData(_xmlParser, parser);
813 parser->
init(p,
this);
828 _ids.push_back(index);
829 _sampleData.push_back(data);
844 return _sampleData[
i];
849 return _mapAttrib.at(
"name");
856 _sampleFather(father)
871 DEBTRACE(
"sampleParser::onStart" << elem);
872 string element(elem);
874 if (element ==
"index") parser =
new attrParser();
875 else if (element ==
"value") parser =
new valueParser();
878 _what =
"expected index or value, got <" + element +
">";
886 parser->
init(p,
this);
894 _what =
"no attribute index in sample ";
898 int index = atoi(
_mapAttrib[
"index"].c_str());
937 string what =
"Abort Parse: " + parser->
_what;
943 string what =
"Abort Parse: unknown execution problem";
952 DEBTRACE(
"YACS::ENGINE::loadState");
957 myStateLoader.
parse(xmlStateFile);