variablebuffer Class Reference

Inherited by stringbuffer.

## Public Member Functions

| variablebuffer (size_t initialsize, size_t increment)
| variablebuffer (unsigned char *initialcontents, size_t initialsize, size_t increment)
| variablebuffer (const variablebuffer &v)
variablebuffer & | operator= (const variablebuffer &v)
virtual | ~variablebuffer ()
void | setPosition (size_t pos)
size_t | getPosition ()
variablebuffer * | write (const unsigned char *data, size_t size)
variablebuffer * | write (const char *string)
variablebuffer * | write (const char *string, size_t size)
variablebuffer * | write (char character)
variablebuffer * | write (int16_t number)
variablebuffer * | write (int32_t number)
variablebuffer * | write (int64_t number)
variablebuffer * | write (unsigned char character)
variablebuffer * | write (uint16_t number)
variablebuffer * | write (uint32_t number)
variablebuffer * | write (uint64_t number)
variablebuffer * | write (float number)
variablebuffer * | write (double number)
variablebuffer * | writeFormatted (const char *format,...)
variablebuffer * | writeFormatted (const char *format, va_list *argp)
variablebuffer * | append (const unsigned char *data, size_t size)
variablebuffer * | append (const char *string)
variablebuffer * | append (const char *string, size_t size)
variablebuffer * | append (char character)
variablebuffer * | append (int16_t number)
variablebuffer * | append (int32_t number)
variablebuffer * | append (int64_t number)
variablebuffer * | append (unsigned char character)
variablebuffer * | append (uint16_t number)
variablebuffer * | append (uint32_t number)
variablebuffer * | append (uint64_t number)
variablebuffer * | append (float number)
variablebuffer * | append (double number)
variablebuffer * | appendFormatted (const char *format,...)
variablebuffer * | appendFormatted (const char *format, va_list *argp)
virtual void | truncate (size_t pos)
virtual void | truncate ()
ssize_t | read (unsigned char *data, size_t size)
void | clear ()
const unsigned char * | getBuffer ()
size_t | getSize ()
size_t | getEnd ()
size_t | getActualSize ()
unsigned char * | detachBuffer ()

## Detailed Description

The variablebuffer class can be used to store raw data of arbitrary length.

The class allocates a buffer internally of either a default or specified initial size. If a write or append operation would exceed the size of the existing buffer, then it is grown by a multiple of either a default or specified incremental size. This growth is accomplished by allocating a new, larger buffer and copying the contents of the old buffer into it along with whatever data was written or appended.

If the buffer is cleared, then if the existing buffer has grown beyond its initial size then it is deleted and a new buffer is allocated using the initial size. However if the buffer has not grown then no action is taken except to reset the internal position pointers.

It is generally more efficient to reuse the same variablebuffer over and over than to allocate a new one for each operation.

## Constructor & Destructor Documentation

variablebuffer::variablebuffer | ( | size_t | initialsize,
|  | size_t | increment
| ) |  |

Creates an instance of the variablebuffer class with the specified "initialsize" and "increment" parameters.

variablebuffer::variablebuffer | ( | unsigned char * | initialcontents,
|  | size_t | initialsize,
|  | size_t | increment
| ) |  |

Creates an instance of the variablebuffer class. The buffer "initialcontents" will be attached to the instance and used as the initial contents. This buffer should not be freed by the calling program. The initial size and increment may be specified respectively by the "initialsize" and "increment" parameters.

variablebuffer::variablebuffer | ( | const variablebuffer & | v | ) |

Creates an instance of the variablebuffer class that is a copy of "v".

virtual variablebuffer::~variablebuffer | ( |  | ) |

virtual

Deletes this instance of the variablebuffer class.

## Member Function Documentation

variablebuffer* variablebuffer::append | ( | const unsigned char * | data,
|  | size_t | size
| ) |  |

Appends the first "size" bytes of "data" to the variablebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

variablebuffer* variablebuffer::append | ( | const char * | string | ) |

Appends "string" to the variablebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

variablebuffer* variablebuffer::append | ( | const char * | string,
|  | size_t | size
| ) |  |

Appends the first "size" bytes of "string" to the variablebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

variablebuffer* variablebuffer::append | ( | char | character | ) |

Appends "character" to the variablebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

variablebuffer* variablebuffer::append | ( | int16_t | number | ) |

Appends "number" to the variablebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

variablebuffer* variablebuffer::append | ( | int32_t | number | ) |

Appends "number" to the variablebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

variablebuffer* variablebuffer::append | ( | int64_t | number | ) |

Appends "number" to the variablebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

variablebuffer* variablebuffer::append | ( | unsigned char | character | ) |

Appends "character" to the variablebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

variablebuffer* variablebuffer::append | ( | uint16_t | number | ) |

Appends "number" to the variablebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

variablebuffer* variablebuffer::append | ( | uint32_t | number | ) |

Appends "number" to the variablebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

variablebuffer* variablebuffer::append | ( | uint64_t | number | ) |

Appends "number" to the variablebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

variablebuffer* variablebuffer::append | ( | float | number | ) |

Appends "number" to the variablebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

variablebuffer* variablebuffer::append | ( | double | number | ) |

Appends "number" to the variablebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

variablebuffer* variablebuffer::appendFormatted | ( | const char * | format,
|  |  | ...
| ) |  |

Appends "..." to the variable buffer using "format" which should comply with standard printf formatting rules.

variablebuffer* variablebuffer::appendFormatted | ( | const char * | format,
|  | va_list * | argp
| ) |  |

Appends "argp" to the variable buffer using "format" which should comply with standard printf formatting rules.

Note that argp is a pointer to a va_list, not just a va_list.

void variablebuffer::clear | ( |  | ) |

Empties the variablebuffer.

unsigned char* variablebuffer::detachBuffer | ( |  | ) |

Returns a pointer to the buffer currently stored in the variablebuffer, then resets the variablebuffer such that it will no longer use that buffer.

The calling program must deallocate the buffer returned from this method.

size_t variablebuffer::getActualSize | ( |  | ) |

Returns the actual size of the buffer which may be larger than the value returned by getSize() since the buffer grows in chunks.

const unsigned char* variablebuffer::getBuffer | ( |  | ) |

Returns the current data stored in the variablebuffer.

size_t variablebuffer::getEnd | ( |  | ) |

Returns the position in the buffer at which the next append will occur.

size_t variablebuffer::getPosition | ( |  | ) |

Returns the position in the buffer at which the next write will occur.

size_t variablebuffer::getSize | ( |  | ) |

Returns the amount of data currently stored in the variablebuffer.

variablebuffer& variablebuffer::operator= | ( | const variablebuffer & | v | ) |

Makes this instance of the variablebuffer class identical to "v".

ssize_t variablebuffer::read | ( | unsigned char * | data,
|  | size_t | size
| ) |  |

Reads "size" bytes from the variablebuffer at the current position into "data". Also increments the current position by "size" bytes.

void variablebuffer::setPosition | ( | size_t | pos | ) |

Sets the position in the internal buffer at which the next read or write will occur to "pos". If the position is set beyond the end of the buffer, the buffer will grow but the data between the current end of the buffer and the new position will be undefined.

virtual void variablebuffer::truncate | ( | size_t | pos | ) |

virtual

Truncates the variablebuffer at position "pos".

Reimplemented in stringbuffer.

virtual void variablebuffer::truncate | ( |  | ) |

virtual

Truncates the variablebuffer at the current position.

Reimplemented in stringbuffer.

variablebuffer* variablebuffer::write | ( | const unsigned char * | data,
|  | size_t | size
| ) |  |

Writes the first "size" bytes of "data" to the variablebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

variablebuffer* variablebuffer::write | ( | const char * | string | ) |

Writes "string" to the variablebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

variablebuffer* variablebuffer::write | ( | const char * | string,
|  | size_t | size
| ) |  |

Writes the first "size" bytes of "string" to the variablebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

variablebuffer* variablebuffer::write | ( | char | character | ) |

Writes "character" to the variablebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

variablebuffer* variablebuffer::write | ( | int16_t | number | ) |

Writes "number" to the variablebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

variablebuffer* variablebuffer::write | ( | int32_t | number | ) |

Writes "number" to the variablebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

variablebuffer* variablebuffer::write | ( | int64_t | number | ) |

Writes "number" to the variablebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

variablebuffer* variablebuffer::write | ( | unsigned char | character | ) |

Writes "character" to the variablebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

variablebuffer* variablebuffer::write | ( | uint16_t | number | ) |

Writes "number" to the variablebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

variablebuffer* variablebuffer::write | ( | uint32_t | number | ) |

Writes "number" to the variablebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

variablebuffer* variablebuffer::write | ( | uint64_t | number | ) |

Writes "number" to the variablebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

variablebuffer* variablebuffer::write | ( | float | number | ) |

Writes "number" to the variablebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

variablebuffer* variablebuffer::write | ( | double | number | ) |

Writes "number" to the variablebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

variablebuffer* variablebuffer::writeFormatted | ( | const char * | format,
|  |  | ...
| ) |  |

Writes "..." to the variable buffer using "format" which should comply with standard printf formatting rules.

variablebuffer* variablebuffer::writeFormatted | ( | const char * | format,
|  | va_list * | argp
| ) |  |

Writes "argp" to the variable buffer using "format" which should comply with standard printf formatting rules.

Note that argp is a pointer to a va_list, not just a va_list.