CFx SDK Documentation  2020SP3
slot_iterator.h
Go to the documentation of this file.
1 //
2 // slot_iterator.h
3 // slimsig
4 //
5 // Created by Christopher Tarquini on 5/20/14.
6 //
7 //
8 
9 #ifndef slimsig_slot_iterator_h
10 #define slimsig_slot_iterator_h
11 #include <iterator>
12 #include <type_traits>
13 #include <algorithm>
14 namespace slimsig {
15 
16 
17 template <class Container, class Traits = std::iterator_traits<typename Container::iterator>>
18 class offset_iterator : public std::iterator<
19  typename Traits::iterator_category,
20  typename Traits::value_type,
21  typename Traits::difference_type,
22  typename Traits::pointer,
23  std::forward_iterator_tag>
24 {
25 using traits = std::iterator_traits<offset_iterator>;
26 public:
28  using size_type = typename Container::size_type;
29  using reference = typename traits::reference;
30  using pointer = typename traits::pointer;
31  using difference_type = typename traits::difference_type;
32  using value_type = typename traits::value_type;
33 
34  offset_iterator() : p_container(nullptr), m_offset(0) {};
35  offset_iterator(const offset_iterator&) = default;
39  bool operator ==(const offset_iterator& rhs) const {
40  return m_offset == rhs.m_offset && p_container == rhs.p_container;
41  }
42  bool operator !=(const offset_iterator rhs) const{
43  return !(*this == rhs);
44  }
45  bool operator >(const offset_iterator rhs) const{
46  return m_offset > rhs.m_offset && p_container > p_container;
47  }
48  bool operator <(const offset_iterator rhs) const{
49  return m_offset < rhs.m_offset && p_container < p_container;
50  }
51  bool operator <=(const offset_iterator rhs) const {
52  return m_offset <= rhs.m_offset && p_container <= p_container;
53  }
54  bool operator >=(const offset_iterator rhs) const {
55  return m_offset >= rhs.m_offset && p_container >= p_container;
56  }
59  return std::begin(*p_container) + m_offset;
60  }
62  return &(std::begin(*p_container) + m_offset);
63  }
65  ++m_offset;
66  return *this;
67  }
69  offset_iterator it(*this);
70  ++m_offset;
71  return it;
72  }
73  size_type size() const {
74  return p_container == nullptr ? 0 : p_container->size();
75  };
76  operator bool() const {
77  return p_container != nullptr && m_offset < p_container->size();
78  }
81 };
82 template <class Container, class Traits = std::iterator_traits<typename Container::iterator>>
83 class slot_iterator : private offset_iterator<Container, Traits>
84 {
86 public:
88  using base::size_type;
89  using base::reference;
90  using base::pointer;
92  using base::value_type;
93 
94  using base::base;
95  using base::operator ==;
96  using base::operator !=;
97  using base::operator >;
98  using base::operator <;
99  using base::operator >=;
100  using base::operator <=;
101  operator bool() const {
102  return bool(*this) && bool(**this);
103  }
105  do {
107  } while (bool(*this) && !(bool(**this)));
108  return *this;
109  }
111  slot_iterator it(*this);
112  ++(*this);
113  return it;
114  }
115 };
116 
117 }
118 
119 #endif
slimsig::offset_iterator::offset_iterator
offset_iterator(const offset_iterator &)=default
slimsig::offset_iterator::offset_iterator
offset_iterator(offset_iterator &&)=default
slimsig::offset_iterator::operator>=
bool operator>=(const offset_iterator rhs) const
Definition: slot_iterator.h:54
slimsig::offset_iterator< Container, std::iterator_traits< typename Container::iterator > >::container_type
typename std::decay< Container >::type container_type
Definition: slot_iterator.h:27
slimsig::offset_iterator< Container, std::iterator_traits< typename Container::iterator > >::value_type
typename traits::value_type value_type
Definition: slot_iterator.h:32
slimsig::offset_iterator::operator++
offset_iterator operator++(int)
Definition: slot_iterator.h:68
type
GLuint GLsizei GLsizei GLint GLenum * type
Definition: gles2_ext.h:274
slimsig::slot_iterator
Definition: slot_iterator.h:84
slimsig::offset_iterator::size
size_type size() const
Definition: slot_iterator.h:73
slimsig::offset_iterator::operator*
reference operator*()
Definition: slot_iterator.h:58
slimsig
Definition: connection.h:17
slimsig::offset_iterator::operator->
pointer operator->()
Definition: slot_iterator.h:61
slimsig::offset_iterator::operator=
offset_iterator & operator=(offset_iterator &&)=default
offset
GLintptr offset
Definition: gles2_ext.h:183
slimsig::offset_iterator::offset_iterator
offset_iterator(container_type &container, size_type offset=0)
Definition: slot_iterator.h:57
slimsig::offset_iterator::operator>
bool operator>(const offset_iterator rhs) const
Definition: slot_iterator.h:45
slimsig::offset_iterator::operator++
offset_iterator & operator++()
Definition: slot_iterator.h:64
pointer
GLenum void ** pointer
Definition: gles2_ext.h:288
slimsig::offset_iterator::operator==
bool operator==(const offset_iterator &rhs) const
Definition: slot_iterator.h:39
slimsig::offset_iterator::operator<
bool operator<(const offset_iterator rhs) const
Definition: slot_iterator.h:48
slimsig::slot_iterator::operator++
slot_iterator & operator++(int)
Definition: slot_iterator.h:110
slimsig::offset_iterator
Definition: slot_iterator.h:24
slimsig::offset_iterator::operator=
offset_iterator & operator=(const offset_iterator &)=default
slimsig::offset_iterator::p_container
const container_type * p_container
Definition: slot_iterator.h:79
slimsig::offset_iterator< Container, std::iterator_traits< typename Container::iterator > >::size_type
typename Container::size_type size_type
Definition: slot_iterator.h:28
slimsig::offset_iterator< Container, std::iterator_traits< typename Container::iterator > >::difference_type
typename traits::difference_type difference_type
Definition: slot_iterator.h:31
slimsig::offset_iterator< Container, std::iterator_traits< typename Container::iterator > >::reference
typename traits::reference reference
Definition: slot_iterator.h:29
slimsig::offset_iterator::operator!=
bool operator!=(const offset_iterator rhs) const
Definition: slot_iterator.h:42
slimsig::offset_iterator< Container, std::iterator_traits< typename Container::iterator > >::pointer
typename traits::pointer pointer
Definition: slot_iterator.h:30
slimsig::offset_iterator::operator<=
bool operator<=(const offset_iterator rhs) const
Definition: slot_iterator.h:51
slimsig::offset_iterator::offset_iterator
offset_iterator()
Definition: slot_iterator.h:34
slimsig::offset_iterator::m_offset
size_type m_offset
Definition: slot_iterator.h:80
slimsig::slot_iterator::operator++
slot_iterator & operator++()
Definition: slot_iterator.h:104