X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Farray.h;h=3c84fdd34a39193c4e98f5a56191838320b7b028;hb=c0dc760a3d87b346c9f267cd9d74c67c55d3bdc3;hp=8ae95bc000b437ec8d33636eb40b96f387f60a1e;hpb=8c61df76c4b35ab58316f35b6a09a3f977efd596;p=casparcg diff --git a/common/array.h b/common/array.h index 8ae95bc00..3c84fdd34 100644 --- a/common/array.h +++ b/common/array.h @@ -8,27 +8,34 @@ #include #include +#include "assert.h" + namespace caspar { template -class array sealed +class array final { - array(const array&); - array& operator=(const array&); + array(const array&); + array& operator=(const array&); template friend class array; public: + // Boost Range support + + typedef T* iterator; + typedef const T* const_iterator; + // Static Members // Constructors - template - explicit array(std::uint8_t* ptr, std::size_t size, bool cacheable, T&& storage) + template + explicit array(T* ptr, std::size_t size, bool cacheable, T2&& storage) : ptr_(ptr) , size_(size) , cacheable_(cacheable) - , storage_(new boost::any(std::forward(storage))) + , storage_(new boost::any(std::forward(storage))) { } @@ -59,41 +66,55 @@ public: T* begin() const {return ptr_;} T* data() const {return ptr_;} - T* end() const {return reinterpret_cast(reinterpret_cast(ptr_) + size_);} + T* end() const {return ptr_ + size_;} std::size_t size() const {return size_;} bool empty() const {return size() == 0;} bool cacheable() const {return cacheable_;} - template - T* storage() const + template + T2* storage() const { - return boost::any_cast(storage_.get()); + return boost::any_cast(storage_.get()); } private: - T* ptr_; - std::size_t size_; - bool cacheable_; + T* ptr_; + std::size_t size_; + bool cacheable_; std::unique_ptr storage_; }; template -class array sealed +class array final { public: + // Boost Range support + + typedef const T* iterator; + typedef const T* const_iterator; + // Static Members // Constructors + array() = default; // Needed by std::future - template - explicit array(const std::uint8_t* ptr, std::size_t size, bool cacheable, T&& storage) + template + explicit array(const T* ptr, std::size_t size, bool cacheable, T2&& storage) : ptr_(ptr) , size_(size) , cacheable_(cacheable) - , storage_(new boost::any(std::forward(storage))) + , storage_(new boost::any(std::forward(storage))) { } - + + explicit array(const T* ptr, std::size_t size, bool cacheable) + : ptr_(ptr) + , size_(size) + , cacheable_(cacheable) + , storage_(new boost::any) + { + } + array(const array& other) : ptr_(other.ptr_) , size_(other.size_) @@ -132,21 +153,21 @@ public: const T* begin() const {return ptr_;} const T* data() const {return ptr_;} - const T* end() const {return reinterpret_cast(reinterpret_cast(ptr_) + size_);} + const T* end() const {return ptr_ + size_;} std::size_t size() const {return size_;} bool empty() const {return size() == 0;} bool cacheable() const {return cacheable_;} - template - T* storage() const + template + T2* storage() const { - return boost::any_cast(storage_.get()); + return boost::any_cast(storage_.get()); } private: - const T* ptr_; - std::size_t size_; - bool cacheable_; + const T* ptr_ = nullptr; + std::size_t size_ = 0; + bool cacheable_ = false; std::shared_ptr storage_; };