#include <buffer.hh>
Collaboration diagram for atoms::Buffer:

This class is primarily intended for use in the BufferedStreamFilter class. It is an independent, publically-accessible class to aid unit testing and because in the future, high-performance applications may directly access buffers.
It is similar to Java's java.nio.Buffer class, and I've deliberately chosen the variable names to be the same as theirs.
The main buffer region starts at position and extends until limit (and thus is of size limit - position.) There are two main reasons it is not simple a buffer region starting at 0:
memove() the entire contents of the buffer after retrieving data. This would be an O(n) operation with the size of the buffer. This way, it is O(n) with the size of the retrieval, which is much better.
Definition at line 53 of file buffer.hh.
Public Member Functions | |
| Buffer () | |
| ~Buffer () | |
| Destroys the buffer. | |
| void | append (const void *src, size_t n) |
| Appends n bytes to the buffer. | |
| template<typename internT, typename externT, typename stateT> void | append (const internT *from, const internT *fromEnd, stateT &, const std::codecvt< internT, externT, stateT > &) |
| void | replace (const void *src, size_t p, size_t n) |
| Replaces up to n bytes beginning at p, extending the buffer if necessary. | |
| void | shift (void *dest, size_t n) |
| Copies n bytes from the beginning of the buffer and removes them. | |
| size_t | truncate (size_t n) |
| Truncates the buffer to length n. | |
| size_t | getSize () const |
| Returns the current size of the main region. | |
| size_t | getCapacity () const |
| Returns the current capacity of the buffer. | |
| size_t | getRollbackSize () const |
| Returns the current size of the rollback region. | |
| void | setMark () |
| Sets a mark at the current position. | |
| void | rollback () |
| Rolls back to the mark. | |
| void | rollback (size_t n) |
| Rolls back n bytes. | |
| void | clear () |
| Clears the mark. | |
| size_t | readAndAppend (Stream *s, size_t min) |
| size_t | readAndAppend (const boost::shared_ptr< Stream > &s, size_t min) |
| size_t | writeAndShift (Stream *s, size_t max) |
| size_t | writeAndShift (const boost::shared_ptr< Stream > &s, size_t max) |
Private Member Functions | |
| void | prepareForAppend (size_t n) |
| Ensures there is capacity to append n bytes. | |
Private Attributes | |
| size_t | position |
| The start of meaningful data within the buffer. | |
| size_t | limit |
| First free byte within the buffer. | |
| size_t | capacity |
| The first byte beyond the allocation of the buffer. | |
| char * | buf |
| The buffer itself, allocated and deallocated with C-style functions. | |
| size_t | mark |
| bool | markSet |
Static Private Attributes | |
| size_t | MINIMUM_ALLOCATION = 1024 |
| This is smallest chunk of memory we'll ever allocate. | |
| DebugLogger | LOGGER |
|
|
|
|
|
Destroys the buffer.
|
|
||||||||||||||||||||||||
|
|
|
||||||||||||
|
Appends n bytes to the buffer. In preparation, it may cause the non-guaranteed rollback region to be destroyed. Adjusts the size of the buffer to reflect the read.
Definition at line 35 of file buffer.cc. References buf, limit, NULL, and prepareForAppend(). |
Here is the call graph for this function:

|
|
Clears the mark.
Definition at line 190 of file buffer.hh. References markSet. |
|
|
Returns the current capacity of the buffer.
Definition at line 146 of file buffer.hh. References position. |
|
|
Returns the current size of the rollback region.
|
|
|
Returns the current size of the main region.
Definition at line 143 of file buffer.hh. References capacity. |
|
|
Ensures there is capacity to append n bytes. If necessary, the non-guaranteed rollback region will be destroyed. Definition at line 76 of file buffer.cc. References buf, capacity, limit, atoms::DebugLogger::log(), LOGGER, mark, markSet, std::max(), MINIMUM_ALLOCATION, NULL, and position. Referenced by append(), readAndAppend(), and replace(). |
Here is the call graph for this function:

|
||||||||||||
|
In preparation, it may cause the non-guaranteed rollback region to be destroyed. Adjusts the size of the buffer to reflect the read.
|
|
||||||||||||
|
In preparation, it may cause the non-guaranteed rollback region to be destroyed. Adjusts the size of the buffer to reflect the read.
Definition at line 26 of file buffer.cc. References buf, capacity, limit, std::min(), NULL, prepareForAppend(), and atoms::Stream::read(). |
Here is the call graph for this function:

|
||||||||||||||||
|
Replaces up to n bytes beginning at p, extending the buffer if necessary. In preparation, it may cause the non-guaranteed rollback region to be destroyed. Adjusts the size of the buffer to reflect the read.
Definition at line 42 of file buffer.cc. References buf, limit, NULL, position, and prepareForAppend(). |
Here is the call graph for this function:

|
|
Rolls back n bytes.
|
|
|
Rolls back to the mark.
|
|
|
Sets a mark at the current position. The buffer can be rolled back to this state with a reset.
|
|
||||||||||||
|
Copies n bytes from the beginning of the buffer and removes them.
The bytes remain in the rollback region, but the
|
|
|
Truncates the buffer to length n.
|
|
||||||||||||
|
The bytes remain in the rollback region, but the
|
|
||||||||||||
|
The bytes remain in the rollback region, but the
Definition at line 54 of file buffer.cc. References buf, limit, std::max(), NULL, position, and atoms::Stream::write(). |
Here is the call graph for this function:

|
|
The buffer itself, allocated and deallocated with C-style functions. Always NULL when not memory is allocated. Definition at line 228 of file buffer.hh. Referenced by append(), prepareForAppend(), readAndAppend(), replace(), shift(), and writeAndShift(). |
|
|
The first byte beyond the allocation of the buffer.
Definition at line 222 of file buffer.hh. Referenced by getSize(), prepareForAppend(), and readAndAppend(). |
|
|
First free byte within the buffer.
Definition at line 219 of file buffer.hh. Referenced by append(), prepareForAppend(), readAndAppend(), replace(), shift(), truncate(), and writeAndShift(). |
|
|
Referenced by prepareForAppend(). |
|
|
If markSet is false, mark's contents are undefined. Otherwise, the standard invariant applies. Definition at line 208 of file buffer.hh. Referenced by prepareForAppend(), rollback(), and setMark(). |
|
|
If markSet is false, mark's contents are undefined. Otherwise, the standard invariant applies. Definition at line 209 of file buffer.hh. Referenced by clear(), prepareForAppend(), rollback(), and setMark(). |
|
|
This is smallest chunk of memory we'll ever allocate.
Definition at line 22 of file buffer.cc. Referenced by prepareForAppend(). |
|
|
The start of meaningful data within the buffer.
Definition at line 213 of file buffer.hh. Referenced by getCapacity(), prepareForAppend(), replace(), rollback(), setMark(), shift(), truncate(), and writeAndShift(). |
1.3.5