Savarese Software Research Corporation
detail::ByteBuffer Class Reference

ByteBuffer provides the ability to write and read bytes to and from a buffer and reuse the buffer for input or output. More...

#include <ByteBuffer.h>

Inheritance diagram for detail::ByteBuffer:
Inheritance graph
[legend]

List of all members.

Public Types

typedef char  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

  ByteBuffer (const unsigned int capacity)
  Creates a buffer with the specified capacity and sets its size and offset to zero.
  ByteBuffer (const ByteBuffer &buffer)
  Creates a copy of a ByteBuffer, including its contents, its read/write position, size, and its capacity.
ByteBuffer operator= (const ByteBuffer &buffer)
  Copies the contents of a ByteBuffer, its read/write position, and its size, but does not necessarily copy its capacity.
unsigned int  offset () const
  Returns the current read/write position.
unsigned int  seek (const unsigned int offset)
  Sets the read/write position to the specified value if the value is less than or equal to the size of the buffer.
void  rewind ()
  Same as seek(0).
void  clear ()
  Rewinds the read/write position befor resizing the buffer to zero.
void  write (const void *data, const unsigned int size)
  Writes the specified number of bytes from the provided data into the buffer at the current read/write position.
unsigned int  read (void *data, unsigned int size)
  Reads the specified number of bytes from the buffer into the provided destination starting from the current read/write position.
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  add (const char &value)
  Appends a value to the end of the buffer and increments the size by one.

Detailed Description

ByteBuffer provides the ability to write and read bytes to and from a buffer and reuse the buffer for input or output.

The class is not meant to be subclassed by library users, but it needs to be documented publicly so you can use its methods in its subclasses.

ByteBuffer maintains a current offset into the buffer where reads and writes will start. The offset is not updated when the buffer is resized.

Definition at line 43 of file ByteBuffer.h.


Member Typedef Documentation

typedef const_pointer detail::Buffer< char >::const_iterator [inherited]

Definition at line 62 of file Buffer.h.

typedef const value_type* detail::Buffer< char >::const_pointer [inherited]

Definition at line 60 of file Buffer.h.

typedef const reference detail::Buffer< char >::const_reference [inherited]

Definition at line 58 of file Buffer.h.

typedef std::reverse_iterator<const_iterator> detail::Buffer< char >::const_reverse_iterator [inherited]

Definition at line 64 of file Buffer.h.

typedef pointer detail::Buffer< char >::iterator [inherited]

Definition at line 61 of file Buffer.h.

typedef value_type* detail::Buffer< char >::pointer [inherited]

Definition at line 59 of file Buffer.h.

typedef value_type& detail::Buffer< char >::reference [inherited]

Definition at line 57 of file Buffer.h.

typedef std::reverse_iterator<iterator> detail::Buffer< char >::reverse_iterator [inherited]

Definition at line 63 of file Buffer.h.

typedef char detail::Buffer< char >::value_type [inherited]

Definition at line 56 of file Buffer.h.


Constructor & Destructor Documentation

detail::ByteBuffer::ByteBuffer ( const unsigned int  capacity ) [inline, explicit]

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

Parameters:
capacity The initial capacity of the buffer.

Definition at line 56 of file ByteBuffer.h.

References detail::Buffer< char >::reserve().

detail::ByteBuffer::ByteBuffer ( const ByteBuffer buffer ) [inline]

Creates a copy of a ByteBuffer, including its contents, its read/write position, size, and its capacity.

Parameters:
buffer The ByteBuffer to copy.

Definition at line 66 of file ByteBuffer.h.

References detail::Buffer< type >::capacity(), offset(), detail::Buffer< char >::reserve(), seek(), detail::Buffer< type >::size(), and write().


Member Function Documentation

void detail::Buffer< char >::add ( const char &  value ) [inline, inherited]

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.

References detail::Buffer< type >::capacity(), and detail::Buffer< type >::reserve().

iterator detail::Buffer< char >::begin ( ) [inline, inherited]

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.

const_iterator detail::Buffer< char >::begin ( ) const [inline, inherited]

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.

unsigned int detail::Buffer< char >::capacity ( ) const [inline, inherited]

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.

void detail::ByteBuffer::clear ( ) [inline]

Rewinds the read/write position befor resizing the buffer to zero.

Reimplemented from detail::Buffer< char >.

Reimplemented in Message.

Definition at line 119 of file ByteBuffer.h.

