Buffer defines a limited set of operations for managing a memory buffer. More...
#include <Buffer.h>

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.
Member Typedef Documentation
| typedef const_pointer detail::Buffer< type >::const_iterator |
| typedef const value_type* detail::Buffer< type >::const_pointer |
| typedef const reference detail::Buffer< type >::const_reference |
| typedef std::reverse_iterator<const_iterator> detail::Buffer< type >::const_reverse_iterator |
| typedef pointer detail::Buffer< type >::iterator |
| typedef value_type* detail::Buffer< type >::pointer |
| typedef value_type& detail::Buffer< type >::reference |
| typedef std::reverse_iterator<iterator> detail::Buffer< type >::reverse_iterator |
| typedef type detail::Buffer< type >::value_type |
Constructor & Destructor Documentation
| detail::Buffer< type >::Buffer | ( | const unsigned int | capacity | ) | [inline, explicit] |
| detail::Buffer< type >::~Buffer | ( | ) | [inline] |
Member Function Documentation
| 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().
| 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().
| const_iterator detail::Buffer< type >::begin | ( | ) | const [inline] |
| 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().
| 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().
| const_iterator detail::Buffer< type >::end | ( | ) | const [inline] |
| 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().
| reference detail::Buffer< type >::operator[] | ( | const unsigned int | index | ) | [inline] |
| const_reference detail::Buffer< type >::operator[] | ( | const unsigned int | index | ) | const [inline] |
| reverse_iterator detail::Buffer< type >::rbegin | ( | ) | [inline] |
| const_reverse_iterator detail::Buffer< type >::rbegin | ( | ) | const [inline] |
| reverse_iterator detail::Buffer< type >::rend | ( | ) | [inline] |
| const_reverse_iterator detail::Buffer< type >::rend | ( | ) | const [inline] |
| 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().
| 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().
| 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: