51Degrees Common C/C++  4.1

A shared functionality library that is used by 51Degrees products

array.h

1 /* *********************************************************************
2  * This Source Code Form is copyright of 51 Degrees Mobile Experts Limited.
3  * Copyright 2019 51 Degrees Mobile Experts Limited, 5 Charlotte Close,
4  * Caversham, Reading, Berkshire, United Kingdom RG4 7BY
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0.
8  *
9  * If a copy of the MPL was not distributed with this file, You can obtain
10  * one at http://mozilla.org/MPL/2.0/.
11  *
12  * This Source Code Form is "Incompatible With Secondary Licenses", as
13  * defined by the Mozilla Public License, v. 2.0.
14  * ********************************************************************* */
15 
16 #ifndef FIFTYONE_DEGREES_ARRAY_H_INCLUDED
17 #define FIFTYONE_DEGREES_ARRAY_H_INCLUDED
18 
41 #define FIFTYONE_DEGREES_ARRAY_TYPE(t, m) \
42  \
44 typedef struct fiftone_degrees_array_##t##_t { \
45  uint32_t count; \
46  uint32_t capacity; \
47  t *items; \
48  m \
49 } t##Array;
50 
54 #define FIFTYONE_DEGREES_ARRAY_SIZE(t, c) (sizeof(t##Array) + (sizeof(t) * c))
55 
59 #define FIFTYONE_DEGREES_ARRAY_CREATE(t, i, c) \
60 i = (t##Array*)Malloc(FIFTYONE_DEGREES_ARRAY_SIZE(t,c)); \
61 if (i != NULL) { \
62 i->items = (t*)(i + 1); \
63 i->count = 0; \
64 i->capacity = c; \
65 }
66 
70 #endif