]> git.sesse.net Git - casparcg/blobdiff - common/array.h
[ffmpeg] Fixed last two frames in all clips not being displayed
[casparcg] / common / array.h
index 8ae95bc000b437ec8d33636eb40b96f387f60a1e..3c84fdd34a39193c4e98f5a56191838320b7b028 100644 (file)
@@ -8,27 +8,34 @@
 #include <cstddef>
 #include <cstdint>
 
+#include "assert.h"
+
 namespace caspar {
        
 template<typename T>
-class array sealed
+class array final
 {
-       array(const array<std::uint8_t>&);
-       array& operator=(const array<std::uint8_t>&);
+       array(const array<T>&);
+       array& operator=(const array<T>&);
 
        template<typename> friend class array;
 public:
 
+       // Boost Range support
+
+       typedef T*                      iterator;
+       typedef const T*        const_iterator;
+
        // Static Members
 
        // Constructors
        
-       template<typename T>
-       explicit array(std::uint8_t* ptr, std::size_t size, bool cacheable, T&& storage)
+       template<typename T2>
+       explicit array(T* ptr, std::size_t size, bool cacheable, T2&& storage)
                : ptr_(ptr)
                , size_(size)
                , cacheable_(cacheable)
-               , storage_(new boost::any(std::forward<T>(storage)))
+               , storage_(new boost::any(std::forward<T2>(storage)))
        {
        }
 
@@ -59,41 +66,55 @@ public:
                        
        T* begin() const                        {return ptr_;}          
        T* data() const                         {return ptr_;}
-       T* end() const                          {return reinterpret_cast<T*>(reinterpret_cast<char*>(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<typename T>
-       T* storage() const
+       template<typename T2>
+       T2* storage() const
        {
-               return boost::any_cast<T>(storage_.get());
+               return boost::any_cast<T2>(storage_.get());
        }
 private:
-       T*                      ptr_;
-       std::size_t     size_;
-       bool            cacheable_;
+       T*                                                      ptr_;
+       std::size_t                                     size_;
+       bool                                            cacheable_;
        std::unique_ptr<boost::any>     storage_;
 };
 
 template<typename T>
-class array<const T> sealed
+class array<const T> final
 {
 public:
 
+       // Boost Range support
+
+       typedef const T*        iterator;
+       typedef const T*        const_iterator;
+
        // Static Members
 
        // Constructors
+       array() = default; // Needed by std::future
 
-       template<typename T>
-       explicit array(const std::uint8_t* ptr, std::size_t size, bool cacheable, T&& storage)
+       template<typename T2>
+       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<T>(storage)))
+               , storage_(new boost::any(std::forward<T2>(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<const T*>(reinterpret_cast<const char*>(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<typename T>
-       T* storage() const
+       template<typename T2>
+       T2* storage() const
        {
-               return boost::any_cast<T>(storage_.get());
+               return boost::any_cast<T2>(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<boost::any>     storage_;
 };