Version: 9.16.0
OutputDataStreamPort.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
22#include "ComposedNode.hxx"
23#include "InPort.hxx"
24#include "TypeCode.hxx"
25#include <iostream>
26
27//#define _DEVDEBUG_
28#include "YacsTrace.hxx"
29
30using namespace YACS::ENGINE;
31using namespace std;
32
33const char OutputDataStreamPort::NAME[]="OutputDataStreamPort";
34
35OutputDataStreamPort::OutputDataStreamPort(const OutputDataStreamPort& other, Node *newHelder):DataStreamPort(other,newHelder),
36 OutPort(other,newHelder),
37 DataPort(other,newHelder),
38 Port(other,newHelder)
39{
40}
41
42OutputDataStreamPort::OutputDataStreamPort(const std::string& name, Node *node, TypeCode* type):DataStreamPort(name,node,type),
43OutPort(name,node,type),
44DataPort(name,node,type),
45Port(node)
46{
47}
48
50{
51}
52
54{
55 return new OutputDataStreamPort(*this,newHelder);
56}
57
58std::set<InPort *> OutputDataStreamPort::edSetInPort() const
59{
60 set<InPort *> s;
61 for(set<InputDataStreamPort *>::const_iterator iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
62 (*iter)->getAllRepresentants(s);
63 return s;
64}
65
67{
68 set<InPort *> s;
69 set<InputDataStreamPort *>::const_iterator iter;
70 for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
71 if(*iter==with)
72 return true;
73 for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
74 (*iter)->getAllRepresentants(s);
75 for(set<InPort *>::iterator iter2=s.begin();iter2!=s.end();iter2++)
76 if((*iter2)==with)
77 return true;
78 return false;
79}
80
82{
83 return NAME;
84}
85
87{
88 DEBTRACE("OutputDataStreamPort::edAddInputDataStreamPort");
89 if(!isAlreadyInSet(port))
90 {
91 if(!port->edGetType()->isAdaptable(edGetType()))
92 {
93 string what="Can not connect 2 ports with incompatible types : ";
94 what=what+ port->edGetType()->id();
95 what=what+" is not a ";
96 what=what+ edGetType()->id();
97 throw ConversionException(what);
98 }
99 _setOfInputDataStreamPort.insert(port);
100 port->edAddOutputDataStreamPort(this);
101 return true;
102 }
103 else
104 return false;
105}
106
108{
109 if(forward)
110 {
111 set<InPort *> s;
112 inPort->getAllRepresentants(s);
113 for(set<InPort *>::iterator iter=s.begin();iter!=s.end();iter++)
114 _node->getRootNode()->edRemoveLink(this,*iter);
115 return -1;
116 }
117 else
118 {
119 set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.find(inPort);
120 if(iter!=_setOfInputDataStreamPort.end())
121 {
122 (*iter)->modified();
123 _setOfInputDataStreamPort.erase(iter);
124 modified();
125 return edGetNumberOfOutLinks();
126 }
127 else
128 throw Exception("OutputDataStreamPort::edRemoveInputPort : link does not exist, unable to remove it");
129 }
130}
131
133{
134 DEBTRACE("OutputDataStreamPort::addInPort");
136 {
137 string what="not compatible type of port requested during building of link FROM ";
138 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
139 throw Exception(what);
140 }
141 return edAddInputDataStreamPort(static_cast<InputDataStreamPort*>(inPort));
142}
143
145{
146 set<InputDataStreamPort *>::iterator iter;
147 set<InputDataStreamPort *> vec(_setOfInputDataStreamPort);
148 for( set<InputDataStreamPort *>::iterator iter2=vec.begin();iter2!=vec.end();iter2++)
149 edRemoveInputDataStreamPort(*iter2,true);
151}
152
154{
155 DEBTRACE("OutputDataStreamPort::removeInPort");
157 {
158 string what="not compatible type of port requested during destruction of for link FROM ";
159 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
160 throw Exception(what);
161 }
162 return edRemoveInputDataStreamPort(static_cast<InputDataStreamPort *>(inPort),forward);
163}
164
166{
167 return _setOfInputDataStreamPort.find(inPort)!=_setOfInputDataStreamPort.end();
168}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
void edRemoveLink(OutPort *start, InPort *end)
Remove a dataflow link.
TypeCode * edGetType() const
Definition: DataPort.hxx:53
std::string getNameOfTypeOfCurrentInstance() const
Definition: DataPort.cxx:56
virtual void getAllRepresentants(std::set< InPort * > &repr) const
Definition: InPort.cxx:110
virtual void edAddOutputDataStreamPort(OutputDataStreamPort *port)
Base class for all nodes.
Definition: Node.hxx:70
virtual ComposedNode * getRootNode() const
Definition: Node.cxx:431
virtual int edGetNumberOfOutLinks() const
Definition: OutPort.cxx:50
OutputDataStreamPort(const OutputDataStreamPort &other, Node *newHelder)
virtual bool addInPort(InPort *inPort)
std::set< InputDataStreamPort * > _setOfInputDataStreamPort
virtual OutputDataStreamPort * clone(Node *newHelder) const
int edRemoveInputDataStreamPort(InputDataStreamPort *inPort, bool forward)
virtual bool edAddInputDataStreamPort(InputDataStreamPort *port)
bool isAlreadyInSet(InputDataStreamPort *inPort) const
int removeInPort(InPort *inPort, bool forward)
std::set< InPort * > edSetInPort() const
bool isAlreadyLinkedWith(InPort *withp) const
virtual std::string getNameOfTypeOfCurrentInstance() const
Base class for all ports.
Definition: Port.hxx:43
void modified()
Definition: Port.cxx:53
Node * _node
Definition: Port.hxx:55
Base class for all type objects.
Definition: TypeCode.hxx:68
virtual const char * id() const
Definition: TypeCode.cxx:82
virtual int isAdaptable(const TypeCode *tc) const
Check if this TypeCode is adaptable to a given TypeCode (tc)
Definition: TypeCode.cxx:116