22 #ifndef DBALLE_CORE_STRUCTBUF_H 23 #define DBALLE_CORE_STRUCTBUF_H 33 int make_anonymous_tmpfile();
34 void write_buffer(
int fd,
void* buf,
size_t size);
44 template<
typename T,
int bufsize=1024>
130 tmpfile_fd = structbuf::make_anonymous_tmpfile();
const T * readbuf
Memory area used for reading.
Definition: structbuf.h:61
unsigned membuf_last
Number of items in membuf.
Definition: structbuf.h:55
T * membuf
In-memory buffer using during appending.
Definition: structbuf.h:52
Buffer of simple structures that becomes file backed if it grows beyond a certain size...
Definition: structbuf.h:45
size_t m_count
Number of items appended so far.
Definition: structbuf.h:64
size_t size() const
Get the number of structures that have been added to the buffer so far.
Definition: structbuf.h:87
void ready_to_read()
Stop appending and get ready to read back the data.
Definition: structbuf.h:104
int tmpfile_fd
Unix file descriptor to the temporary file, or -1 if we are memory backed.
Definition: structbuf.h:68
void append(const T &val)
Append an item to the buffer.
Definition: structbuf.h:93
bool is_file_backed() const
Return true if the buffer has become file-backed.
Definition: structbuf.h:90
const T & operator[](size_t idx) const
Read back an item.
Definition: structbuf.h:121