Savarese Software Research Corporation
detail::Buffer< type > Class Template Reference

Buffer defines a limited set of operations for managing a memory buffer. More...

#include <Buffer.h>

Inheritance diagram for detail::Buffer< type >:
Inheritance graph
[legend]

List of all members.

Public Types

typedef type  value_type
typedef value_type reference
typedef const reference  const_reference
typedef value_type pointer
typedef const value_type const_pointer
typedef pointer  iterator
typedef const_pointer  const_iterator
typedef std::reverse_iterator
< iterator
reverse_iterator
typedef std::reverse_iterator
< const_iterator
const_reverse_iterator

Public Member Functions

  Buffer (const unsigned int capacity)
  Creates a buffer with the specified capacity and sets its size to zero.
  ~Buffer ()
  Deallocates all memory used by the buffer.
unsigned int  capacity () const
  Returns the maximum number of elements that can be written to the buffer without reallocating memory.
reference  operator[] (const unsigned int index)
  Returns the element at the specified index.
const_reference  operator[] (const unsigned int index) const
  Returns the element at the specified index.
iterator  begin ()
  Returns an iterator pointing to the first element in the buffer.
const_iterator  begin () const
  Returns a const iterator pointing to the first element in the buffer.
iterator  end ()
  Returns an iterator pointing to one position beyond the last element in the buffer.
const_iterator  end () const
  Returns an iterator pointing to one position beyond the last element in the buffer.
reverse_iterator  rbegin ()
  Returns reverse_iterator(end()).
const_reverse_iterator  rbegin () const
  Returns const_reverse_iterator(end()).
reverse_iterator  rend ()
  Returns reverse_iterator(begin()).
const_reverse_iterator  rend () const
  Returns const_reverse_iterator(begin()).
void  reserve (const unsigned int capacity)
  Increases the buffer capacity to the specified size.
void  resize (const unsigned int size)
  Resizes the buffer to the specified size.
unsigned int  size () const
  Returns the number of elements contained in the buffer.
void  clear ()
  Same as resize(0).
void  add (const type &value)
  Appends a value to the end of the buffer and increments the size by one.

Detailed Description

template<typename type>
class detail::Buffer< type >

Buffer defines a limited set of operations for managing a memory buffer.

It is intended only for internal use by the library. Please do not subclass Buffer, but do examine its public methods that are inherited by its subclasses.

We define Buffer instead of using std::vector because we want to avoid the overhead of std::vector::clear() and std::vector::resize(), both of which cause unused data elements to be erased. The buffers used by the library may be resized often (potentially on every send and receive). We are unconcerned with erasing (or initializing) unused elements because we read and write to the buffer's raw memory. Therefore, we merely require an index that tracks the size of the buffer.

Definition at line 49 of file Buffer.h.


Member Typedef Documentation

template<typename type>
typedef const_pointer detail::Buffer< type >::const_iterator

Definition at line 62 of file Buffer.h.

template<typename type>
typedef const value_type* detail::Buffer< type >::const_pointer

Definition at line 60 of file Buffer.h.

template<typename type>
typedef const reference detail::Buffer< type >::const_reference

Definition at line 58 of file Buffer.h.

template<typename type>
typedef std::reverse_iterator<const_iterator> detail::Buffer< type >::const_reverse_iterator

Definition at line 64 of file Buffer.h.

template<typename type>
typedef pointer detail::Buffer< type >::iterator

Definition at line 61 of file Buffer.h.

template<typename type>
typedef value_type* detail::Buffer< type >::pointer

Definition at line 59 of file Buffer.h.

template<typename type>
typedef value_type& detail::Buffer< type >::reference

Definition at line 57 of file Buffer.h.

template<typename type>
typedef std::reverse_iterator<iterator> detail::Buffer< type >::reverse_iterator

Definition at line 63 of file Buffer.h.

template<typename type>
typedef type detail::Buffer< type >::value_type

Definition at line 56 of file Buffer.h.


Constructor & Destructor Documentation

template<typename type>
detail::Buffer< type >::Buffer ( const unsigned int  capacity ) [inline, explicit]

Creates a buffer with the specified capacity and sets its size to zero.

Parameters:
capacity The initial capacity of the buffer.

Definition at line 71 of file Buffer.h.

template<typename type>
detail::Buffer< type >::~Buffer ( ) [inline]

Deallocates all memory used by the buffer.

Definition at line 78 of file Buffer.h.


Member Function Documentation

template<typename type>
void detail::Buffer< type >::add ( const type &  value ) [inline]

Appends a value to the end of the buffer and increments the size by one.

If the buffer is at full capacity, its capacity is increased to be able to hold more data. Currently, this is done by doubling the current capacity, but you should not rely on that behavior.

Parameters:
value The value to append to the buffer.

Definition at line 241 of file Buffer.h.

Referenced by GroupList::add().

template<typename type>
iterator detail::Buffer< type >::begin ( ) [inline]

Returns an iterator pointing to the first element in the buffer.

Returns:
An iterator pointing to the first element in the buffer.

Definition at line 115 of file Buffer.h.

Referenced by detail::Buffer< char >::rend().

template<typename type>
const_iterator detail::Buffer< type >::begin ( ) const [inline]

Returns a const iterator pointing to the first element in the buffer.

Returns:
A const iterator pointing to the first element in the buffer.

Definition at line 124 of file Buffer.h.

template<typename type>
unsigned int detail::Buffer< type >::capacity ( ) const [inline]

Returns the maximum number of elements that can be written to the buffer without reallocating memory.

Returns:
The buffer capacity.

Definition at line 86 of file Buffer.h.

Referenced by detail::Buffer< char >::add(), detail::ByteBuffer::ByteBuffer(), and detail::Buffer< char >::reserve().

template<typename type>
void detail::Buffer< type >::clear ( ) [inline]

Same as resize(0).

Reimplemented in detail::ByteBuffer, and Message.

Definition at line 228 of file Buffer.h.

Referenced by GroupList::clear().

template<typename type>
const_iterator detail::Buffer< type >::end ( ) const [inline]

Returns an iterator pointing to one position beyond the last element in the buffer.

Returns:
An iterator pointing to one position beyond the last element in the buffer.

Definition at line 146 of file Buffer.h.

template<typename type>
iterator detail::Buffer< type >::end ( ) [inline]

Returns an iterator pointing to one position beyond the last element in the buffer.

Returns:
An iterator pointing to one position beyond the last element in the buffer.

Definition at line 135 of file Buffer.h.

Referenced by detail::Buffer< char >::rbegin().

template<typename type>
reference detail::Buffer< type >::operator[] ( const unsigned int  index ) [inline]

Returns the element at the specified index.

Parameters:
index The index of the element to retrieve.
Returns:
The element at the specified index.

Definition at line 96 of file Buffer.h.

template<typename type>
const_reference detail::Buffer< type >::operator[] ( const unsigned int  index ) const [inline]

Returns the element at the specified index.

Parameters:
index The index of the element to retrieve.
Returns:
The element at the specified index.

Definition at line 106 of file Buffer.h.

template<typename type>
reverse_iterator detail::Buffer< type >::rbegin ( ) [inline]

Returns reverse_iterator(end()).

Returns:
reverse_iterator(end()).

Definition at line 155 of file Buffer.h.

template<typename type>
const_reverse_iterator detail::Buffer< type >::rbegin ( ) const [inline]

Returns const_reverse_iterator(end()).

Returns:
const_reverse_iterator(end()).

Definition at line 164 of file Buffer.h.

template<typename type>
reverse_iterator detail::Buffer< type >::rend ( ) [inline]

Returns reverse_iterator(begin()).

Returns:
reverse_iterator(begin()).

Definition at line 173 of file Buffer.h.

template<typename type>
const_reverse_iterator detail::Buffer< type >::rend ( ) const [inline]

Returns const_reverse_iterator(begin()).

Returns:
const_reverse_iterator(begin()).

Definition at line 182 of file Buffer.h.

template<typename type>
void detail::Buffer< type >::reserve ( const unsigned int  capacity ) [inline]

Increases the buffer capacity to the specified size.

If the new size is less than or equal to the buffer capacity, no action is performed. If the size is greater than the capacity, new memory is reserved, increasing the capacity while preserving the existing buffer contents.

Parameters:
capacity The new buffer capacity.

Definition at line 195 of file Buffer.h.

Referenced by detail::Buffer< char >::add(), and detail::Buffer< char >::resize().

template<typename type>
void detail::Buffer< type >::resize ( const unsigned int  size ) [inline]

Resizes the buffer to the specified size.

If the new size is less than or equal to the buffer capacity, the size is simply set to the new value. If the size is greater than the capacity, new memory is reserved—preserving the existing buffer contents—before setting the size to the new value.

Parameters:
size The new buffer size.

Definition at line 214 of file Buffer.h.

Referenced by detail::Buffer< char >::clear().

template<typename type>
unsigned int detail::Buffer< type >::size ( ) const [inline]

Returns the number of elements contained in the buffer.

Returns:
The number of elements contained in the buffer.

Reimplemented in Message.

Definition at line 223 of file Buffer.h.

Referenced by detail::ByteBuffer::ByteBuffer(), detail::ByteBuffer::operator=(), detail::Buffer< char >::resize(), and GroupList::size().


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

Savarese Software Research Corporation
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.