56#define CX_BUFFER_DEFAULT 0x00
64#define CX_BUFFER_FREE_CONTENTS 0x01
69#define CX_BUFFER_AUTO_EXTEND 0x02
77#define CX_BUFFER_COPY_ON_WRITE 0x04
86#define CX_BUFFER_COPY_ON_EXTEND 0x08
93#define CX_BUFFER_DO_NOT_FREE 0x10
99#define cxBufferWriteFunc ((cx_write_func) cxBufferWrite)
104#define cxBufferReadFunc ((cx_read_func) cxBufferRead)
578#define cxBufferPutString(buffer, str) cx_buffer_put_string(buffer, cx_strcast(str))
600#define cxBufferAppendString(buffer, str) cx_buffer_append_string(buffer, cx_strcast(str))
Interface for custom allocators.
struct cx_allocator_s CxAllocator
High-Level type alias for the allocator type.
Definition allocator.h:80
size_t cx_buffer_put_string(CxBuffer *buffer, cxstring str)
Internal function - do not use.
void cxBufferReset(CxBuffer *buffer)
Resets the buffer by resetting the position and size to zero.
size_t cxBufferWrite(const void *ptr, size_t size, size_t nitems, CxBuffer *buffer)
Writes data to a CxBuffer.
bool cxBufferEof(const CxBuffer *buffer)
Tests, if the buffer position has exceeded the buffer size.
CxBuffer * cxBufferCreate(const CxAllocator *allocator, void *space, size_t capacity, int flags)
Allocates and initializes a fresh buffer.
int cxBufferReserve(CxBuffer *buffer, size_t capacity)
Ensures that the buffer has the required capacity.
void cxBufferClear(CxBuffer *buffer)
Clears the buffer by resetting the position and deleting the data.
int cxBufferShift(CxBuffer *buffer, off_t shift)
Shifts the contents of the buffer by the given offset.
size_t cxBufferAppend(const void *ptr, size_t size, size_t nitems, CxBuffer *buffer)
Appends data to a CxBuffer.
void cxBufferFree(CxBuffer *buffer)
Deallocates the buffer.
int cxBufferInit(CxBuffer *buffer, const CxAllocator *allocator, void *space, size_t capacity, int flags)
Initializes a fresh buffer.
int cxBufferShiftLeft(CxBuffer *buffer, size_t shift)
Shifts the buffer to the left.
int cxBufferGet(CxBuffer *buffer)
Gets a character from a buffer.
static cxmutstr cx_bstr_m(CxBuffer *buffer)
Gets the data in a buffer as a cxmutstr.
Definition buffer.h:631
struct cx_buffer_s CxBuffer
UCX buffer.
Definition buffer.h:143
int cxBufferMaximumCapacity(CxBuffer *buffer, size_t capacity)
Limits the buffer's capacity.
int cxBufferMinimumCapacity(CxBuffer *buffer, size_t capacity)
Ensures that the buffer has a minimum capacity.
void cxBufferDestroy(CxBuffer *buffer)
Destroys the buffer contents.
int cxBufferShiftRight(CxBuffer *buffer, size_t shift)
Shifts the buffer to the right.
size_t cxBufferPop(CxBuffer *buffer, size_t size, size_t nitems)
Discards items from the end of the buffer.
int cxBufferTerminate(CxBuffer *buffer)
Writes a terminating zero to a buffer at the current position.
int cxBufferSeek(CxBuffer *buffer, off_t offset, int whence)
Moves the position of the buffer.
static cxstring cx_bstr(CxBuffer *buffer)
Gets the data in a buffer as a cxstring.
Definition buffer.h:620
int cxBufferPut(CxBuffer *buffer, int c)
Writes a character to a buffer.
size_t cxBufferRead(void *ptr, size_t size, size_t nitems, CxBuffer *buffer)
Reads data from a CxBuffer.
void cxBufferShrink(CxBuffer *buffer, size_t reserve)
Shrinks the capacity of the buffer to fit its current size.
size_t cx_buffer_append_string(CxBuffer *buffer, cxstring str)
Internal function - do not use.
Common definitions and feature checks.
#define CX_MALLOC
The attributed function always returns freshly allocated memory.
Definition common.h:156
#define CX_DEALLOC(...)
Not supported in clang.
Definition common.h:172
#define CX_INLINE
Declares a function to be inlined.
Definition common.h:311
#define CX_NONNULL
All pointer arguments must be non-NULL.
Definition common.h:141
#define CX_NODISCARD
Warn about discarded return value.
Definition common.h:256
#define CX_NONNULL_ARG(...)
The specified pointer arguments must be non-NULL.
Definition common.h:146
#define CX_EXTERN
Declares a function with external linkage.
Definition common.h:297
Strings that know their length.
struct cx_string_s cxstring
An immutable string.
Definition string.h:92
struct cx_mutstr_s cxmutstr
A mutable string.
Definition string.h:74
static cxmutstr cx_mutstrn(char *cstring, size_t length)
Wraps a string that does not need to be zero-terminated.
Definition string.h:187
static cxstring cx_strn(const char *cstring, size_t length)
Wraps a string that does not need to be zero-terminated.
Definition string.h:237
Structure for the UCX buffer data.
Definition buffer.h:108
char * space
Data is interpreted as text.
Definition buffer.h:114
size_t capacity
Current capacity (i.e.
Definition buffer.h:125
unsigned char * bytes
Data is interpreted as binary.
Definition buffer.h:118
size_t pos
Current position of the buffer.
Definition buffer.h:123
size_t max_capacity
Maximum capacity that this buffer may grow to.
Definition buffer.h:127
int flags
Flag register for buffer features.
Definition buffer.h:137
size_t size
Current size of the buffer content.
Definition buffer.h:129
const CxAllocator * allocator
The allocator to use for automatic memory management.
Definition buffer.h:121