Face Engine SDK  4.6.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 
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 }
Span(ContiguousContainer &&container)
Constructor by contiguous container.
Definition: Span.h:80
bool empty() const
Returns true if the span is empty.
Definition: Span.h:117
const_iterator begin() const
Returns an const iterator to the beginning of the span.
Definition: Span.h:161
reference operator[](std::size_t index)
Square brackets operator for convenient acces to underlying array; param index Array index...
Definition: Span.h:100
pointer data() const
Returns a pointer to the beginning of the span.
Definition: Span.h:124
Span & operator=(ContiguousContainer &&container)
Assignment operator with contiguous container.
Definition: Span.h:90
std::size_t size() const
Returns the number of elements in the span.
Definition: Span.h:131
Span(T *data, std::size_t size)
Constructor by pointer and size.
Definition: Span.h:71
const_iterator cend() const
Returns an const iterator to one past the end of the span.
Definition: Span.h:189
iterator begin()
Returns an iterator to the beginning of the span.
Definition: Span.h:154
std::size_t getSize() const
Returns the number of elements in the span.
Definition: Span.h:138
const_iterator cbegin() const
Returns an iterator to the beginning of the span.
Definition: Span.h:168
const_iterator end() const
Returns an const iterator to one past the end of the span.
Definition: Span.h:182
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
iterator end()
Returns an iterator to one past the end of the span.
Definition: Span.h:175
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
Span. Not owning data view. It incapsulated pointer to the continuous array with one or more T objec...
Definition: Span.h:13