Mercurial > hg > dmlib
annotate src/dmgrowbuf.h @ 1694:e568535e1a96
Backed out changeset 9611ecd2c4fb
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 05 Jun 2018 11:03:17 +0300 |
parents | ce8d4552ffd5 |
children | 1036b0dcccb5 |
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 |
1687 | 16 |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 typedef struct |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 { |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1477
diff
changeset
|
19 Uint8 *data, *adata; |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1477
diff
changeset
|
20 size_t len, size, mingrow, offs; |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 BOOL allocated; |
1533 | 22 |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1477
diff
changeset
|
23 int nstack; |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1477
diff
changeset
|
24 struct { size_t offs, len; } stack[32]; |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 } DMGrowBuf; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 |
1694
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
28 int dmGrowBufInit(DMGrowBuf *buf); |
1458
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
29 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
|
30 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
|
31 void dmGrowBufFree(DMGrowBuf *buf); |
1687 | 32 |
33 void dmGrowBufPush(DMGrowBuf *buf); | |
34 void dmGrowBufPop(DMGrowBuf *buf); | |
35 | |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount); |
1455
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
37 BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize); |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value); |
1477
e8fe529f4341
Rename one of the growbuf functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1458
diff
changeset
|
40 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
|
41 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val); |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val); |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val); |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val); |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 |
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 #ifdef __cplusplus |
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 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 #endif // DMGROWBUF_H |