]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/OutputDataStreamPort.cxx
Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[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 "TypeCode.hxx"
6 #include <iostream>
7
8 //#define _DEVDEBUG_
9 #include "YacsTrace.hxx"
10
11 using namespace YACS::ENGINE;
12 using namespace std;
13
14 const char OutputDataStreamPort::NAME[]="OutputDataStreamPort";
15
16 OutputDataStreamPort::OutputDataStreamPort(const OutputDataStreamPort& other, Node *newHelder):DataStreamPort(other,newHelder),
17                                                                                                OutPort(other,newHelder),
18                                                                                                DataPort(other,newHelder),
19                                                                                                Port(other,newHelder)
20 {
21 }
22
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),
26 Port(node)
27 {
28 }
29
30 OutputDataStreamPort::~OutputDataStreamPort()
31 {
32 }
33
34 OutputDataStreamPort *OutputDataStreamPort::clone(Node *newHelder) const
35 {
36   return new OutputDataStreamPort(*this,newHelder);
37 }
38
39 std::set<InPort *> OutputDataStreamPort::edSetInPort() const
40 {
41   set<InPort *> s;
42   for(set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
43     (*iter)->getAllRepresentants(s);
44   return s;
45 }
46
47 bool OutputDataStreamPort::isAlreadyLinkedWith(InPort *with) const
48 {
49   set<InPort *> s;
50   set<InputDataStreamPort *>::iterator iter;
51   for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
52     if(*iter==with)
53       return true;
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++)
57     if((*iter2)==with)
58       return true;
59   return false;
60 }
61
62 string OutputDataStreamPort::getNameOfTypeOfCurrentInstance() const
63 {
64   return NAME;
65 }
66
67 bool OutputDataStreamPort::edAddInputDataStreamPort(InputDataStreamPort *port)
68   throw(ConversionException)
69 {
70   DEBTRACE("OutputDataStreamPort::edAddInputDataStreamPort");
71   if(!isAlreadyInSet(port))
72     {
73       if(!port->edGetType()->isAdaptable(edGetType()))
74         {
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);
80         }
81       _setOfInputDataStreamPort.insert(port);
82       return true;
83     }
84   else
85     return false;
86 }
87
88 int OutputDataStreamPort::edRemoveInputDataStreamPort(InputDataStreamPort *inPort, bool forward) throw(Exception)
89 {
90   if(forward)
91     {
92       set<InPort *> s;
93       inPort->getAllRepresentants(s);
94       for(set<InPort *>::iterator iter=s.begin();iter!=s.end();iter++)
95         _node->getRootNode()->edRemoveLink(this,*iter);
96       return -1;
97     }
98   else    
99     {
100       set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.find(inPort);
101       if(iter!=_setOfInputDataStreamPort.end())
102         {
103           (*iter)->modified();
104           _setOfInputDataStreamPort.erase(iter);
105           modified();
106           return edGetNumberOfOutLinks();
107         }
108       else
109         throw Exception("OutputDataStreamPort::edRemoveInputPort : link does not exist, unable to remove it");
110     }
111 }
112
113 bool OutputDataStreamPort::addInPort(InPort *inPort) throw(Exception)
114 {
115   DEBTRACE("OutputDataStreamPort::addInPort");
116   if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME)
117     {
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);
121     }
122   return edAddInputDataStreamPort(static_cast<InputDataStreamPort*>(inPort));
123 }
124
125 void OutputDataStreamPort::edRemoveAllLinksLinkedWithMe() throw(Exception)
126 {
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();
132 }
133
134 int OutputDataStreamPort::removeInPort(InPort *inPort, bool forward) throw(Exception)
135 {
136   DEBTRACE("OutputDataStreamPort::removeInPort");
137   if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME && !forward)
138     {
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);
142     }
143   return edRemoveInputDataStreamPort(static_cast<InputDataStreamPort *>(inPort),forward);
144 }
145
146 bool OutputDataStreamPort::isAlreadyInSet(InputDataStreamPort *inPort) const
147 {
148   return _setOfInputDataStreamPort.find(inPort)!=_setOfInputDataStreamPort.end();
149 }