COPASI API  4.16.103
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CMathDependencyNodeIterator Class Reference

#include <CMathDependencyNodeIterator.h>

Collaboration diagram for CMathDependencyNodeIterator:
Collaboration graph
[legend]

Classes

class  CStackElement
 

Public Types

typedef CMathFlags< StateFlag
 
enum  State {
  Start = 0x00, Before = 0x01, After = 0x02, Intermediate = 0x04,
  End = 0x08, Recursive = 0x10
}
 
enum  Type { Dependents, Prerequisites }
 

Public Member Functions

 CMathDependencyNodeIterator ()
 
 CMathDependencyNodeIterator (const CMathDependencyNodeIterator &src)
 
 CMathDependencyNodeIterator (CMathDependencyNode *pNode, const Type &type=Dependents)
 
Flag getProcessingModes () const
 
size_t level () const
 
bool next ()
 
CMathDependencyNodeoperator* ()
 
CMathDependencyNodeoperator-> ()
 
const CMathDependencyNodeparent ()
 
void setProcessingModes (const Flag &processingModes)
 
const StateskipChildren ()
 
const Statestate () const
 
 ~CMathDependencyNodeIterator ()
 

Private Member Functions

void increment ()
 

Private Attributes

State mCurrentState
 
Flag mProcessingModes
 
std::stack< CStackElementmStack
 
Type mType
 
std::set< const
CMathDependencyNode * > 
mVisited
 

Detailed Description

This class allows to iterator over the nodes of a dependency graph in both directions (Dependents and Prerequisites) which is indicated by the type.

Definition at line 27 of file CMathDependencyNodeIterator.h.

Member Typedef Documentation

A flag indicating to which state the iterator should advance. These may be any combination of the enumeration value State. Please note the iterator will always return and End and Recursive

Definition at line 58 of file CMathDependencyNodeIterator.h.

Member Enumeration Documentation

The state of the iterator. Please note that the graph might be recursive which will cause the iterator to stop.

Enumerator
Start 
Before 
After 
Intermediate 
End 
Recursive 

Definition at line 43 of file CMathDependencyNodeIterator.h.

Type defining whether we iterate over the dependents or prerequisites

Enumerator
Dependents 
Prerequisites 

Definition at line 33 of file CMathDependencyNodeIterator.h.

Constructor & Destructor Documentation

CMathDependencyNodeIterator::CMathDependencyNodeIterator ( )
CMathDependencyNodeIterator::CMathDependencyNodeIterator ( const CMathDependencyNodeIterator src)

Copy constructor

Parameters
constCMathDependencyNodeIterator & src

Definition at line 65 of file CMathDependencyNodeIterator.cpp.

CMathDependencyNodeIterator::CMathDependencyNodeIterator ( CMathDependencyNode pNode,
const Type type = Dependents 
)
CMathDependencyNodeIterator::~CMathDependencyNodeIterator ( )

Destructor

Definition at line 85 of file CMathDependencyNodeIterator.cpp.

86 {}

Member Function Documentation

CMathDependencyNodeIterator::Flag CMathDependencyNodeIterator::getProcessingModes ( ) const

Retrieve the valid states for which the method next() should return

Returns
Flag processingModes

Definition at line 223 of file CMathDependencyNodeIterator.cpp.

References End, mProcessingModes, and Recursive.

void CMathDependencyNodeIterator::increment ( )
private

This method advances the iterator to the next internal state. The tree is traversed depth first.

Please note that the iterator points to the same node multiple times, once before every child, and once after the last child to allow pre and post processing. This behavior is also true for childless nodes. To determine whether the iterator is in the pre, intermediate or post processing phase one may check the processing mode with: const State & state()

Definition at line 88 of file CMathDependencyNodeIterator.cpp.

References After, Before, End, Intermediate, mCurrentState, CMathDependencyNodeIterator::CStackElement::mEndChild, CMathDependencyNodeIterator::CStackElement::mItChild, CMathDependencyNodeIterator::CStackElement::mpNode, mStack, CMathDependencyNodeIterator::CStackElement::mType, mVisited, and Recursive.

Referenced by next().

89 {
90  // We must not further process any recursive
91  if (mCurrentState == Recursive)
92  {
93  mStack.pop();
94  }
95 
96  if (mStack.empty())
97  {
99 
100  return;
101  }
102 
103  CStackElement & Current = mStack.top();
104 
105  if (mCurrentState != After)
106  {
107  if (Current.mItChild != Current.mEndChild)
108  {
109  CMathDependencyNode * pNode = *Current.mItChild;
110 
111  mStack.push(CStackElement(*Current.mItChild, Current.mType, Current.mpNode));
112 
113  // This will process any children since the iterator is context unaware.
114  // It is therefore expected that we encounter recursive dependencies for
115  // intensive/extensive value pairs.
116  Current.mItChild++;
117 
118  if (mVisited.find(pNode) != mVisited.end())
119  {
120  // Indicate that this node is already in the stack and processing would lead to an
121  // infinite recursion.
123  }
124  else
125  {
126  mVisited.insert(pNode);
128  }
129 
130  return;
131  }
132 
133  if (Current.mItChild == Current.mEndChild)
134  {
136 
137  return;
138  }
139  }
140 
141  mVisited.erase(Current.mpNode);
142  mStack.pop();
143 
144  if (mStack.empty())
145  {
146  mCurrentState = End;
147 
148  return;
149  }
150 
151  CStackElement & Parent = mStack.top();
152 
153  if (Parent.mItChild != Parent.mEndChild)
154  {
156  }
157  else
158  {
160  }
161 
162  return;
163 }
std::stack< CStackElement > mStack
std::set< const CMathDependencyNode * > mVisited
size_t CMathDependencyNodeIterator::level ( ) const