References detail::Buffer< char >::resize(), and rewind().

Referenced by operator=().

iterator detail::Buffer< char >::end ( ) [inline, inherited]

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.

const_iterator detail::Buffer< char >::end ( ) const [inline, inherited]

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.

unsigned int detail::ByteBuffer::offset ( ) const [inline]

Returns the current read/write position.

Returns:
The current read/write position.

Definition at line 93 of file ByteBuffer.h.

Referenced by ByteBuffer(), operator=(), and seek().

ByteBuffer& detail::ByteBuffer::operator= ( const ByteBuffer buffer ) [inline]

Copies the contents of a ByteBuffer, its read/write position, and its size, but does not necessarily copy its capacity.

Parameters:
buffer The ByteBuffer to copy.
Returns:
*this

Definition at line 79 of file ByteBuffer.h.

References clear(), offset(), seek(), detail::Buffer< type >::size(), and write().

reference detail::Buffer< char >::operator[] ( const unsigned int  index ) [inline, inherited]

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.

const_reference detail::Buffer< char >::operator[] ( const unsigned int  index ) const [inline, inherited]

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.

const_reverse_iterator detail::Buffer< char >::rbegin ( ) const [inline, inherited]

Returns const_reverse_iterator(end()).

Returns:
const_reverse_iterator(end()).

Definition at line 164 of file Buffer.h.

References detail::Buffer< type >::end().

reverse_iterator detail::Buffer< char >::rbegin ( ) [inline, inherited]

Returns reverse_iterator(end()).

Returns:
reverse_iterator(end()).

Definition at line 155 of file Buffer.h.

References detail::Buffer< type >::end().

unsigned int detail::ByteBuffer::read ( void *  data,
unsigned int  size 
) [inline]

Reads the specified number of bytes from the buffer into the provided destination starting from the current read/write position.

If the number of bytes to be read would result in running off the end of the buffer, the read is truncated at the end of the buffer.

Parameters:
data A pointer to the read destination.
size The number of bytes to read.
Returns:
The number of bytes read.

Definition at line 157 of file ByteBuffer.h.

References detail::Buffer< char >::size().

const_reverse_iterator detail::Buffer< char >::rend ( ) const [inline, inherited]

Returns const_reverse_iterator(begin()).

Returns:
const_reverse_iterator(begin()).

Definition at line 182 of file Buffer.h.

References detail::Buffer< type >::begin().

reverse_iterator detail::Buffer< char >::rend ( ) [inline, inherited]

Returns reverse_iterator(begin()).

Returns:
reverse_iterator(begin()).

Definition at line 173 of file Buffer.h.

References detail::Buffer< type >::begin().

void detail::Buffer< char >::reserve ( const unsigned int  capacity ) [inline, inherited]

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.

References detail::Buffer< type >::capacity().

Referenced by ByteBuffer().

void detail::Buffer< char >::resize ( const unsigned int  size ) [inline, inherited]

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.

References detail::Buffer< type >::reserve(), and detail::Buffer< type >::size().

Referenced by clear(), and write().

void detail::ByteBuffer::rewind ( ) [inline]

Same as seek(0).

Definition at line 112 of file ByteBuffer.h.

References seek().

Referenced by clear().

unsigned int detail::ByteBuffer::seek ( const unsigned int  offset ) [inline]

Sets the read/write position to the specified value if the value is less than or equal to the size of the buffer.

Otherwise, the current offset is left unchanged.

Parameters:
offset The buffer offset of the new read/write position.
Returns:
The new read/write position.

Definition at line 105 of file ByteBuffer.h.

References offset(), and detail::Buffer< char >::size().

Referenced by ByteBuffer(), operator=(), and rewind().

unsigned int detail::Buffer< char >::size ( ) const [inline, inherited]

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 read(), seek(), and write().

void detail::ByteBuffer::write ( const void *  data,
const unsigned int  size 
) [inline]

Writes the specified number of bytes from the provided data into the buffer at the current read/write position.

If the buffer is not large enough to hold the data, it is resized automatically to the current offset plus the size of the data to be written. After writing the data, the read/write position is incremented by the size of the data written.

Parameters:
data A pointer to the data to be written.
size The number of bytes to write.

Definition at line 135 of file ByteBuffer.h.

References detail::Buffer< char >::resize(), and detail::Buffer< char >::size().

Referenced by ByteBuffer(), and operator=().


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.