]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/OutputDataStreamPort.cxx
Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / engine / OutputDataStreamPort.cxx
1 #include "OutputDataStreamPort.hxx"
2 #include "InputDataStreamPort.hxx"
3 #include "ComposedNode.hxx"
4 #include "InPort.hxx"
5 #include <iostream>
6
7 using namespace YACS::ENGINE;
8 using namespace std;
9
10 const char OutputDataStreamPort::NAME[]="OutputDataStreamPort";
11
12 OutputDataStreamPort::OutputDataStreamPort(const OutputDataStreamPort& other, Node *newHelder):DataStreamPort(other,newHelder),
13                                                                                                OutPort(other,newHelder),
14                                                                                                DataPort(other,newHelder),
15                                                                                                Port(other,newHelder)
16 {
17 }
18
19 OutputDataStreamPort::OutputDataStreamPort(const std::string& name, Node *node, TypeCode* type):DataStreamPort(name,node,type),
20 OutPort(name,node,type),
21 DataPort(name,node,type),
22 Port(node)
23 {
24 }
25
26 OutputDataStreamPort::~OutputDataStreamPort()
27 {
28 }
29
30 OutputDataStreamPort *OutputDataStreamPort::clone(Node *newHelder) const
31 {
32   return new OutputDataStreamPort(*this,newHelder);
33 }
34
35 std::set<InPort *> OutputDataStreamPort::edSetInPort() const
36 {
37   set<InPort *> s;
38   for(set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
39     (*iter)->getAllRepresentants(s);
40   return s;
41 }
42
43 bool OutputDataStreamPort::isAlreadyLinkedWith(InPort *with) const
44 {
45   set<InPort *> s;
46   set<InputDataStreamPort *>::iterator iter;
47   for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
48     if(*iter==with)
49       return true;
50   for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
51     (*iter)->getAllRepresentants(s);
52   for(set<InPort *>::iterator iter2=s.begin();iter2!=s.end();iter2++)
53     if((*iter2)==with)
54       return true;
55   return false;
56 }
57
58 string OutputDataStreamPort::getNameOfTypeOfCurrentInstance() const
59 {
60   return NAME;
61 }
62
63 bool OutputDataStreamPort::edAddInputDataStreamPort(InputDataStreamPort *port)
64   throw(ConversionException)
65 {
66   if(!isAlreadyInSet(port))
67     {
68       _setOfInputDataStreamPort.insert(port);
69       return true;
70     }
71   else
72     return false;
73 }
74
75 int OutputDataStreamPort::edRemoveInputDataStreamPort(InputDataStreamPort *inPort, bool forward) throw(Exception)
76 {
77   if(forward)
78     {
79       set<InPort *> s;
80       inPort->getAllRepresentants(s);
81       for(set<InPort *>::iterator iter=s.begin();iter!=s.end();iter++)
82         _node->getRootNode()->edRemoveLink(this,*iter);
83       return -1;
84     }
85   else    
86     {
87       set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.find(inPort);
88       if(iter!=_setOfInputDataStreamPort.end())
89         {
90           _setOfInputDataStreamPort.erase(iter);
91           return edGetNumberOfOutLinks();
92         }
93       else
94         throw Exception("OutputDataStreamPort::edRemoveInputPort : link does not exist, unable to remove it");
95     }
96 }
97
98 bool OutputDataStreamPort::addInPort(InPort *inPort) throw(Exception)
99 {
100   if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME)
101     {
102       string what="not compatible type of port requested during building of link FROM ";
103       what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
104       throw Exception(what);
105     }
106   return edAddInputDataStreamPort(static_cast<InputDataStreamPort*>(inPort));
107 }
108
109 void OutputDataStreamPort::edRemoveAllLinksLinkedWithMe() throw(Exception)
110 {
111   set<InputDataStreamPort *>::iterator iter;
112   set<InputDataStreamPort *> vec(_setOfInputDataStreamPort);
113   for( set<InputDataStreamPort *>::iterator iter2=vec.begin();iter2!=vec.end();iter2++)
114     edRemoveInputDataStreamPort(*iter2,true);
115   _setOfInputDataStreamPort.clear();
116 }
117
118 int OutputDataStreamPort::removeInPort(InPort *inPort, bool forward) throw(Exception)
119 {
120   if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME && !forward)
121     {
122       string what="not compatible type of port requested during destruction of for link FROM ";
123       what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
124       throw Exception(what);
125     }
126   return edRemoveInputDataStreamPort(static_cast<InputDataStreamPort *>(inPort),forward);
127 }
128
129 bool OutputDataStreamPort::isAlreadyInSet(InputDataStreamPort *inPort) const
130 {
131   return _setOfInputDataStreamPort.find(inPort)!=_setOfInputDataStreamPort.end();
132 }