1 #ifndef WIBBLE_SYS_BUFFER_H
2 #define WIBBLE_SYS_BUFFER_H
47 Data(
void* buf,
size_t size,
bool own =
true);
154 if (
size() == newSize)
172 if (
item == 0 && buf.item == 0)
174 if (
item == 0 || buf.item == 0)
176 return *
item == *buf.item;
187 if (
item == 0 && buf.item == 0)
193 return *
item < *buf.item;
205 std::ostream&
operator<<(std::ostream& o,
const Buffer& b);
bool operator==(const Buffer &buf) const
Compare the contents of two buffers.
Definition: buffer.h:170
Variable-size, reference-counted memory buffer.
Definition: buffer.h:33
Buffer(const void *buf, size_t size)
Create a buffer with a copy of the given data.
Definition: buffer.h:112
void * _data
Definition: buffer.h:41
~Buffer()
Definition: buffer.h:127
bool unref() const
Decrement the reference count for this object, returning true when it reaches 0.
Definition: buffer.h:56
Buffer(const Buffer &buf)
Definition: buffer.h:121
void resize(size_t size)
Resize (enlarging or shrinking it) the buffer to `size' bytes.
Definition: buffer.cpp:61
Data()
Definition: buffer.h:44
bool operator<(const Data &d) const
Compare the contents of two buffers.
Definition: buffer.cpp:91
void ref() const
Increment the reference count for this object.
Definition: buffer.h:52
bool operator==(const Data &d) const
Compare the contents of two buffers.
Definition: buffer.cpp:79
Buffer(size_t size)
Create a buffer with the specified size.
Definition: buffer.h:77
const void * data() const
Return a pointer to the buffer.
Definition: buffer.h:146
size_t _size
Definition: buffer.h:40
int _ref
Definition: buffer.h:39
Data * item
Definition: buffer.h:70
std::ostream & operator<<(std::ostream &o, const Buffer &b)
Definition: buffer.cpp:118
std::string print_preview(unsigned size) const
Render a c-string escaped print preview of maximum size buffer bytes.
Definition: buffer.cpp:106
void * data()
Return a pointer to the buffer.
Definition: buffer.h:143
bool operator<(const Buffer &buf) const
Compare the contents of two buffers.
Definition: buffer.h:185
size_t size() const
Return the buffer size.
Definition: buffer.h:149
bool operator!=(const Buffer &buf) const
Definition: buffer.h:179
Buffer(void *buf, size_t size, bool own=true)
Create a buffer from existing data.
Definition: buffer.h:98
~Data()
Definition: buffer.cpp:54
Buffer & operator=(const Buffer &buf)
Definition: buffer.h:132
Buffer()
Create a 0-lenght buffer.
Definition: buffer.h:74
void resize(size_t newSize)
Resize the buffer to hold exactly the specified amount of bytes.
Definition: buffer.h:152