1 #include "OutputDataStreamPort.hxx"
2 #include "InputDataStreamPort.hxx"
3 #include "ComposedNode.hxx"
5 #include "TypeCode.hxx"
9 #include "YacsTrace.hxx"
11 using namespace YACS::ENGINE;
14 const char OutputDataStreamPort::NAME[]="OutputDataStreamPort";
16 OutputDataStreamPort::OutputDataStreamPort(const OutputDataStreamPort& other, Node *newHelder):DataStreamPort(other,newHelder),
17 OutPort(other,newHelder),
18 DataPort(other,newHelder),
23 OutputDataStreamPort::OutputDataStreamPort(const std::string& name, Node *node, TypeCode* type):DataStreamPort(name,node,type),
24 OutPort(name,node,type),
25 DataPort(name,node,type),
30 OutputDataStreamPort::~OutputDataStreamPort()
34 OutputDataStreamPort *OutputDataStreamPort::clone(Node *newHelder) const
36 return new OutputDataStreamPort(*this,newHelder);
39 std::set<InPort *> OutputDataStreamPort::edSetInPort() const
42 for(set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
43 (*iter)->getAllRepresentants(s);
47 bool OutputDataStreamPort::isAlreadyLinkedWith(InPort *with) const
50 set<InputDataStreamPort *>::iterator iter;
51 for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
54 for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
55 (*iter)->getAllRepresentants(s);
56 for(set<InPort *>::iterator iter2=s.begin();iter2!=s.end();iter2++)
62 string OutputDataStreamPort::getNameOfTypeOfCurrentInstance() const
67 bool OutputDataStreamPort::edAddInputDataStreamPort(InputDataStreamPort *port)
68 throw(ConversionException)
70 DEBTRACE("OutputDataStreamPort::edAddInputDataStreamPort");
71 if(!isAlreadyInSet(port))
73 if(!port->edGetType()->isAdaptable(edGetType()))
75 string what="Can not connect 2 ports with incompatible types : ";
76 what=what+ port->edGetType()->id();
77 what=what+" is not a ";
78 what=what+ edGetType()->id();
79 throw ConversionException(what);
81 _setOfInputDataStreamPort.insert(port);
88 int OutputDataStreamPort::edRemoveInputDataStreamPort(InputDataStreamPort *inPort, bool forward) throw(Exception)
93 inPort->getAllRepresentants(s);
94 for(set<InPort *>::iterator iter=s.begin();iter!=s.end();iter++)
95 _node->getRootNode()->edRemoveLink(this,*iter);
100 set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.find(inPort);
101 if(iter!=_setOfInputDataStreamPort.end())
104 _setOfInputDataStreamPort.erase(iter);
106 return edGetNumberOfOutLinks();
109 throw Exception("OutputDataStreamPort::edRemoveInputPort : link does not exist, unable to remove it");
113 bool OutputDataStreamPort::addInPort(InPort *inPort) throw(Exception)
115 DEBTRACE("OutputDataStreamPort::addInPort");
116 if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME)
118 string what="not compatible type of port requested during building of link FROM ";
119 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
120 throw Exception(what);
122 return edAddInputDataStreamPort(static_cast<InputDataStreamPort*>(inPort));
125 void OutputDataStreamPort::edRemoveAllLinksLinkedWithMe() throw(Exception)
127 set<InputDataStreamPort *>::iterator iter;
128 set<InputDataStreamPort *> vec(_setOfInputDataStreamPort);
129 for( set<InputDataStreamPort *>::iterator iter2=vec.begin();iter2!=vec.end();iter2++)
130 edRemoveInputDataStreamPort(*iter2,true);
131 _setOfInputDataStreamPort.clear();
134 int OutputDataStreamPort::removeInPort(InPort *inPort, bool forward) throw(Exception)
136 DEBTRACE("OutputDataStreamPort::removeInPort");
137 if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME && !forward)
139 string what="not compatible type of port requested during destruction of for link FROM ";
140 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
141 throw Exception(what);
143 return edRemoveInputDataStreamPort(static_cast<InputDataStreamPort *>(inPort),forward);
146 bool OutputDataStreamPort::isAlreadyInSet(InputDataStreamPort *inPort) const
148 return _setOfInputDataStreamPort.find(inPort)!=_setOfInputDataStreamPort.end();