]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/PresetNode.cxx
Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / runtime / PresetNode.cxx
1
2 #include "PresetNode.hxx"
3 #include "PresetPorts.hxx"
4 #include "Visitor.hxx"
5
6 #include <iostream>
7 #include <set>
8 #include <cassert>
9
10 //#define _DEVDEBUG_
11 #include "YacsTrace.hxx"
12
13 using namespace YACS::ENGINE;
14 using namespace std;
15
16 const char PresetNode::IMPL_NAME[]="XML";
17
18 PresetNode::PresetNode(const std::string& name)
19   : DataNode(name)
20 {
21   _implementation=IMPL_NAME;
22 }
23
24 PresetNode::PresetNode(const PresetNode& other, ComposedNode *father)
25   : DataNode(other, father)
26 {
27 }
28
29 OutputPort* PresetNode::createOutputPort(const std::string& outputPortName, TypeCode* type)
30 {
31   return new OutputPresetPort(outputPortName, this, type);
32 }
33
34 void PresetNode::execute()
35 {
36   DEBTRACE("+++++++ PresetNode::execute +++++++++++");
37   list<OutputPort *>::const_iterator iter;
38   for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
39     {
40       OutputPresetPort *outp = dynamic_cast<OutputPresetPort *>(*iter);
41       assert(outp);
42       string data = outp->getData();
43       DEBTRACE("data: " << data );
44       outp->put(data.c_str());
45     }
46   DEBTRACE("+++++++ end PresetNode::execute +++++++++++" );
47 }
48
49 void PresetNode::accept(Visitor *visitor)
50 {
51   visitor->visitPresetNode(this);
52 }
53
54 void PresetNode::setData(OutputPort* port, std::string& data)
55 {
56   OutputPresetPort *outp = dynamic_cast<OutputPresetPort *>(port);
57   outp->setData(data);
58 }
59
60 void PresetNode::checkBasicConsistency() const throw(Exception)
61 {
62   DEBTRACE("PresetNode::checkBasicConsistency");
63   if (! _setOfInputPort.empty())
64     {
65       string what = "PresetNode ";
66       what += getName();
67       what += " only accepts OutputPresetPorts, no InputPorts";
68       throw Exception(what);
69     }
70
71   list<OutputPort *>::const_iterator iter;
72   for(iter=_setOfOutputPort.begin();iter!=_setOfOutputPort.end();iter++)
73     {
74       OutputPresetPort *preset = dynamic_cast<OutputPresetPort*>(*iter);
75       if (!preset)
76         {
77           string what("Output port: ");
78           what += (*iter)->getName();
79           what += " is not an OutputPresetPort. PresetNode ";
80           what += getName();
81           what += "only accepts OutputPresetPorts";
82           throw Exception(what);
83         }
84       preset->checkBasicConsistency();
85     }
86 }
87
88 Node *PresetNode::simpleClone(ComposedNode *father, bool editionOnly) const
89 {
90   return new PresetNode(*this,father);
91 }