Wrote array_header.h. Now for array_impl.h.
This commit is contained in:
parent
2dd68fc47f
commit
dca2e5f038
|
@ -30,31 +30,11 @@ extern bool uiprivSysCheckThread(void);
|
||||||
// alloc.c
|
// alloc.c
|
||||||
#define sharedbitsPrefix uipriv
|
#define sharedbitsPrefix uipriv
|
||||||
#include "../sharedbits/alloc_header.h"
|
#include "../sharedbits/alloc_header.h"
|
||||||
typedef struct uiprivArray uiprivArray;
|
#include "../sharedbits/array_header.h"
|
||||||
struct uiprivArray {
|
|
||||||
void *buf;
|
|
||||||
size_t len;
|
|
||||||
size_t cap;
|
|
||||||
size_t elemsize;
|
|
||||||
size_t nGrow;
|
|
||||||
const char *what;
|
|
||||||
};
|
|
||||||
#define uiprivArrayStaticInit(T, grow, whatstr) { NULL, 0, 0, sizeof (T), grow, whatstr }
|
#define uiprivArrayStaticInit(T, grow, whatstr) { NULL, 0, 0, sizeof (T), grow, whatstr }
|
||||||
#define uiprivArrayInit(arr, T, grow, whatstr) \
|
#define uiprivArrayInit(arr, T, nGrow, what) uiprivArrayInitFull(&(arr), sizeof (T), nGrow, what)
|
||||||
memset(&(arr), 0, sizeof (uiprivArray)); \
|
#define uiprivArrayFree(arr) uiprivArrayFreeFull(&(arr))
|
||||||
arr.elemsize = sizeof (T); \
|
|
||||||
arr.nGrow = grow; \
|
|
||||||
arr.what = whatstr;
|
|
||||||
#define uiprivArrayFree(arr) \
|
|
||||||
uiprivFree(arr.buf); \
|
|
||||||
memset(&arr, 0, sizeof (uiprivArray));
|
|
||||||
#define uiprivArrayAt(arr, T, n) (((T *) (arr.buf)) + (n))
|
#define uiprivArrayAt(arr, T, n) (((T *) (arr.buf)) + (n))
|
||||||
extern void *uiprivArrayAppend(uiprivArray *arr, size_t n);
|
|
||||||
extern void *uiprivArrayInsertAt(uiprivArray *arr, size_t pos, size_t n);
|
|
||||||
extern void uiprivArrayDelete(uiprivArray *arr, size_t pos, size_t n);
|
|
||||||
extern void uiprivArrayDeleteItem(uiprivArray *arr, void *p, size_t n);
|
|
||||||
extern void *uiprivArrayBsearch(const uiprivArray *arr, const void *key, int (*compare)(const void *, const void *));
|
|
||||||
extern void uiprivArrayQsort(uiprivArray *arr, int (*compare)(const void *, const void *));
|
|
||||||
#undef sharedbitsPrefix
|
#undef sharedbitsPrefix
|
||||||
|
|
||||||
// errors.c
|
// errors.c
|
||||||
|
|
|
@ -3,4 +3,33 @@
|
||||||
|
|
||||||
#include "start.h"
|
#include "start.h"
|
||||||
|
|
||||||
|
typedef struct sharedbitsPrefixName(Array) sharedbitsPrefixName(Array);
|
||||||
|
|
||||||
|
struct sharedbitsPrefixName(Array) {
|
||||||
|
void *buf;
|
||||||
|
size_t len;
|
||||||
|
size_t cap;
|
||||||
|
size_t elemsize;
|
||||||
|
size_t nGrow;
|
||||||
|
const char *what;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void sharedbitsPrefixName(ArrayInitFull)(sharedbitsPrefixName(Array) *arr, size_t elemsize, size_t nGrow, const char *what);
|
||||||
|
extern void sharedbitsPrefixName(ArrayFreeFull)(sharedbitsPrefixName(Array) *arr);
|
||||||
|
extern void *sharedbitsPrefixName(ArrayAppend)(sharedbitsPrefixName(Array) *arr, size_t n);
|
||||||
|
extern void *sharedbitsPrefixName(ArrayInsertAt)(sharedbitsPrefixName(Array) *arr, size_t pos, size_t n);
|
||||||
|
extern void sharedbitsPrefixName(ArrayDelete)(sharedbitsPrefixName(Array) *arr, size_t pos, size_t n);
|
||||||
|
extern void sharedbitsPrefixName(ArrayDeleteItem)(sharedbitsPrefixName(Array) *arr, void *p, size_t n);
|
||||||
|
extern void *sharedbitsPrefixName(ArrayBsearch)(const sharedbitsPrefixName(Array) *arr, const void *key, int (*compare)(const void *, const void *));
|
||||||
|
extern void sharedbitsPrefixName(ArrayQsort)(sharedbitsPrefixName(Array) *arr, int (*compare)(const void *, const void *));
|
||||||
|
|
||||||
|
/*
|
||||||
|
you may also want to define the following:
|
||||||
|
|
||||||
|
#define sharedbitsPrefixName(StaticInit)(T, nGrow, what) { NULL, 0, 0, sizeof (T), nGrow, what }
|
||||||
|
#define sharedbitsPrefixName(Init)(arr, T, nGrow, what) sharedbitsPrefixName(InitFull)(&(arr), sizeof (T), nGrow, what)
|
||||||
|
#define sharedbitsPrefixName(ArrayFree)(arr) sharedbitsPrefixName(ArrayFreeFull)(&(arr))
|
||||||
|
#define sharedbitsPrefixName(ArrayAt)(arr, T, n) (((T *) (arr.buf)) + (n))
|
||||||
|
*/
|
||||||
|
|
||||||
#include "end.h"
|
#include "end.h"
|
||||||
|
|
|
@ -3,4 +3,18 @@
|
||||||
|
|
||||||
#include "start.h"
|
#include "start.h"
|
||||||
|
|
||||||
|
void sharedbitsPrefixName(ArrayInitFull)(sharedbitsPrefixName(Array) *arr, size_t elemsize, size_t nGrow, const char *what)
|
||||||
|
{
|
||||||
|
memset(arr, 0, sizeof (sharedbitsPrefixName(Array)));
|
||||||
|
arr->elemsize = elemsize;
|
||||||
|
arr->nGrow = nGrow;
|
||||||
|
arr->what = what;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sharedbitsPrefixName(ArrayFreeFull)(sharedbitsPrefixName(Array) *arr)
|
||||||
|
{
|
||||||
|
sharedbitsPrefixName(Free)(arr->buf);
|
||||||
|
memset(arr, 0, sizeof (sharedbitsPrefixName(Array)));
|
||||||
|
}
|
||||||
|
|
||||||
#include "end.h"
|
#include "end.h"
|
||||||
|
|
|
@ -9,31 +9,11 @@ extern void testingprivInternalError(const char *fmt, ...);
|
||||||
#define testingprivNewArray(T, n) ((T *) testingprivAlloc(n * sizeof (T), #T "[]"))
|
#define testingprivNewArray(T, n) ((T *) testingprivAlloc(n * sizeof (T), #T "[]"))
|
||||||
#define testingprivResizeArray(x, T, old, new) ((T *) testingprivRealloc(x, old * sizeof (T), new * sizeof (T), #T "[]"))
|
#define testingprivResizeArray(x, T, old, new) ((T *) testingprivRealloc(x, old * sizeof (T), new * sizeof (T), #T "[]"))
|
||||||
|
|
||||||
typedef struct testingprivArray testingprivArray;
|
#include "../../sharedbits/array_header.h"
|
||||||
struct testingprivArray {
|
#define testingprivArrayStaticInit(T, nGrow, what) { NULL, 0, 0, sizeof (T), nGrow, what }
|
||||||
void *buf;
|
#define testingprivArrayInit(arr, T, nGrow, what) testingprivArrayInitFull(&(arr), sizeof (T), nGrow, what)
|
||||||
size_t len;
|
#define testingprivArrayFree(arr) testingprivArrayFreeFull(&(arr))
|
||||||
size_t cap;
|
|
||||||
size_t elemsize;
|
|
||||||
size_t nGrow;
|
|
||||||
const char *what;
|
|
||||||
};
|
|
||||||
#define testingprivArrayStaticInit(T, grow, whatstr) { NULL, 0, 0, sizeof (T), grow, whatstr }
|
|
||||||
#define testingprivArrayInit(arr, T, grow, whatstr) \
|
|
||||||
memset(&(arr), 0, sizeof (testingprivArray)); \
|
|
||||||
arr.elemsize = sizeof (T); \
|
|
||||||
arr.nGrow = grow; \
|
|
||||||
arr.what = whatstr;
|
|
||||||
#define testingprivArrayFree(arr) \
|
|
||||||
testingprivFree(arr.buf); \
|
|
||||||
memset(&arr, 0, sizeof (testingprivArray));
|
|
||||||
#define testingprivArrayAt(arr, T, n) (((T *) (arr.buf)) + (n))
|
#define testingprivArrayAt(arr, T, n) (((T *) (arr.buf)) + (n))
|
||||||
extern void *testingprivArrayAppend(testingprivArray *arr, size_t n);
|
|
||||||
extern void *testingprivArrayInsertAt(testingprivArray *arr, size_t pos, size_t n);
|
|
||||||
extern void testingprivArrayDelete(testingprivArray *arr, size_t pos, size_t n);
|
|
||||||
extern void testingprivArrayDeleteItem(testingprivArray *arr, void *p, size_t n);
|
|
||||||
extern void *testingprivArrayBsearch(const testingprivArray *arr, const void *key, int (*compare)(const void *, const void *));
|
|
||||||
extern void testingprivArrayQsort(testingprivArray *arr, int (*compare)(const void *, const void *));
|
|
||||||
|
|
||||||
#undef sharedbitsPrefix
|
#undef sharedbitsPrefix
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue