OSVR-Core
Public Types | Public Member Functions | List of all members
osvr::common::Buffer< ContainerType > Class Template Reference

A buffer of bytes, built on a byte-vector-like container. More...

#include <Buffer.h>

Public Types

typedef ContainerType::value_type ElementType
 The (necessarily byte-size) type of elements in the underlying container. More...
 
typedef BufferReader< ContainerType > Reader
 The corresponding BufferReader type.
 

Public Member Functions

 Buffer ()
 Constructs an empty buffer.
 
 Buffer (ContainerType const &buf)
 Constructs a buffer wrapper by copy-constructing the contained type. More...
 
template<typename InputIterator >
 Buffer (InputIterator beginIt, InputIterator endIt)
 Constructs a buffer by copying from two input iterators, representing a half-open range [beginIt, endIt) More...
 
template<typename T >
void append (T const v)
 Append the binary representation of a value. More...
 
template<typename T >
void appendAligned (T const v, size_t const alignment)
 Append the binary representation of a value, after adding the necessary number of padding bytes to begin the write at the given alignment within the buffer. More...
 
void append (ElementType const *v, size_t const n)
 Append a byte-array's contents.
 
void appendAligned (ElementType const *v, size_t const n, size_t const alignment)
 Append a byte-array's contents, after adding the necessary number of padding bytes to begin the write at the given alignment within the buffer. More...
 
void appendPadding (size_t const bytes)
 Append the specified number of bytes of padding.
 
Reader startReading () const
 Returns a reader object, for making a single read pass over the buffer. More...
 
size_t size () const
 Gets the current size, in bytes.
 
ContainerType & getContents ()
 Provides access to the underlying container.
 
ElementType const * data () const
 Provides access to the underlying data.
 

Detailed Description

template<typename ContainerType = BufferByteVector>
class osvr::common::Buffer< ContainerType >

A buffer of bytes, built on a byte-vector-like container.

Provides methods for easily appending to the buffer (including alignment padding), and a nested class for reading from such a buffer.

Member Typedef Documentation

§ ElementType

template<typename ContainerType = BufferByteVector>
typedef ContainerType::value_type osvr::common::Buffer< ContainerType >::ElementType

The (necessarily byte-size) type of elements in the underlying container.

Constructor & Destructor Documentation

§ Buffer() [1/2]

template<typename ContainerType = BufferByteVector>
osvr::common::Buffer< ContainerType >::Buffer ( ContainerType const &  buf)
inlineexplicit

Constructs a buffer wrapper by copy-constructing the contained type.

§ Buffer() [2/2]

template<typename ContainerType = BufferByteVector>
template<typename InputIterator >
osvr::common::Buffer< ContainerType >::Buffer ( InputIterator  beginIt,
InputIterator  endIt 
)
inline

Constructs a buffer by copying from two input iterators, representing a half-open range [beginIt, endIt)

Passed directly to contained type, so semantics are identical.

Member Function Documentation

§ append()

template<typename ContainerType = BufferByteVector>
template<typename T >
void osvr::common::Buffer< ContainerType >::append ( T const  v)
inline

Append the binary representation of a value.

The value cannot be a pointer here.

Safe to do without violating strict aliasing because ElementType is a character type.

§ appendAligned() [1/2]

template<typename ContainerType = BufferByteVector>
template<typename T >
void osvr::common::Buffer< ContainerType >::appendAligned ( T const  v,
size_t const  alignment 
)
inline

Append the binary representation of a value, after adding the necessary number of padding bytes to begin the write at the given alignment within the buffer.

The value cannot be a pointer here.

§ appendAligned() [2/2]

template<typename ContainerType = BufferByteVector>
void osvr::common::Buffer< ContainerType >::appendAligned ( ElementType const *  v,
size_t const  n,
size_t const  alignment 
)
inline

Append a byte-array's contents, after adding the necessary number of padding bytes to begin the write at the given alignment within the buffer.

§ startReading()

template<typename ContainerType = BufferByteVector>
Reader osvr::common::Buffer< ContainerType >::startReading ( ) const
inline

Returns a reader object, for making a single read pass over the buffer.

Do not modify this buffer during the lifetime of a reader!


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