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

Public Member Functions

 PreorderStrategy ()
 
virtual PreorderStrategyclone () 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 parents before their children.

Definition at line 36 of file IterationStrategy.h.

Constructor & Destructor Documentation

◆ PreorderStrategy()

PreorderStrategy::PreorderStrategy ( )
default

Referenced by clone().

Member Function Documentation

◆ clone()

PreorderStrategy * PreorderStrategy::clone ( ) const
virtual

Implements IterationStrategy.

Definition at line 21 of file IterationStrategy.cpp.

22 {
23  return new PreorderStrategy();
24 }

References PreorderStrategy().

Here is the call graph for this function:

◆ first()

IteratorMemento PreorderStrategy::first ( const INode p_root)
virtual

Implements IterationStrategy.

Definition at line 26 of file IterationStrategy.cpp.

27 {
28  IteratorMemento iterator_stack;
29  iterator_stack.push_state(IteratorState(p_root));
30  return iterator_stack;
31 }
Holds all iterator states encountered for SampleTreeIterator.
Definition: NodeIterator.h:56
void push_state(const IteratorState &state)
Definition: NodeIterator.h:61
Holds state of iterator at single level for SampleTreeIterator.
Definition: NodeIterator.h:27

References IteratorMemento::push_state().

Here is the call graph for this function:

◆ next()

void PreorderStrategy::next ( IteratorMemento iterator_stack) const
virtual

Implements IterationStrategy.

Definition at line 33 of file IterationStrategy.cpp.

34 {
35  const INode* node = iterator_stack.getCurrent();
36  ASSERT(node);
37  std::vector<const INode*> children = node->getChildren();
38  if (children.size() > 0) {
39  iterator_stack.push_state(IteratorState(children));
40  return;
41  }
42  iterator_stack.next();
43  while (!iterator_stack.empty() && iterator_stack.get_state().isEnd()) {
44  iterator_stack.pop_state();
45  if (!iterator_stack.empty())
46  iterator_stack.next();
47  }
48 }
#define ASSERT(condition)
Definition: Assert.h:26
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:49
virtual std::vector< const INode * > getChildren() const
Returns a vector of children (const).
Definition: INode.cpp:64
IteratorState & get_state()
Definition: NodeIterator.h:63
const INode * getCurrent()
Definition: NodeIterator.h:70
bool empty() const
Definition: NodeIterator.h:64
bool isEnd() const
Definition: NodeIterator.h:35

References ASSERT, IteratorMemento::empty(), 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 PreorderStrategy::isDone ( IteratorMemento iterator_stack) const
virtual

Implements IterationStrategy.

Definition at line 50 of file IterationStrategy.cpp.

51 {
52  return iterator_stack.empty();
53 }

References IteratorMemento::empty().

Here is the call graph for this function:

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