Hasty Badger
Small UI library (a branch of Turbo Badger)
|
TBTempBuffer manages a buffer that will be deleted on destruction. More...
#include <tb_tempbuffer.h>
Public Member Functions | |
bool | Reserve (int size) |
Make sure the buffer has at least size bytes. More... | |
char * | GetData () const |
Get a pointer to the buffer data. More... | |
int | GetCapacity () const |
Return the size of the buffer in bytes. More... | |
bool | Append (const char *data, int size) |
Append data with size bytes at the end of the buffer and increase the append position with the same amount. More... | |
bool | AppendSpace (int size) |
Increase the append position with size bytes without writing any data. More... | |
bool | AppendString (const char *str) |
Append a null terminated string (including the null termination) at the end of the buffer. More... | |
bool | AppendString (const TBStr &str) |
Append a TBStr. More... | |
bool | AppendPath (const char *full_path_and_filename) |
Append a path without the ending filename. More... | |
bool | AppendFile (const TBStr &filename) |
Append file content at the end of the buffer. More... | |
void | SetAppendPos (int append_pos) |
Set the position (in bytes) in the buffer where Append should write. More... | |
void | ResetAppendPos () |
Reset the append position to 0. More... | |
int | GetAppendPos () const |
Return the current append position in in bytes. More... | |
TBTempBuffer manages a buffer that will be deleted on destruction.
The buffer size can grow by calling Reserve or Append, but it will never shrink during the lifetime of the object.
bool tb::TBTempBuffer::Append | ( | const char * | data, |
int | size | ||
) |
Append data with size bytes at the end of the buffer and increase the append position with the same amount.
Returns false on OOM.
bool tb::TBTempBuffer::AppendFile | ( | const TBStr & | filename | ) |
Append file content at the end of the buffer.
The append position will be increased by the size of the file. It will always append null termination (not included in append position). Returns false of OOM or if loading failed.
bool tb::TBTempBuffer::AppendPath | ( | const char * | full_path_and_filename | ) |
Append a path without the ending filename.
The buffer will be null terminated and the append position will be increased with the length of the path (excluding the null termination).
bool tb::TBTempBuffer::AppendSpace | ( | int | size | ) |
Increase the append position with size bytes without writing any data.
This is useful if you want to write the data later and want to make sure space is reserved. Returns false on OOM.
bool tb::TBTempBuffer::AppendString | ( | const char * | str | ) |
Append a null terminated string (including the null termination) at the end of the buffer.
The append position will be increased with the length of the text (excluding the null termination) so multiple calls will produce a concatenated null terminated string. Returns false on OOM.
|
inline |
Return the current append position in in bytes.
|
inline |
Return the size of the buffer in bytes.
|
inline |
Get a pointer to the buffer data.
bool tb::TBTempBuffer::Reserve | ( | int | size | ) |
Make sure the buffer has at least size bytes.
Returns false on OOM.
|
inline |
Reset the append position to 0.
void tb::TBTempBuffer::SetAppendPos | ( | int | append_pos | ) |
Set the position (in bytes) in the buffer where Append should write.