wibble::sys::Buffer Class Reference

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

`#include <buffer.h>`

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

## Classes

class | Data

## Public Member Functions

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

## Public Attributes

Data * | item

## 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 wibble::sys::Buffer::Data::Data(), and wibble::sys::Buffer::Data::ref().

## Buffer() [3/5]

wibble::sys::Buffer::Buffer | ( | void * | buf,
|  | size_t | size,
|  | bool | own = `true`
| ) |  |

inline

Create a buffer from existing data.

Parameters

  buf | The data to put in this buffer
  size | The dimension of buf
  own | If 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 wibble::sys::Buffer::Data::Data(), and wibble::sys::Buffer::Data::ref().

## 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 wibble::sys::Buffer::Data::Data(), and wibble::sys::Buffer::Data::ref().

## Buffer() [5/5]

wibble::sys::Buffer::Buffer | ( | const Buffer & | buf | ) |
throw | ( |
| ) |  |

inline

## ~Buffer()

wibble::sys::Buffer::~Buffer | ( |  | ) |

inline

References wibble::sys::Buffer::Data::unref().

## Member Function Documentation

## data() [1/2]

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

inline

Return a pointer to the buffer.

References wibble::sys::Buffer::Data::_data.

Referenced by wibble::sys::NetBuffer::cast(), TestBuffer::copy(), wibble::sys::NetBuffer::data(), TestBuffer::emptiness(), TestBuffer::nonemptiness(), print_preview(), TestBuffer::resize(), and TestBuffer::takeover().

## data() [2/2]

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

inline

Return a pointer to the buffer.

References wibble::sys::Buffer::Data::_data.

## operator!=()

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

inline

References wibble::sys::Buffer::Data::operator==().

## operator<()

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

inline

Compare the contents of two buffers.

References wibble::sys::operator<<(), print_preview(), and size().

## operator=()

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

inline

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

Referenced by wibble::sys::NetBuffer::operator=().

## operator==()

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

inline

Compare the contents of two buffers.

## 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().

Referenced by operator<(), and wibble::sys::operator<<().

## resize()

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

inline

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

References wibble::sys::Buffer::Data::Data(), 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

Return the buffer size.

References wibble::sys::Buffer::Data::_size.

Referenced by TestBuffer::copy(), wibble::sys::Buffer::Data::Data(), TestBuffer::emptiness(), TestBuffer::nonemptiness(), operator<(), print_preview(), wibble::sys::Buffer::Data::resize(), TestBuffer::resize(), resize(), wibble::sys::NetBuffer::size(), and TestBuffer::takeover().

## Member Data Documentation

## item

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

Referenced by operator=().

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

- buffer.h
- buffer.cpp