src/GraphBase/DataFlowBase_StreamNode.hxx

Go to the documentation of this file.
00001 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
00002 //
00003 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
00005 // 
00006 //  This library is free software; you can redistribute it and/or 
00007 //  modify it under the terms of the GNU Lesser General Public 
00008 //  License as published by the Free Software Foundation; either 
00009 //  version 2.1 of the License. 
00010 // 
00011 //  This library is distributed in the hope that it will be useful, 
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00014 //  Lesser General Public License for more details. 
00015 // 
00016 //  You should have received a copy of the GNU Lesser General Public 
00017 //  License along with this library; if not, write to the Free Software 
00018 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
00019 // 
00020 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  File   : DataFlowBase_StreamNode.hxx
00023 //  Author : Jean Rahuel
00024 //  Module : SUPERV
00025 
00026 #ifndef _DATAFLOWBASE_STREAMNODE_HXX
00027 #define _DATAFLOWBASE_STREAMNODE_HXX
00028 
00029 #include "DataFlowBase_PortsOfNode.hxx"
00030 
00031 namespace GraphEditor {
00032 
00033   class DataFlow ;
00034 
00035 }
00036 
00037 namespace GraphBase {
00038 
00039   class Graph ;
00040 
00041   class StreamNode : public PortsOfNode {
00042 
00043     private:
00044     
00045       char                 * _Name ;
00046       SUPERV::KindOfNode     _Kind ;
00047 
00048 // _LinkedNodes are the nodes with link(s) from OutPort(s) of this node
00049 // Nodes with LinkedInPortsNumber InPort(s) linked to Outport(s) of this node :
00050       map< string , int >   _MapOfLinkedNodes ;
00051       int                   _LinkedNodesSize ;
00052       vector<StreamNode * > _LinkedNodes ;
00053       vector<int >          _LinkedInPortsNumber ;
00054 
00055 // _LinkedFromNodes are the nodes with link(s) to InPort(s) of this node
00056       map< string , int >   _MapOfLinkedFromNodes ;
00057       int                   _LinkedFromNodesSize ;
00058       vector<StreamNode * > _LinkedFromNodes ;
00059       vector<int >          _LinkedFromInPortsNumber ;
00060 
00061 // Nodes with InStreamPort(s) linked to OutStreamport(s) of this node :
00062 // NodeName <--> index of that linked node in _LinkedNodes
00063       map< string , int >   _MapOfLinkedStreamNodes ;
00064       int                   _LinkedStreamNodesSize ;
00065       vector<StreamNode * > _LinkedStreamNodes ;
00066       vector<int >          _LinkedInStreamPortsNumber ;
00067 
00068       bool                  _NodeDoneInBranchOfSwitch ;
00069 
00070       bool                  _HeadNode ;
00071       int                   _LevelNumber ;
00072       int                   _SortedIndex ;
00073 
00074       GraphEditor::DataFlow   * _GraphEditor ;
00075 // If DataFlowGraph/DataStreamGraph in another graph :
00076 // the Graph if MacroNode and MacroNode if Graph
00077       SUPERV::Graph_var       _GraphMacroNode ;
00078       GraphBase::Graph        * _GraphOfNode ;
00079 
00080       int                   _GraphMacroLevel ;
00081       int                   _SubGraphNumber ;
00082       int                   _SubStreamGraphNumber ;
00083 
00084     protected:
00085 
00086       int                  * _Graph_prof_debug ;
00087       ofstream             * _Graph_fdebug ;
00088 
00089       StreamNode() ;
00090 
00091       StreamNode( const char * NodeName ,
00092                   const SUPERV::KindOfNode DataFlowkind ,
00093                   int * Graph_prof_debug ,
00094                   ofstream * Graph_fdebug ) ;
00095 
00096       StreamNode( int * Graph_prof_debug ,
00097                   ofstream * Graph_fdebug ) ;
00098 
00099       virtual ~StreamNode() ;
00100 
00101     public:
00102 
00103 //JR 17.02.2005 Memory Leak      char * Name() const { return my_strdup( _Name ) ; } ;
00104       char * Name() const {
00105 //             cdebug << "StreamNode::Name " << (void * ) _Name << " = " << _Name << endl ;
00106 //JR 21.02.2005 Memory Leak             return my_strdup( _Name ) ; } ;
00107              return _Name ; } ;
00108       const char *const * NamePtr() const {
00109 //            cdebug << "StreamNode::NamePtr " << (void ** ) &_Name << " = Name " << (void * ) _Name
00110 //                   << " = " << _Name << endl ;
00111             return &_Name ; } ;
00112       bool Name( const char * aName ) ;
00113 
00114       SUPERV::KindOfNode Kind() const {
00115             return _Kind; } ;
00116       bool Kind( SUPERV::KindOfNode aKind) {
00117         _Kind = aKind ;
00118         return true ; } ;
00119       const bool IsComputingNode() const {
00120             return (Kind() == SUPERV::ComputingNode ) ; } ;
00121       const bool IsFactoryNode() const {
00122             return (Kind() == SUPERV::FactoryNode ) ; } ;
00123       const bool IsOneOfGOTONodes() const {
00124             return (Kind() == SUPERV::LoopNode ||
00125                     Kind() == SUPERV::EndLoopNode ||
00126                     Kind() == SUPERV::SwitchNode ||
00127                     Kind() == SUPERV::EndSwitchNode ||
00128                     Kind() == SUPERV::GOTONode ||
00129                     Kind() == SUPERV::MacroNode ) ; } ;
00130       const bool IsOneOfInLineNodes() const {
00131             return (Kind() == SUPERV::InLineNode || IsOneOfGOTONodes() ) ; } ;
00132       const bool IsInLineNode() const {
00133             return (Kind() == SUPERV::InLineNode ) ; } ;
00134       const bool IsMacroNode() const {
00135             return (Kind() == SUPERV::MacroNode ) ; } ;
00136       const bool IsDataFlowNode() const {
00137             return (Kind() == SUPERV::DataFlowGraph ) ; } ;
00138       const bool IsDataStreamNode() const {
00139             return (Kind() == SUPERV::DataStreamGraph ) ; } ;
00140       const bool IsLoopNode() const {
00141             return (Kind() == SUPERV::LoopNode ) ; } ;
00142       const bool IsEndLoopNode() const {
00143             return (Kind() == SUPERV::EndLoopNode ) ; } ;
00144       const bool IsSwitchNode() const {
00145             return (Kind() == SUPERV::SwitchNode ) ; } ;
00146       const bool IsEndSwitchNode() const {
00147             return (Kind() == SUPERV::EndSwitchNode ) ; } ;
00148       const bool IsGOTONode() const {
00149             return (Kind() == SUPERV::GOTONode ) ; } ;
00150 
00151       int GetLinkedNodeIndex( const char * name ) {
00152           int index = _MapOfLinkedNodes[ name ] -1 ;
00153           if ( index >= 0 ) {
00154             cdebug << "GetLinkedNodeIndex of " << name
00155                    << " in _MapOfLinkedNodes : "
00156                    << index << " Node " << hex << (void *) _LinkedNodes[ index ]
00157                    << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
00158                    << endl ;
00159        }
00160           return index ; } ;
00161       void SetLinkedNodeIndex( const char * name , const int index ) {
00162           _MapOfLinkedNodes[ name ] = index +1 ;
00163           cdebug << "SetLinkedNodeIndex of " << name << " in _MapOfLinkedNodes : index "
00164                  << index << " of " << Name() << " Node " << hex << (void *) _LinkedNodes[ index ]
00165                  << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
00166                  << " _MapOfLinkedNodes " << _MapOfLinkedNodes[ name ] - 1
00167                  << endl ;
00168           } ;
00169       void DelLinkedNodeIndex( const char * name ) {
00170            _MapOfLinkedNodes.erase( name ) ; } ;
00171 
00172       int LinkedNodesSize() const { return _LinkedNodesSize ; } ;
00173 
00174       const int LinkedInPortsNumber( int i ) const { return _LinkedInPortsNumber[ i ] ; } ;
00175       void IncrLinkedInPortsNumber( int i ) {
00176            cdebug << Name() << "->IncrLinkedInPortsNumber LinkedInPortsNumber --> "
00177                   << _LinkedInPortsNumber[ i ] + 1 << endl ;
00178            _LinkedInPortsNumber[ i ]++ ; } ;
00179       void DecrLinkedInPortsNumber( int i ) {
00180            cdebug << Name() << "->DecrLinkedInPortsNumber LinkedInPortsNumber --> "
00181                   << _LinkedInPortsNumber[ i ] - 1 << endl ;
00182            _LinkedInPortsNumber[ i ]-- ; } ;
00183 
00184       StreamNode * LinkedNodes( int i ) const { return _LinkedNodes[ i ] ; } ;
00185 
00186       int GetLinkedFromNodeIndex( const char * name ) {
00187           int index = _MapOfLinkedFromNodes[ name ] -1 ;
00188           if ( index >= 0 ) {
00189             cdebug << "StreamNode::GetLinkedFromNodeIndex of " << name
00190                    << " in _MapOfLinkedFromNodes : "
00191                    << index << " FromNode " << hex << (void *) _LinkedFromNodes[ index ]
00192                    << dec << " '" << _LinkedFromNodes[ index ]->Name() << "'"
00193                    << endl ;
00194        }
00195           else {
00196             cdebug << "StreamNode::GetLinkedFromNodeIndex of " << name
00197                    << " in _MapOfLinkedFromNodes not found. Known nodes :" << endl ;
00198 #if 0
00199             map< string , int >::iterator aMapOfLinkedFromNodesIterator1 ;
00200             int iifrom = 0 ;
00201             for ( aMapOfLinkedFromNodesIterator1 = ToNode->_MapOfLinkedFromNodes.begin() ;
00202                   aMapOfLinkedFromNodesIterator1 != ToNode->_MapOfLinkedFromNodes.end() &&
00203                   iifrom < ToNode->_LinkedFromNodesSize ; aMapOfLinkedFromNodesIterator1++ ) {
00204               if ( aMapOfLinkedFromNodesIterator1->second ) {
00205                 cdebug << "_MapOfLinkedFromNodes" << iifrom++ << " of " << ToNode->Name() << " : "
00206                        << aMapOfLinkedFromNodesIterator1->first << " --> "
00207                        << aMapOfLinkedFromNodesIterator1->second << " "
00208                        << ToNode->_LinkedFromNodes[ aMapOfLinkedFromNodesIterator1->second - 1 ]->Name()
00209                        << endl ;
00210               }
00211               else {
00212                 cdebug << "_MapOfLinkedFromNodes" << iifrom << " of " << ToNode->Name() << " : "
00213                        << aMapOfLinkedFromNodesIterator1->second - 1 << endl ;
00214            }
00215          }
00216 #endif
00217        }
00218           return index ; } ;
00219       void SetLinkedFromNodeIndex( const char * name , const int index ) {
00220           _MapOfLinkedFromNodes[ name ] = index +1 ;
00221           cdebug << "SetLinkedFromNodeIndex of " << name << " in _MapOfLinkedFromNodes : index "
00222                  << index << " of " << Name() << " FromNode " << hex
00223                  << (void *) _LinkedFromNodes[ index ]
00224                  << dec << " '" << _LinkedFromNodes[ index ]->Name() << "'"
00225                  << " _MapOfLinkedFromNodes " << _MapOfLinkedFromNodes[ name ] - 1
00226                  << endl ;
00227           } ;
00228       void DelLinkedFromNodeIndex( const char * name ) {
00229            _MapOfLinkedFromNodes.erase( name ) ; } ;
00230 
00231       int LinkedFromNodesSize() const {
00232           return _LinkedFromNodesSize ; } ;
00233       void DecrLinkedFromNodesSize() {
00234            _LinkedFromNodesSize-- ; } ;
00235 
00236       const int LinkedFromInPortsNumber( int i ) const {
00237             return _LinkedFromInPortsNumber[ i ] ; } ;
00238       void IncrLinkedFromInPortsNumber( int i ) {
00239            cdebug << Name() << "->IncrLinkedFromInPortsNumber LinkedFromInPortsNumber --> "
00240                   << _LinkedFromInPortsNumber[ i ] + 1 << endl ;
00241            _LinkedFromInPortsNumber[ i ]++ ; } ;
00242       void DecrLinkedFromInPortsNumber( int i ) {
00243            cdebug << Name() << "->DecrLinkedFromInPortsNumber LinkedFromInPortsNumber --> "
00244                   << _LinkedFromInPortsNumber[ i ] - 1 << endl ;
00245            _LinkedFromInPortsNumber[ i ]-- ; } ;
00246 
00247       StreamNode * LinkedFromNodes( int i ) const { return _LinkedFromNodes[ i ] ; } ;
00248 
00249       int GetLinkedStreamNodeIndex( const char * name ) {
00250           int index = _MapOfLinkedStreamNodes[ name ] -1 ;
00251           if ( index >= 0 ) {
00252             cdebug << "GetLinkedStreamNodeIndex of " << name
00253                    << " in _MapOfLinkedStreamNodes : "
00254                    << index << " Node " << hex << (void *) _LinkedStreamNodes[ index ]
00255                    << dec << " '" << _LinkedStreamNodes[ index ]->Name() << "'"
00256                    << endl ;
00257        }
00258           return index ; } ;
00259       void SetLinkedStreamNodeIndex( const char * name , const int index ) {
00260           _MapOfLinkedStreamNodes[ name ] = index +1 ;
00261           cdebug << "SetLinkedStreamNodeIndex of " << name << " in _MapOfLinkedStreamNodes : "
00262                  << index << " Node " << hex << (void *) _LinkedStreamNodes[ index ]
00263                  << dec << " '" << _LinkedStreamNodes[ index ]->Name() << "'"
00264                  << " _MapOfLinkedStreamNodes " << _MapOfLinkedStreamNodes[ name ] - 1
00265                  << endl ;
00266           } ;
00267       void DelLinkedStreamNodeIndex( const char * name ) {
00268            _MapOfLinkedStreamNodes.erase( name ) ; } ;
00269 
00270       int LinkedStreamNodesSize() const { return _LinkedStreamNodesSize ; } ;
00271 
00272       const int LinkedInStreamPortsNumber( int i ) const {
00273             return _LinkedInStreamPortsNumber[ i ] ; } ;
00274 
00275       StreamNode * LinkedStreamNodes( int i ) const {
00276                    return _LinkedStreamNodes[ i ] ; } ;
00277 
00278       bool BranchOfSwitchDone( bool aNodeDoneInBranchOfSwitch ) {
00279            bool prevalue = _NodeDoneInBranchOfSwitch ;
00280            _NodeDoneInBranchOfSwitch = aNodeDoneInBranchOfSwitch ;
00281            if ( prevalue && !aNodeDoneInBranchOfSwitch ) {
00282              return false ;
00283         }
00284            return true ; } ;
00285       bool BranchOfSwitchDone() {
00286            return _NodeDoneInBranchOfSwitch ; } ;
00287 
00288       void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
00289       const bool IsHeadNode() const { return _HeadNode ; } ;
00290 
00291       int Level() const { return _LevelNumber ; } ;
00292       void Level( int LevelNumber ) {
00293            _LevelNumber = LevelNumber ; } ;
00294 
00295       void SortedIndex( int aSortedIndex ) {
00296            _SortedIndex = aSortedIndex ; } ;
00297       int SortedIndex() const {
00298            return _SortedIndex ; } ;
00299 
00300       void SetSubStreamGraph( int SubStreamGraphsNumber , int & RetVal ) ;
00301 
00302       void GraphEditor( GraphEditor::DataFlow * aGraphEditor ) {
00303            cdebug << "StreamNode::GraphEditor this " << this << " " << Name() << " : _GraphEditor = " << aGraphEditor << endl ;
00304            _GraphEditor = aGraphEditor ; } ;
00305       GraphEditor::DataFlow * GraphEditor() const {
00306            cdebug << "StreamNode::GraphEditor this " << this << " " << Name() << " : " << _GraphEditor << endl ;
00307                           return _GraphEditor ; } ;
00308 
00309       void GraphMacroLevel( int aGraphMacroLevel ) {
00310            cdebug << "GraphMacroLevel " << Name() << " " << aGraphMacroLevel << endl ;
00311            _GraphMacroLevel = aGraphMacroLevel ; } ;
00312       int GraphMacroLevel() const {
00313           return _GraphMacroLevel ; } ;
00314 
00315       void MacroObject( SUPERV::Graph_var aGraphMacroNode ) {
00316            if ( CORBA::is_nil( aGraphMacroNode ) ) {
00317              cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
00318                     << " MacroObject(nil object). Error" << endl ;
00319         }
00320            else {
00321              cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
00322                     << " MacroObject " << _GraphMacroNode << endl ;
00323         }
00324            _GraphMacroNode = aGraphMacroNode ; } ;
00325       SUPERV::Graph_var MacroObject() const {
00326                         if ( CORBA::is_nil( _GraphMacroNode ) ) {
00327                           cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
00328                                  << " returns nil object. Error" << endl ;
00329                      }
00330                         return _GraphMacroNode ; } ;
00331 
00332       void GraphOfNode( GraphBase::Graph * aGraph ) {
00333            _GraphOfNode = aGraph ; } ;
00334       GraphBase::Graph * GraphOfNode() const {
00335                          return _GraphOfNode ; } ;
00336       GraphBase::Graph * GraphOfNode() {
00337                          return _GraphOfNode ; } ;
00338 
00339       int SubGraph() const { return _SubGraphNumber ; } ;
00340       void SubGraph( int SubGraphNumber ) {
00341            _SubGraphNumber = SubGraphNumber ; } ;
00342 
00343       int SubStreamGraph() const { return _SubStreamGraphNumber ; } ;
00344       void SubStreamGraph( int SubStreamGraphNumber ) {
00345            _SubStreamGraphNumber = SubStreamGraphNumber ; } ;
00346 
00347       void AddLinkedNode( StreamNode * ToNode ) ;
00348       bool RemoveLinkedNode( StreamNode * ToNode ,
00349                              bool DoLinkedFromNode = true ) ;
00350       void ReNameLinkedNode( const char* OldNodeName ,
00351                              const char* NewNodeName ) ;
00352       void ReNameLinkedFromNode( const char* OldNodeName ,
00353                                  const char* NewNodeName ) ;
00354 
00355       void AddStreamLinkedNode( StreamNode * ToNode ) ;
00356       bool RemoveStreamLinkedNode( StreamNode * ToNode ) ;
00357       void ReNameStreamLinkedNode( const char* OldNodeName ,
00358                                    const char* NewNodeName ) ;
00359 
00360   };
00361   
00362 };
00363 
00364 #endif