Version: 8.3.0
YACS::ENGINE::nodeParser Class Reference

#include <LoadState.hxx>

Inheritance diagram for YACS::ENGINE::nodeParser:
Collaboration diagram for YACS::ENGINE::nodeParser:

Public Member Functions

virtual void init (const xmlChar **p, xmlParserBase *father=0)
 
virtual void onStart (const XML_Char *elem, const xmlChar **p)
 
virtual void onEnd (const XML_Char *name)
 
AnyxmlToAny (const std::string &data, const TypeCode *tc) const
 

Public Attributes

std::string _nodeName
 
std::string _nodeState
 

Private Attributes

std::list< loopPortParser * > _loopSamples
 

Additional Inherited Members

- Static Public Member Functions inherited from YACS::ENGINE::stateParser
static void setProc (Proc *p)
 
static void setRuntime (Runtime *runtime)
 
- Static Public Attributes inherited from YACS::ENGINE::stateParser
static XMLReadState _state
 
static std::string _what
 
- Protected Member Functions inherited from YACS::ENGINE::stateParser
virtual void charData (std::string data)
 
- Protected Attributes inherited from xmlParserBase
std::map< std::string,
std::string > 
_mapAttrib
 
std::string _data
 
xmlParserBase_father
 
- Static Protected Attributes inherited from YACS::ENGINE::stateParser
static std::stack< XMLReadState_stackState
 
static Proc_p
 
static Runtime_runtime
 
static std::map< std::string,
YACS::StatesForNode
_nodeStateValue
 
static std::map< std::string,
YACS::StatesForNode
_nodeStates
 

Detailed Description

Definition at line 116 of file LoadState.hxx.

Member Function Documentation

void nodeParser::init ( const xmlChar **  p,
xmlParserBase father = 0 
)
virtual

all parsers must know their father parser (father tag), in order to set values or attributes in father.

Reimplemented from YACS::ENGINE::stateParser.

Definition at line 234 of file LoadState.cxx.

References DEBTRACE, and YACS::ENGINE::XMLINNODE.

235 {
236  DEBTRACE("nodeParser::init()");
237  _loopSamples.clear();
238  _state = XMLINNODE;
239  _father = father;
240  _stackState.push(_state);
241  if (p) getAttributes(p);
242 }
void nodeParser::onEnd ( const XML_Char name)
virtual

Reimplemented from YACS::ENGINE::stateParser.

Definition at line 277 of file LoadState.cxx.

References YACS::ENGINE::ForEachLoop::assignPassedResults(), DEBTRACE, YACS::ENGINE::WhileLoop::edGetConditionPort(), YACS::ENGINE::Switch::edGetConditionPort(), YACS::ENGINE::ForLoop::edGetNbOfTimesInputPort(), YACS::ENGINE::InputPort::edInit(), YACS::ENGINE::Node::getChildByName(), YACS::ENGINE::ForEachLoop::getOutputPortType(), CORBAEngineTest::i, YACS::ENGINE::NbDoneLoader(), YACS::ENGINE::SequenceAny::New(), YACS::ENGINE::stateParser::onEnd(), YACS::ENGINE::SequenceAny::setEltAtRank(), YACS::ENGINE::StateLoader(), YACS::ENGINE::XMLFATALERROR, and YASSERT.

