Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[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             _Port = SUPERV::Port::_nil() ;
66             _KindOfPort = aKindOfPort ;
67             if ( IsDataStream() ) {
68               _Dependency = aDependency ;
69             }
70             else {
71               _Dependency = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED ;
72             } } ;
73       virtual ~Port() {
74          cdebug << "~Port" << endl ; } ;
75
76       SUPERV::Port_var ObjRef() const { return _Port ; } ;
77       void ObjRef(SUPERV::Port_var aPort) {
78                   _Port = aPort ; } ;
79
80       const char * NodeName() const { return *_NodeName ; } ;
81       const char * NodePortName() const {
82 //            cout << "NodePortName " << hex << (void *) _NodeName << " "
83 //                 << dec << _NodeName << endl ;
84             char * _NodePortName = new char [ strlen( *_NodeName ) +
85                                    strlen( ServicesParameterName() ) + 3 ] ;
86             strcpy( _NodePortName , *_NodeName ) ;
87             strcat( _NodePortName , "\\" ) ;
88             strcat( _NodePortName , ServicesParameterName() ) ;
89             return _NodePortName ; } ;          
90
91       const char * PortName() const {
92             if ( this == NULL )
93               return NULLSTRING ;
94             return ServicesParameterName() ; } ;
95       const char * PortType() const { return ServicesParameterType() ; } ;
96
97       void Kind( SUPERV::KindOfPort aKindOfPort ) {
98            if ( _KindOfPort == SUPERV::GateParameter && aKindOfPort == SUPERV::InLineParameter ) {
99              cdebug << "GraphBase::Port::Kind " << _KindOfPort << " --> " << aKindOfPort
100                     << endl ;
101            }
102            _KindOfPort = aKindOfPort ; } ;
103       const SUPERV::KindOfPort Kind() const {
104             return _KindOfPort ; } ;
105       bool IsParam() const {
106            return _KindOfPort == SUPERV::ServiceParameter ; } ;
107       bool IsGate() const {
108            return _KindOfPort == SUPERV::GateParameter ||
109                   _KindOfPort == SUPERV::GOTOParameter ; } ;
110       bool IsInLine() const {
111            return _KindOfPort == SUPERV::InLineParameter ; } ;
112       bool IsLoop() const {
113            return _KindOfPort == SUPERV::LoopParameter ; } ;
114       bool IsSwitch() const {
115            return _KindOfPort == SUPERV::SwitchParameter ; } ;
116       bool IsEndSwitch() const {
117            return _KindOfPort == SUPERV::EndSwitchParameter ; } ;
118       bool IsGOTO() const {
119            return _KindOfPort == SUPERV::GOTOParameter ; } ;
120       bool IsDataStream() const {
121            return _KindOfPort == SUPERV::DataStreamParameter ; } ;
122
123       const SALOME_ModuleCatalog::DataStreamDependency Dependency() const {
124                                      return _Dependency ; } ;
125       bool Dependency( SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
126            if ( IsDataStream() ) {
127              _Dependency = aDependency ;
128              return true ;
129            }
130            return false ; } ;
131
132       bool AddCoord( const int nxy , const int *x , const int *y ) ;
133       bool AddCoord( const int index , const int x , const int y ) ;
134       bool ChangeCoord( const int index ,
135                         const int x ,
136                         const int y ) ;
137       bool RemoveCoord( const int index ) ;
138       bool RemoveCoords() ;
139       int GetCoord() const ;
140       bool GetCoord( int *x , int *y ) const ;
141       const GraphBase::ListOfCoords * Coords() const ;
142       bool GetCoord( const int index , long &x , long &y ) const ;
143
144   } ;
145
146 } ;
147
148 ostream & operator<< (ostream &,const SUPERV::KindOfPort &);
149
150 ostream & operator<< (ostream &,const SALOME_ModuleCatalog::DataStreamDependency &);
151
152 #endif