eq::base::Buffer< T > Class Template Reference

A simple memory buffer with some helper functions. More...

#include <buffer.h>

List of all members.

Public Member Functions

 Buffer ()
 Construct a new, empty buffer.
 ~Buffer ()
 Destruct the buffer.
void clear ()
 Flush the buffer, deleting all _data.
 Buffer (Buffer &from)
 Copy constructor, transfers ownership to new Buffer.
const Bufferoperator= (Buffer &from)
 Assignment operator, copies _data from Buffer.
T & operator[] (const size_t position)
 Direct access to the element at the given index.
const T & operator[] (const size_t position) const
 Direct const access to the element at the given index.
void resize (const uint64_t newSize)
 Ensure that the buffer contains at least newSize elements, retaining existing _data.
void reserve (const uint64_t newSize)
 Ensure that the buffer contains at least newSize elements, potentially deleting existing _data.
void append (const T *addData, const uint64_t addSize)
 Append addSize elements to the buffer, increasing the _size.
void append (const T &element)
 Append one element to the buffer, increasing the _size.
void replace (const void *newData, const uint64_t newSize)
 Replace the existing _data with new _data.
void swap (Buffer &buffer)
 Swap the buffer contents with another Buffer.
T * getData ()
const T * getData () const
bool setSize (const uint64_t size)
 Set the size of the buffer without changing its allocation.
uint64_t getSize () const
bool isEmpty () const
uint64_t getMaxSize () const


Detailed Description

template<typename T>
class eq::base::Buffer< T >

A simple memory buffer with some helper functions.

For bigger data (>100k) using a std::vector< uint8_t > has a high overhead when resizing (>1ms). This buffer just memcpy's elements, i.e., it should be used on PODs only since the copy constructor or assignment operator is not called on the copied elements. Primarily used for binary data, e.g., in eq::Image.

Definition at line 38 of file buffer.h.


Constructor & Destructor Documentation

template<typename T>
eq::base::Buffer< T >::Buffer (  )  [inline]

Construct a new, empty buffer.

Definition at line 42 of file buffer.h.

template<typename T>
eq::base::Buffer< T >::~Buffer (  )  [inline]

Destruct the buffer.

Definition at line 45 of file buffer.h.

template<typename T>
eq::base::Buffer< T >::Buffer ( Buffer< T > &  from  )  [inline]

Copy constructor, transfers ownership to new Buffer.

Definition at line 52 of file buffer.h.


Member Function Documentation

template<typename T>
void eq::base::Buffer< T >::clear (  )  [inline]

Flush the buffer, deleting all _data.

Definition at line 48 of file buffer.h.

Referenced by eq::base::Buffer< pollfd >::~Buffer().

Here is the caller graph for this function:

template<typename T>
const Buffer& eq::base::Buffer< T >::operator= ( Buffer< T > &  from  )  [inline]

Assignment operator, copies _data from Buffer.

Definition at line 59 of file buffer.h.

template<typename T>
T& eq::base::Buffer< T >::operator[] ( const size_t  position  )  [inline]

Direct access to the element at the given index.

Definition at line 66 of file buffer.h.

template<typename T>
const T& eq::base::Buffer< T >::operator[] ( const size_t  position  )  const [inline]

Direct const access to the element at the given index.

Definition at line 69 of file buffer.h.

template<typename T>
void eq::base::Buffer< T >::append ( const T *  addData,
const uint64_t  addSize 
) [inline]

Append addSize elements to the buffer, increasing the _size.

Definition at line 108 of file buffer.h.

Referenced by eq::net::DataOStream::write(), eq::net::BufferConnection::write(), and eq::net::DataOStream::writeOnce().

Here is the caller graph for this function:

template<typename T>
void eq::base::Buffer< T >::append ( const T &  element  )  [inline]

Append one element to the buffer, increasing the _size.

Definition at line 119 of file buffer.h.

template<typename T>
void eq::base::Buffer< T >::replace ( const void *  newData,
const uint64_t  newSize 
) [inline]

Replace the existing _data with new _data.

Definition at line 126 of file buffer.h.

Referenced by eq::base::Buffer< pollfd >::operator=().

Here is the caller graph for this function:

template<typename T>
void eq::base::Buffer< T >::swap ( Buffer< T > &  buffer  )  [inline]

Swap the buffer contents with another Buffer.

Definition at line 137 of file buffer.h.

template<typename T>
T* eq::base::Buffer< T >::getData (  )  [inline]

Returns:
a pointer to the _data.

Definition at line 153 of file buffer.h.

Referenced by eq::net::FullMasterCM::addSlave(), eq::net::DataOStream::disable(), EqCompressorGetResult(), eq::net::DataOStream::flush(), eq::net::DataOStream::resend(), and eq::net::ConnectionSet::select().

Here is the caller graph for this function:

template<typename T>
const T* eq::base::Buffer< T >::getData (  )  const [inline]

Returns:
a const pointer to the _data.

Definition at line 156 of file buffer.h.

template<typename T>
bool eq::base::Buffer< T >::setSize ( const uint64_t  size  )  [inline]

Set the size of the buffer without changing its allocation.

This method only modifies the size parameter. If the current allocation of the buffer is too small, it asserts, returns false and does not change the size.

Definition at line 165 of file buffer.h.

template<typename T>
uint64_t eq::base::Buffer< T >::getSize (  )  const [inline]

template<typename T>
bool eq::base::Buffer< T >::isEmpty (  )  const [inline]

Returns:
true if the buffer is empty, false if not.

Definition at line 179 of file buffer.h.

template<typename T>
uint64_t eq::base::Buffer< T >::getMaxSize (  )  const [inline]

Returns:
the maximum _size of the buffer.

Definition at line 182 of file buffer.h.

Referenced by EqCompressorGetResult().

Here is the caller graph for this function:


The documentation for this class was generated from the following file:
Generated on Mon Aug 10 18:58:43 2009 for Equalizer 0.9 by  doxygen 1.5.8