]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/DataPort.cxx
Salome HOME
1c12fb73f44548454fa17b7191116aa57b5e40c4
[modules/yacs.git] / src / engine / DataPort.cxx
1 #include "DataPort.hxx"
2 #include "TypeCode.hxx"
3 #include <iostream>
4
5 using namespace YACS::ENGINE;
6 using namespace std;
7
8 const char DataPort::NAME[]="DataPort";
9
10 DataPort::~DataPort()
11 {
12   _type->decrRef();
13 }
14
15 DataPort::DataPort(const std::string& name, Node *node, TypeCode* type):Port(node),_name(name),_type(type)
16 {
17   _type->incrRef();
18 }
19
20 DataPort::DataPort(const DataPort& other, Node *newHelder):Port(other,newHelder),_name(other._name),_type(other._type)
21 {
22   _type->incrRef();
23 }
24
25 void DataPort::edSetType(TypeCode* type)
26 {
27   if(_type)
28     _type->decrRef();
29   _type=type;
30   if(_type)
31     _type->incrRef();
32 }
33
34 string DataPort::getNameOfTypeOfCurrentInstance() const
35 {
36   return NAME;
37 }
38
39 bool DataPort::isDifferentTypeOf(const DataPort *other) const
40 {
41   return getTypeOfChannel()!=other->getTypeOfChannel();
42 }
43
44 /*!
45  * If in historyOfLink different type of Port are detected : The first one (by starting from the end of 'historyOfLink')
46  * is returned. Else 0 is returned if they are all of the same type.
47  */
48 DataPort *DataPort::isCrossingType(const std::vector<DataPort *>& historyOfLink)
49 {
50   vector<DataPort *>::const_reverse_iterator iter=historyOfLink.rbegin()+1;
51   const DataPort *base=historyOfLink.back();
52   for(;iter!=historyOfLink.rend();iter++)
53     if(base->isDifferentTypeOf(*iter))
54       return *iter;
55   return 0;
56 }