Version: 9.16.0
OutNode.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#include "PresetPorts.hxx"
21#include "OutNode.hxx"
22#include "Visitor.hxx"
23
24#include <iostream>
25#include <fstream>
26#include <list>
27#include <cassert>
28
29//#define _DEVDEBUG_
30#include "YacsTrace.hxx"
31
32using namespace std;
33
34namespace YACS
35{
36 namespace ENGINE
37 {
38
45const char OutNode::IMPL_NAME[]="XML";
46
47OutNode::OutNode(const std::string& name)
48 : DataNode(name)
49{
51}
52
54 : DataNode(other, father)
55{
56}
57
58InputPort* OutNode::createInputPort(const std::string& inputPortName, TypeCode* type)
59{
60 return new InputPresetPort(inputPortName, this, type);
61}
62
63void OutNode::dump(std::ostream &out)
64{
65 std::list<InputPort *>::const_iterator iter;
66 for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
67 {
68 InputPresetPort *inp = dynamic_cast<InputPresetPort *>(*iter);
69 if(inp->getData() != "")
70 {
71 //save the file in the given reference
72 std::string xmlValue=inp->dump();
73 std::string::size_type i=xmlValue.find_first_of('/',0);
74 xmlValue=xmlValue.substr(i);
75 i=xmlValue.find_first_of('<',0);
76 std::ifstream fin(xmlValue.substr(0,i).c_str());
77 std::ofstream fout(inp->getData().c_str());
78 fout << fin.rdbuf(); // Dumps file contents to file
79 out << "<value><objref>" << inp->getData() << "</objref></value>" << std::endl;
80 }
81 else
82 out << inp->dump() << std::endl;
83 }
84}
85
87{
88 DEBTRACE("+++++++ OutNode::execute +++++++++++");
89 if(_ref != "")
90 {
91 std::ofstream out(_ref.c_str());
92 dump(out);
93 }
94 else
95 dump(std::cout);
96 DEBTRACE("+++++++ end OutNode::execute +++++++++++" );
97}
98
100{
101 visitor->visitOutNode(this);
102}
103
104void OutNode::setData(InputPort* port, const std::string& data)
105{
106 InputPresetPort *inp = dynamic_cast<InputPresetPort *>(port);
107 inp->setData(data);
108}
109
111{
112 DEBTRACE("OutNode::checkBasicConsistency");
113 if (! _setOfOutputPort.empty())
114 {
115 string what = "OutNode ";
116 what += getName();
117 what += " only accepts InputPorts, no OutputPorts";
118 throw Exception(what);
119 }
120 list<InputPort *>::const_iterator iter;
121 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
122 {
123 InputPresetPort *preset = dynamic_cast<InputPresetPort*>(*iter);
124 if (!preset)
125 {
126 string what("Input port: ");
127 what += (*iter)->getName();
128 what += " is not an InputPresetPort. PresetNode ";
129 what += getName();
130 what += " only accepts InputPresetPorts";
131 throw Exception(what);
132 }
133 preset->checkBasicConsistency();
134 }
135
136}
137
138Node *OutNode::simpleClone(ComposedNode *father, bool editionOnly) const
139{
140 return new OutNode(*this,father);
141}
142
143 }
144}
145
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
Base class for all composed nodes.
Class for data parameters specification.
Definition: DataNode.hxx:38
std::list< InputPort * > _setOfInputPort
std::list< OutputPort * > _setOfOutputPort
Base class for Input Ports.
Definition: InputPort.hxx:44
virtual void checkBasicConsistency() const
Check basically that this port has one chance to be specified on time. It's a necessary condition not...
Definition: InputPort.cxx:148
Class for PRESET input Ports.
Definition: PresetPorts.hxx:50
void setData(std::string data)
virtual std::string dump()
Base class for all nodes.
Definition: Node.hxx:70
const std::string & getName() const
Definition: Node.hxx:125
std::string _implementation
Definition: Node.hxx:97
Class for data out node.
Definition: OutNode.hxx:30
virtual void accept(Visitor *visitor)
Definition: OutNode.cxx:99
static const char IMPL_NAME[]
Definition: OutNode.hxx:43
virtual void dump(std::ostream &os)
Definition: OutNode.cxx:63
virtual void setData(InputPort *port, const std::string &data)
Definition: OutNode.cxx:104
OutNode(const std::string &name)
Definition: OutNode.cxx:47
virtual void execute()
Definition: OutNode.cxx:86
virtual void checkBasicConsistency() const
Definition: OutNode.cxx:110
virtual InputPort * createInputPort(const std::string &inputPortName, TypeCode *type)
Definition: OutNode.cxx:58
Node * simpleClone(ComposedNode *father, bool editionOnly) const
Definition: OutNode.cxx:138
Base class for all type objects.
Definition: TypeCode.hxx:68
virtual void visitOutNode(DataNode *node)=0