annotate src/dmgrowbuf.h @ 1531:260bf529a8f2

Implement current len/offs push/pop for growbuf.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 12 May 2018 03:23:32 +0300
parents e8fe529f4341
children 907160399b24
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * DMLib
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * -- Growable buffer implementation
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 * (C) Copyright 2018 Tecnic Software productions (TNSP)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 */
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #ifndef DMGROWBUF_H
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #define DMGROWBUF_H
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include "dmlib.h"
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #ifdef __cplusplus
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 extern "C" {
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #endif
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 typedef struct
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 {
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1477
diff changeset
18 Uint8 *data, *adata;
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1477
diff changeset
19 size_t len, size, mingrow, offs;
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 BOOL allocated;
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1477
diff changeset
21 int nstack;
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1477
diff changeset
22 struct { size_t offs, len; } stack[32];
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 } DMGrowBuf;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
1458
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
26 int dmGrowBufInit(DMGrowBuf *buf);
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
27 int dmGrowBufAlloc(DMGrowBuf *buf, const size_t initial, const size_t mingrow);
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
28 int dmGrowBufNew(DMGrowBuf **pbuf, const size_t initial, const size_t mingrow);
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 void dmGrowBufFree(DMGrowBuf *buf);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount);
1455
a957b318fbe2 Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1454
diff changeset
31 BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize);
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 int dmGrowBufResize(DMGrowBuf *buf);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value);
1477
e8fe529f4341 Rename one of the growbuf functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1458
diff changeset
35 BOOL dmGrowBufPut(DMGrowBuf *buf, const void *str, const size_t len);
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1477
diff changeset
42 void dmGrowBufPush(DMGrowBuf *buf);
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1477
diff changeset
43 void dmGrowBufPop(DMGrowBuf *buf);
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1477
diff changeset
44
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 #ifdef __cplusplus
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 #endif
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 #endif // DMGROWBUF_H