array_range.h
Go to the documentation of this file.
1
2/************************************************************************************
3* *
4* Copyright (c) 2014 - 2018 Axel Menzel <info@rttr.org> *
5* *
6* This file is part of RTTR (Run Time Type Reflection) *
7* License: MIT License *
8* *
9* Permission is hereby granted, free of charge, to any person obtaining *
10* a copy of this software and associated documentation files (the "Software"), *
11* to deal in the Software without restriction, including without limitation *
12* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
13* and/or sell copies of the Software, and to permit persons to whom the *
14* Software is furnished to do so, subject to the following conditions: *
15* *
16* The above copyright notice and this permission notice shall be included in *
17* all copies or substantial portions of the Software. *
18* *
19* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
20* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
21* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
22* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
23* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
24* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
25* SOFTWARE. *
26* *
27*************************************************************************************/
28
29#ifndef RTTR_ARRAY_RANGE_H_
30#define RTTR_ARRAY_RANGE_H_
31
32#include "rttr/detail/base/core_prerequisites.h"
33#include <vector>
34#include <cstddef>
35
36namespace rttr
37{
38class property;
39class method;
40class constructor;
41class enumeration;
42class parameter_info;
43
44namespace detail
45{
46template<typename T>
47struct default_predicate;
48
49} // end namespace detail
50
51
62template<typename T, typename Predicate = detail::default_predicate<T>>
64{
65public:
66 using value_type = T;
67 using bounds_type = T*;
68 using size_type = std::size_t;
69
74
82 array_range(const T* begin, size_type size, const Predicate& pred = Predicate());
83
84#ifndef DOXYGEN
88 template<typename DataType>
89 class array_iterator_base
90 {
91 public:
92 using self_type = array_iterator_base<DataType>;
93 using value_type = DataType;
94 using reference = DataType&;
95 using pointer = DataType*;
96 using iterator_category = std::forward_iterator_tag;
97 using difference_type = std::ptrdiff_t;
98
99 bool operator==(const self_type& rhs) const;
100 bool operator!=(const self_type& rhs) const;
101
102 array_iterator_base& operator=(const self_type& other);
103
104 protected:
105 friend class array_range<T, Predicate>;
106 array_iterator_base();
107 array_iterator_base(pointer ptr, const array_range<T, Predicate>* const range);
108
109 pointer m_ptr;
110 const array_range<T, Predicate>* m_range;
111 };
112
116 template<typename DataType>
117 class array_iterator : public array_iterator_base<DataType>
118 {
119 public:
120 using self_type = array_iterator<DataType>;
121 using reference = typename array_iterator_base<DataType>::reference;
122 using pointer = typename array_iterator_base<DataType>::pointer;
123
124 array_iterator();
125 array_iterator(const array_iterator<DataType>& other);
126
127
128 reference operator*() const;
129 pointer operator->();
130
131 self_type& operator++();
132 self_type operator++(int index);
133
134 private:
135 array_iterator(typename array_iterator_base<DataType>::pointer ptr,
136 const array_range<T, Predicate>* const range);
137 friend class array_range<T, Predicate>;
138 };
139
143 template<typename DataType>
144 class array_reverse_iterator : public array_iterator_base<DataType>
145 {
146 public:
147 using self_type = array_reverse_iterator<DataType>;
148 using reference = typename array_iterator_base<DataType>::reference;
149 using pointer = typename array_iterator_base<DataType>::pointer;
150
151 array_reverse_iterator();
152 array_reverse_iterator(const array_reverse_iterator<DataType>& other);
153
154 reference operator*() const;
155 pointer operator->();
156
157 self_type& operator++();
158 self_type operator++(int index);
159
160 private:
161 array_reverse_iterator(typename array_iterator_base<DataType>::pointer ptr,
162 const array_range<T, Predicate>* const range);
163 friend class array_range<T, Predicate>;
164 };
165#endif
166
171
176
185
195
204
214
223
233
243
253
263
273
283
293
304 size_t size() const;
305
316 bool empty() const;
317
318private:
319 template<typename DataType>
320 void next(array_iterator<DataType>& itr) const;
321
322 template<typename DataType>
323 void prev(array_reverse_iterator<DataType>& itr) const;
324
325 bool empty_() const;
327
328private:
329 const T* const m_begin;
330 const T* const m_end;
331 const Predicate m_pred;
332};
333
335
336} // end namespace rttr
337
338#include "rttr/detail/impl/array_range_impl.h"
339
340#endif // RTTR_ARRAY_RANGE_H_
The array_range class provides a view into an underlying data structure with lower and upper limits.
Definition array_range.h:64
const_iterator end()
Returns an iterator to the element following the last element of the range.
const_reverse_iterator rbegin() const
Returns a constant reverse iterator to the first element of the reversed range.
const_reverse_iterator rend()
Returns a reverse iterator to the element following the last element of the reversed range.
bool empty() const
Checks if the range has no elements, i.e.
array_range(const T *begin, size_type size, const Predicate &pred=Predicate())
Constructs an array range starting from begin to end [begin, end).
T value_type
Definition array_range.h:66
array_iterator< const T > const_iterator
A constant forward iterator.
Definition array_range.h:170
const_iterator begin()
Returns an iterator to the first element of the range.
T * bounds_type
Definition array_range.h:67
const_reverse_iterator crbegin() const
Returns a constant reverse iterator to the first element of the reversed range.
const_iterator begin() const
Returns a constant iterator to the first element of the range.
const_iterator cend() const
Returns a constant iterator to the element following the last element of the range.
const_reverse_iterator rbegin()
Returns a reverse iterator to the first element of the reversed range.
const_iterator end() const
Returns a constant iterator to the element following the last element of the range.
const_reverse_iterator rend() const
Returns a constant reverse iterator to the element following the last element of the reversed range.
const_reverse_iterator crend() const
Returns a constant reverse iterator to the element following the last element of the reversed range.
std::size_t size_type
Definition array_range.h:68
const_iterator cbegin() const
Returns a constant iterator to the first element of the range.
size_t size() const
Returns the number of elements in the range.
array_range()
Default constructor.
Definition access_levels.h:34
constexpr bool operator!=(basic_string_view< CharT, Traits > lhs, basic_string_view< CharT, Traits > rhs) noexcept
Compares the two views lhs and rhs.
constexpr bool operator==(basic_string_view< CharT, Traits > lhs, basic_string_view< CharT, Traits > rhs) noexcept
Compares the two views lhs and rhs.