diff --git a/modules/core/include/opencv2/core/utility.hpp b/modules/core/include/opencv2/core/utility.hpp index cfe98401db..517a997498 100644 --- a/modules/core/include/opencv2/core/utility.hpp +++ b/modules/core/include/opencv2/core/utility.hpp @@ -102,11 +102,18 @@ template class AutoBuffer { public: typedef _Tp value_type; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + typedef const _Tp* const_iterator; + typedef _Tp* iterator; + typedef const _Tp& const_reference; + typedef _Tp& reference; //! the default constructor AutoBuffer(); //! constructor taking the real buffer size explicit AutoBuffer(size_t _size); + AutoBuffer(size_t _size, const _Tp& value); //! the copy constructor AutoBuffer(const AutoBuffer<_Tp, fixed_size>& buf); @@ -140,7 +147,25 @@ public: //! returns a reference to the element at specified location. No bounds checking is performed in Release builds. inline const _Tp& operator[] (size_t i) const { CV_DbgCheckLT(i, sz, "out of range"); return ptr[i]; } #endif - +public: + inline iterator begin() { return data(); } + inline const_iterator begin() const { return data(); } + inline const_iterator cbegin() const { return begin(); } + inline iterator end() { return data()+size(); } + inline const_iterator end() const { return data()+size(); } + inline const_iterator cend() const { return end(); } +public: + inline bool empty() const { return !size(); } + inline void clear() {resize(0);} + inline const_reference front() const { return (*this)[0] ;} + inline reference front() { return (*this)[0] ;} + inline const_reference back() const { CV_DbgCheckGT(sz, (size_t)0, "out of range"); return (*this)[size()-1] ;} + inline reference back() { CV_DbgCheckGT(sz, (size_t)0, "out of range"); return (*this)[size()-1] ;} +public: + inline void push_back( const _Tp& value ) {resize(size()+1); back() = value;} + inline void push_back( _Tp&& value ) {resize(size()+1); back() = std::move(value);} + inline void emplace_back( _Tp&& value ) {push_back(value);} + inline void pop_back() {CV_DbgCheckGT(sz, (size_t)0, "out of range"); resize(size()-1);} protected: //! pointer to the real buffer, can point to buf if the buffer is small enough _Tp* ptr; @@ -1054,6 +1079,13 @@ AutoBuffer<_Tp, fixed_size>::AutoBuffer(size_t _size) allocate(_size); } +template inline +AutoBuffer<_Tp, fixed_size>::AutoBuffer(size_t _size, const _Tp& value) + :AutoBuffer<_Tp, fixed_size>(_size) +{ + std::fill(begin(), end(), value); +} + template inline AutoBuffer<_Tp, fixed_size>::AutoBuffer(const AutoBuffer<_Tp, fixed_size>& abuf ) {