Savarese Software Research Corporation

ssrc::spread::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 ssrc::spread::detail::ByteBuffer:

List of all members.

Public Types

typedef char value_type
typedef value_typereference
typedef const reference const_reference
typedef value_typepointer
typedef const pointer const_pointer

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.
ByteBufferoperator= (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.
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 ssrc::spread::detail::Buffer< char >::const_pointer [inherited]

Definition at line 61 of file Buffer.h.

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

Definition at line 59 of file Buffer.h.

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

Definition at line 60 of file Buffer.h.

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

Definition at line 58 of file Buffer.h.

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

Definition at line 57 of file Buffer.h.


Constructor & Destructor Documentation

ssrc::spread::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.

ssrc::spread::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 ssrc::spread::detail::Buffer< type >::capacity(), offset(), and ssrc::spread::detail::Buffer< type >::size().


Member Function Documentation

void ssrc::spread::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 162 of file Buffer.h.

unsigned int ssrc::spread::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 83 of file Buffer.h.

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

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

Reimplemented from ssrc::spread::detail::Buffer< char >.

Reimplemented in ssrc::spread::Message.

Definition at line 119 of file ByteBuffer.h.

unsigned int ssrc::spread::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(), and operator=().

ByteBuffer& ssrc::spread::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 offset(), and ssrc::spread::detail::Buffer< type >::size().

const_reference ssrc::spread::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 103 of file Buffer.h.

reference ssrc::spread::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 93 of file Buffer.h.

unsigned int ssrc::spread::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.

void ssrc::spread::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 116 of file Buffer.h.

void ssrc::spread::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 135 of file Buffer.h.

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

Same as seek(0).

Definition at line 112 of file ByteBuffer.h.

unsigned int ssrc::spread::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.

unsigned int ssrc::spread::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 ssrc::spread::Message.

Definition at line 144 of file Buffer.h.

void ssrc::spread::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.


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

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