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

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Span.h
1 #pragma once
2
3 #include <cassert>
4 #include <type_traits>
5
6 namespace fsdk {
7
13 template <class T>
14 class Span {
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)
73 , size_(size) {
74 }
75
79 template <class ContiguousContainer>
80 Span(ContiguousContainer&& container)
81 : data_(container.data())
82 , size_(container.size()) {
83 }
84
88 template <class ContiguousContainer>
89 Span& operator=(ContiguousContainer&& container) {
90 data_ = container.data();
91 size_ = container.size();
92 return *this;
93 }
94
98 reference operator[](std::size_t index) {
99 assert(index < size_);
100 return data_[index];
101 }
102
106 const_reference operator[](std::size_t index) const {
107 assert(index < size_);
108 return data_[index];
109 }
110
113 bool empty() const {
114 return size_ == 0;
115 }
116
119 pointer data() const {
120 return data_;
121 }
122
125 std::size_t size() const {
126 return getSize();
127 }
128
131 std::size_t getSize() const {
132 return size_;
133 }
134
139 void setSize(std::size_t size) {
140 size_ = size;
141 }
142
145 iterator begin() {
146 return data_;
147 }
148
151 const_iterator begin() const {
152 return data_;
153 }
154
157 const_iterator cbegin() const {
158 return data_;
159 }
160
163 iterator end() {
164 return data_ + size_;
165 }
166
169 const_iterator end() const {
170 return data_ + size_;
171 }
172
175 const_iterator cend() const {
176 return data_ + size_;
177 }
178 };
179 } // namespace fsdk
fsdk::Span::Span
Span(ContiguousContainer &&container)
Constructor by contiguous container.
Definition: Span.h:80
fsdk::Span::empty
bool empty() const
Returns true if the span is empty.
Definition: Span.h:113
fsdk::Span::begin
const_iterator begin() const
Returns an const iterator to the beginning of the span.
Definition: Span.h:151
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:98
fsdk::Span::data
pointer data() const
Returns a pointer to the beginning of the span.
Definition: Span.h:119
fsdk::Span::operator=
Span & operator=(ContiguousContainer &&container)
Assignment operator with contiguous container.
Definition: Span.h:89
fsdk::Span::size
std::size_t size() const
Returns the number of elements in the span.
Definition: Span.h:125
fsdk::Span::Span
Span(T *data, std::size_t size)
Constructor by pointer and size.
Definition: Span.h:71
fsdk::Span::cend
const_iterator cend() const
Returns an const iterator to one past the end of the span.
Definition: Span.h:175
fsdk::Span::begin
iterator begin()
Returns an iterator to the beginning of the span.
Definition: Span.h:145
fsdk::Span::getSize
std::size_t getSize() const
Returns the number of elements in the span.
Definition: Span.h:131
fsdk::Span::cbegin
const_iterator cbegin() const
Returns an iterator to the beginning of the span.
Definition: Span.h:157
fsdk::Span::end
const_iterator end() const
Returns an const iterator to one past the end of the span.
Definition: Span.h:169
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:106
fsdk::Span::end
iterator end()
Returns an iterator to one past the end of the span.
Definition: Span.h:163
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:139
fsdk::Span
Span. Not owning data view. It incapsulated pointer to the continuous array with one or more T objec...
Definition: Span.h:14