Retrieve the current nesting level of the iterator

Returns
size_t level

Definition at line 213 of file CMathDependencyNodeIterator.cpp.

References mStack.

214 {
215  return mStack.size();
216 }
std::stack< CStackElement > mStack
bool CMathDependencyNodeIterator::next ( )

This method advances the iterator to the next node and state combination for which the state is in the Flag of processing modes. A return value of true indicates that such a node has been found whereas false indicates the iteration has been completed or failed. To determine the current state of the iterator use: const State & state()

Returns
bool success

Definition at line 165 of file CMathDependencyNodeIterator.cpp.

References Before, End, increment(), mCurrentState, mProcessingModes, and Start.

Referenced by CMathDependencyNode::buildUpdateSequence(), CMathDependencyNode::updateDependentState(), and CMathDependencyNode::updatePrerequisiteState().

CMathDependencyNode * CMathDependencyNodeIterator::operator* ( )

This operator dereferences the iterator and returns a pointer the node of the graph

Returns
CMathDependencyNode * pNode

Definition at line 193 of file CMathDependencyNodeIterator.cpp.

References mStack.

194 {
195  return mStack.top().mpNode;
196 }
std::stack< CStackElement > mStack
CMathDependencyNode * CMathDependencyNodeIterator::operator-> ( )

This operator dereferences the iterator and returns a pointer the node of the graph

Returns
CMathDependencyNode * pNode

Definition at line 198 of file CMathDependencyNodeIterator.cpp.

References mStack.

199 {
200  return mStack.top().mpNode;
201 }
std::stack< CStackElement > mStack
const CMathDependencyNode * CMathDependencyNodeIterator::parent ( )

Retrieve the pointer to the parent node of the current node if known otherwise NULL

Returns
const CMathDependencyNode * pParent

Definition at line 203 of file CMathDependencyNodeIterator.cpp.

References mStack.

Referenced by CMathDependencyNode::updateDependentState(), and CMathDependencyNode::updatePrerequisiteState().

204 {
205  return mStack.top().mpParent;
206 }
std::stack< CStackElement > mStack
void CMathDependencyNodeIterator::setProcessingModes ( const Flag processingModes)
const CMathDependencyNodeIterator::State & CMathDependencyNodeIterator::skipChildren ( )

Calling this method causes the iterator to skip processing the children of the current node and advance to the State to next state allowed by the processing mode

Returns
const State & state

Definition at line 184 of file CMathDependencyNodeIterator.cpp.

References After, mCurrentState, CMathDependencyNodeIterator::CStackElement::mEndChild, CMathDependencyNodeIterator::CStackElement::mItChild, and mStack.

Referenced by CMathDependencyNode::buildUpdateSequence(), CMathDependencyNode::updateDependentState(), and CMathDependencyNode::updatePrerequisiteState().

185 {
186  CStackElement & Current = mStack.top();
187  Current.mItChild = Current.mEndChild;
189 
190  return mCurrentState;
191 }
std::stack< CStackElement > mStack
const CMathDependencyNodeIterator::State & CMathDependencyNodeIterator::state ( ) const

Retrieve the current state of the iterator

Returns
const State & state

Definition at line 208 of file CMathDependencyNodeIterator.cpp.

References mCurrentState.

Referenced by CMathDependencyNode::buildUpdateSequence(), CMathDependencyNode::updateDependentState(), and CMathDependencyNode::updatePrerequisiteState().

209 {
210  return mCurrentState;
211 }

Member Data Documentation

State CMathDependencyNodeIterator::mCurrentState
private

The current state of the iterator

Definition at line 241 of file CMathDependencyNodeIterator.h.

Referenced by increment(), next(), skipChildren(), and state().

Flag CMathDependencyNodeIterator::mProcessingModes
private

The flag indicating to which state the iterator should advance. These may be any combination of the enumeration value State. Please note that this flag will always include return and End and Recursive

Definition at line 248 of file CMathDependencyNodeIterator.h.

Referenced by getProcessingModes(), next(), and setProcessingModes().

std::stack< CStackElement > CMathDependencyNodeIterator::mStack
private

A stack of context for each nesting level of the iterator

Definition at line 225 of file CMathDependencyNodeIterator.h.

Referenced by CMathDependencyNodeIterator(), increment(), level(), operator*(), operator->(), parent(), and skipChildren().

Type CMathDependencyNodeIterator::mType
private

The iterator type (Dependents or Prerequisites)

Definition at line 236 of file CMathDependencyNodeIterator.h.

Referenced by CMathDependencyNodeIterator().

std::set< const CMathDependencyNode * > CMathDependencyNodeIterator::mVisited
private

A set of currently visited nodes in the stack used to determine loops or recursive dependencies

Definition at line 231 of file CMathDependencyNodeIterator.h.

Referenced by CMathDependencyNodeIterator(), and increment().


The documentation for this class was generated from the following files: