comparison src/dmgrowbuf.h @ 1697:1036b0dcccb5

Refactor DMGrowBuf so that there can be buffers that grow "backwards". This also removes some support functions like the buffer state push/pop.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Jun 2018 12:55:17 +0300
parents e568535e1a96
children f71cd6691e05
comparison
equal deleted inserted replaced
1696:cf0fddd4bf52 1697:1036b0dcccb5
14 #endif 14 #endif
15 15
16 16
17 typedef struct 17 typedef struct
18 { 18 {
19 Uint8 *data, *adata; 19 Uint8
20 size_t len, size, mingrow, offs; 20 *data; // Actually allocated data pointer
21 BOOL allocated;
22 21
23 int nstack; 22 size_t
24 struct { size_t offs, len; } stack[32]; 23 offs, // Current offset
24 min_offs,
25 max_offs,
26 size, // Actual allocated size
27 len, // Size requested
28 mingrow; // Minimum amount of bytes the allocation size grows by
29
30 BOOL
31 allocated, // TRUE if this structure itself has been allocated and can be freed, FALSE if static
32 backwards, // TRUE if the buffer grows backwards (e.g. "offs" moves backwards)
33 literal; // TRUE if dmGrowBufPut*() functions stores data "literally" in backwards mode
25 } DMGrowBuf; 34 } DMGrowBuf;
26 35
27 36
28 int dmGrowBufInit(DMGrowBuf *buf); 37 int dmGrowBufInit(DMGrowBuf *buf);
29 int dmGrowBufAlloc(DMGrowBuf *buf, const size_t initial, const size_t mingrow); 38 int dmGrowBufAlloc(DMGrowBuf *buf, const size_t initial, const size_t mingrow);
30 int dmGrowBufNew(DMGrowBuf **pbuf, const size_t initial, const size_t mingrow); 39 int dmGrowBufNew(DMGrowBuf **pbuf, const size_t initial, const size_t mingrow);
31 void dmGrowBufFree(DMGrowBuf *buf); 40 void dmGrowBufFree(DMGrowBuf *buf);
32 41
33 void dmGrowBufPush(DMGrowBuf *buf);
34 void dmGrowBufPop(DMGrowBuf *buf);
35
36 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount); 42 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount);
37 BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize); 43 BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize);
38 44
45 BOOL dmGrowBufPut(DMGrowBuf *buf, const Uint8 *data, const size_t len);
39 BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value); 46 BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value);
40 BOOL dmGrowBufPut(DMGrowBuf *buf, const void *str, const size_t len);
41
42 BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val); 47 BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val);
43 BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val); 48 BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val);
44 BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val); 49 BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val);
45 BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val); 50 BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val);
46 51