Belle II Software light-2406-ragdoll
PathIterator.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/core/Path.h>
12#include <memory>
13
14
15namespace Belle2 {
21 class Module;
22
27 public:
29 explicit PathIterator(const PathPtr& path) :
30 m_path(path),
31 m_iter(path->m_elements.begin()),
32 m_end(path->m_elements.end()),
34 {
36 }
37
39 explicit PathIterator(const PathPtr& path, const PathIterator& parentIterator) :
40 m_path(path),
41 m_iter(path->m_elements.begin()),
42 m_end(path->m_elements.end()),
43 m_parentIterator(new PathIterator(parentIterator))
44 {
46 }
47
49 void next()
50 {
51 if (!isDone())
52 ++m_iter;
54 }
55
58 {
59 if (!isDone() and dynamic_cast<Path*>(m_iter->get())) {
60 //we're pointing to another Path
61 *this = PathIterator(std::static_pointer_cast<Path>(*m_iter), *this);
62 }
63 //check _afterwards_ if we need to jump back up
64 if (isDone() and m_parentIterator) {
65 //jump back to parent iterator
66 *this = *(m_parentIterator.get());
67 next(); //go to next module
68 }
69 }
70
72 bool isDone() const { return (m_iter == m_end); }
73
75 Module* get() const { return dynamic_cast<Module*>(m_iter->get()); }
76
77
78 private:
80 std::list<std::shared_ptr<PathElement> >::const_iterator m_iter;
81 std::list<std::shared_ptr<PathElement> >::const_iterator m_end;
82 std::shared_ptr<PathIterator> m_parentIterator;
83 };
84
86} // end namespace Belle2
Base class for Modules.
Definition: Module.h:72
Iterator over a Path (returning Module pointers).
Definition: PathIterator.h:26
void next()
increment.
Definition: PathIterator.h:49
bool isDone() const
Are we finished iterating?
Definition: PathIterator.h:72
PathIterator(const PathPtr &path)
Constructor.
Definition: PathIterator.h:29
std::shared_ptr< PathIterator > m_parentIterator
If this is non-NULL, we jump to m_parentIterator+1 after m_iter is done.
Definition: PathIterator.h:82
std::list< std::shared_ptr< PathElement > >::const_iterator m_end
iterator to end of Path.
Definition: PathIterator.h:81
std::list< std::shared_ptr< PathElement > >::const_iterator m_iter
wrapped path list iterator.
Definition: PathIterator.h:80
PathPtr m_path
keep the path around to ensure iterators remain valid.
Definition: PathIterator.h:79
Module * get() const
dereference.
Definition: PathIterator.h:75
PathIterator(const PathPtr &path, const PathIterator &parentIterator)
Constructor with back-reference to an iterator over the parent path.
Definition: PathIterator.h:39
void descendIfNecessary()
Check if we're pointing to another path and descend if that is the case.
Definition: PathIterator.h:57
Implements a path consisting of Module and/or Path objects.
Definition: Path.h:38
std::shared_ptr< Path > PathPtr
Defines a pointer to a path object as a boost shared pointer.
Definition: Path.h:35
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24