1 // SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : DataFlowBase_StreamNode.hxx
8 // Author : Jean Rahuel
12 #ifndef _DATAFLOWBASE_STREAMNODE_HXX
13 #define _DATAFLOWBASE_STREAMNODE_HXX
15 #include "DataFlowBase_PortsOfNode.hxx"
17 namespace GraphEditor {
27 class StreamNode : public PortsOfNode {
32 SUPERV::KindOfNode _Kind ;
34 // _LinkedNodes are the nodes with link(s) from OutPort(s) of this node
35 // Nodes with LinkedInPortsNumber InPort(s) linked to Outport(s) of this node :
36 map< string , int > _MapOfLinkedNodes ;
37 int _LinkedNodesSize ;
38 vector<StreamNode * > _LinkedNodes ;
39 vector<int > _LinkedInPortsNumber ;
41 // _LinkedFromNodes are the nodes with link(s) to InPort(s) of this node
42 map< string , int > _MapOfLinkedFromNodes ;
43 int _LinkedFromNodesSize ;
44 vector<StreamNode * > _LinkedFromNodes ;
45 vector<int > _LinkedFromInPortsNumber ;
47 // Nodes with InStreamPort(s) linked to OutStreamport(s) of this node :
48 // NodeName <--> index of that linked node in _LinkedNodes
49 map< string , int > _MapOfLinkedStreamNodes ;
50 int _LinkedStreamNodesSize ;
51 vector<StreamNode * > _LinkedStreamNodes ;
52 vector<int > _LinkedInStreamPortsNumber ;
54 bool _NodeDoneInBranchOfSwitch ;
60 GraphEditor::DataFlow * _GraphEditor ;
61 // If DataFlowGraph/DataStreamGraph in another graph :
62 // the Graph if MacroNode and MacroNode if Graph
63 SUPERV::Graph_var _GraphMacroNode ;
64 GraphBase::Graph * _GraphOfNode ;
66 int _GraphMacroLevel ;
68 int _SubStreamGraphNumber ;
72 int * _Graph_prof_debug ;
73 ofstream * _Graph_fdebug ;
77 StreamNode( const char * NodeName ,
78 const SUPERV::KindOfNode DataFlowkind ,
79 int * Graph_prof_debug ,
80 ofstream * Graph_fdebug ) ;
82 StreamNode( int * Graph_prof_debug ,
83 ofstream * Graph_fdebug ) ;
85 virtual ~StreamNode() ;
89 //JR 17.02.2005 Memory Leak char * Name() const { return my_strdup( _Name ) ; } ;
91 // cdebug << "StreamNode::Name " << (void * ) _Name << " = " << _Name << endl ;
92 //JR 21.02.2005 Memory Leak return my_strdup( _Name ) ; } ;
94 const char *const * NamePtr() const {
95 // cdebug << "StreamNode::NamePtr " << (void ** ) &_Name << " = Name " << (void * ) _Name
96 // << " = " << _Name << endl ;
98 bool Name( const char * aName ) ;
100 SUPERV::KindOfNode Kind() const {
102 bool Kind( SUPERV::KindOfNode aKind) {
105 const bool IsComputingNode() const {
106 return (Kind() == SUPERV::ComputingNode ) ; } ;
107 const bool IsFactoryNode() const {
108 return (Kind() == SUPERV::FactoryNode ) ; } ;
109 const bool IsOneOfGOTONodes() const {
110 return (Kind() == SUPERV::LoopNode ||
111 Kind() == SUPERV::EndLoopNode ||
112 Kind() == SUPERV::SwitchNode ||
113 Kind() == SUPERV::EndSwitchNode ||
114 Kind() == SUPERV::GOTONode ||
115 Kind() == SUPERV::MacroNode ) ; } ;
116 const bool IsOneOfInLineNodes() const {
117 return (Kind() == SUPERV::InLineNode || IsOneOfGOTONodes() ) ; } ;
118 const bool IsInLineNode() const {
119 return (Kind() == SUPERV::InLineNode ) ; } ;
120 const bool IsMacroNode() const {
121 return (Kind() == SUPERV::MacroNode ) ; } ;
122 const bool IsDataFlowNode() const {
123 return (Kind() == SUPERV::DataFlowGraph ) ; } ;
124 const bool IsDataStreamNode() const {
125 return (Kind() == SUPERV::DataStreamGraph ) ; } ;
126 const bool IsLoopNode() const {
127 return (Kind() == SUPERV::LoopNode ) ; } ;
128 const bool IsEndLoopNode() const {
129 return (Kind() == SUPERV::EndLoopNode ) ; } ;
130 const bool IsSwitchNode() const {
131 return (Kind() == SUPERV::SwitchNode ) ; } ;
132 const bool IsEndSwitchNode() const {
133 return (Kind() == SUPERV::EndSwitchNode ) ; } ;
134 const bool IsGOTONode() const {
135 return (Kind() == SUPERV::GOTONode ) ; } ;
137 int GetLinkedNodeIndex( const char * name ) {
138 int index = _MapOfLinkedNodes[ name ] -1 ;
140 cdebug << "GetLinkedNodeIndex of " << name
141 << " in _MapOfLinkedNodes : "
142 << index << " Node " << hex << (void *) _LinkedNodes[ index ]
143 << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
147 void SetLinkedNodeIndex( const char * name , const int index ) {
148 _MapOfLinkedNodes[ name ] = index +1 ;
149 cdebug << "SetLinkedNodeIndex of " << name << " in _MapOfLinkedNodes : index "
150 << index << " of " << Name() << " Node " << hex << (void *) _LinkedNodes[ index ]
151 << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
152 << " _MapOfLinkedNodes " << _MapOfLinkedNodes[ name ] - 1
155 void DelLinkedNodeIndex( const char * name ) {
156 _MapOfLinkedNodes.erase( name ) ; } ;
158 int LinkedNodesSize() const { return _LinkedNodesSize ; } ;
160 const int LinkedInPortsNumber( int i ) const { return _LinkedInPortsNumber[ i ] ; } ;
161 void IncrLinkedInPortsNumber( int i ) {
162 cdebug << Name() << "->IncrLinkedInPortsNumber LinkedInPortsNumber --> "
163 << _LinkedInPortsNumber[ i ] + 1 << endl ;
164 _LinkedInPortsNumber[ i ]++ ; } ;
165 void DecrLinkedInPortsNumber( int i ) {
166 cdebug << Name() << "->DecrLinkedInPortsNumber LinkedInPortsNumber --> "
167 << _LinkedInPortsNumber[ i ] - 1 << endl ;
168 _LinkedInPortsNumber[ i ]-- ; } ;
170 StreamNode * LinkedNodes( int i ) const { return _LinkedNodes[ i ] ; } ;
172 int GetLinkedFromNodeIndex( const char * name ) {
173 int index = _MapOfLinkedFromNodes[ name ] -1 ;
175 cdebug << "StreamNode::GetLinkedFromNodeIndex of " << name
176 << " in _MapOfLinkedFromNodes : "
177 << index << " FromNode " << hex << (void *) _LinkedFromNodes[ index ]
178 << dec << " '" << _LinkedFromNodes[ index ]->Name() << "'"
182 cdebug << "StreamNode::GetLinkedFromNodeIndex of " << name
183 << " in _MapOfLinkedFromNodes not found. Known nodes :" << endl ;
185 map< string , int >::iterator aMapOfLinkedFromNodesIterator1 ;
187 for ( aMapOfLinkedFromNodesIterator1 = ToNode->_MapOfLinkedFromNodes.begin() ;
188 aMapOfLinkedFromNodesIterator1 != ToNode->_MapOfLinkedFromNodes.end() &&
189 iifrom < ToNode->_LinkedFromNodesSize ; aMapOfLinkedFromNodesIterator1++ ) {
190 if ( aMapOfLinkedFromNodesIterator1->second ) {
191 cdebug << "_MapOfLinkedFromNodes" << iifrom++ << " of " << ToNode->Name() << " : "
192 << aMapOfLinkedFromNodesIterator1->first << " --> "
193 << aMapOfLinkedFromNodesIterator1->second << " "
194 << ToNode->_LinkedFromNodes[ aMapOfLinkedFromNodesIterator1->second - 1 ]->Name()
198 cdebug << "_MapOfLinkedFromNodes" << iifrom << " of " << ToNode->Name() << " : "
199 << aMapOfLinkedFromNodesIterator1->second - 1 << endl ;
205 void SetLinkedFromNodeIndex( const char * name , const int index ) {
206 _MapOfLinkedFromNodes[ name ] = index +1 ;
207 cdebug << "SetLinkedFromNodeIndex of " << name << " in _MapOfLinkedFromNodes : index "
208 << index << " of " << Name() << " FromNode " << hex
209 << (void *) _LinkedFromNodes[ index ]
210 << dec << " '" << _LinkedFromNodes[ index ]->Name() << "'"
211 << " _MapOfLinkedFromNodes " << _MapOfLinkedFromNodes[ name ] - 1
214 void DelLinkedFromNodeIndex( const char * name ) {
215 _MapOfLinkedFromNodes.erase( name ) ; } ;
217 int LinkedFromNodesSize() const {
218 return _LinkedFromNodesSize ; } ;
219 void DecrLinkedFromNodesSize() {
220 _LinkedFromNodesSize-- ; } ;
222 const int LinkedFromInPortsNumber( int i ) const {
223 return _LinkedFromInPortsNumber[ i ] ; } ;
224 void IncrLinkedFromInPortsNumber( int i ) {
225 cdebug << Name() << "->IncrLinkedFromInPortsNumber LinkedFromInPortsNumber --> "
226 << _LinkedFromInPortsNumber[ i ] + 1 << endl ;
227 _LinkedFromInPortsNumber[ i ]++ ; } ;
228 void DecrLinkedFromInPortsNumber( int i ) {
229 cdebug << Name() << "->DecrLinkedFromInPortsNumber LinkedFromInPortsNumber --> "
230 << _LinkedFromInPortsNumber[ i ] - 1 << endl ;
231 _LinkedFromInPortsNumber[ i ]-- ; } ;
233 StreamNode * LinkedFromNodes( int i ) const { return _LinkedFromNodes[ i ] ; } ;
235 int GetLinkedStreamNodeIndex( const char * name ) {
236 int index = _MapOfLinkedStreamNodes[ name ] -1 ;
238 cdebug << "GetLinkedStreamNodeIndex of " << name
239 << " in _MapOfLinkedStreamNodes : "
240 << index << " Node " << hex << (void *) _LinkedStreamNodes[ index ]
241 << dec << " '" << _LinkedStreamNodes[ index ]->Name() << "'"
245 void SetLinkedStreamNodeIndex( const char * name , const int index ) {
246 _MapOfLinkedStreamNodes[ name ] = index +1 ;
247 cdebug << "SetLinkedStreamNodeIndex of " << name << " in _MapOfLinkedStreamNodes : "
248 << index << " Node " << hex << (void *) _LinkedStreamNodes[ index ]
249 << dec << " '" << _LinkedStreamNodes[ index ]->Name() << "'"
250 << " _MapOfLinkedStreamNodes " << _MapOfLinkedStreamNodes[ name ] - 1
253 void DelLinkedStreamNodeIndex( const char * name ) {
254 _MapOfLinkedStreamNodes.erase( name ) ; } ;
256 int LinkedStreamNodesSize() const { return _LinkedStreamNodesSize ; } ;
258 const int LinkedInStreamPortsNumber( int i ) const {
259 return _LinkedInStreamPortsNumber[ i ] ; } ;
261 StreamNode * LinkedStreamNodes( int i ) const {
262 return _LinkedStreamNodes[ i ] ; } ;
264 bool BranchOfSwitchDone( bool aNodeDoneInBranchOfSwitch ) {
265 bool prevalue = _NodeDoneInBranchOfSwitch ;
266 _NodeDoneInBranchOfSwitch = aNodeDoneInBranchOfSwitch ;
267 if ( prevalue && !aNodeDoneInBranchOfSwitch ) {
271 bool BranchOfSwitchDone() {
272 return _NodeDoneInBranchOfSwitch ; } ;
274 void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
275 const bool IsHeadNode() const { return _HeadNode ; } ;
277 int Level() const { return _LevelNumber ; } ;
278 void Level( int LevelNumber ) {
279 _LevelNumber = LevelNumber ; } ;
281 void SortedIndex( int aSortedIndex ) {
282 _SortedIndex = aSortedIndex ; } ;
283 int SortedIndex() const {
284 return _SortedIndex ; } ;
286 void SetSubStreamGraph( int SubStreamGraphsNumber , int & RetVal ) ;
288 void GraphEditor( GraphEditor::DataFlow * aGraphEditor ) {
289 cdebug << "StreamNode::GraphEditor this " << this << " " << Name() << " : _GraphEditor = " << aGraphEditor << endl ;
290 _GraphEditor = aGraphEditor ; } ;
291 GraphEditor::DataFlow * GraphEditor() const {
292 cdebug << "StreamNode::GraphEditor this " << this << " " << Name() << " : " << _GraphEditor << endl ;
293 return _GraphEditor ; } ;
295 void GraphMacroLevel( int aGraphMacroLevel ) {
296 cdebug << "GraphMacroLevel " << Name() << " " << aGraphMacroLevel << endl ;
297 _GraphMacroLevel = aGraphMacroLevel ; } ;
298 int GraphMacroLevel() const {
299 return _GraphMacroLevel ; } ;
301 void MacroObject( SUPERV::Graph_var aGraphMacroNode ) {
302 if ( CORBA::is_nil( aGraphMacroNode ) ) {
303 cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
304 << " MacroObject(nil object). Error" << endl ;
307 cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
308 << " MacroObject " << _GraphMacroNode << endl ;
310 _GraphMacroNode = aGraphMacroNode ; } ;
311 SUPERV::Graph_var MacroObject() const {
312 if ( CORBA::is_nil( _GraphMacroNode ) ) {
313 cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
314 << " returns nil object. Error" << endl ;
316 return _GraphMacroNode ; } ;
318 void GraphOfNode( GraphBase::Graph * aGraph ) {
319 _GraphOfNode = aGraph ; } ;
320 GraphBase::Graph * GraphOfNode() const {
321 return _GraphOfNode ; } ;
322 GraphBase::Graph * GraphOfNode() {
323 return _GraphOfNode ; } ;
325 int SubGraph() const { return _SubGraphNumber ; } ;
326 void SubGraph( int SubGraphNumber ) {
327 _SubGraphNumber = SubGraphNumber ; } ;
329 int SubStreamGraph() const { return _SubStreamGraphNumber ; } ;
330 void SubStreamGraph( int SubStreamGraphNumber ) {
331 _SubStreamGraphNumber = SubStreamGraphNumber ; } ;
333 void AddLinkedNode( StreamNode * ToNode ) ;
334 bool RemoveLinkedNode( StreamNode * ToNode ,
335 bool DoLinkedFromNode = true ) ;
336 void ReNameLinkedNode( const char* OldNodeName ,
337 const char* NewNodeName ) ;
338 void ReNameLinkedFromNode( const char* OldNodeName ,
339 const char* NewNodeName ) ;
341 void AddStreamLinkedNode( StreamNode * ToNode ) ;
342 bool RemoveStreamLinkedNode( StreamNode * ToNode ) ;
343 void ReNameStreamLinkedNode( const char* OldNodeName ,
344 const char* NewNodeName ) ;