2017-11-01 20:14:23 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
/* BUFFERS ********************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
/* Buffers can be used to manipulate raw data. No constructors or destructors
|
|
|
|
* will ever be called.
|
|
|
|
*
|
|
|
|
* Buffers are available in two flavors: fixed size (where the size of the
|
|
|
|
* buffer is a template argument) and dynamic (where the size can be changed).
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:44:54 +01:00
|
|
|
#ifndef _H_EBCL_BUFFERS
|
|
|
|
#define _H_EBCL_BUFFERS
|
|
|
|
#include <ebcl/Externals.hh>
|
|
|
|
namespace ebcl {
|
2017-11-01 20:14:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*============================================================================*/
|
|
|
|
|
|
|
|
class T_BufferBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
uint8_t* data_;
|
|
|
|
|
|
|
|
T_BufferBase( ) = delete;
|
|
|
|
explicit T_BufferBase( uint8_t* buffer ) noexcept;
|
|
|
|
explicit T_BufferBase( size_t size );
|
|
|
|
T_BufferBase( T_BufferBase&& source ) noexcept;
|
|
|
|
|
|
|
|
public:
|
|
|
|
~T_BufferBase( );
|
|
|
|
|
|
|
|
friend void swap( T_BufferBase& lhs , T_BufferBase& rhs );
|
|
|
|
|
|
|
|
uint8_t * data( ) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*============================================================================*/
|
|
|
|
|
|
|
|
template< size_t SIZE , class T >
|
|
|
|
class T_FixedBuffer : public T_BufferBase
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
typedef T_FixedBuffer< SIZE , T > MyType_;
|
|
|
|
static constexpr size_t BYTES_ = SIZE * sizeof( T );
|
|
|
|
|
|
|
|
public:
|
|
|
|
T_FixedBuffer( );
|
|
|
|
T_FixedBuffer( MyType_&& source ) noexcept;
|
|
|
|
T_FixedBuffer( MyType_ const& source );
|
|
|
|
|
|
|
|
template< size_t SZ , typename TP >
|
|
|
|
friend void swap( T_FixedBuffer< SZ , TP >& lhs , T_FixedBuffer< SZ , TP >& rhs ) noexcept;
|
|
|
|
|
|
|
|
MyType_& operator= ( MyType_ const& other );
|
|
|
|
MyType_& operator= ( MyType_&& other ) noexcept;
|
|
|
|
|
|
|
|
size_t bytes( ) const;
|
|
|
|
T& operator[] ( size_t index );
|
|
|
|
T const& operator[] ( size_t index ) const;
|
|
|
|
|
|
|
|
MyType_& setAll( T const& value );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*============================================================================*/
|
|
|
|
|
|
|
|
template< class T >
|
|
|
|
class T_Buffer : public T_BufferBase
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
typedef T_Buffer< T > MyType_;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
size_t size_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
T_Buffer( ) noexcept;
|
|
|
|
T_Buffer( size_t size );
|
|
|
|
T_Buffer( T const* data , size_t size );
|
|
|
|
|
|
|
|
T_Buffer( MyType_ const& other );
|
|
|
|
T_Buffer( MyType_&& other ) noexcept;
|
|
|
|
|
|
|
|
MyType_& operator= ( MyType_ const& other );
|
|
|
|
MyType_& operator= ( MyType_&& other );
|
|
|
|
|
|
|
|
template< typename TP >
|
|
|
|
friend void swap( T_Buffer< TP >& lhs , T_Buffer< TP >& rhs ) noexcept;
|
|
|
|
|
|
|
|
size_t size( ) const;
|
|
|
|
size_t bytes( ) const;
|
|
|
|
|
|
|
|
T& operator[] ( size_t index );
|
|
|
|
T const& operator[] ( size_t index ) const;
|
|
|
|
|
|
|
|
MyType_& resize( size_t newSize );
|
|
|
|
MyType_& setAll( T const& value );
|
|
|
|
MyType_& copyAll( T const* data );
|
2018-04-30 09:10:39 +02:00
|
|
|
MyType_& append( T const* data , size_t size );
|
2017-11-01 20:14:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
2017-11-01 21:44:54 +01:00
|
|
|
#include <ebcl/inline/Buffers.hh>
|
|
|
|
#endif // _H_EBCL_BUFFERS
|