STXXL  1.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stxxl::binary_buffer Class Reference

Detailed Description

binary_buffer represents a dynamically growable area of memory, which can be modified by appending integral data types via put() and other basic operations.

Definition at line 41 of file binary_buffer.h.

Public Member Functions

 binary_buffer ()
 Create a new empty object. More...
 
 binary_buffer (const binary_buffer &other)
 Copy-Constructor, duplicates memory content. More...
 
 binary_buffer (const void *data, size_t n)
 Constructor, copy memory area. More...
 
 binary_buffer (size_t n)
 Constructor, create object with n bytes pre-allocated. More...
 
 binary_buffer (const std::string &str)
 Constructor from std::string, copies string content. More...
 
 ~binary_buffer ()
 Destroys the memory space. More...
 
binary_bufferalign (size_t n)
 Align the size of the buffer to a multiple of n. Fills up with 0s. More...
 
binary_bufferalloc (size_t n)
 Make sure that at least n bytes are allocated. More...
 
binary_bufferappend (const void *data, size_t len)
 Append a memory range to the buffer. More...
 
binary_bufferappend (const class binary_buffer &bb)
 Append the contents of a different buffer object to this one. More...
 
binary_bufferappend (const std::string &s)
 Append to contents of a std::string, excluding the null (which isn't contained in the string size anyway). More...
 
binary_bufferassign (const void *data, size_t len)
 Copy a memory range into the buffer, overwrites all current data. Roughly equivalent to clear() followed by append(). More...
 
binary_bufferassign (const binary_buffer &other)
 Copy the contents of another buffer object into this buffer, overwrites all current data. Roughly equivalent to clear() followed by append(). More...
 
size_t capacity () const
 Return the currently allocated buffer capacity. More...
 
binary_bufferclear ()
 Clears the memory contents, does not deallocate the memory. More...
 
const char * data () const
 Return a pointer to the currently kept memory area. More...
 
char * data ()
 Return a writeable pointer to the currently kept memory area. More...
 
binary_bufferdealloc ()
 Deallocates the kept memory space (we use dealloc() instead of free() as a name, because sometimes "free" is replaced by the preprocessor) More...
 
const char * detach ()
 Detach the memory from the object, returns the memory pointer. More...
 
binary_bufferdynalloc (size_t n)
 Dynamically allocate more memory. At least n bytes will be available, probably more to compensate future growth. More...
 
binary_bufferoperator= (const binary_buffer &other)
 Assignment operator: copy other's memory range into buffer. More...
 
template<typename Type >
binary_bufferput (const Type item)
 Put (append) a single item of the template type T to the buffer. Be careful with implicit type conversions! More...
 
binary_bufferput_string (const char *data, size_t len)
 Put a string by saving it's length followed by the data itself. More...
 
binary_bufferput_string (const std::string &str)
 Put a string by saving it's length followed by the data itself. More...
 
binary_bufferput_string (const binary_buffer &bb)
 Put a binary_buffer by saving it's length followed by the data itself. More...
 
binary_bufferput_varint (uint32 v)
 Append a varint to the buffer. More...
 
binary_bufferput_varint (int v)
 Append a varint to the buffer. More...
 
binary_bufferput_varint (uint64 v)
 Append a varint to the buffer. More...
 
binary_bufferset_size (size_t n)
 Set the valid bytes in the buffer, use if the buffer is filled directly. More...
 
size_t size () const
 Return the currently used length in bytes. More...
 
std::string str () const
 Explicit conversion to std::string (copies memory of course). More...
 

Protected Attributes

size_t m_capacity
 Total capacity of buffer. More...
 
char * m_data
 Allocated buffer pointer. More...
 
size_t m_size
 Size of valid data. More...
 

Constructor & Destructor Documentation

stxxl::binary_buffer::binary_buffer ( )
inline

Create a new empty object.

Definition at line 55 of file binary_buffer.h.

stxxl::binary_buffer::binary_buffer ( const binary_buffer other)
inline

Copy-Constructor, duplicates memory content.

Definition at line 60 of file binary_buffer.h.

stxxl::binary_buffer::binary_buffer ( const void *  data,
size_t  n 
)
inline

Constructor, copy memory area.

Definition at line 67 of file binary_buffer.h.

stxxl::binary_buffer::binary_buffer ( size_t  n)
inline

Constructor, create object with n bytes pre-allocated.

Definition at line 74 of file binary_buffer.h.

stxxl::binary_buffer::binary_buffer ( const std::string &  str)
inline

Constructor from std::string, copies string content.

Definition at line 81 of file binary_buffer.h.

stxxl::binary_buffer::~binary_buffer ( )
inline

Destroys the memory space.

Definition at line 88 of file binary_buffer.h.

Member Function Documentation

binary_buffer& stxxl::binary_buffer::align ( size_t  n)
inline

Align the size of the buffer to a multiple of n. Fills up with 0s.

Definition at line 204 of file binary_buffer.h.

binary_buffer& stxxl::binary_buffer::alloc ( size_t  n)
inline

Make sure that at least n bytes are allocated.

Definition at line 134 of file binary_buffer.h.

binary_buffer& stxxl::binary_buffer::append ( const void *  data,
size_t  len 
)
inline

Append a memory range to the buffer.

Definition at line 244 of file binary_buffer.h.

Referenced by put_string().

binary_buffer& stxxl::binary_buffer::append ( const class binary_buffer bb)
inline

Append the contents of a different buffer object to this one.

Definition at line 255 of file binary_buffer.h.

References data(), and size().

binary_buffer& stxxl::binary_buffer::append ( const std::string &  s)
inline

Append to contents of a std::string, excluding the null (which isn't contained in the string size anyway).

Definition at line 262 of file binary_buffer.h.

binary_buffer& stxxl::binary_buffer::assign ( const void *  data,
size_t  len 
)
inline

Copy a memory range into the buffer, overwrites all current data. Roughly equivalent to clear() followed by append().

Definition at line 174 of file binary_buffer.h.

binary_buffer& stxxl::binary_buffer::assign ( const binary_buffer other)
inline

Copy the contents of another buffer object into this buffer, overwrites all current data. Roughly equivalent to clear() followed by append().

Definition at line 186 of file binary_buffer.h.

References data(), and size().

size_t stxxl::binary_buffer::capacity ( ) const
inline

Return the currently allocated buffer capacity.

Definition at line 112 of file binary_buffer.h.

binary_buffer& stxxl::binary_buffer::clear ( )
inline

Clears the memory contents, does not deallocate the memory.

Definition at line 166 of file binary_buffer.h.

const char* stxxl::binary_buffer::data ( ) const
inline

Return a pointer to the currently kept memory area.

Definition at line 94 of file binary_buffer.h.

Referenced by append(), assign(), operator=(), and put_string().

char* stxxl::binary_buffer::data ( )
inline

Return a writeable pointer to the currently kept memory area.

Definition at line 100 of file binary_buffer.h.

binary_buffer& stxxl::binary_buffer::dealloc ( )
inline

Deallocates the kept memory space (we use dealloc() instead of free() as a name, because sometimes "free" is replaced by the preprocessor)

Definition at line 147 of file binary_buffer.h.

const char* stxxl::binary_buffer::detach ( )
inline

Detach the memory from the object, returns the memory pointer.

Definition at line 157 of file binary_buffer.h.

binary_buffer& stxxl::binary_buffer::dynalloc ( size_t  n)
inline

Dynamically allocate more memory. At least n bytes will be available, probably more to compensate future growth.

Definition at line 222 of file binary_buffer.h.

binary_buffer& stxxl::binary_buffer::operator= ( const binary_buffer other)
inline

Assignment operator: copy other's memory range into buffer.

Definition at line 195 of file binary_buffer.h.

References data(), and size().

template<typename Type >
binary_buffer& stxxl::binary_buffer::put ( const Type  item)
inline

Put (append) a single item of the template type T to the buffer. Be careful with implicit type conversions!

Definition at line 270 of file binary_buffer.h.

binary_buffer& stxxl::binary_buffer::put_string ( const char *  data,
size_t  len 
)
inline

Put a string by saving it's length followed by the data itself.

Definition at line 401 of file binary_buffer.h.

References append().

binary_buffer& stxxl::binary_buffer::put_string ( const std::string &  str)
inline

Put a string by saving it's length followed by the data itself.

Definition at line 407 of file binary_buffer.h.

binary_buffer& stxxl::binary_buffer::put_string ( const binary_buffer bb)
inline

Put a binary_buffer by saving it's length followed by the data itself.

Definition at line 413 of file binary_buffer.h.

References data(), and size().

binary_buffer& stxxl::binary_buffer::put_varint ( uint32  v)
inline

Append a varint to the buffer.

Definition at line 281 of file binary_buffer.h.

binary_buffer& stxxl::binary_buffer::put_varint ( int  v)
inline

Append a varint to the buffer.

Definition at line 313 of file binary_buffer.h.

binary_buffer& stxxl::binary_buffer::put_varint ( uint64  v)
inline

Append a varint to the buffer.

Definition at line 319 of file binary_buffer.h.

binary_buffer& stxxl::binary_buffer::set_size ( size_t  n)
inline

Set the valid bytes in the buffer, use if the buffer is filled directly.

Definition at line 125 of file binary_buffer.h.

size_t stxxl::binary_buffer::size ( ) const
inline

Return the currently used length in bytes.

Definition at line 106 of file binary_buffer.h.

Referenced by append(), assign(), operator=(), and put_string().

std::string stxxl::binary_buffer::str ( ) const
inline

Explicit conversion to std::string (copies memory of course).

Definition at line 118 of file binary_buffer.h.

Member Data Documentation

size_t stxxl::binary_buffer::m_capacity
protected

Total capacity of buffer.

Definition at line 51 of file binary_buffer.h.

char* stxxl::binary_buffer::m_data
protected

Allocated buffer pointer.

Definition at line 45 of file binary_buffer.h.

size_t stxxl::binary_buffer::m_size
protected

Size of valid data.

Definition at line 48 of file binary_buffer.h.


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