Face Engine SDK  5.14.0
A face detection, recognition and tracking engine.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Span.h
1 #pragma once
2 
3 #include <type_traits>
4 #include <cassert>
5 
6 namespace fsdk {
7 
13  template<class T>
14  class Span
15  {
16  T* data_ = nullptr;
17  std::size_t size_ = 0;
18 
19  public:
20  /* @brief The type of value, including cv qualifiers
21  */
22  using element_type = T;
23 
24  /* @brief The type of value of each span element
25  */
26  using value_type = typename std::remove_const<T>::type;
27 
28  /* @brief The type of integer used to index the span
29  */
30  using index_type = std::ptrdiff_t;
31 
32  /* @brief A pointer to a span element
33  */
34  using pointer = T*;
35 
36  /* @brief A reference to a span element
37  */
38  using reference = T&;
39 
40  /* @brief The iterator used by the container
41  */
42  using iterator = pointer;
43 
44  /* @brief The const pointer used by the container
45  */
46  using const_pointer = T const*;
47 
48  /* @brief The const reference used by the container
49  */
50  using const_reference = T const&;
51 
52  /* @brief The const iterator used by the container
53  */
54  using const_iterator = const_pointer;
55 
56  /* @brief Initializes the empty Span.
57  */
58  Span() = default;
59 
60  /* @brief Default copy constructor
61  */
62  Span(Span const&) = default;
63 
64  /* @brief Default assignment
65  */
66  Span& operator=(Span const&) = default;
67 
72  Span(T* data, std::size_t size)
73  : data_(data), size_(size)
74  {
75  }
76 
80  template<class ContiguousContainer>
81  Span(ContiguousContainer&& container)
82  : data_(container.data())
83  , size_(container.size())
84  {
85  }
86 
90  template<class ContiguousContainer>
91  Span& operator=(ContiguousContainer&& container) {
92  data_ = container.data();
93  size_ = container.size();
94  return *this;
95  }
96 
100  reference
101  operator[](std::size_t index) {
102  assert(index < size_);
103  return data_[index];
104  }
105 
109  const_reference
110  operator[](std::size_t index) const {
111  assert(index < size_);
112  return data_[index];
113  }
114 
117  bool
118  empty() const {
119  return size_ == 0;
120  }
121 
124  pointer
125  data() const {
126  return data_;
127  }
128 
131  std::size_t
132  size() const {
133  return getSize();
134  }
135 
138  std::size_t
139  getSize() const {
140  return size_;
141  }
142 
147  void
148  setSize(std::size_t size) {
149  size_ = size;
150  }
151 
154  iterator
155  begin() {
156  return data_;
157  }
158 
161  const_iterator
162  begin() const {
163  return data_;
164  }
165 
168  const_iterator
169  cbegin() const {
170  return data_;
171  }
172 
175  iterator
176  end() {
177  return data_ + size_;
178  }
179 
182  const_iterator
183  end() const {
184  return data_ + size_;
185  }
186 
189  const_iterator
190  cend() const {
191  return data_ + size_;
192  }
193  };
194 }
Span(ContiguousContainer &&container)
Constructor by contiguous container.
Definition: Span.h:81
bool empty() const
Returns true if the span is empty.
Definition: Span.h:118
const_iterator begin() const
Returns an const iterator to the beginning of the span.
Definition: Span.h:162
reference operator[](std::size_t index)
Square brackets operator for convenient acces to underlying array; param index Array index...
Definition: Span.h:101
pointer data() const
Returns a pointer to the beginning of the span.
Definition: Span.h:125
Span & operator=(ContiguousContainer &&container)
Assignment operator with contiguous container.
Definition: Span.h:91
std::size_t size() const
Returns the number of elements in the span.
Definition: Span.h:132
Span(T *data, std::size_t size)
Constructor by pointer and size.
Definition: Span.h:72
const_iterator cend() const
Returns an const iterator to one past the end of the span.
Definition: Span.h:190
iterator begin()
Returns an iterator to the beginning of the span.
Definition: Span.h:155
std::size_t getSize() const
Returns the number of elements in the span.
Definition: Span.h:139
const_iterator cbegin() const
Returns an iterator to the beginning of the span.
Definition: Span.h:169
const_iterator end() const
Returns an const iterator to one past the end of the span.
Definition: Span.h:183
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:110
iterator end()
Returns an iterator to one past the end of the span.
Definition: Span.h:176
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:148
Span. Not owning data view. It incapsulated pointer to the continuous array with one or more T objec...
Definition: Span.h:14