hamcast  Version 0.7
Public Types | Public Member Functions | List of all members
hamcast::util::const_buffer Class Reference

#include <const_buffer.hpp>

Inherits noncopyable.

Public Types

typedef boost::uint32_t size_type
 

Public Member Functions

 const_buffer ()
 
 const_buffer (size_type buf_size, const void *buf)
 
 const_buffer (size_type buf_size, void *buf, bool ownership)
 
 ~const_buffer ()
 
void swap (const_buffer &other)
 
void reset ()
 
void reset (size_type buf_size, const void *buf)
 
void reset (size_type buf_size, void *buf, bool ownership)
 
size_type size () const
 
bool ownership () const
 
const void * data () const
 
bool empty () const
 
std::pair< size_type, void * > take ()
 

Detailed Description

Holds a buffer that cannot be modified.

The const_buffer class provides a representation of an immutable buffer. The object deletes the its data if it has ownership but does not modify it otherwise.

Warning
The given (const) buffer must stay valid for the whole lifetime of the buffer object if ownership() == false.
The data must have the type char* if ownership() == true because the dtor calls delete[] reinterpret_cast<char*>(data).

Member Typedef Documentation

typedef boost::uint32_t hamcast::util::const_buffer::size_type

The used integer type to store the size of the buffer.

Constructor & Destructor Documentation

hamcast::util::const_buffer::const_buffer ( )

Creates a buffer without data and size() == 0.

hamcast::util::const_buffer::const_buffer ( const_buffer::size_type  buf_size,
const void *  buf 
)

Creates a buffer without ownership.

Parameters
buf_sizeThe size of buf.
bufThe const C-buffer.
Warning
buf must stay valid for the whole lifetime of this object.
hamcast::util::const_buffer::const_buffer ( const_buffer::size_type  buf_size,
void *  buf,
bool  ownership 
)

Creates a buffer with optional ownership.

Parameters
buf_sizeThe size of buf.
bufThe C-buffer.
ownershipDenotes if this object should take ownership of buf.
Warning
buf must stay valid for the whole lifetime of this object if ownership() == false.
buf must be allocated with new char[...] if ownership() == true.
hamcast::util::const_buffer::~const_buffer ( )

Deletes its data if ownership() == false.

Warning
Calls delete[] reinterpret_cast<char*>(data) if the const buffer has ownership of its data.

Member Function Documentation

const void* hamcast::util::const_buffer::data ( ) const

Get the data of this buffer.

Returns
The internal C-buffer.
bool hamcast::util::const_buffer::empty ( ) const

Check if the buffer is empty (equivalent to size() == 0).

Returns
true if size() == 0; otherwise false
bool hamcast::util::const_buffer::ownership ( ) const

Check if the buffer owns its data.

Returns
true if this object owns the internal C-buffer; otherwise false.
void hamcast::util::const_buffer::reset ( )

Equivalent to const_buffer().swap(*this).

void hamcast::util::const_buffer::reset ( size_type  buf_size,
const void *  buf 
)

Equivalent to const_buffer(buf_size, buf).swap(*this).

Parameters
buf_sizeThe size of buf.
bufThe new const buffer.
void hamcast::util::const_buffer::reset ( size_type  buf_size,
void *  buf,
bool  ownership 
)

Equivalent to const_buffer(...).swap(*this).

Parameters
buf_sizeThe size of buf.
bufThe new buffer.
ownershipDenotes if this object should take ownership of buf.
size_type hamcast::util::const_buffer::size ( ) const

Get the size of data().

Returns
The size of the internal C-buffer.
void hamcast::util::const_buffer::swap ( const_buffer other)

Exchange the contents of the two buffers.

Parameters
otherThe const_buffer that should be swapped with this object.
std::pair< const_buffer::size_type, void * > hamcast::util::const_buffer::take ( )

Get the internal buffer and reset the buffer afterwards.

Returns
std::make_pair(size(), data())
Warning
Throws an exception if !ownership().
Precondition
ownership() || empty().

The documentation for this class was generated from the following files: