BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
PostorderStrategy Class Reference
Inheritance diagram for PostorderStrategy:
Collaboration diagram for PostorderStrategy:

Public Member Functions

 PostorderStrategy ()
 
virtual PostorderStrategyclone () const
 
virtual IteratorMemento first (const INode *p_root)
 
virtual void next (IteratorMemento &iterator_stack) const
 
virtual bool isDone (IteratorMemento &iterator_stack) const
 

Detailed Description

Traverse tree; visit children before their parents.

Definition at line 49 of file IterationStrategy.h.

Constructor & Destructor Documentation

◆ PostorderStrategy()

PostorderStrategy::PostorderStrategy ( )
default

Referenced by clone().

Member Function Documentation

◆ clone()

PostorderStrategy * PostorderStrategy::clone ( ) const
virtual

Implements IterationStrategy.

Definition at line 57 of file IterationStrategy.cpp.

58 {
59  return new PostorderStrategy();
60 }

References PostorderStrategy().

Here is the call graph for this function:

◆ first()

IteratorMemento PostorderStrategy::first ( const INode p_root)
virtual

Implements IterationStrategy.

Definition at line 62 of file IterationStrategy.cpp.

63 {
64  IteratorMemento iterator_stack;
65  iterator_stack.push_state(IteratorState(p_root));
66  std::vector<const INode*> children = p_root->getChildren();
67  while (children.size() > 0) {
68  iterator_stack.push_state(IteratorState(children));
69  children = iterator_stack.getCurrent()->getChildren();
70  }
71  return iterator_stack;
72 }
virtual std::vector< const INode * > getChildren() const
Returns a vector of children (const).
Definition: INode.cpp:64
Holds all iterator states encountered for SampleTreeIterator.
Definition: NodeIterator.h:56
const INode * getCurrent()
Definition: NodeIterator.h:70
void push_state(const IteratorState &state)
Definition: NodeIterator.h:61
Holds state of iterator at single level for SampleTreeIterator.
Definition: NodeIterator.h:27

References INode::getChildren(), IteratorMemento::getCurrent(), and IteratorMemento::push_state().

Here is the call graph for this function:

◆ next()

void PostorderStrategy::next ( IteratorMemento iterator_stack) const
virtual

Implements IterationStrategy.

Definition at line 74 of file IterationStrategy.cpp.

75 {
76  iterator_stack.next();
77  if (iterator_stack.get_state().isEnd()) {
78  iterator_stack.pop_state();
79  return;
80  }
81  std::vector<const INode*> children = iterator_stack.getCurrent()->getChildren();
82  while (children.size() > 0) {
83  iterator_stack.push_state(IteratorState(children));
84  children = iterator_stack.getCurrent()->getChildren();
85  }
86 }
IteratorState & get_state()
Definition: NodeIterator.h:63
bool isEnd() const
Definition: NodeIterator.h:35

References IteratorMemento::get_state(), INode::getChildren(), IteratorMemento::getCurrent(), IteratorState::isEnd(), IteratorMemento::next(), IteratorMemento::pop_state(), and IteratorMemento::push_state().

Here is the call graph for this function:

◆ isDone()

bool PostorderStrategy::isDone ( IteratorMemento iterator_stack) const
virtual

Implements IterationStrategy.

Definition at line 88 of file IterationStrategy.cpp.

89 {
90  return iterator_stack.empty();
91 }
bool empty() const
Definition: NodeIterator.h:64

References IteratorMemento::empty().

Here is the call graph for this function:

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