Face Engine SDK  5.23.1
A face detection, recognition and tracking engine.
include/fsdk/Types/Span.h
00001 #pragma once
00002 
00003 #include <cassert>
00004 #include <type_traits>
00005 
00006 namespace fsdk {
00007 
00013     template <class T>
00014     class Span {
00015         T* data_ = nullptr;
00016         std::size_t size_ = 0;
00017 
00018     public:
00019         /* @brief The type of value, including cv qualifiers
00020          */
00021         using element_type = T;
00022 
00023         /* @brief The type of value of each span element
00024          */
00025         using value_type = typename std::remove_const<T>::type;
00026 
00027         /* @brief The type of integer used to index the span
00028          */
00029         using index_type = std::ptrdiff_t;
00030 
00031         /* @brief A pointer to a span element
00032          */
00033         using pointer = T*;
00034 
00035         /* @brief A reference to a span element
00036          */
00037         using reference = T&;
00038 
00039         /* @brief The iterator used by the container
00040          */
00041         using iterator = pointer;
00042 
00043         /* @brief The const pointer used by the container
00044          */
00045         using const_pointer = T const*;
00046 
00047         /* @brief The const reference used by the container
00048          */
00049         using const_reference = T const&;
00050 
00051         /* @brief The const iterator used by the container
00052          */
00053         using const_iterator = const_pointer;
00054 
00055         /* @brief Initializes the empty Span.
00056          */
00057         Span() = default;
00058 
00059         /* @brief Default copy constructor
00060          */
00061         Span(Span const&) = default;
00062 
00063         /* @brief Default assignment
00064          */
00065         Span& operator=(Span const&) = default;
00066 
00071         Span(T* data, std::size_t size)
00072             : data_(data)
00073             , size_(size) {
00074         }
00075 
00079         template <class ContiguousContainer>
00080         Span(ContiguousContainer&& container)
00081             : data_(container.data())
00082             , size_(container.size()) {
00083         }
00084 
00088         template <class ContiguousContainer>
00089         Span& operator=(ContiguousContainer&& container) {
00090             data_ = container.data();
00091             size_ = container.size();
00092             return *this;
00093         }
00094 
00098         reference operator[](std::size_t index) {
00099             assert(index < size_);
00100             return data_[index];
00101         }
00102 
00106         const_reference operator[](std::size_t index) const {
00107             assert(index < size_);
00108             return data_[index];
00109         }
00110 
00113         bool empty() const {
00114             return size_ == 0;
00115         }
00116 
00119         pointer data() const {
00120             return data_;
00121         }
00122 
00125         std::size_t size() const {
00126             return getSize();
00127         }
00128 
00131         std::size_t getSize() const {
00132             return size_;
00133         }
00134 
00139         void setSize(std::size_t size) {
00140             size_ = size;
00141         }
00142 
00145         iterator begin() {
00146             return data_;
00147         }
00148 
00151         const_iterator begin() const {
00152             return data_;
00153         }
00154 
00157         const_iterator cbegin() const {
00158             return data_;
00159         }
00160 
00163         iterator end() {
00164             return data_ + size_;
00165         }
00166 
00169         const_iterator end() const {
00170             return data_ + size_;
00171         }
00172 
00175         const_iterator cend() const {
00176             return data_ + size_;
00177         }
00178     };
00179 } // namespace fsdk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines