Mercurial > hg > dmlib
view src/dmgrowbuf.h @ 1704:7eb00206b36d
Add helper function dmGrowBufCreateFromOffs().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 05 Jun 2018 19:49:49 +0300 |
parents | a2e65aa47554 |
children | 5e928618fdc8 |
line wrap: on
line source
/* * DMLib * -- Growable buffer implementation * Programmed and designed by Matti 'ccr' Hamalainen * (C) Copyright 2018 Tecnic Software productions (TNSP) */ #ifndef DMGROWBUF_H #define DMGROWBUF_H #include "dmlib.h" #ifdef __cplusplus extern "C" { #endif typedef struct { Uint8 *data; // Actually allocated data pointer size_t offs, // Current offset min_offs, max_offs, size, // Actual allocated size len, // Size requested mingrow; // Minimum amount of bytes the allocation size grows by BOOL allocated, // TRUE if this structure itself has been allocated and can be freed, FALSE if static backwards, // TRUE if the buffer grows backwards (e.g. "offs" moves backwards) literal, // TRUE if dmGrowBufPut*() functions stores data "literally" in backwards mode is_const; // TRUE will cause any reallocs etc. modifications to fail } DMGrowBuf; int dmGrowBufInit(DMGrowBuf *buf); int dmGrowBufAlloc(DMGrowBuf *buf, const size_t initial, const size_t mingrow); int dmGrowBufNew(DMGrowBuf **pbuf, const size_t initial, const size_t mingrow); void dmGrowBufFree(DMGrowBuf *buf); DMGrowBuf * dmGrowBufConstCopy(DMGrowBuf *dst, const DMGrowBuf *src); DMGrowBuf * dmGrowBufCreateFrom(DMGrowBuf *buf, Uint8 *data, size_t len); static inline DMGrowBuf * dmGrowBufCreateFromOffs(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs) { return dmGrowBufCreateFrom(dst, src->data + offs, src->len - offs); } BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount); BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize); BOOL dmGrowBufPut(DMGrowBuf *buf, const Uint8 *data, const size_t len); BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value); BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val); BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val); BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val); BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val); BOOL dmGrowBufGetU8(DMGrowBuf *buf, Uint8 *value); #ifdef __cplusplus } #endif #endif // DMGROWBUF_H