#include "OutputDataStreamPort.hxx"
#include "InputDataStreamPort.hxx"
-//#include "TypeCheckerDataStream.hxx"
+#include "ComposedNode.hxx"
+#include "InPort.hxx"
+#include <iostream>
using namespace YACS::ENGINE;
using namespace std;
const char OutputDataStreamPort::NAME[]="OutputDataStreamPort";
-OutputDataStreamPort::OutputDataStreamPort(const string& name, Node *node, TypeCode* type):DataStreamPort(name,node,type),OutPort(node),Port(node)
+OutputDataStreamPort::OutputDataStreamPort(const OutputDataStreamPort& other, Node *newHelder):DataStreamPort(other,newHelder),
+ OutPort(other,newHelder),
+ DataPort(other,newHelder),
+ Port(other,newHelder)
{
}
+OutputDataStreamPort::OutputDataStreamPort(const std::string& name, Node *node, TypeCode* type):DataStreamPort(name,node,type),
+OutPort(name,node,type),
+DataPort(name,node,type),
+Port(node)
+{
+}
+
+OutputDataStreamPort::~OutputDataStreamPort()
+{
+}
+
+OutputDataStreamPort *OutputDataStreamPort::clone(Node *newHelder) const
+{
+ return new OutputDataStreamPort(*this,newHelder);
+}
+
+std::set<InPort *> OutputDataStreamPort::edSetInPort() const
+{
+ set<InPort *> s;
+ for(set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
+ (*iter)->getAllRepresentants(s);
+ return s;
+}
+
+bool OutputDataStreamPort::isAlreadyLinkedWith(InPort *with) const
+{
+ set<InPort *> s;
+ set<InputDataStreamPort *>::iterator iter;
+ for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
+ if(*iter==with)
+ return true;
+ for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
+ (*iter)->getAllRepresentants(s);
+ for(set<InPort *>::iterator iter2=s.begin();iter2!=s.end();iter2++)
+ if((*iter2)==with)
+ return true;
+ return false;
+}
+
string OutputDataStreamPort::getNameOfTypeOfCurrentInstance() const
{
return NAME;
}
-bool OutputDataStreamPort::edAddInputDataStreamPort(InputDataStreamPort *port) throw(ConversionException)
+bool OutputDataStreamPort::edAddInputDataStreamPort(InputDataStreamPort *port)
+ throw(ConversionException)
{
-// if(!TypeCheckerDataStream::areStaticallyCompatible(edGetType(),port->edGetType()))
-// throw ConversionException(TypeCheckerDataStream::edGetTypeInPrintableForm(edGetType()),TypeCheckerDataStream::edGetTypeInPrintableForm(port-> throw ConversionException(TypeCheckerDataStream::edGetTypeInPrintableForm(edGetType()),TypeCheckerDataStream::edGetTypeInPrintableForm(port->edGetType()));
if(!isAlreadyInSet(port))
{
_setOfInputDataStreamPort.insert(port);
return false;
}
-void OutputDataStreamPort::edRemoveInputDataStreamPort(InputDataStreamPort *inputPort) throw(Exception)
+int OutputDataStreamPort::edRemoveInputDataStreamPort(InputDataStreamPort *inPort, bool forward) throw(Exception)
{
- if(isAlreadyInSet(inputPort))
- _setOfInputDataStreamPort.erase(inputPort);
-// else
-// throw Exception("OutputDataStreamPort::edRemoveInputDataStreamPort : link does not exist, unable to remove it");
-}
-
-//Idem OutputDataStreamPort::edRemoveInputDataStreamPort but no exception thrown if inputPort is not known
-void OutputDataStreamPort::edRemoveInputDataStreamPortOneWay(InputDataStreamPort *inputPort)
-{
- _setOfInputDataStreamPort.erase(inputPort);
+ if(forward)
+ {
+ set<InPort *> s;
+ inPort->getAllRepresentants(s);
+ for(set<InPort *>::iterator iter=s.begin();iter!=s.end();iter++)
+ _node->getRootNode()->edRemoveLink(this,*iter);
+ return -1;
+ }
+ else
+ {
+ set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.find(inPort);
+ if(iter!=_setOfInputDataStreamPort.end())
+ {
+ _setOfInputDataStreamPort.erase(iter);
+ return edGetNumberOfOutLinks();
+ }
+ else
+ throw Exception("OutputDataStreamPort::edRemoveInputPort : link does not exist, unable to remove it");
+ }
}
bool OutputDataStreamPort::addInPort(InPort *inPort) throw(Exception)
{
+ if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME)
+ {
+ string what="not compatible type of port requested during building of link FROM ";
+ what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
+ throw Exception(what);
+ }
+ return edAddInputDataStreamPort(static_cast<InputDataStreamPort*>(inPort));
}
-void OutputDataStreamPort::removeInPort(InPort *inPort) throw(Exception)
+void OutputDataStreamPort::edRemoveAllLinksLinkedWithMe() throw(Exception)
{
+ set<InputDataStreamPort *>::iterator iter;
+ set<InputDataStreamPort *> vec(_setOfInputDataStreamPort);
+ for( set<InputDataStreamPort *>::iterator iter2=vec.begin();iter2!=vec.end();iter2++)
+ edRemoveInputDataStreamPort(*iter2,true);
+ _setOfInputDataStreamPort.clear();
}
-bool OutputDataStreamPort::isLinked()
+int OutputDataStreamPort::removeInPort(InPort *inPort, bool forward) throw(Exception)
{
- return _setOfInputDataStreamPort.empty();
+ if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME && !forward)
+ {
+ string what="not compatible type of port requested during destruction of for link FROM ";
+ what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
+ throw Exception(what);
+ }
+ return edRemoveInputDataStreamPort(static_cast<InputDataStreamPort *>(inPort),forward);
}
-bool OutputDataStreamPort::isAlreadyInSet(InputDataStreamPort *inputPort) const
+bool OutputDataStreamPort::isAlreadyInSet(InputDataStreamPort *inPort) const
{
- bool ret=false;
- for(set<InputDataStreamPort *>::const_iterator iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
- if((*iter)==inputPort)
- ret=true;
- return ret;
+ return _setOfInputDataStreamPort.find(inPort)!=_setOfInputDataStreamPort.end();
}