278 {
279  string nodeName = _mapAttrib["name"];
280  string nodeType = _mapAttrib["type"];
281  string nodeState = _mapAttrib["state"];
282  DEBTRACE( "nodeName: " << nodeName << " nodeType: " << nodeType << " nodeState: " << nodeState );
283 // for (std::map< std::string, Node * >::iterator it=_p->nodeMap.begin(); it != _p->nodeMap.end(); it++)
284 // cerr << "nodeMap: " << it->first << endl;
285  _nodeStates[nodeName] = _nodeStateValue[nodeState];
286  Node *node =0;
287  if(_p->getName() == nodeName)
288  node=_p;
289  else
290  node = _p->getChildByName(nodeName);
291 
292  YASSERT(_nodeStateValue.find(nodeState) != _nodeStateValue.end());
293  YACS::ENGINE::StateLoader(node, _nodeStateValue[nodeState]);
294 
295  if (nodeType == "forLoop")
296  {
297  if (_mapAttrib.find("nsteps") == _mapAttrib.end())
298  {
299  _what = "no attribute nsteps in forLoop " + _mapAttrib["name"];
301  stopParse(_what);
302  }
303  int nsteps = atoi(_mapAttrib["nsteps"].c_str());
304 
305  if (_mapAttrib.find("nbdone") == _mapAttrib.end())
306  {
307  _what = "no attribute nbdone in forLoop " + _mapAttrib["name"];
309  stopParse(_what);
310  }
311  int nbdone = atoi(_mapAttrib["nbdone"].c_str());
312  DEBTRACE("nsteps = " << nsteps << ", nbdone = " << nbdone);
313 
314  ForLoop* loop = dynamic_cast<ForLoop*>(node);
315  if (!loop)
316  {
317  _what = "node is not a ForLoop: " + _mapAttrib["name"];
319  stopParse(_what);
320  }
321  loop->edGetNbOfTimesInputPort()->edInit(nsteps);
322  YACS::ENGINE::NbDoneLoader(loop, nbdone);
323  }
324 
325  else if (nodeType == "whileLoop")
326  {
327  if (_mapAttrib.find("nbdone") == _mapAttrib.end())
328  {
329  _what = "no attribute nbdone in forLoop " + _mapAttrib["name"];
331  stopParse(_what);
332  }
333  int nbdone = atoi(_mapAttrib["nbdone"].c_str());
334 
335  if (_mapAttrib.find("condition") == _mapAttrib.end())
336  {
337  _what = "no attribute condition in forLoop " + _mapAttrib["name"];
339  stopParse(_what);
340  }
341  bool condition = atoi(_mapAttrib["condition"].c_str());
342  DEBTRACE("condition = " << condition << ", nbdone = " << nbdone);
343 
344  WhileLoop* loop = dynamic_cast<WhileLoop*>(node);
345  if (!loop)
346  {
347  _what = "node is not a WhileLoop: " + _mapAttrib["name"];
349  stopParse(_what);
350  }
351  loop->edGetConditionPort()->edInit(condition);
352  YACS::ENGINE::NbDoneLoader(loop, nbdone);
353  }
354 
355  else if (nodeType == "switch")
356  {
357  if (_mapAttrib.find("condition") == _mapAttrib.end())
358  {
359  _what = "no attribute condition in switch " + _mapAttrib["name"];
361  stopParse(_what);
362  }
363  int condition = atoi(_mapAttrib["condition"].c_str());
364  DEBTRACE("condition = " << condition);
365 
366  Switch* mySwitch = dynamic_cast<Switch*>(node);
367  if (!mySwitch)
368  {
369  _what = "node is not a Switch: " + _mapAttrib["name"];
371  stopParse(_what);
372  }
373  mySwitch->edGetConditionPort()->edInit(condition);
374  }
375  else if (nodeType == "forEachLoop")
376  {
377  ForEachLoop* feNode = dynamic_cast<ForEachLoop*>(node);
378  if(!feNode)
379  {
380  _what = "node is not a ForEachLoop: " + _mapAttrib["name"];
382  stopParse(_what);
383  }
384  else
385  {
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++)
392  {
393  const std::string& portName =(*itPort)->getPortName();
394  nameOfOutputs.push_back(portName);
395  const YACS::ENGINE::TypeCode* tc = feNode->getOutputPortType(portName);
396  if(!tc)
397  {
398  _what = "Impossible to find the type of the port " + portName;
400  stopParse(_what);
401  return;
402  }
403  unsigned int nbSamples = (*itPort)->getNbSamples();
404  SequenceAny* seqValues = SequenceAny::New(tc, nbSamples);
405  passedOutputs.push_back(seqValues);
406  for(unsigned int i = 0; i < nbSamples; i++)
407  {
408  unsigned int sampleId = (*itPort)->getSampleId(i);
409  const std::string& sampleData = (*itPort)->getSampleData(i);
410  Any* value = xmlToAny(sampleData, tc);
411  if(firstPort)
412  {
413  passedIds.push_back(sampleId);
414  seqValues->setEltAtRank(i, value);
415  }
416  else
417  {
418  unsigned int pos = 0;
419  while(pos < passedIds.size() && sampleId != passedIds[pos])
420  pos++;
421  if(pos < passedIds.size())
422  seqValues->setEltAtRank(pos, value);
423  else
424  {
425  _what = "Inconsistent sample id in foreach node " + _mapAttrib["name"];
427  stopParse(_what);
428  itPort=_loopSamples.end();
429  return;
430  }
431  }
432  }
433  firstPort = false;
434  }
435  feNode->assignPassedResults(passedIds, passedOutputs, nameOfOutputs);
436  }
437  }
438 
439  stateParser::onEnd(name);
440 }
void nodeParser::onStart ( const XML_Char elem,
const xmlChar **  p 
)
virtual

