Version: 9.16.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
 
virtual void init (const xmlChar **p, xmlParserBase *father=0)
 
- Public Member Functions inherited from xmlParserBase
void setAttribute (std::string key, std::string value)
 
std::string getAttribute (std::string key)
 
virtual void addData (std::string value)
 
virtual void init (const xmlChar **p, xmlParserBase *father=0)
 

Public Attributes

std::string _nodeName
 
std::string _nodeState
 
- Public Attributes inherited from xmlParserBase
std::map< std::string, int > counts
 

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 Member Functions inherited from xmlParserBase
static void XMLCALL start_document (void *userData)
 
static void XMLCALL end_document (void *userData)
 
static void XMLCALL start_element (void *userData, const xmlChar *name, const xmlChar **p)
 
static void XMLCALL end_element (void *userData, const xmlChar *name)
 
static void XMLCALL characters (void *userData, const xmlChar *ch, int len)
 
static void XMLCALL comment (void *userData, const xmlChar *value)
 
static void XMLCALL warning (void *userData, const char *fmt,...)
 
static void XMLCALL error (void *userData, const char *fmt,...)
 
static void XMLCALL fatal_error (void *userData, const char *fmt,...)
 
static void XMLCALL cdata_block (void *userData, const xmlChar *value, int len)
 
static void cleanGarbage ()
 
static int getGarbageSize ()
 
static void XML_SetUserData (_xmlParserCtxt *ctxt, xmlParserBase *parser)
 
- Static Public Attributes inherited from YACS::ENGINE::stateParser
static XMLReadState _state
 
static std::string _what
 
- Static Public Attributes inherited from xmlParserBase
static _xmlParserCtxt * _xmlParser
 
static std::stack< xmlParserBase * > _stackParser
 
- Protected Member Functions inherited from YACS::ENGINE::stateParser
virtual void onStart (const XML_Char *elem, const xmlChar **p)
 
virtual void onEnd (const XML_Char *name)
 
virtual void charData (std::string data)
 
- Protected Member Functions inherited from xmlParserBase
void getAttributes (const xmlChar **p)
 
virtual void onStart (const XML_Char *elem, const xmlChar **p)
 
virtual void onEnd (const XML_Char *name)
 
virtual void charData (std::string data)
 
virtual void incrCount (const XML_Char *elem)
 
virtual void end ()
 
virtual void stopParse (std::string what)
 
- 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
 
- Static Protected Attributes inherited from xmlParserBase
static std::list< xmlParserBase * > _garbage
 

Detailed Description

Definition at line 116 of file LoadState.hxx.

Member Function Documentation

◆ init()

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.

235{
236 DEBTRACE("nodeParser::init()");
237 _loopSamples.clear();
239 _father = father;
240 _stackState.push(_state);
241 if (p) getAttributes(p);
242}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
std::list< loopPortParser * > _loopSamples
Definition: LoadState.hxx:126
static std::stack< XMLReadState > _stackState
Definition: LoadState.hxx:98
static XMLReadState _state
Definition: LoadState.hxx:83
xmlParserBase * _father
void getAttributes(const xmlChar **p)
Proc * p
Definition: driver.cxx:216

References xmlParserBase::_father, _loopSamples, YACS::ENGINE::stateParser::_stackState, YACS::ENGINE::stateParser::_state, DEBTRACE, xmlParserBase::getAttributes(), p, and YACS::ENGINE::XMLINNODE.

◆ onEnd()

void nodeParser::onEnd ( const XML_Char name)
virtual

Reimplemented from YACS::ENGINE::stateParser.

