Version: 8.3.0
YACS::ENGINE::VisitorSaveState Class Reference

#include <VisitorSaveState.hxx>

Inheritance diagram for YACS::ENGINE::VisitorSaveState:
Collaboration diagram for YACS::ENGINE::VisitorSaveState:

Public Member Functions

 VisitorSaveState (ComposedNode *root)
 
virtual ~VisitorSaveState ()
 
void openFileDump (const std::string &xmlDump) throw (Exception)
 
void closeFileDump ()
 
virtual void visitBloc (Bloc *node)
 
virtual void visitElementaryNode (ElementaryNode *node)
 
virtual void visitForEachLoop (ForEachLoop *node)
 
virtual void visitOptimizerLoop (OptimizerLoop *node)
 
virtual void visitDynParaLoop (DynParaLoop *node)
 
virtual void visitForLoop (ForLoop *node)
 
virtual void visitInlineNode (InlineNode *node)
 
virtual void visitInlineFuncNode (InlineFuncNode *node)
 
virtual void visitLoop (Loop *node)
 
virtual void visitProc (Proc *node)
 
virtual void visitServiceNode (ServiceNode *node)
 
virtual void visitServerNode (ServerNode *node)
 
virtual void visitServiceInlineNode (ServiceInlineNode *node)
 
virtual void visitSwitch (Switch *node)
 
virtual void visitWhileLoop (WhileLoop *node)
 
virtual void visitPresetNode (DataNode *node)
 
virtual void visitOutNode (DataNode *node)
 
virtual void visitStudyInNode (DataNode *node)
 
virtual void visitStudyOutNode (DataNode *node)
 
- Public Member Functions inherited from YACS::ENGINE::Visitor
 Visitor (ComposedNode *root)
 

Protected Attributes

std::ofstream _out
 
std::map< int, std::string > _nodeStateName
 
- Protected Attributes inherited from YACS::ENGINE::Visitor
ComposedNode_root
 

Additional Inherited Members

- Protected Member Functions inherited from YACS::ENGINE::Visitor
std::map< std::string,
std::string > 
getNodeProperties (Node *node)
 
std::map< std::string, TypeCode * > getTypeCodeMap (Proc *proc)
 
std::map< std::string,
Container * > 
getContainerMap (Proc *proc)
 
std::list< TypeCodeObjref * > getListOfBases (TypeCodeObjref *objref)
 

Detailed Description

Definition at line 35 of file VisitorSaveState.hxx.

Constructor & Destructor Documentation

VisitorSaveState::VisitorSaveState ( ComposedNode root)
VisitorSaveState::~VisitorSaveState ( )
virtual

Definition at line 66 of file VisitorSaveState.cxx.

References _out.

67 {
68  if (_out)
69  {
70  _out << "</graphState>" << endl;
71  _out.close();
72  }
73 }

Member Function Documentation

void VisitorSaveState::closeFileDump ( )

Definition at line 87 of file VisitorSaveState.cxx.

References _out.

Referenced by Handler(), main(), YACS::ENGINE::Proc::saveState(), YACS::ENGINE::Executor::saveState(), and YACS::ENGINE::schemaSaveState().

88 {
89  if (!_out) throw Exception("No file open for dump state");
90  _out << "</graphState>" << endl;
91  _out.close();
92 }
void VisitorSaveState::openFileDump ( const std::string &  xmlDump) throw (Exception)

Definition at line 75 of file VisitorSaveState.cxx.

Referenced by Handler(), main(), YACS::ENGINE::Proc::saveState(), YACS::ENGINE::Executor::saveState(), and YACS::ENGINE::schemaSaveState().

