Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
ancestor_iterator.h
1 #pragma once
2 
3 #include <cstdint>
4 #include <iterator>
5 
6 namespace smlt {
7 
8 class StageNode;
9 
10 template<bool IsConst>
12 public:
13  using iterator_category = std::forward_iterator_tag;
14  using value_type = StageNode;
15  using difference_type = uint32_t;
16 
17  using pointer = typename std::conditional<
18  IsConst, const StageNode*, StageNode*
19  >::type;
20 
21  using reference = typename std::conditional<
22  IsConst, const StageNode&, StageNode&
23  >::type;
24 
25  bool operator==(const AncestorIterator& rhs) const {
26  return current_ == rhs.current_;
27  }
28 
29  bool operator!=(const AncestorIterator& rhs) const {
30  return !(*this == rhs);
31  }
32 
33  AncestorIterator& operator++();
34 
35  /* Non-const versions */
36  template<bool _IsConst=IsConst>
37  typename std::enable_if<!_IsConst, pointer>::type
38  operator->() {
39  return current_;
40  }
41 
42  template<bool _IsConst=IsConst>
43  typename std::enable_if<!_IsConst, reference>::type
44  operator*() {
45  return *current_;
46  }
47 
48  /* Const versions */
49  template<bool _IsConst=IsConst>
50  typename std::enable_if<_IsConst, pointer>::type
51  operator->() const {
52  return current_;
53  }
54 
55  template<bool _IsConst=IsConst>
56  typename std::enable_if<_IsConst, reference>::type
57  operator*() const {
58  return *current_;
59  }
60 
61 private:
62  friend class StageNode;
63 
65  AncestorIterator(StageNode* start, StageNode* current);
66 
67  StageNode* start_ = nullptr;
68  StageNode* current_ = nullptr;
69 };
70 
71 }
smlt
Definition: animation.cpp:25
smlt::StageNode
Definition: stage_node.h:61
smlt::AncestorIterator
Definition: ancestor_iterator.h:11