Definition at line 277 of file LoadState.cxx.

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());
294
295 if (nodeType == "forLoop")
296 {
297 if (_mapAttrib.find("nsteps") == _mapAttrib.end())
298 {
299 _what = "no attribute nsteps in forLoop " + _mapAttrib["name"];
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"];
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"];
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"];
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"];
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"];
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"];
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"];
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"];
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;
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"];
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}
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
: Interface for management of storage of data formated dynamically in its TypeCode....
Definition: Any.hxx:79
Node * getChildByName(const std::string &name) const
std::string getName() const
void assignPassedResults(const std::vector< unsigned int > &passedIds, const std::vector< SequenceAny * > &passedOutputs, const std::vector< std::string > &nameOfOutputs)
const TypeCode * getOutputPortType(const std::string &portName) const
Loop node for parametric calculation.
Class for for loop node.
Definition: ForLoop.hxx:33
InputPort * edGetNbOfTimesInputPort()
Definition: ForLoop.hxx:45
void edInit(T value)
Definition: InputPort.hxx:129
Base class for all nodes.
Definition: Node.hxx:70
void setEltAtRank(int i, const Any *elem)
Definition: Any.cxx:696
static SequenceAny * New(const std::vector< T > &vec)
Definition: Any.hxx:318
Control node that emulates the C switch.
Definition: Switch.hxx:85
InputPort * edGetConditionPort()
Definition: Switch.hxx:115
Base class for all type objects.
Definition: TypeCode.hxx:68
Class for a while loop.
Definition: WhileLoop.hxx:39
InputPort * edGetConditionPort()
Definition: WhileLoop.hxx:48
Any * xmlToAny(const std::string &data, const TypeCode *tc) const
Definition: LoadState.cxx:442
static std::string _what
Definition: LoadState.hxx:84
virtual void onEnd(const XML_Char *name)
Definition: LoadState.cxx:111
static std::map< std::string, YACS::StatesForNode > _nodeStates
Definition: LoadState.hxx:102
static std::map< std::string, YACS::StatesForNode > _nodeStateValue
Definition: LoadState.hxx:101
virtual void stopParse(std::string what)
std::map< std::string, std::string > _mapAttrib
void YACSLIBENGINE_EXPORT NbDoneLoader(Loop *node, int val)
Definition: Loop.cxx:705
void YACSLIBENGINE_EXPORT StateLoader(Node *node, YACS::StatesForNode state)
Definition: Node.cxx:719

References _loopSamples, xmlParserBase::_mapAttrib, YACS::ENGINE::stateParser::_nodeStates, YACS::ENGINE::stateParser::_nodeStateValue, YACS::ENGINE::stateParser::_p, YACS::ENGINE::stateParser::_state, YACS::ENGINE::stateParser::_what, YACS::ENGINE::ForEachLoopGen::assignPassedResults(), DEBTRACE, YACS::ENGINE::Switch::edGetConditionPort(), YACS::ENGINE::WhileLoop::edGetConditionPort(), YACS::ENGINE::ForLoop::edGetNbOfTimesInputPort(), YACS::ENGINE::InputPort::edInit(), YACS::ENGINE::ComposedNode::getChildByName(), YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::ForEachLoopGen::getOutputPortType(), yacsorb.CORBAEngineTest::i, YACS::ENGINE::NbDoneLoader(), YACS::ENGINE::SequenceAny::New(), YACS::ENGINE::stateParser::onEnd(), YACS::ENGINE::SequenceAny::setEltAtRank(), YACS::ENGINE::StateLoader(), xmlParserBase::stopParse(), YACS::ENGINE::XMLFATALERROR, xmlToAny(), and YASSERT.

◆ onStart()

void nodeParser::onStart ( const XML_Char elem,
const xmlChar **  p 
)
virtual

Reimplemented from YACS::ENGINE::stateParser.

Definition at line 245 of file LoadState.cxx.

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 + ">";
268 }
269 if (parser)
270 {
271 _stackParser.push(parser);
273 parser->init(p, this);
274 }
275}
specialized parser to load SALOME execution saved states.
Definition: LoadState.hxx:81
virtual void init(const xmlChar **p, xmlParserBase *father=0)
Definition: LoadState.cxx:65
static void XML_SetUserData(_xmlParserCtxt *ctxt, xmlParserBase *parser)
static _xmlParserCtxt * _xmlParser
static std::stack< xmlParserBase * > _stackParser

References _loopSamples, xmlParserBase::_stackParser, YACS::ENGINE::stateParser::_state, YACS::ENGINE::stateParser::_what, xmlParserBase::_xmlParser, DEBTRACE, YACS::parser::init(), p, xmlParserBase::stopParse(), xmlParserBase::XML_SetUserData(), and YACS::ENGINE::XMLFATALERROR.

◆ xmlToAny()

Any * nodeParser::xmlToAny ( const std::string &  data,
const TypeCode tc 
) const

Definition at line 442 of file LoadState.cxx.

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}
static char doc[]
Definition: driver.cxx:63
YACS::ENGINE::Any * convertXmlNeutral(const TypeCode *t, xmlDocPtr doc, xmlNodePtr cur)

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

Referenced by onEnd().

Member Data Documentation

◆ _loopSamples

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

Definition at line 126 of file LoadState.hxx.

Referenced by init(), onEnd(), and onStart().

◆ _nodeName

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

Definition at line 123 of file LoadState.hxx.

◆ _nodeState

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: