Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/superv.git] / src / GraphBase / DataFlowBase_Port.hxx
1 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DataFlowBase_Port.hxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 #ifndef _DATAFLOWBASE_PORT_HXX
30 #define _DATAFLOWBASE_PORT_HXX
31
32 #include <list>
33 #include <vector>
34
35 #include "DataFlowBase_ServicesParameter.hxx"
36
37 namespace GraphBase {
38
39   class Port : public ServicesParameter {
40
41     private:
42
43       const char *const * _NodeName ;
44       SUPERV::Port_var    _Port ;
45       SUPERV::KindOfPort  _KindOfPort ;
46
47       vector<long > _X ;    
48       vector<long > _Y ;    
49
50       SALOME_ModuleCatalog::DataStreamDependency _Dependency ; // Time or Iteration only for DataStreamPorts
51
52     public:   
53
54       Port() {
55            _NodeName = NULL ;
56            _Port = SUPERV::Port::_nil() ;
57            _KindOfPort = SUPERV::UndefinedParameter ;
58            _Dependency  = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED ; } ;
59       Port( const char *const * NodeName ,
60             const SALOME_ModuleCatalog::ServicesParameter aserviceParameter ,
61             const SUPERV::KindOfPort aKindOfPort = SUPERV::ServiceParameter ,
62             const SALOME_ModuleCatalog::DataStreamDependency aDependency = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED ) :
63             ServicesParameter( aserviceParameter ) {
64             _NodeName = NodeName ;
65 //            cdebug << "Port::Port _NodeName " << _NodeName << " = " << (void * ) *_NodeName
66 //                   << " = " << _NodeName << " in Port " << PortName() << endl ;
67             _Port = SUPERV::Port::_nil() ;
68             _KindOfPort = aKindOfPort ;
69             if ( IsDataStream() ) {
70               _Dependency = aDependency ;
71             }
72             else {
73               _Dependency = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED ;
74             } } ;
75       virtual ~Port() {
76          cdebug << "~Port _NodeName " << *_NodeName << endl ; } ;
77
78       SUPERV::Port_var ObjRef() const { return _Port ; } ;
79       void ObjRef(SUPERV::Port_var aPort) {
80                   _Port = aPort ; } ;
81
82       const char * NodeName() const {
83 //            cdebug << "Port::NodeName _NodeName " << _NodeName << " = " << (void * ) *_NodeName
84 //                   << " = " << *_NodeName << " in Port " << PortName() << endl ;
85             return *_NodeName ; } ;
86       const char * NodePortName() const {
87 //            cout << "NodePortName " << hex << (void *) _NodeName << " "
88 //                 << dec << _NodeName << endl ;
89             char * _NodePortName = new char [ strlen( *_NodeName ) +
90                                    strlen( ServicesParameterName() ) + 4 ] ;
91             strcpy( _NodePortName , *_NodeName ) ;
92 //            strcat( _NodePortName , "\\" ) ;
93             strcat( _NodePortName , "__" ) ;
94             strcat( _NodePortName , ServicesParameterName() ) ;
95             return _NodePortName ; } ;          
96
97       const char * PortName() const {
98             if ( this == NULL )
99               return NULLSTRING ;
100             return ServicesParameterName() ; } ;
101       const char * PortType() const { return ServicesParameterType() ; } ;
102
103       void PortType(char * aParametertype ) { ServicesParameterType( aParametertype ) ; } ;
104       void Kind( SUPERV::KindOfPort aKindOfPort ) {
105            if ( _KindOfPort == SUPERV::GateParameter && aKindOfPort == SUPERV::InLineParameter ) {
106              cdebug << "GraphBase::Port::Kind " << _KindOfPort << " --> " << aKindOfPort
107                     << endl ;
108            }
109            _KindOfPort = aKindOfPort ; } ;
110       const SUPERV::KindOfPort Kind() const {
111             return _KindOfPort ; } ;
112       bool IsParam() const {
113            return _KindOfPort == SUPERV::ServiceParameter ; } ;
114       bool IsGate() const {
115            return _KindOfPort == SUPERV::GateParameter ||
116                   _KindOfPort == SUPERV::GOTOParameter ; } ;
117       bool IsInLine() const {
118            return _KindOfPort == SUPERV::InLineParameter ; } ;
119       bool IsLoop() const {
120            return _KindOfPort == SUPERV::LoopParameter ; } ;
121       bool IsSwitch() const {
122            return _KindOfPort == SUPERV::SwitchParameter ; } ;
123       bool IsEndSwitch() const {
124            return _KindOfPort == SUPERV::EndSwitchParameter ; } ;
125       bool IsGOTO() const {
126            return _KindOfPort == SUPERV::GOTOParameter ; } ;
127       bool IsDataStream() const {
128            return _KindOfPort == SUPERV::DataStreamParameter ; } ;
129
130       const SALOME_ModuleCatalog::DataStreamDependency Dependency() const {
131                                      return _Dependency ; } ;
132       bool Dependency( SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
133            if ( IsDataStream() ) {
134              _Dependency = aDependency ;
135              return true ;
136            }
137            return false ; } ;
138
139       bool AddCoord( const int nxy , const int *x , const int *y ) ;
140       bool AddCoord( const int index , const int x , const int y ) ;
141       bool ChangeCoord( const int index ,
142                         const int x ,
143                         const int y ) ;
144       bool RemoveCoord( const int index ) ;
145       bool RemoveCoords() ;
146       int GetCoord() const ;
147       bool GetCoord( int *x , int *y ) const ;
148       const GraphBase::ListOfCoords * Coords() const ;
149       bool GetCoord( const int index , CORBA::Long &x , CORBA::Long &y ) const ;
150
151   } ;
152
153 } ;
154
155 ostream & operator<< (ostream &,const SUPERV::KindOfPort &);
156
157 ostream & operator<< (ostream &,const SALOME_ModuleCatalog::DataStreamDependency &);
158
159 ostream & operator<< (ostream &,const StatusOfPort &);
160
161 #endif