]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/OutNode.cxx
Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / runtime / OutNode.cxx
1
2 #include "OutNode.hxx"
3 #include "PresetPorts.hxx"
4 #include "Visitor.hxx"
5
6 #include <iostream>
7 #include <fstream>
8 #include <list>
9 #include <cassert>
10
11 //#define _DEVDEBUG_
12 #include "YacsTrace.hxx"
13
14 using namespace std;
15
16 namespace YACS
17 {
18   namespace ENGINE
19     {
20
21 const char OutNode::IMPL_NAME[]="XML";
22
23 OutNode::OutNode(const std::string& name)
24   : DataNode(name)
25 {
26   _implementation=IMPL_NAME;
27 }
28
29 OutNode::OutNode(const OutNode& other, ComposedNode *father)
30   : DataNode(other, father)
31 {
32 }
33
34 InputPort* OutNode::createInputPort(const std::string& inputPortName, TypeCode* type)
35 {
36   return new InputPresetPort(inputPortName, this, type);
37 }
38
39 void OutNode::dump(std::ostream &out)
40 {
41   std::list<InputPort *>::const_iterator iter;
42   for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
43     {
44       InputPresetPort *inp = dynamic_cast<InputPresetPort *>(*iter);
45       if(inp->getData() != "")
46         {
47           //save the file in the given reference
48           std::string xmlValue=inp->dump();
49           std::string::size_type i=xmlValue.find_first_of('/',0);
50           xmlValue=xmlValue.substr(i);
51           i=xmlValue.find_first_of('<',0);
52           std::ifstream fin(xmlValue.substr(0,i).c_str());
53           std::ofstream fout(inp->getData().c_str());
54           fout << fin.rdbuf(); // Dumps file contents to file
55           out << "<value><objref>" << inp->getData() << "</objref></value>" << std::endl;
56         }
57       else
58         out << inp->dump() << std::endl;
59     }
60 }
61
62 void OutNode::execute()
63 {
64   DEBTRACE("+++++++ OutNode::execute +++++++++++");
65   if(_ref != "")
66     {
67       std::ofstream out(_ref.c_str());
68       dump(out);
69     }
70   else
71     dump(std::cout);
72   DEBTRACE("+++++++ end OutNode::execute +++++++++++" );
73 }
74
75 void OutNode::accept(Visitor *visitor)
76 {
77   visitor->visitOutNode(this);
78 }
79
80 void OutNode::setData(InputPort* port, std::string& data)
81 {
82   InputPresetPort *inp = dynamic_cast<InputPresetPort *>(port);
83   inp->setData(data);
84 }
85
86 void OutNode::checkBasicConsistency() const throw(Exception)
87 {
88   DEBTRACE("OutNode::checkBasicConsistency");
89   if (! _setOfOutputPort.empty())
90     {
91       string what = "OutNode ";
92       what += getName();
93       what += " only accepts InputPorts, no OutputPorts";
94       throw Exception(what);
95     }
96   list<InputPort *>::const_iterator iter;
97   for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
98     {
99       InputPresetPort *preset = dynamic_cast<InputPresetPort*>(*iter);
100       if (!preset)
101         {
102           string what("Input port: ");
103           what += (*iter)->getName();
104           what += " is not an InputPresetPort. PresetNode ";
105           what += getName();
106           what += " only accepts InputPresetPorts";
107           throw Exception(what);
108         }
109       preset->checkBasicConsistency();
110     }
111
112 }
113
114 Node *OutNode::simpleClone(ComposedNode *father, bool editionOnly) const
115 {
116   return new OutNode(*this,father);
117 }
118
119     }
120 }
121