libfilezilla
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | List of all members
buffer Class Referencefinal

The buffer class is a simple buffer where data can be appended at the end and consumed at the front. Think of it as a deque with contiguous storage. More...

#include <buffer.hpp>

Public Member Functions

 buffer (size_t capacity)
 Initially reserves the passed capacity.
 
 buffer (buffer const &buf)
 
 buffer (buffer &&buf)
 
bufferoperator= (buffer const &buf)
 
bufferoperator= (buffer &&buf)
 
unsigned char * get ()
 
unsigned char * get (size_t write_size)
 Returns a writable buffer guaranteed to be large enough for write_size bytes, call add when done. More...
 
void add (size_t added)
 
void consume (size_t consumed)
 Removes consumed bytes from the beginning of the buffer. More...
 
size_t size () const
 
void clear ()
 
void append (unsigned char const *data, size_t len)
 Appends the passed data to the buffer. More...
 
void append (std::string const &str)
 
bool empty () const
 
 operator bool () const
 
void reserve (size_t capacity)
 
unsigned char operator[] (size_t i) const
 Gets element at offset i. Does not do bounds checking.
 
unsigned char & operator[] (size_t i)
 

Detailed Description

The buffer class is a simple buffer where data can be appended at the end and consumed at the front. Think of it as a deque with contiguous storage.

This class is useful when buffering data for sending over the network, or for buffering data for further piecemeal processing after having received it.

Member Function Documentation

void append ( unsigned char const *  data,
size_t  len 
)

Appends the passed data to the buffer.

The number of reallocations as result to repeated append are armortized O(1)

void clear ( )

Does not release the memory.

void consume ( size_t  consumed)

Removes consumed bytes from the beginning of the buffer.

Undefined if consumed > size

unsigned char* get ( size_t  write_size)

Returns a writable buffer guaranteed to be large enough for write_size bytes, call add when done.

See Also
append

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