Salome HOME
NRI : First integration.
[modules/superv.git] / src / GraphBase / DataFlowBase_OutPort.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : DataFlowBase_OutPort.cxx
4 // Created   : 2002
5 // Author    : Jean Rahuel, CEA
6 // Project   : SALOME
7 // $Header:
8 //=============================================================================
9
10 #include "DataFlowBase_OutPort.hxx"
11
12 //GraphBase::OutPort::~OutPort() {
13 // In GraphExecutor::OutPort
14 //  int i ;
15 //  for ( i = 1 ; i <= _InPortsSize  ; i++ ) {
16 //    if ( !_InPorts[ i ]->RemoveLink() )
17 //      cout << "GraphBase::OutPort::~OutPort error "
18 //           << _InPorts[ i ]->PortName() << endl ;
19 //  }
20 //}
21
22 bool GraphBase::OutPort::HasInPort() const {
23   return _InPortsSize != 0 ;
24 }
25
26 const GraphBase::InPort * GraphBase::OutPort::GetInPort(
27                          const GraphBase::InPort * toPort ) {
28   const GraphBase::InPort * anInPort = NULL ;
29   int index = _MapOfInPorts[ toPort->NodePortName() ] ;
30   if ( index > 0 && index <= _InPortsSize ) {
31     anInPort = _InPorts[ index-1 ] ;
32     if ( anInPort != toPort ) {
33       cout << "GraphBase::OutPort::GetInPort inconsistency toPort "
34            << hex << (void *) toPort << " != anInPort " << (void *) anInPort
35            << dec << endl ;
36       anInPort = NULL ;
37     }
38   }
39   return anInPort ;
40 }
41
42 SUPERV::Link_var GraphBase::OutPort::InPortObjRef(
43                          const GraphBase::InPort * toPort ) {
44   SUPERV::Link_var aLink = SUPERV::Link::_nil() ;
45   int index = _MapOfInPorts[ toPort->NodePortName() ] ;
46   if ( index > 0 && index <= _InPortsSize ) {
47     aLink = _Links[ index-1 ] ;
48   }
49   return aLink ;
50 }
51
52 bool GraphBase::OutPort::AddInPort( GraphBase::InPort * toPort ) {
53   int index = _MapOfInPorts[ toPort->NodePortName() ] ;
54   if ( index > 0 && index <= _InPortsSize ) {
55     return false ;
56   }
57   _InPortsSize += 1 ;
58   _InPorts.resize( _InPortsSize ) ;
59   _MapOfInPorts[ toPort->NodePortName() ] = _InPortsSize ;
60   _InPorts[ _InPortsSize-1 ] = toPort ;
61   _Links.resize( _InPortsSize ) ;
62   _Links[ _InPortsSize-1 ] = SUPERV::Link::_nil() ;
63   cdebug << "OutPort " << NodeName() << "(" << PortName() << ") --> InPort "
64          << toPort->NodeName() << "(" << toPort->PortName() << ") SwitchPort "
65          << toPort->IsEndSwitch() << endl ;
66   return true ;
67 }
68
69 bool GraphBase::OutPort::AddInPortObjRef( GraphBase::InPort * toPort ,
70                                           SUPERV::Link_var aLink ) {
71   int index = _MapOfInPorts[ toPort->NodePortName() ] ;
72   if ( index <= 0 || index > _InPortsSize ) {
73     return false ;
74   }
75   _Links[ index - 1 ] = aLink ;
76   return true ;
77 }
78
79 bool GraphBase::OutPort::RemoveInPort( GraphBase::InPort * toPort ) {
80   int i ;
81   int index = _MapOfInPorts[ toPort->NodePortName() ] ;
82   if ( index <= 0 || index > _InPortsSize ) {
83     cdebug << "GraphBase::OutPort::RemoveInPort Error " << NodePortName()
84            << " --> " << toPort->NodePortName() << endl ;
85     return false ;
86   }
87   _InPortsSize -= 1 ;
88   for ( i = index - 1 ; i < _InPortsSize  ; i++ ) {
89     _MapOfInPorts[ _InPorts[ i+1 ]->NodePortName() ] = i + 1 ;
90     _InPorts[ i ] = _InPorts[ i+1 ]  ;
91     _Links[ i ] = _Links[ i+1 ]  ;
92   }
93   _InPorts.resize( _InPortsSize ) ;
94   _Links.resize( _InPortsSize ) ;
95   _MapOfInPorts.erase( toPort->NodePortName() ) ;
96   if ( _InPortsSize == 0 ) {
97     PortStatus(NotConnected ) ;
98   }
99   toPort->RemoveOutPort() ;
100   return true ;
101 }
102
103 bool GraphBase::OutPort::ReNameInPort( const char* OldNodePortName ,
104                                        const char* NewNodePortName ) {
105   int index = _MapOfInPorts[ OldNodePortName ] ;
106   if ( index <= 0 || index > _InPortsSize ) {
107     cdebug << "GraphBase::OutPort::ReNameLink Error " << OldNodePortName
108            << " --> " << NewNodePortName << " index " << index << endl ;
109     return false ;
110   }
111   _MapOfInPorts.erase( OldNodePortName ) ;
112   _MapOfInPorts[ NewNodePortName ] = index ;
113   return true ;
114 }
115
116 #if 0
117 bool GraphBase::OutPort::RemoveLinks() {
118   bool RetVal = true ;
119   int i ;
120   for ( i = 0 ; i < _InPortsSize ; i++ ) {
121     MESSAGE( "       to " << *_InPorts[ i ] );
122     RetVal = _InPorts[ i ]->RemoveLink() ;
123     if ( !RetVal )
124       break ;
125     RetVal = RemoveLink( _InPorts[ i ] ) ;
126     if ( !RetVal )
127       break ;
128   }
129   PortStatus(NotConnected ) ;
130   return RetVal ;
131 }
132 #endif
133
134 ostream & operator<< (ostream &f ,const GraphBase::OutPort &P)
135 {
136   f << P.PortName() << ", " 
137     << "type : " << P.PortType() << ", " ;
138
139     f << "from "
140       << P.NodeName() << ", ";
141
142   return f;
143 }
144