Plasma Engine  2.0
Loading...
Searching...
No Matches
RangeView.h
1#pragma once
2
3#include <Foundation/Types/Delegate.h>
4
22template <typename ValueType, typename IteratorType>
24{
25public:
26 using BeginCallback = plDelegate<IteratorType()>;
27 using EndCallback = plDelegate<IteratorType()>;
28 using NextCallback = plDelegate<void(IteratorType&)>;
29 using ValueCallback = plDelegate<ValueType(const IteratorType&)>;
30
32 PL_ALWAYS_INLINE plRangeView(BeginCallback begin, EndCallback end, NextCallback next, ValueCallback value);
33
36 {
37 PL_DECLARE_POD_TYPE();
38
39 using iterator_category = std::forward_iterator_tag;
41 using pointer = ConstIterator*;
42 using reference = ConstIterator&;
43
44 PL_ALWAYS_INLINE ConstIterator(const ConstIterator& rhs) = default;
45 PL_FORCE_INLINE void Next();
46 PL_FORCE_INLINE ValueType Value() const;
47 PL_ALWAYS_INLINE ValueType operator*() const { return Value(); }
48 PL_ALWAYS_INLINE void operator++() { Next(); }
49 PL_FORCE_INLINE bool operator==(const typename plRangeView<ValueType, IteratorType>::ConstIterator& it2) const;
50 PL_FORCE_INLINE bool operator!=(const typename plRangeView<ValueType, IteratorType>::ConstIterator& it2) const;
51
52 protected:
53 PL_FORCE_INLINE explicit ConstIterator(const plRangeView<ValueType, IteratorType>* view, IteratorType pos);
54
55 friend class plRangeView<ValueType, IteratorType>;
56 const plRangeView<ValueType, IteratorType>* m_pView = nullptr;
57 IteratorType m_Pos;
58 };
59
61 struct Iterator : public ConstIterator
62 {
63 PL_DECLARE_POD_TYPE();
64
65 using iterator_category = std::forward_iterator_tag;
66 using value_type = Iterator;
67 using pointer = Iterator*;
68 using reference = Iterator&;
69
70 using ConstIterator::Value;
71 PL_ALWAYS_INLINE Iterator(const Iterator& rhs) = default;
72 PL_FORCE_INLINE ValueType Value();
73 PL_ALWAYS_INLINE ValueType operator*() { return Value(); }
74
75 protected:
76 PL_FORCE_INLINE explicit Iterator(const plRangeView<ValueType, IteratorType>* view, IteratorType pos);
77 };
78
79 Iterator begin() { return Iterator(this, m_Begin()); }
80 Iterator end() { return Iterator(this, m_End()); }
81 ConstIterator begin() const { return ConstIterator(this, m_Begin()); }
82 ConstIterator end() const { return ConstIterator(this, m_End()); }
83 ConstIterator cbegin() const { return ConstIterator(this, m_Begin()); }
84 ConstIterator cend() const { return ConstIterator(this, m_End()); }
85
86private:
87 friend struct Iterator;
88 friend struct ConstIterator;
89
90 BeginCallback m_Begin;
91 EndCallback m_End;
92 NextCallback m_Next;
93 ValueCallback m_Value;
94};
95
96template <typename V, typename I>
97typename plRangeView<V, I>::Iterator begin(plRangeView<V, I>& in_container)
98{
99 return in_container.begin();
100}
101
102template <typename V, typename I>
103typename plRangeView<V, I>::ConstIterator begin(const plRangeView<V, I>& container)
104{
105 return container.cbegin();
106}
107
108template <typename V, typename I>
109typename plRangeView<V, I>::ConstIterator cbegin(const plRangeView<V, I>& container)
110{
111 return container.cbegin();
112}
113
114template <typename V, typename I>
115typename plRangeView<V, I>::Iterator end(plRangeView<V, I>& in_container)
116{
117 return in_container.end();
118}
119
120template <typename V, typename I>
121typename plRangeView<V, I>::ConstIterator end(const plRangeView<V, I>& container)
122{
123 return container.cend();
124}
125
126template <typename V, typename I>
127typename plRangeView<V, I>::ConstIterator cend(const plRangeView<V, I>& container)
128{
129 return container.cend();
130}
131
132#include <Foundation/Types/Implementation/RangeView_inl.h>
This class uses delegates to define a range of values that can be enumerated using a forward iterator...
Definition RangeView.h:24
PL_ALWAYS_INLINE plRangeView(BeginCallback begin, EndCallback end, NextCallback next, ValueCallback value)
Initializes the plRangeView with the delegates used to enumerate the range.
Definition RangeView_inl.h:3
Const iterator, don't use directly, use ranged based for loops or call begin() end().
Definition RangeView.h:36
Iterator, don't use directly, use ranged based for loops or call begin() end().
Definition RangeView.h:62