76 {
77  _out.open(xmlDump.c_str(), ios::out);
78  if (!_out)
79  {
80  string what = "Impossible to open file for writing: " + xmlDump;
81  throw Exception(what);
82  }
83  _out << "<?xml version='1.0'?>" << endl;
84  _out << "<graphState>" << endl;
85 }
void VisitorSaveState::visitBloc ( Bloc node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 145 of file VisitorSaveState.cxx.

References _nodeStateName, _out, YACS::ENGINE::Visitor::_root, DEBTRACE, YACS::ENGINE::ComposedNode::getChildName(), YACS::ENGINE::ComposedNode::getName(), and YACS::ENGINE::Node::getState().

146 {
147  node->ComposedNode::accept(this);
148  if (!_out) throw Exception("No file open for dump state");
149  string name = _root->getName();
150  if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
151  DEBTRACE("VisitorSaveState::visitBloc ------------- " << name);
152  _out << " <node type='bloc'>" << endl;
153  _out << " <name>" << name << "</name>" << endl;
154  _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
155 
156  _out << " </node>" << endl;
157 }
void VisitorSaveState::visitDynParaLoop ( DynParaLoop node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 201 of file VisitorSaveState.cxx.

202 {
203  node->ComposedNode::accept(this);
204 }
void VisitorSaveState::visitElementaryNode ( ElementaryNode node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 94 of file VisitorSaveState.cxx.

References _nodeStateName, _out, YACS::ENGINE::Visitor::_root, DEBTRACE, YACS::ENGINE::ComposedNode::getChildName(), YACS::ENGINE::ElementaryNode::getSetOfInputPort(), YACS::ENGINE::ElementaryNode::getSetOfOutputPort(), YACS::ENGINE::ElementaryNode::getState(), and YACS::Exception::what().

Referenced by visitInlineFuncNode(), visitInlineNode(), visitOutNode(), visitPresetNode(), visitServerNode(), visitServiceInlineNode(), visitServiceNode(), visitStudyInNode(), and visitStudyOutNode().

95 {
96  if (!_out) throw Exception("No file open for dump state");
97  string name = _root->getChildName(node);
98  DEBTRACE("VisitorSaveState::visitElementaryNode --- " << name);
99  _out << " <node type='elementaryNode'>" << endl;
100  _out << " <name>" << name << "</name>" << endl;
101  int nodeState = node->getState();
102  _out << " <state>" << _nodeStateName[nodeState] << "</state>" << endl;
103 
104  list<InputPort *> setOfInputPort = node->getSetOfInputPort();
105  list<InputPort *>::iterator iter;
106  for(iter = setOfInputPort.begin(); iter != setOfInputPort.end(); iter++)
107  {
108  _out << " <inputPort>" << endl;
109  _out << " <name>" << (*iter)->getName() << "</name>" << endl;
110  try
111  {
112  _out << " ";
113  _out << (*iter)->dump();
114  }
115  catch (YACS::Exception &e)
116  {
117  DEBTRACE("caught YACS:Exception: " << e.what());
118  _out << "<value><error><![CDATA[" << e.what() << "]]></error></value>" << endl;
119  }
120  _out << " </inputPort>" << endl;
121  }
122 
123  list<OutputPort *> setOfOutputPort = node->getSetOfOutputPort();
124  list<OutputPort *>::iterator oiter;
125  for(oiter = setOfOutputPort.begin(); oiter != setOfOutputPort.end(); oiter++)
126  {
127  _out << " <outputPort>" << endl;
128  _out << " <name>" << (*oiter)->getName() << "</name>" << endl;
129  try
130  {
131  _out << " ";
132  _out << (*oiter)->dump();
133  }
134  catch (YACS::Exception &e)
135  {
136  DEBTRACE("caught YACS:Exception: " << e.what());
137  _out << "<value><error><![CDATA[" << e.what() << "]]></error></value>" << endl;
138  }
139  _out << " </outputPort>" << endl;
140  }
141 
142  _out << " </node>" << endl;
143 }
void VisitorSaveState::visitForEachLoop ( ForEachLoop node)
virtual

Implements YACS::ENGINE::Visitor.

Reimplemented in YACS::ENGINE::VisitorSalomeSaveState.

Definition at line 173 of file VisitorSaveState.cxx.

References _nodeStateName, _out, YACS::ENGINE::Visitor::_root, DEBTRACE, YACS::ENGINE::ComposedNode::getChildName(), YACS::ENGINE::ComposedNode::getName(), and YACS::ENGINE::Node::getState().

174 {
175  node->ComposedNode::accept(this);
176  if (!_out) throw Exception("No file open for dump state");
177  string name = _root->getName();
178  if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
179  DEBTRACE("VisitorSaveState::visitForEachLoop ------ " << name);
180  _out << " <node type='forEachLoop'>" << endl;
181  _out << " <name>" << name << "</name>" << endl;
182  _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
183 
184  _out << " </node>" << endl;
185 }
void VisitorSaveState::visitForLoop ( ForLoop node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 221 of file VisitorSaveState.cxx.

References _nodeStateName, _out, YACS::ENGINE::Visitor::_root, DEBTRACE, YACS::ENGINE::ForLoop::edGetNbOfTimesInputPort(), YACS::ENGINE::InputPort::get(), YACS::ENGINE::ComposedNode::getChildName(), YACS::ENGINE::Any::getIntValue(), YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Loop::getNbOfTurns(), YACS::ENGINE::Node::getState(), and YACS::ENGINE::InputPort::isEmpty().

222 {
223  node->ComposedNode::accept(this);
224  if (!_out) throw Exception("No file open for dump state");
225  string name = _root->getName();
226  if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
227  DEBTRACE("VisitorSaveState::visitForLoop ---------- " << name);
228  _out << " <node type='forLoop'>" << endl;
229  _out << " <name>" << name << "</name>" << endl;
230  _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
231  _out << " <nbdone>" << node->getNbOfTurns() << "</nbdone>" << endl;
232  InputPort * ip = node->edGetNbOfTimesInputPort();
233  if (ip->isEmpty())
234  throw Exception("NbOfTimesInputPort in forLoop empty, case not handled yet...");
235  Any *val = static_cast<Any*>(ip->get());
236  int nsteps = val->getIntValue();
237  _out << " <nsteps>" << nsteps << "</nsteps>" << endl;
238 
239  _out << " </node>" << endl;
240 }
void VisitorSaveState::visitInlineFuncNode ( InlineFuncNode node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 290 of file VisitorSaveState.cxx.

References visitElementaryNode().

291 {
292  visitElementaryNode(node);
293 }
void VisitorSaveState::visitInlineNode ( InlineNode node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 285 of file VisitorSaveState.cxx.

References visitElementaryNode().

286 {
287  visitElementaryNode(node);
288 }
void VisitorSaveState::visitLoop ( Loop node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 206 of file VisitorSaveState.cxx.

References _nodeStateName, _out, YACS::ENGINE::Visitor::_root, DEBTRACE, YACS::ENGINE::ComposedNode::getChildName(), YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Loop::getNbOfTurns(), and YACS::ENGINE::Node::getState().

207 {
208  node->ComposedNode::accept(this);
209  if (!_out) throw Exception("No file open for dump state");
210  string name = _root->getName();
211  if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
212  DEBTRACE("VisitorSaveState::visitLoop ------------- " << name);
213  _out << " <node type ='loop'>" << endl;
214  _out << " <name>" << name << "</name>" << endl;
215  _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
216  _out << " <nbdone>" << node->getNbOfTurns() << "</nbdone>" << endl;
217 
218  _out << " </node>" << endl;
219 }
void VisitorSaveState::visitOptimizerLoop ( OptimizerLoop node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 187 of file VisitorSaveState.cxx.

References _nodeStateName, _out, YACS::ENGINE::Visitor::_root, DEBTRACE, YACS::ENGINE::ComposedNode::getChildName(), YACS::ENGINE::ComposedNode::getName(), and YACS::ENGINE::Node::getState().

188 {
189  node->ComposedNode::accept(this);
190  if (!_out) throw Exception("No file open for dump state");
191  string name = _root->getName();
192  if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
193  DEBTRACE("VisitorSaveState::visitOptimizerLoop ------ " << name);
194  _out << " <node type='optimizerLoop'>" << endl;
195  _out << " <name>" << name << "</name>" << endl;
196  _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
197 
198  _out << " </node>" << endl;
199 }
void VisitorSaveState::visitOutNode ( DataNode node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 315 of file VisitorSaveState.cxx.

References visitElementaryNode().

316 {
317  visitElementaryNode(node);
318 }
void VisitorSaveState::visitPresetNode ( DataNode node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 310 of file VisitorSaveState.cxx.

References visitElementaryNode().

311 {
312  visitElementaryNode(node);
313 }
void VisitorSaveState::visitProc ( Proc node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 159 of file VisitorSaveState.cxx.

References _nodeStateName, _out, YACS::ENGINE::Visitor::_root, DEBTRACE, YACS::ENGINE::ComposedNode::getChildName(), YACS::ENGINE::ComposedNode::getName(), and YACS::ENGINE::Node::getState().

160 {
161  node->ComposedNode::accept(this);
162  if (!_out) throw Exception("No file open for dump state");
163  string name = _root->getName();
164  if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
165  DEBTRACE("VisitorSaveState::visitProc ------------- " << name);
166  _out << " <node type='proc'>" << endl;
167  _out << " <name>" << name << "</name>" << endl;
168  _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
169 
170  _out << " </node>" << endl;
171 }
void VisitorSaveState::visitServerNode ( ServerNode node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 300 of file VisitorSaveState.cxx.

References visitElementaryNode().

301 {
302  visitElementaryNode(node);
303 }
void VisitorSaveState::visitServiceInlineNode ( ServiceInlineNode node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 305 of file VisitorSaveState.cxx.

References visitElementaryNode().

306 {
307  visitElementaryNode(node);
308 }
void VisitorSaveState::visitServiceNode ( ServiceNode node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 295 of file VisitorSaveState.cxx.

References visitElementaryNode().

296 {
297  visitElementaryNode(node);
298 }
void VisitorSaveState::visitStudyInNode ( DataNode node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 320 of file VisitorSaveState.cxx.

References visitElementaryNode().

321 {
322  visitElementaryNode(node);
323 }
void VisitorSaveState::visitStudyOutNode ( DataNode node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 325 of file VisitorSaveState.cxx.

References visitElementaryNode().

326 {
327  visitElementaryNode(node);
328 }
void VisitorSaveState::visitSwitch ( Switch node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 265 of file VisitorSaveState.cxx.

References _nodeStateName, _out, YACS::ENGINE::Visitor::_root, DEBTRACE, YACS::ENGINE::Switch::edGetConditionPort(), YACS::ENGINE::InputPort::get(), YACS::ENGINE::ComposedNode::getChildName(), YACS::ENGINE::Any::getIntValue(), YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Node::getState(), and YACS::ENGINE::InputPort::isEmpty().

266 {
267  node->ComposedNode::accept(this);
268  if (!_out) throw Exception("No file open for dump state");
269  string name = _root->getName();
270  if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
271  DEBTRACE("VisitorSaveState::visitSwitch ----------- " << name);
272  _out << " <node type='switch'>" << endl;
273  _out << " <name>" << name << "</name>" << endl;
274  _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
275  InputPort * ip = node->edGetConditionPort();
276  if (ip->isEmpty())
277  throw Exception("condition in switch empty, case not handled yet...");
278  Any *val = static_cast<Any*>(ip->get());
279  int condition = val->getIntValue();
280  _out << " <condition>" << condition << "</condition>" << endl;
281 
282  _out << " </node>" << endl;
283 }
void VisitorSaveState::visitWhileLoop ( WhileLoop node)
virtual

Implements YACS::ENGINE::Visitor.

Definition at line 242 of file VisitorSaveState.cxx.

References _nodeStateName, _out, YACS::ENGINE::Visitor::_root, DEBTRACE, YACS::ENGINE::WhileLoop::edGetConditionPort(), YACS::ENGINE::ComposedNode::getChildName(), YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Loop::getNbOfTurns(), YACS::ENGINE::Node::getState(), and YACS::ENGINE::InputPort::isEmpty().

243 {
244  node->ComposedNode::accept(this);
245  if (!_out) throw Exception("No file open for dump state");
246  string name = _root->getName();
247  if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
248  DEBTRACE("VisitorSaveState::visitWhileLoop -------- " << name);
249  _out << " <node type='whileLoop'>" << endl;
250  _out << " <name>" << name << "</name>" << endl;
251  _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
252  _out << " <nbdone>" << node->getNbOfTurns() << "</nbdone>" << endl;
253  InputPort * ip = node->edGetConditionPort();
254  if (ip->isEmpty())
255  throw Exception("condition in WhileLoop empty, case not handled yet...");
256  if ( ConditionInputPort* cip = dynamic_cast<ConditionInputPort*>(ip) )
257  {
258  bool condition = cip->getValue();
259  _out << " <condition>" << condition << "</condition>" << endl;
260  }
261 
262  _out << " </node>" << endl;
263 }

Member Data Documentation

std::map<int, std::string> YACS::ENGINE::VisitorSaveState::_nodeStateName
protected

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