Reimplemented from YACS::ENGINE::stateParser.

Definition at line 245 of file LoadState.cxx.

References DEBTRACE, YACS::ENGINE::stateParser::init(), and YACS::ENGINE::XMLFATALERROR.

246 {
247  DEBTRACE("nodeParser::onStart" << elem);
248  string element(elem);
249  stateParser *parser = 0;
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")
258  {
259  loopPortParser* sparser = new loopPortParser();
260  _loopSamples.push_back(sparser);
261  parser = sparser;
262  }
263  else
264  {
265  _what = "expected name, state or inputPort, got <" + element + ">";
267  stopParse(_what);
268  }
269  if (parser)
270  {
271  _stackParser.push(parser);
272  XML_SetUserData(_xmlParser, parser);
273  parser->init(p, this);
274  }
275 }
Any * nodeParser::xmlToAny ( const std::string &  data,
const TypeCode tc 
) const

Definition at line 442 of file LoadState.cxx.

References YACS::ENGINE::convertXmlNeutral(), and doc.

443 {
444  xmlDocPtr doc;
445  xmlNodePtr cur;
446  //YACS::ENGINE::Any *ob=YACS::ENGINE::AtomAny::New(0);
447  YACS::ENGINE::Any *ob=NULL;
448  {
449  doc = xmlParseMemory(data.c_str(), data.length());
450  if (doc == NULL )
451  {
452  stringstream msg;
453  msg << "Problem in conversion: XML Document not parsed successfully ";
454  msg << " (" << __FILE__ << ":" << __LINE__ << ")";
455  throw ConversionException(msg.str());
456  }
457  cur = xmlDocGetRootElement(doc);
458  if (cur == NULL)
459  {
460  xmlFreeDoc(doc);
461  stringstream msg;
462  msg << "Problem in conversion: empty XML Document";
463  msg << " (" << __FILE__ << ":" << __LINE__ << ")";
464  throw ConversionException(msg.str());
465  }
466  while (cur != NULL)
467  {
468  if ((!xmlStrcmp(cur->name, (const xmlChar *)"value")))
469  {
470  ob=convertXmlNeutral(tc,doc,cur);
471  break;
472  }
473  cur = cur->next;
474  }
475  xmlFreeDoc(doc);
476  if(ob==NULL)
477  {
478  stringstream msg;
479  msg << "Problem in conversion: incorrect XML value";
480  msg << " (" << __FILE__ << ":" << __LINE__ << ")";
481  throw ConversionException(msg.str());
482  }
483  }
484  return ob;
485 }

Member Data Documentation

std::list<loopPortParser*> YACS::ENGINE::nodeParser::_loopSamples
private

Definition at line 126 of file LoadState.hxx.

std::string YACS::ENGINE::nodeParser::_nodeName

Definition at line 123 of file LoadState.hxx.

std::string YACS::ENGINE::nodeParser::_nodeState

Definition at line 124 of file LoadState.hxx.


The documentation for this class was generated from the following files: