Mercurial > hg > dmlib
annotate src/dmgrowbuf.h @ 2634:f3c7115cbf85 default tip
Fix verbose build echos.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 29 Feb 2024 21:47:31 +0200 |
parents | 9807ae37ad69 |
children |
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 |
2539 | 5 * (C) Copyright 2018-2021 Tecnic Software productions (TNSP) |
1454
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 { |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
19 Uint8 |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
20 *data; // Actually allocated data pointer |
1533 | 21 |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
22 size_t |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
23 offs, // Current offset |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
24 size, // Actual allocated size |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
25 len, // Size requested |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
26 mingrow; // Minimum amount of bytes the allocation size grows by |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
27 |
2586
9807ae37ad69
Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents:
2539
diff
changeset
|
28 bool |
9807ae37ad69
Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents:
2539
diff
changeset
|
29 backwards, // true if the buffer grows backwards (e.g. "offs" moves backwards) |
9807ae37ad69
Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents:
2539
diff
changeset
|
30 literal, // true if dmGrowBufPut*() functions stores data "literally" in backwards mode |
9807ae37ad69
Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents:
2539
diff
changeset
|
31 is_const; // true will cause any reallocs etc. modifications to fail |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 } DMGrowBuf; |
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 |
1694
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
35 int dmGrowBufInit(DMGrowBuf *buf); |
1458
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
36 int dmGrowBufAlloc(DMGrowBuf *buf, const size_t initial, const size_t mingrow); |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 void dmGrowBufFree(DMGrowBuf *buf); |
1687 | 38 |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1704
diff
changeset
|
39 DMGrowBuf * dmGrowBufCopy(DMGrowBuf *dst, const DMGrowBuf *src, const size_t enlarge); |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1704
diff
changeset
|
40 DMGrowBuf * dmGrowBufCopyOffs(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t enlarge); |
2298
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
41 DMGrowBuf * dmGrowBufCopyOffsSize(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t len, const size_t enlarge); |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
42 |
1700
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
43 DMGrowBuf * dmGrowBufConstCopy(DMGrowBuf *dst, const DMGrowBuf *src); |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1704
diff
changeset
|
44 DMGrowBuf * dmGrowBufConstCopyOffs(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs); |
2298
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
45 DMGrowBuf * dmGrowBufConstCopyOffsSize(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t len); |
2296 | 46 DMGrowBuf * dmGrowBufConstCreateFrom(DMGrowBuf *buf, Uint8 *data, const size_t len); |
1704
7eb00206b36d
Add helper function dmGrowBufCreateFromOffs().
Matti Hamalainen <ccr@tnsp.org>
parents:
1700
diff
changeset
|
47 |
1700
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
48 |
2586
9807ae37ad69
Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents:
2539
diff
changeset
|
49 bool dmGrowBufGrow(DMGrowBuf *buf, const size_t amount); |
9807ae37ad69
Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents:
2539
diff
changeset
|
50 bool dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize); |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 |
2586
9807ae37ad69
Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents:
2539
diff
changeset
|
52 bool dmGrowBufPut(DMGrowBuf *buf, const Uint8 *data, const size_t len); |
9807ae37ad69
Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents:
2539
diff
changeset
|
53 bool dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value); |
9807ae37ad69
Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents:
2539
diff
changeset
|
54 bool dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val); |
9807ae37ad69
Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents:
2539
diff
changeset
|
55 bool dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val); |
9807ae37ad69
Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents:
2539
diff
changeset
|
56 bool dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val); |
9807ae37ad69
Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents:
2539
diff
changeset
|
57 bool dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val); |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 |
2586
9807ae37ad69
Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents:
2539
diff
changeset
|
59 bool dmGrowBufGetU8(DMGrowBuf *buf, Uint8 *value); |
1699
f71cd6691e05
Implement dmGrowBufGetU8().
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
60 |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 #ifdef __cplusplus |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 #endif |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 #endif // DMGROWBUF_H |