annotate src/dmgrowbuf.h @ 2298:b5abfff07ca9

Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and dmGrowBufConstCopyOffsSize().
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 04 Jul 2019 10:54:16 +0300
parents 39b4e06785f5
children c801995cbb13
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
2297
39b4e06785f5 Bump copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 2296
diff changeset
5 * (C) Copyright 2018-2019 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
383ca5f6e78b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1533
diff changeset
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
907160399b24 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
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
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1694
diff changeset
28 BOOL
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1694
diff changeset
29 backwards, // TRUE if the buffer grows backwards (e.g. "offs" moves backwards)
1700
a2e65aa47554 Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents: 1699
diff changeset
30 literal, // TRUE if dmGrowBufPut*() functions stores data "literally" in backwards mode
a2e65aa47554 Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents: 1699
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
383ca5f6e78b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1533
diff changeset
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
732fa926a5ef Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 1830
diff changeset
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
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount);
1455
a957b318fbe2 Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1454
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
1697
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1694
diff changeset
52 BOOL dmGrowBufPut(DMGrowBuf *buf, const Uint8 *data, const size_t len);
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
1699
f71cd6691e05 Implement dmGrowBufGetU8().
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
59 BOOL dmGrowBufGetU8(DMGrowBuf *buf, Uint8 *value);
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