| Face Engine SDK 4.7.0 A face detection, recognition and tracking engine.

Span.h
1 #pragma once
2
3 #include <type_traits>
4
5 namespace fsdk {
6
12 template<class T>
13 class Span
14 {
15 T* data_ = nullptr;
16 std::size_t size_ = 0;
17
18 public:
19 /* @brief The type of value, including cv qualifiers
20 */
21 using element_type = T;
22
23 /* @brief The type of value of each span element
24 */
25 using value_type = typename std::remove_const<T>::type;
26
27 /* @brief The type of integer used to index the span
28 */
29 using index_type = std::ptrdiff_t;
30
31 /* @brief A pointer to a span element
32 */
33 using pointer = T*;
34
35 /* @brief A reference to a span element
36 */
37 using reference = T&;
38
39 /* @brief The iterator used by the container
40 */
41 using iterator = pointer;
42
43 /* @brief The const pointer used by the container
44 */
45 using const_pointer = T const*;
46
47 /* @brief The const reference used by the container
48 */
49 using const_reference = T const&;
50
51 /* @brief The const iterator used by the container
52 */
53 using const_iterator = const_pointer;
54
55 /* @brief Initializes the empty Span.
56 */
57 Span() = default;
58
59 /* @brief Default copy constructor
60 */
61 Span(Span const&) = default;
62
63 /* @brief Default assignment
64 */
65 Span& operator=(Span const&) = default;
66
71 Span(T* data, std::size_t size)
72 : data_(data), size_(size)
73 {
74 }
75
79 template<class ContiguousContainer>
80 Span(ContiguousContainer&& container)
81 : data_(container.data())
82 , size_(container.size())
83 {
84 }
85
89 template<class ContiguousContainer>
90 Span& operator=(ContiguousContainer&& container) {
91 data_ = container.data();
92 size_ = container.size();
93 return *this;
94 }
95
99 reference
100 operator[](std::size_t index) {
101 assert(index < size_);
102 return data_[index];
103 }
104
108 const_reference
109 operator[](std::size_t index) const {
110 assert(index < size_);
111 return data_[index];
112 }
113
116 bool
117 empty() const {
118 return size_ == 0;
119 }
120
123 pointer
124 data() const {
125 return data_;
126 }
127
130 std::size_t
131 size() const {
132 return getSize();
133 }
134
137 std::size_t
138 getSize() const {
139 return size_;
140 }
141
146 void
147 setSize(std::size_t size) {
148 size_ = size;
149 }
150
153 iterator
154 begin() {
155 return data_;
156 }
157
160 const_iterator
161 begin() const {
162 return data_;
163 }
164
167 const_iterator
168 cbegin() const {
169 return data_;
170 }
171
174 iterator
175 end() {
176 return data_ + size_;
177 }
178
181 const_iterator
182 end() const {
183 return data_ + size_;
184 }
185
188 const_iterator
189 cend() const {
190 return data_ + size_;
191 }
192 };
193 }
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
fsdk::Span::Span
Span(ContiguousContainer &&container)
Constructor by contiguous container.
Definition: Span.h:80
fsdk::Span::size
std::size_t size() const
Returns the number of elements in the span.
Definition: Span.h:131
fsdk::Span::empty
bool empty() const
Returns true if the span is empty.
Definition: Span.h:117
fsdk::Span::operator[]
reference operator[](std::size_t index)
Square brackets operator for convenient acces to underlying array; param index Array index...
Definition: Span.h:100
fsdk::Span::operator[]
const_reference operator[](std::size_t index) const
Non-modifying square brackets operator for convenient acces to underlying array; param index Array in...
Definition: Span.h:109
fsdk::Span::operator=
Span & operator=(ContiguousContainer &&container)
Assignment operator with contiguous container.
Definition: Span.h:90
fsdk::Span::Span
Span(T *data, std::size_t size)
Constructor by pointer and size.
Definition: Span.h:71
fsdk::Span::begin
iterator begin()
Returns an iterator to the beginning of the span.
Definition: Span.h:154
fsdk::Span::end
const_iterator end() const
Returns an const iterator to one past the end of the span.
Definition: Span.h:182
fsdk::Span::begin
const_iterator begin() const
Returns an const iterator to the beginning of the span.
Definition: Span.h:161
fsdk::Span::getSize
std::size_t getSize() const
Returns the number of elements in the span.
Definition: Span.h:138
fsdk::Span::cbegin
const_iterator cbegin() const
Returns an iterator to the beginning of the span.
Definition: Span.h:168
fsdk::Span::cend
const_iterator cend() const
Returns an const iterator to one past the end of the span.
Definition: Span.h:189
fsdk::Span::data
pointer data() const
Returns a pointer to the beginning of the span.
Definition: Span.h:124
fsdk::Span::end
iterator end()
Returns an iterator to one past the end of the span.
Definition: Span.h:175
fsdk::Span::setSize
void setSize(std::size_t size)
Sets the number of elements in the span. Because the span is not owning, this method will no constru...
Definition: Span.h:147
fsdk::Span
Span. Not owning data view. It incapsulated pointer to the continuous array with one or more T objec...
Definition: Span.h:13