Mercurial > hg > dmlib
annotate src/dmgrowbuf.h @ 1533:907160399b24
Cosmetic.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 12 May 2018 03:26:14 +0300 |
parents | 260bf529a8f2 |
children | 383ca5f6e78b |
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; |
1533 | 21 |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1477
diff
changeset
|
22 int nstack; |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1477
diff
changeset
|
23 struct { size_t offs, len; } stack[32]; |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 } DMGrowBuf; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 |
1458
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
27 int dmGrowBufInit(DMGrowBuf *buf); |
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
28 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
|
29 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
|
30 void dmGrowBufFree(DMGrowBuf *buf); |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount); |
1455
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
32 BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize); |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 int dmGrowBufResize(DMGrowBuf *buf); |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value); |
1477
e8fe529f4341
Rename one of the growbuf functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1458
diff
changeset
|
36 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
|
37 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val); |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val); |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val); |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val); |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 |
1533 | 43 void dmGrowBufPush(DMGrowBuf *buf); |
44 void dmGrowBufPop(DMGrowBuf *buf); | |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1477
diff
changeset
|
45 |
1454
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 #ifdef __cplusplus |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 #endif |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 #endif // DMGROWBUF_H |