Salome HOME
4c4c04d2e8e06698f71e25c17a2d745e091a97cd
[modules/superv.git] / src / GraphBase / DataFlowBase_PortsOfNode.cxx
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_PortsOfNode.cxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 using namespace std;
30 #include "DataFlowBase_PortsOfNode.hxx"
31
32 GraphBase::PortsOfNode::PortsOfNode() :
33   GraphBase::Service::Service( SALOME_ModuleCatalog::Service() ) {
34 //  MESSAGE( "GraphBase::PortsOfNode::PortsOfNode "  << this ) ;
35 //  cout << "GraphBase::PortsOfNode::PortsOfNode "  << this << endl ;
36 //  cdebug << "GraphBase::PortsOfNode::PortsOfNode "  << this << endl ;
37   _NodeInPortsSize = 0 ;
38   _NodeOutPortsSize = 0 ;
39   _DataStreamInPortsNumber = 0 ;
40   _DataStreamOutPortsNumber = 0 ;
41 }
42
43 GraphBase::PortsOfNode::PortsOfNode( const char *DataFlowName ) :
44   GraphBase::Service::Service( SALOME_ModuleCatalog::Service() ) {
45 //  MESSAGE( "GraphBase::PortsOfNode::PortsOfNode "  << this ) ;
46 //  cout << "GraphBase::PortsOfNode::PortsOfNode "  << this << endl ;
47 //  cdebug << "GraphBase::PortsOfNode::PortsOfNode "  << this << endl ;
48   _NodeInPortsSize = 0 ;
49   _NodeOutPortsSize = 0 ;
50   _DataStreamInPortsNumber = 0 ;
51   _DataStreamOutPortsNumber = 0 ;
52 }
53
54 GraphBase::PortsOfNode::~PortsOfNode() {
55   cdebug << "GraphBase::PortsOfNode::~PortsOfNode "  << this 
56          << endl ;
57 //  int i ;
58 //  for ( i = 0 ; i < _NodeInPortsSize ; i++ ) {
59 //    delete _NodeInPorts[ i ] ;
60 //  }
61 //  for ( i = 0 ; i < _NodeOutPortsSize ; i++ ) {
62 //    delete _NodeOutPorts[ i ] ;
63 //  }
64 }
65
66 void GraphBase::PortsOfNode::DefPortsOfNode(
67                            CORBA::ORB_ptr ORB ,
68                            const SALOME_ModuleCatalog::Service& aService ,
69                            const char *const * NodeName ,
70                            const SUPERV::KindOfNode aKind ,
71                            int * Graph_prof_debug ,
72                            ofstream * Graph_fdebug ) {
73   int i ;
74   SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
75 //  MESSAGE( "DefPortsOfNode " << NodeName << " Graph_prof_debug  "
76 //           << Graph_prof_debug << " _prof_debug " << _prof_debug ) ;
77   cdebug_in << "DefPortsOfNode : " << *NodeName << " ServiceName " << aService.ServiceName << endl ;
78   const bool DataFlowOrComputing = (aKind == SUPERV::DataFlowGraph) ||
79                                    (aKind == SUPERV::ComputingNode) ||
80                                    (aKind == SUPERV::FactoryNode) ;
81 // WithInLoop : InitLoop or DoLoop
82   const bool WithInLoop = (aKind == SUPERV::LoopNode) || (aKind == SUPERV::EndLoopNode) ;
83 // WithInGate : InGate or Default
84   const bool WithInGate = (aKind == SUPERV::DataFlowGraph) || (aKind == SUPERV::DataStreamGraph) ||
85                           (aKind == SUPERV::ComputingNode) || (aKind == SUPERV::FactoryNode) ||
86                           (aKind == SUPERV::InLineNode) || (aKind == SUPERV::GOTONode) ||
87                           (aKind == SUPERV::LoopNode) || (aKind == SUPERV::EndLoopNode) ||
88                           (aKind == SUPERV::SwitchNode) || (aKind == SUPERV::EndSwitchNode) ||
89                           (aKind == SUPERV::MacroNode) ;
90 // WithOutGate : OutGate or Default
91   const bool WithOutGate = (aKind == SUPERV::DataFlowGraph) || (aKind == SUPERV::DataStreamGraph) ||
92                            (aKind == SUPERV::ComputingNode) || (aKind == SUPERV::FactoryNode) ||
93                            (aKind == SUPERV::InLineNode) || (aKind == SUPERV::GOTONode) ||
94                              /* asv : 15.12.04 : adding out gate ports for Loop/EndLoop, too. p2.5, PAL7385*/
95                            (aKind == SUPERV::LoopNode) || (aKind == SUPERV::EndLoopNode) ||
96                            (aKind == SUPERV::SwitchNode) || (aKind == SUPERV::EndSwitchNode) ||
97                            (aKind == SUPERV::MacroNode) ;
98   SUPERV::KindOfPort aPortKind = SUPERV::ServiceParameter ;
99   if ( aKind == SUPERV::InLineNode ) {
100     aPortKind = SUPERV::InLineParameter ;
101   }
102   else if ( aKind == SUPERV::LoopNode || aKind == SUPERV::EndLoopNode ) {
103     aPortKind = SUPERV::InLineParameter ;
104   }
105   else if ( aKind == SUPERV::SwitchNode || aKind == SUPERV::EndSwitchNode ) {
106     aPortKind = SUPERV::InLineParameter ;
107   }
108   else if ( aKind == SUPERV::GOTONode ) {
109     aPortKind = SUPERV::InLineParameter ;
110   }
111   else if ( aKind == SUPERV::MacroNode ) {
112     aPortKind = SUPERV::InLineParameter ;
113   }
114   for ( i = 0 ; i < _NodeInPortsSize ; i++ ) {
115     cdebug << "DefPortsOfNode delete In" << i << ". "  << _NodeInPorts[i]->PortName()
116            << endl ;
117     _MapOfNodeInPorts.erase( _NodeInPorts[i]->PortName() ) ;
118     delete _NodeInPorts[i] ;
119   }
120   _NodeInPorts.resize( 0 );
121   for ( i = 0 ; i < _NodeOutPortsSize ; i++ ) {
122     cdebug << "DefPortsOfNode delete Out" << i << ". " << _NodeOutPorts[i]->PortName()
123            << endl ;
124     _MapOfNodeOutPorts.erase( _NodeOutPorts[i]->PortName() ) ;
125     delete _NodeOutPorts[i] ;
126   }
127   _NodeOutPorts.resize( 0 );
128
129   SetService( aService ) ;
130
131   int iVec = 0 ;
132   _NodeInPortsSize = aService.ServiceinParameter.length() ;
133   if ( WithInLoop ) {
134     SALOME_ModuleCatalog::ServicesParameter anInLoopParameter ;
135     _NodeInPortsSize = _NodeInPortsSize + 1 ;
136     iVec += 1 ;
137 //    char *aParametername = "InitLoop" ;
138 //    if ( aKind == SUPERV::EndLoopNode ) {
139       char * aParametername = "DoLoop" ;
140 //    }
141     anInLoopParameter.Parametertype = CORBA::string_dup( "long" ) ;
142     anInLoopParameter.Parametername = CORBA::string_dup( aParametername ) ;
143     if ( _NodeInPortsSize > (int ) _NodeInPorts.size() ) {
144       _NodeInPorts.resize( _NodeInPortsSize );
145     }
146     _MapOfNodeInPorts[ aParametername ] = iVec ;
147     _NodeInPorts[iVec-1] = new GraphBase::InPort( NodeName , anInLoopParameter ,
148                                                   SUPERV::LoopParameter );
149     _NodeInPorts[iVec-1]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
150     cdebug << "DefPortsOfNode : " << "_MapOfNodeInPorts[ " << aParametername
151            << " ] = " << iVec << " " << _NodeInPorts[iVec-1]->Kind() << " "
152             << _NodeInPorts[iVec-1]  << endl ;
153   }
154   if ( _NodeInPortsSize > (int ) _NodeInPorts.size() ) {
155     _NodeInPorts.resize(_NodeInPortsSize);
156   }
157   cdebug << "NodeInPortsSize " << _NodeInPortsSize << endl ;
158   for ( i = iVec ; i < _NodeInPortsSize ; i++ ) {
159 //JR 24.02.2005 Memory Leak    string _aParametername = CORBA::string_dup(aService.ServiceinParameter[i-iVec].Parametername) ;
160     string _aParametername = string(aService.ServiceinParameter[i-iVec].Parametername) ;
161     const char *aParametername = _aParametername.c_str() ;
162     if ( _MapOfNodeInPorts[ aParametername ] ) {
163       if ( !DataFlowOrComputing &&
164            !strcmp( aParametername , "Gate" ) ) {
165       }
166       else {
167         cdebug << "Error, Parametername duplicated : " << aParametername
168                << endl ;
169       }
170     }
171     else {
172       _MapOfNodeInPorts[ aParametername ] = i+1 ;
173 //      cdebug << "DefPortsOfNode : " << "_MapOfNodeInPorts[ " << aParametername
174 //             << " ] = " << i+1 << endl ;
175       const SALOME_ModuleCatalog::ServicesParameter aServiceParameter = aService.ServiceinParameter[i-iVec] ;
176       _NodeInPorts[i] = new GraphBase::InPort( NodeName , aServiceParameter ,
177                                                aPortKind );
178       _NodeInPorts[i]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
179       cdebug << i << ". " << *_NodeInPorts[i] << " " << _NodeInPorts[i]->Kind() << endl ;
180     }
181   }
182   iVec += aService.ServiceinParameter.length() ;
183   if ( WithInGate ) {
184     SALOME_ModuleCatalog::ServicesParameter anInGateParameter ;
185     _NodeInPortsSize = _NodeInPortsSize + 1 ;
186     iVec += 1 ;
187     char *aParametername = "Gate" ;
188     if ( aKind == SUPERV::EndSwitchNode ) {
189       aParametername = "Default" ;
190     }
191     anInGateParameter.Parametertype = CORBA::string_dup( "long" ) ;
192     anInGateParameter.Parametername = CORBA::string_dup( aParametername ) ;
193     _NodeInPorts.resize( _NodeInPortsSize );
194     _MapOfNodeInPorts[ aParametername ] = iVec ;
195     _NodeInPorts[iVec-1] = new GraphBase::InPort( NodeName , anInGateParameter ,
196                                                   SUPERV::GateParameter );
197     _NodeInPorts[iVec-1]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
198 //    cdebug << "DefPortsOfNode : " << "_MapOfNodeInPorts[ " << aParametername
199 //           << " ] = " << iVec << " " << _NodeInPorts[iVec-1]->Kind() << " "
200 //            << _NodeInPorts[iVec-1]  << endl ;
201   }
202   
203   iVec = 0 ;
204   _NodeOutPortsSize = aService.ServiceoutParameter.length() ;
205   if ( WithInLoop ) {
206     SALOME_ModuleCatalog::ServicesParameter anOutLoopParameter ;
207     _NodeOutPortsSize = _NodeOutPortsSize + 1 ;
208     iVec += 1 ;
209     char *aParametername = "DoLoop" ;
210     anOutLoopParameter.Parametertype = CORBA::string_dup( "long" ) ;
211     anOutLoopParameter.Parametername = CORBA::string_dup( aParametername ) ;
212     if ( _NodeOutPortsSize > (int ) _NodeOutPorts.size() ) {
213       _NodeOutPorts.resize(_NodeOutPortsSize);
214     }
215     _MapOfNodeOutPorts[ aParametername ] = iVec ;
216     _NodeOutPorts[iVec-1] = new GraphBase::OutPort( NodeName , anOutLoopParameter ,
217                                                     SUPERV::LoopParameter );
218     _NodeOutPorts[iVec-1]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
219 //    cdebug << "DefPortsOfNode : " << "_MapOfNodeOutPorts[ " << aParametername
220 //           << " ] = " << iVec << " " << _NodeOutPorts[iVec-1]->Kind() << " "
221 //           << _NodeOutPorts[iVec-1]  << endl ;
222   }
223   if ( _NodeOutPortsSize > (int ) _NodeOutPorts.size() ) {
224     _NodeOutPorts.resize(_NodeOutPortsSize);
225   }
226   cdebug << "NodeOutPortsSize " << _NodeOutPortsSize << endl ;
227   for ( i = iVec ; i < _NodeOutPortsSize ; i++ ) {
228 //JR 24.02.2005 Memory Leak    string _aParametername = CORBA::string_dup(aService.ServiceoutParameter[i-iVec].Parametername) ;
229     string _aParametername = string(aService.ServiceoutParameter[i-iVec].Parametername) ;
230     const char *aParametername = _aParametername.c_str() ;
231     if ( _MapOfNodeOutPorts[ aParametername ] ) {
232       if ( !DataFlowOrComputing &&
233            !strcmp( aParametername , "Gate" ) ) {
234       }
235       else {
236         cdebug << "Error, Parametername duplicated : " << aParametername
237                << endl ;
238       }
239     }
240     else {
241 //      cdebug << "DefPortsOfNode : " << "_MapOfNodeOutPorts[ " << aParametername
242 //             << " ] = " << i+1 << endl ;
243       _MapOfNodeOutPorts[ aParametername ] = i+1 ;
244       const SALOME_ModuleCatalog::ServicesParameter aServiceParameter = aService.ServiceoutParameter[i-iVec] ;
245       _NodeOutPorts[i] = new GraphBase::OutPort( NodeName , aServiceParameter ,
246                                                  aPortKind );
247       _NodeOutPorts[i]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
248       cdebug << i << ". " << *_NodeOutPorts[i] << " " << _NodeOutPorts[i]->Kind() << endl ;
249     }
250   }
251   iVec += aService.ServiceoutParameter.length() ;
252   if ( WithOutGate ) {
253     SALOME_ModuleCatalog::ServicesParameter anOutGateParameter ;
254     _NodeOutPortsSize = _NodeOutPortsSize + 1 ;
255     iVec += 1 ;
256     char *aParametername = "Gate" ;
257     if ( aKind == SUPERV::SwitchNode ) {
258       aParametername = "Default" ;
259     }
260     anOutGateParameter.Parametertype = CORBA::string_dup( "long" ) ;
261     anOutGateParameter.Parametername = CORBA::string_dup( aParametername ) ;
262     _NodeOutPorts.resize(_NodeOutPortsSize);
263     _MapOfNodeOutPorts[ aParametername ] = iVec ;
264     _NodeOutPorts[iVec-1] = new GraphBase::OutPort( NodeName , anOutGateParameter ,
265                                                     SUPERV::GateParameter );
266     _NodeOutPorts[iVec-1]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
267 //    cdebug << "DefPortsOfNode : " << "_MapOfNodeOutPorts[ " << aParametername
268 //           << " ] = " << iVec << " " << _NodeOutPorts[iVec-1]->Kind() << " "
269 //           << _NodeOutPorts[iVec-1]  << endl ;
270   }
271   cdebug_out << "DefPortsOfNode : " << *NodeName << endl ;
272 }
273
274 GraphBase::InPort * GraphBase::PortsOfNode::AddInPort( CORBA::ORB_ptr ORB ,
275                                                        const char *const * NodeName ,
276                                                        const SUPERV::KindOfNode aKindOfNode ,
277                                                        const char * InputParameterName ,
278                                                        const char * InputParameterType ,
279                                                        SUPERV::KindOfPort aKindOfPort ,
280                                                        int index ,
281                                                        int * Graph_prof_debug ,
282                                                        ofstream * Graph_fdebug ) {
283 //  MESSAGE( "DefPortsOfNode " << *NodeName << " Graph_prof_debug "
284 //           << Graph_prof_debug << " _prof_debug " << _prof_debug ) ;
285   cdebug_in << "PortsOfNode::AddInPort : " << *NodeName << " " << aKindOfNode << " InputParameterName "
286             << InputParameterName << " InputParameterType " << InputParameterType << " aKindOfPort "
287             << aKindOfPort << " DataStreamInPortsNumber " << DataStreamInPortsNumber() << " _NodeInPortsSize "
288             << _NodeInPortsSize << " index " << index << endl ;
289   GraphBase::InPort * anInPort = NULL ;
290 //  int index = 0 ;
291   anInPort = GetChangeInPort( InputParameterName ) ;
292   if ( anInPort == NULL ) {
293     _NodeInPortsSize = _NodeInPortsSize + 1 ;
294     _NodeInPorts.resize(_NodeInPortsSize);
295     SALOME_ModuleCatalog::ServicesParameter aServiceParameter ;
296     aServiceParameter.Parametername = CORBA::string_dup( InputParameterName ) ;
297     aServiceParameter.Parametertype = CORBA::string_dup( InputParameterType ) ;
298     if ( index != -1 ) {
299     }
300     else if ( aKindOfPort == SUPERV::DataStreamParameter ) {
301       index = _NodeInPortsSize-2 ;
302       IncrDataStreamInPorts() ;
303     }
304     else {
305       index = _NodeInPortsSize-2 - DataStreamInPortsNumber() ;
306     }
307     if ( index >= 0 ) {
308       int i ;
309       for ( i = _NodeInPortsSize - 2 ; i >= index ; i-- ) {
310         _NodeInPorts[ i + 1 ] = _NodeInPorts[ i ] ; // Gate - Default
311         _MapOfNodeInPorts.erase( _NodeInPorts[ i + 1 ]->PortName() ) ;
312         _MapOfNodeInPorts[ _NodeInPorts[ i + 1 ]->PortName() ] =  i + 2 ;
313       }
314       _MapOfNodeInPorts[ InputParameterName ] = index + 1 ;
315       if ( aKindOfPort == SUPERV::DataStreamParameter ) {
316         _NodeInPorts[index] = new GraphBase::InDataStreamPort( NodeName ,
317                                                                aServiceParameter ) ;
318       }
319       else {
320         _NodeInPorts[index] = new GraphBase::InPort( NodeName ,
321                                                      aServiceParameter ,
322                                                      aKindOfPort ) ;
323       }
324       _NodeInPorts[index]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
325       anInPort = _NodeInPorts[index] ;
326       cdebug << "NodeInPorts[ " << index << " ]" << endl ;
327     }
328     else {
329       cdebug << "GraphBase::PortsOfNode::AddInPort ERROR index " << index << " _NodeInPortsSize "
330              << _NodeInPortsSize  << endl ;
331     }
332   }
333   else {
334     cdebug << "GraphBase::PortsOfNode::AddInPort InPort already exists" << endl ;
335     anInPort->Kind( aKindOfPort ) ;
336   }
337   cdebug << "GraphBase::PortsOfNode::AddInPort index " << index << " _NodeInPortsSize " << _NodeInPortsSize  << endl ;
338 //#if 0
339   int i ;
340   for ( i = 0 ; i < _NodeInPortsSize ; i++ ) {
341     cdebug << *NodeName << " _NodeInPorts[ " << i << " ] = " << _NodeInPorts[ i ]->PortName()
342            << " _MapOfNodeInPorts[ " << _NodeInPorts[ i ]->PortName() << " ] = "
343            << _MapOfNodeInPorts[ _NodeInPorts[ i ]->PortName() ] << " - 1 "
344            << _NodeInPorts[ i ]->Kind() << " Dependency " << _NodeInPorts[ i ]->Dependency() ;
345     if ( _NodeInPorts[ i ]->IsDataStream() ) {
346        SUPERV::KindOfSchema aKindOfSchema ;
347        SUPERV::KindOfInterpolation aKindOfInterpolation ;
348        SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
349        ((GraphBase::InDataStreamPort * ) _NodeInPorts[ i ])->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
350        cdebug << " " << aKindOfSchema << " " << aKindOfInterpolation << " " << aKindOfExtrapolation ;
351     }
352     if ( _NodeInPorts[ i ]->GetOutPort() ) {
353       cdebug << " <--OutPort " << _NodeInPorts[ i ]->GetOutPort()
354              << " " << _NodeInPorts[ i ]->GetOutPort()->NodeName()
355              << "(" << _NodeInPorts[ i ]->GetOutPort()->PortName() << ")" ;
356     }
357     else {
358       cdebug << " <--NOOutPort " << _NodeInPorts[ i ]->GetOutPort() ;
359     }
360     cdebug << " " << _NodeInPorts[ i ]->PortStatus() << endl ;
361   }
362 //#endif
363   cdebug_out << "GraphBase::PortsOfNode::AddInPort _NodeInPortsSize " << _NodeInPortsSize
364              << " " << anInPort->Kind() << endl ;
365   return anInPort ;
366 }
367
368 GraphBase::OutPort * GraphBase::PortsOfNode::AddOutPort( CORBA::ORB_ptr ORB ,
369                                                          const char * const * NodeName ,
370                                                          const SUPERV::KindOfNode aKindOfNode ,
371                                                          const char * OutputParameterName ,
372                                                          const char * OutputParameterType ,
373                                                          SUPERV::KindOfPort aKindOfPort ,
374                                                          int index ,
375                                                          int * Graph_prof_debug ,
376                                                          ofstream * Graph_fdebug ) {
377   cdebug_in << "GraphBase::PortsOfNode::AddOutPort : " << *NodeName << " " << aKindOfNode
378             << " OutputParameterName " << OutputParameterName << " OutputParameterType " << OutputParameterType
379             << " aKindOfPort " << aKindOfPort << " DataStreamOutPortsNumber " << DataStreamOutPortsNumber()
380             << " _NodeOutPortsSize " << _NodeOutPortsSize << " index " << index << endl ;
381   GraphBase::OutPort * anOutPort = NULL ;
382 //  int index = 0 ;
383   anOutPort = GetChangeOutPort( OutputParameterName ) ;
384   if ( anOutPort == NULL ) {
385     _NodeOutPortsSize = _NodeOutPortsSize + 1 ;
386     _NodeOutPorts.resize(_NodeOutPortsSize);
387     SALOME_ModuleCatalog::ServicesParameter aServiceParameter ;
388     aServiceParameter.Parametername = CORBA::string_dup( OutputParameterName ) ;
389     aServiceParameter.Parametertype = CORBA::string_dup( OutputParameterType ) ;
390     if ( index != -1 ) {
391     }
392     else if ( aKindOfPort == SUPERV::DataStreamParameter ) {
393       index = _NodeOutPortsSize-2 ;
394       IncrDataStreamOutPorts() ;
395     }
396     else {
397       index = _NodeOutPortsSize-2 - DataStreamOutPortsNumber() ;
398     }
399     if ( aKindOfNode == SUPERV::LoopNode || aKindOfNode == SUPERV::EndLoopNode ) {
400       index += 1 ;
401     }
402     if ( index >= 0 ) {
403       int i ;
404       for ( i = _NodeOutPortsSize - 2 ; i >= index ; i-- ) {
405         _NodeOutPorts[ i + 1 ] = _NodeOutPorts[ i ] ; // Gate - Default
406         _MapOfNodeOutPorts.erase( _NodeOutPorts[ i + 1 ]->PortName() ) ;
407         _MapOfNodeOutPorts[ _NodeOutPorts[ i + 1 ]->PortName() ] =  i + 2 ;
408       }
409       _MapOfNodeOutPorts[ OutputParameterName ] = index + 1 ;
410       if ( aKindOfPort == SUPERV::DataStreamParameter ) {
411         _NodeOutPorts[index] = new GraphBase::OutDataStreamPort( NodeName ,
412                                                                aServiceParameter ) ;
413       }
414       else {
415         _NodeOutPorts[index] = new GraphBase::OutPort( NodeName ,
416                                                        aServiceParameter ,
417                                                        aKindOfPort );
418       }
419 //    MESSAGE( "GraphBase::PortsOfNode::AddOutPort " << OutputParameterName << " --> SetDebug" ) ;
420       _NodeOutPorts[index]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
421       anOutPort = _NodeOutPorts[index] ;
422       cdebug << "NodeOutPorts[ " << index << " ]" << endl ;
423     }
424     else {
425       cdebug << "GraphBase::PortsOfNode::AddOutPort ERROR index " << index << " _NodeOutPortsSize "
426              << _NodeOutPortsSize  << endl ;
427     }
428   }
429   else {
430     cdebug << "GraphBase::PortsOfNode::AddOutPort OutPort already exists" << endl ;
431     anOutPort->Kind( aKindOfPort ) ;
432   }
433   cdebug << "GraphBase::PortsOfNode::AddOutPort index " << index << " _NodeOutPortsSize " << _NodeOutPortsSize  << endl ;
434 //#if 0
435   int i ;
436   for ( i = 0 ; i < _NodeOutPortsSize ; i++ ) {
437     cdebug << *NodeName << " _NodeOutPorts[ " << i << " ] = " << _NodeOutPorts[ i ]->PortName()
438            << " _MapOfNodeOutPorts[ " << _NodeOutPorts[ i ]->PortName() << " ] = "
439            << _MapOfNodeOutPorts[ _NodeOutPorts[ i ]->PortName() ] << " - 1 "
440            << _NodeOutPorts[ i ]->Kind() << " Dependency " << _NodeOutPorts[ i ]->Dependency() ;
441     if ( _NodeOutPorts[ i ]->IsDataStream() ) {
442        cdebug << " NumberOfValues " << ((GraphBase::OutDataStreamPort * ) _NodeOutPorts[ i ])->NumberOfValues() ;
443     }
444     cdebug << " " << _NodeOutPorts[ i ]->PortStatus() << endl ;
445   }
446 //#endif
447   cdebug_out << "GraphBase::PortsOfNode::AddOutPort _NodeOutPortsSize "
448              << _NodeOutPortsSize << " " << anOutPort->Kind() << endl ;
449   return anOutPort ;
450 }
451
452 void GraphBase::PortsOfNode::MoveInPort( const char * InputParameterName , int toindex ) {
453   int fromindex = _MapOfNodeInPorts[ InputParameterName ] - 1 ;
454   GraphBase::InPort * anInPort = _NodeInPorts[ toindex ] ;
455   _NodeInPorts[ toindex ] =  _NodeInPorts[ fromindex ] ;
456   _NodeInPorts[ fromindex ] = anInPort ;
457   _MapOfNodeInPorts.erase( _NodeInPorts[ toindex ]->PortName() ) ;
458   _MapOfNodeInPorts[ _NodeInPorts[ toindex ]->PortName() ] = toindex + 1  ;
459   _MapOfNodeInPorts.erase( _NodeInPorts[ fromindex ]->PortName() ) ;
460   _MapOfNodeInPorts[ _NodeInPorts[ fromindex ]->PortName() ] = fromindex + 1  ;
461 }
462
463 void GraphBase::PortsOfNode::MoveOutPort( const char * OutputParameterName , int toindex ) {
464   int fromindex = _MapOfNodeOutPorts[ OutputParameterName ] - 1 ;
465   GraphBase::OutPort * anOutPort = _NodeOutPorts[ toindex ] ;
466   _NodeOutPorts[ toindex ] =  _NodeOutPorts[ fromindex ] ;
467   _NodeOutPorts[ fromindex ] = anOutPort ;
468   _MapOfNodeOutPorts.erase( _NodeOutPorts[ toindex ]->PortName() ) ;
469   _MapOfNodeOutPorts[ _NodeOutPorts[ toindex ]->PortName() ] = toindex + 1  ;
470   _MapOfNodeOutPorts.erase( _NodeOutPorts[ fromindex ]->PortName() ) ;
471   _MapOfNodeOutPorts[ _NodeOutPorts[ fromindex ]->PortName() ] = fromindex + 1  ;
472 }
473
474 void GraphBase::PortsOfNode::DelInPort( const char * InputParameterName ) {
475   cdebug << "DefPortsOfNode::DelInPort : " << InputParameterName << endl ;
476   int index = _MapOfNodeInPorts[ InputParameterName ] -1 ;
477   if ( index >= 0 ) {
478     cdebug << "DefPortsOfNode::DelInPort : _NodeInPorts[" << index << "] "
479            << _NodeInPorts[ index ]->PortName() << " "
480            << _NodeInPorts[ index ]->NodeName() << endl ;
481     if ( _NodeInPorts[ index ]->IsDataStream() ) {
482       DecrDataStreamInPorts() ;
483     }
484     _MapOfNodeInPorts.erase( InputParameterName ) ;
485     _NodeInPorts[ index ]->destroy() ;
486     int i ;
487     for ( i = index ; i < _NodeInPortsSize - 1 ; i++ ) {
488       _MapOfNodeInPorts.erase( _NodeInPorts[ i+1 ]->PortName() ) ;
489       _MapOfNodeInPorts[ _NodeInPorts[ i+1 ]->PortName() ] = i+1 ;
490       _NodeInPorts[ i ] = _NodeInPorts[ i+1 ] ;
491     }
492     _NodeInPortsSize = _NodeInPortsSize - 1 ;
493     _NodeInPorts.resize( _NodeInPortsSize ) ;
494     for ( i = 0 ; i < _NodeInPortsSize ; i++ ) {
495       cdebug << "DefPortsOfNode::DelInPort ListOfInPorts : _NodeInPorts[" << i << "] "
496              << _NodeInPorts[ i ]->PortName() << " "
497              << _NodeInPorts[ i ]->NodeName() << endl ;
498     }
499   }
500   else {
501     cdebug << "DefPortsOfNode::DelInPort : index out of range ERROR " << index
502            << endl ;
503   }
504 }
505
506 void GraphBase::PortsOfNode::DelOutPort( const char * OutputParameterName ) {
507   cdebug << "DefPortsOfNode::DelOutPort : " << OutputParameterName << endl ;
508   int index = _MapOfNodeOutPorts[ OutputParameterName ] - 1 ;
509   if ( index >= 0 ) {
510     cdebug << "DefPortsOfNode::DelOutPort : _NodeOutPorts[" << index << "] "
511            << _NodeOutPorts[ index ]->PortName() << " "
512            << _NodeOutPorts[ index ]->NodeName() << endl ;
513     if ( _NodeOutPorts[ index ]->IsDataStream() ) {
514       DecrDataStreamOutPorts() ;
515     }
516     _MapOfNodeOutPorts.erase( OutputParameterName ) ;
517     _NodeOutPorts[ index ]->destroy() ;
518     int i ;
519     for ( i = index ; i < _NodeOutPortsSize - 1 ; i++ ) {
520       _MapOfNodeOutPorts.erase( _NodeOutPorts[ i+1 ]->PortName() ) ;
521       _MapOfNodeOutPorts[ _NodeOutPorts[ i+1 ]->PortName() ] = i+1 ;
522       _NodeOutPorts[ i ] = _NodeOutPorts[ i+1 ] ;
523     }
524     _NodeOutPortsSize = _NodeOutPortsSize - 1 ;
525     _NodeOutPorts.resize( _NodeOutPortsSize ) ;
526     for ( i = 0 ; i < _NodeOutPortsSize ; i++ ) {
527       cdebug << "DefPortsOfNode::DelOutPort ListOfOutPorts : _NodeOutPorts[" << i
528              << "] " << _NodeOutPorts[ i ]->PortName() << " "
529              << _NodeOutPorts[ i ]->NodeName() << endl ;
530     }
531   }
532   else {
533     cdebug << "DefPortsOfNode::DelOutPort : index out of range ERROR " << index
534            << endl ;
535   }
536 }
537
538 const GraphBase::InPort *GraphBase::PortsOfNode::GetInPort( const char *name) {
539  return GetChangeInPort( name ) ;
540 }
541
542 const GraphBase::OutPort *GraphBase::PortsOfNode::GetOutPort( const char *name) {
543  return GetChangeOutPort( name ) ;
544 }
545
546 GraphBase::InPort *GraphBase::PortsOfNode::GetChangeInPort( const char * name) {
547 //  cdebug_in << "GraphBase::PortsOfNode::GetChangeInPort " << name << endl;
548
549   GraphBase::InPort * pP = NULL;
550   if ( !_MapOfNodeInPorts.empty() ) {
551     int index = 0 ;
552     if ( !strcmp( name , "InGate" ) ) {
553       index = _MapOfNodeInPorts[ "Gate" ] ;
554     }
555     else {
556       index = _MapOfNodeInPorts[ name ] ;
557     }
558     if ( index > 0 ) {
559 //      cdebug << "GraphBase::PortsOfNode::GetChangeInPort _MapOfNodeInPorts[ "
560 //             << name << " ] : " << i-1 << " " << _NodeInPorts[ i-1 ]->NodeName()
561 //             << endl ;
562       pP = _NodeInPorts[ index-1 ] ;
563     }
564     else {
565       cdebug << "GraphBase::PortsOfNode::GetChangeInPort _MapOfNodeInPorts[ "
566              << name << " ] : " << index << " NOT FOUND. Known ports :" << endl ;
567 #if 1
568       map< string , int >::iterator aMapOfNodeInPortsIterator ;
569       int i = 0 ;
570       for ( aMapOfNodeInPortsIterator = _MapOfNodeInPorts.begin() ;
571             aMapOfNodeInPortsIterator != _MapOfNodeInPorts.end() ; aMapOfNodeInPortsIterator++ ) {
572         cdebug << "MapOfNodeInPorts" << i++ << " " << aMapOfNodeInPortsIterator->first << " --> "
573                << aMapOfNodeInPortsIterator->second << endl ;
574       }
575 #endif
576     }
577   }
578 //  cdebug_out << "GraphBase::PortsOfNode::GetChangeInPort " << endl;
579
580   return pP;
581 }
582
583 GraphBase::OutPort *GraphBase::PortsOfNode::GetChangeOutPort( const char * name ) {
584 //  cdebug_in << "GraphBase::PortsOfNode::GetChangeOutPort " << name << endl;
585
586   GraphBase::OutPort * pP = NULL;
587   if ( !_MapOfNodeOutPorts.empty() ) {
588     int index = 0 ;
589     if ( !strcmp( name , "OutGate" ) ) {
590       index = _MapOfNodeOutPorts[ "Gate" ] ;
591     }
592     else {
593       index = _MapOfNodeOutPorts[ name ] ;
594     }
595     if ( index > 0 ) {
596 //      cdebug << "GraphBase::PortsOfNode::GetChangeOutPort _MapOfNodeOutPorts[ "
597 //             << name << " ] : " << i-1 << " " << _NodeOutPorts[ i-1 ]->NodeName() << endl ;
598       pP = _NodeOutPorts[ index-1 ] ;
599     }
600     else {
601       cdebug << "GraphBase::PortsOfNode::GetChangeOutPort _MapOfNodeOutPorts[ "
602              << name << " ] : " << index << " NOT FOUND. Known ports :" << endl ;
603 #if 1
604       map< string , int >::iterator aMapOfNodeOutPortsIterator ;
605       int i = 0 ;
606       for ( aMapOfNodeOutPortsIterator = _MapOfNodeOutPorts.begin() ;
607             aMapOfNodeOutPortsIterator != _MapOfNodeOutPorts.end() ; aMapOfNodeOutPortsIterator++ ) {
608         cdebug << "MapOfNodeInPorts" << i++ << " " << aMapOfNodeOutPortsIterator->first << " --> "
609                << aMapOfNodeOutPortsIterator->second << endl ;
610       }
611 #endif
612     }
613   }
614   return pP;
615 }
616
617 void GraphBase::PortsOfNode::ListPorts( ostream & f,
618                                         const bool klink ) const {
619
620   int i ;
621
622   f << "      Input Ports : " ;
623   if ( klink ) {
624     f << GetNodeInPortsSize() << " port" 
625       << (GetNodeInPortsSize() > 1 ? "s" : "") << endl;
626
627     for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
628       f << "         Port "
629 //        << hex << GetNodeInPort(i) << dec << " "
630         << *(GetNodeInPort(i)) << " " ;
631       GetNodeInPort(i)->StringValue( f ) ;
632       f << endl;
633     }
634
635     f << "      Output Ports : " ;
636   }
637
638   f << GetNodeOutPortsSize() << " port" 
639     << (GetNodeOutPortsSize() > 1 ? "s" : "") << endl;
640
641   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
642     f << "         Port "
643 //      << hex << GetNodeOutPort(i) << dec << " "
644       << *(GetNodeOutPort(i)) << " " ;
645     GetNodeOutPort(i)->StringValue( f ) ;
646     f << endl;
647   }
648
649   if ( !klink ) {
650     f << "      Output Ports : " ;
651     f << GetNodeInPortsSize() << " port" 
652       << (GetNodeInPortsSize() > 1 ? "s" : "") << endl;
653
654     for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
655       f << "         Port "
656 //        << hex << GetNodeInPort(i) << dec << " "
657         << *(GetNodeInPort(i)) << " " ;
658       GetNodeInPort(i)->StringValue( f ) ;
659       f << endl;
660     }
661   }
662
663 }
664
665 ostream & operator<< (ostream & f ,const SUPERV::KindOfNode & s ) {
666   switch (s) {
667   case SUPERV::ComputingNode :
668     f << "ComputingNode";
669     break;
670   case SUPERV::FactoryNode :
671     f << "FactoryNode";
672     break;
673   case SUPERV::InLineNode :
674     f << "InLineNode";
675     break;
676   case SUPERV::MacroNode :
677     f << "MacroNode";
678     break;
679   case SUPERV::DataFlowGraph :
680     f << "DataFlowGraph";
681     break;
682   case SUPERV::DataStreamGraph :
683     f << "DataStreamGraph";
684     break;
685   case SUPERV::LoopNode :
686     f << "LoopNode";
687     break;
688   case SUPERV::EndLoopNode :
689     f << "EndLoopNode";
690     break;
691   case SUPERV::SwitchNode :
692     f << "SwitchNode";
693     break;
694   case SUPERV::EndSwitchNode :
695     f << "EndSwitchNode";
696     break;
697   case SUPERV::GOTONode :
698     f << "GOTONode";
699     break;
700   default :
701     f << "UnknownKindOfNode";
702     break;
703   }
704
705   return f;
706 }
707