wibble 1.1
Classes | Public Member Functions | Public Attributes | List of all members
wibble::sys::Buffer Class Reference

Variable-size, reference-counted memory buffer. More...

#include <buffer.h>

Inheritance diagram for wibble::sys::Buffer:
Inheritance graph
[legend]
Collaboration diagram for wibble::sys::Buffer:
Collaboration graph
[legend]

Classes

class  Data
 

Public Member Functions

 Buffer () throw ()
 Create a 0-lenght buffer.
 
 Buffer (size_t size)
 Create a buffer with the specified size.
 
 Buffer (void *buf, size_t size, bool own=true)
 Create a buffer from existing data.
 
 Buffer (const void *buf, size_t size)
 Create a buffer with a copy of the given data.
 
 Buffer (const Buffer &buf) throw ()
 
 ~Buffer ()
 
Bufferoperator= (const Buffer &buf)
 
voiddata () throw ()
 Return a pointer to the buffer.
 
const voiddata () const throw ()
 Return a pointer to the buffer.
 
size_t size () const throw ()
 Return the buffer size.
 
void resize (size_t newSize)
 Resize the buffer to hold exactly the specified amount of bytes.
 
bool operator== (const Buffer &buf) const throw ()
 Compare the contents of two buffers.
 
bool operator!= (const Buffer &buf) const throw ()
 
bool operator< (const Buffer &buf) const throw ()
 Compare the contents of two buffers.
 
std::string print_preview (unsigned size) const
 Render a c-string escaped print preview of maximum size buffer bytes.
 

Public Attributes

Dataitem
 

Detailed Description

Variable-size, reference-counted memory buffer.

Constructor & Destructor Documentation

◆ Buffer() [1/5]

wibble::sys::Buffer::Buffer ( )
throw (
)
inline

Create a 0-lenght buffer.

◆ Buffer() [2/5]

wibble::sys::Buffer::Buffer ( size_t  size)
inline

Create a buffer with the specified size.

References item, wibble::sys::Buffer::Data::ref(), and size().

◆ Buffer() [3/5]

wibble::sys::Buffer::Buffer ( void buf,
size_t  size,
bool  own = true 
)
inline

Create a buffer from existing data.

Parameters
bufThe data to put in this buffer
sizeThe dimension of buf
ownIf true, take ownership of buf, else make a copy of it. If we take ownership, then buf must have been allocated with malloc, since we will call free() to deallocate it.

References item, wibble::sys::Buffer::Data::ref(), and size().

◆ Buffer() [4/5]

wibble::sys::Buffer::Buffer ( const void buf,
size_t  size 
)
inline

Create a buffer with a copy of the given data.

It will always make a copy of the contents of buf.

References item, wibble::sys::Buffer::Data::ref(), and size().

◆ Buffer() [5/5]

wibble::sys::Buffer::Buffer ( const Buffer buf)
throw (
)
inline

References item.

◆ ~Buffer()

wibble::sys::Buffer::~Buffer ( )
inline

Member Function Documentation

◆ data() [1/2]

void * wibble::sys::Buffer::data ( )
throw (
)
inline

◆ data() [2/2]

const void * wibble::sys::Buffer::data ( ) const
throw (
)
inline

Return a pointer to the buffer.

References wibble::sys::Buffer::Data::_data, and item.

◆ operator!=()

bool wibble::sys::Buffer::operator!= ( const Buffer buf) const
throw (
)
inline

References operator==().

◆ operator<()

bool wibble::sys::Buffer::operator< ( const Buffer buf) const
throw (
)
inline

Compare the contents of two buffers.

References item.

◆ operator=()

Buffer & wibble::sys::Buffer::operator= ( const Buffer buf)
inline

◆ operator==()

bool wibble::sys::Buffer::operator== ( const Buffer buf) const
throw (
)
inline

Compare the contents of two buffers.

References item.

Referenced by operator!=().

◆ print_preview()

std::string wibble::sys::Buffer::print_preview ( unsigned  size) const

Render a c-string escaped print preview of maximum size buffer bytes.

If the buffer is longer than size, "[...]" will be appended to the result.

References wibble::str::c_escape(), data(), and size().

◆ resize()

void wibble::sys::Buffer::resize ( size_t  newSize)
inline

Resize the buffer to hold exactly the specified amount of bytes.

References item, wibble::sys::Buffer::Data::ref(), wibble::sys::Buffer::Data::resize(), size(), and wibble::sys::Buffer::Data::unref().

Referenced by TestBuffer::resize().

◆ size()

size_t wibble::sys::Buffer::size ( ) const
throw (
)
inline

Member Data Documentation

◆ item

Data* wibble::sys::Buffer::item

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