annotate src/dmgrowbuf.h @ 1697:1036b0dcccb5

Refactor DMGrowBuf so that there can be buffers that grow "backwards". This also removes some support functions like the buffer state push/pop.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Jun 2018 12:55:17 +0300
parents e568535e1a96
children f71cd6691e05
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
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 min_offs,
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1694
diff changeset
25 max_offs,
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1694
diff changeset
26 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
27 len, // Size requested
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1694
diff changeset
28 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
29
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1694
diff changeset
30 BOOL
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1694
diff changeset
31 allocated, // TRUE if this structure itself has been allocated and can be freed, FALSE if static
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1694
diff changeset
32 backwards, // TRUE if the buffer grows backwards (e.g. "offs" moves backwards)
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1694
diff changeset
33 literal; // TRUE if dmGrowBufPut*() functions stores data "literally" in backwards mode
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 } DMGrowBuf;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
1694
e568535e1a96 Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents: 1693
diff changeset
37 int dmGrowBufInit(DMGrowBuf *buf);
1458
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
38 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
39 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
40 void dmGrowBufFree(DMGrowBuf *buf);
1687
383ca5f6e78b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1533
diff changeset
41
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount);
1455
a957b318fbe2 Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1454
diff changeset
43 BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize);
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
1697
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1694
diff changeset
45 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
46 BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val);
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
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 #ifdef __cplusplus
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 #endif
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 #endif // DMGROWBUF_H