Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
sibling_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 SiblingIterator& rhs) const {
26  return start_ == rhs.start_ && current_ == rhs.current_;
27  }
28 
29  bool operator!=(const SiblingIterator& rhs) const {
30  return !(*this == rhs);
31  }
32 
33  SiblingIterator& 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  SiblingIterator(StageNode* start);
64  SiblingIterator(StageNode* start, StageNode* current);
65 
66  StageNode* start_ = nullptr;
67  StageNode* current_ = nullptr;
68 };
69 
70 }
smlt::SiblingIterator
Definition: sibling_iterator.h:11
smlt
Definition: animation.cpp:25
smlt::StageNode
Definition: stage_node.h:62