Salome HOME
PR: first version from Antony GEAY, with directory restructuration
[modules/yacs.git] / src / engine / OutputPort.cxx
1 #include "OutputPort.hxx"
2 #include "InputPort.hxx"
3
4 using namespace YACS::ENGINE;
5 using namespace std;
6
7 const char OutputPort::NAME[]="OutputPort";
8
9 OutputPort::OutputPort(const std::string& name, Node *node, DynType type):DataFlowPort(name,node,type),OutPort(node),Port(node)
10 {
11 }
12
13 std::string OutputPort::getNameOfTypeOfCurrentInstance() const
14 {
15   return NAME;
16 }
17
18 Data OutputPort::foGet() const
19 {
20   return _data;
21 }
22
23 void OutputPort::exInit()
24 {
25   _data.exInit();
26 }
27
28 void OutputPort::exPut(Data data) throw(ConversionException)
29 {
30   _data=data;
31   for(list<InputPort *>::iterator iter=_listOfInputPort.begin();iter!=_listOfInputPort.end();iter++)
32     (*iter)->exAccept(data);
33 }
34
35 bool OutputPort::edAddInputPort(InputPort *inputPort) throw(ConversionException)
36 {
37   if(!Data::areStaticallyCompatible(edGetType(),inputPort->edGetType()))
38     throw ConversionException(Data::edGetTypeInPrintableForm(edGetType()),Data::edGetTypeInPrintableForm(inputPort->edGetType()));
39   if(!isAlreadyInList(inputPort))
40     {
41       _listOfInputPort.push_back(inputPort);
42       inputPort->edNotifyReferenced();
43       return true;
44     }
45   else
46     return false;
47 }
48
49 list<InputPort *> OutputPort::edListInputPort()
50 {
51   return _listOfInputPort;
52 }
53
54 void OutputPort::edRemoveInputPort(InputPort *inputPort) throw(Exception)
55 {
56   if(isAlreadyInList(inputPort))
57     _listOfInputPort.remove(inputPort);
58   else
59     throw Exception("OutputPort::edRemoveInputPort : link does not exist, unable to remove it");
60 }
61
62 OutputPort::~OutputPort()
63 {
64 }
65
66 bool OutputPort::isAlreadyInList(InputPort *inputPort) const
67 {
68   bool ret=false;
69   for(list<InputPort *>::const_iterator iter=_listOfInputPort.begin();iter!=_listOfInputPort.end() && !ret;iter++)
70     if((*iter)==inputPort)
71       ret=true;
72   return ret;
73 }
74
75 bool OutputPort::addInPort(InPort *inPort) throw(Exception)
76 {
77   if(inPort->getNameOfTypeOfCurrentInstance()!=InputPort::NAME)
78     {
79       std::string what="not compatible type of port requested during building of link FROM ";
80       what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
81       throw Exception(what);
82     }
83   return edAddInputPort(static_cast<InputPort*>(inPort));
84 }
85
86 void OutputPort::removeInPort(InPort *inPort) throw(Exception)
87 {
88   if(inPort->getNameOfTypeOfCurrentInstance()!=InputPort::NAME)
89     {
90       std::string what="not compatible type of port requested during destruction of for link FROM ";
91       what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
92       throw Exception(what);
93     }
94   edRemoveInputPort(static_cast<InputPort*>(inPort));
95 }
96
97 bool OutputPort::isLinked()
98 {
99   return _listOfInputPort.empty();
100 }