Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add WakeupTreeIterator and WakeupTree skeletons
[simgrid.git] / src / mc / explo / odpor / WakeupTreeIterator.hpp
1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_MC_ODPOR_WAKEUP_TREE_ITERATOR_HPP
7 #define SIMGRID_MC_ODPOR_WAKEUP_TREE_ITERATOR_HPP
8
9 #include "src/mc/explo/odpor/WakeupTree.hpp"
10
11 #include <boost/iterator/iterator_facade.hpp>
12 #include <list>
13 #include <stack>
14
15 namespace simgrid::mc::odpor {
16
17 struct WakeupTreeIterator
18     : public boost::iterator_facade<WakeupTreeIterator, const WakeupTreeNode*, boost::forward_traversal_tag> {
19 public:
20   WakeupTreeIterator() = default;
21   explicit WakeupTreeIterator(const WakeupTree& tree);
22
23 private:
24   using node_handle = std::list<const WakeupTreeNode*>::iterator;
25
26   /**
27    * @brief The current "view" of the iteration in post-order traversal
28    */
29   std::stack<node_handle> post_order_iteration;
30
31   /**
32    *
33    */
34   void push_until_left_most_found();
35
36   // boost::iterator_facade<...> interface to implement
37   void increment();
38   bool equal(const WakeupTreeIterator& other) const { return post_order_iteration == other.post_order_iteration; }
39   const WakeupTreeNode*& dereference() const { return *post_order_iteration.top(); }
40
41   // Allows boost::iterator_facade<...> to function properly
42   friend class boost::iterator_core_access;
43 };
44
45 } // namespace simgrid::mc::odpor
46 #endif