Ion C
C library for Ion
Loading...
Searching...
No Matches
ion_collection.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at:
7 *
8 * http://aws.amazon.com/apache2.0/
9 *
10 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
12 * language governing permissions and limitations under the License.
13 */
14
17#ifndef ION_COLLECTION_H_
18#define ION_COLLECTION_H_
19
20#include "ion_types.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
28
29
30#define IPCN_DATA_SIZE sizeof(void *)
31#define IPCN_OVERHEAD_SIZE (sizeof(ION_COLLECTION_NODE) - IPCN_DATA_SIZE)
32
33#define IPCN_pNODE_TO_pDATA(x) (&((x)->_data[0]))
34#define IPCN_pDATA_TO_pNODE(x) ((ION_COLLECTION_NODE *) (((uint8_t *)(x)) - IPCN_OVERHEAD_SIZE))
35
36
42{
45 uint8_t _data[IPCN_DATA_SIZE]; // this is a place holder, length is max value length
46};
47
48
72{
73 void *_owner;
74 int32_t _node_size;
75 int32_t _count;
78 ION_COLLECTION_NODE *_freelist;
79};
80
81// BOOL ion_collection_is_empty(ION_COLLECTION *collection)
82#define ION_COLLECTION_IS_EMPTY(collection) \
83 ((collection)->_head == NULL)
84
85// SIZE count = ion_collection_size(ION_COLLECTION_CURSOR *pcursor)
86#define ION_COLLECTION_SIZE(pcol) \
87 ((pcol)->_count)
88
89// ION_COLLECTION_CURSOR pcursor = ion_collection_open(ION_COLLECTION *collection)
90#define ION_COLLECTION_OPEN(collection, pcursor) \
91 (pcursor) = (collection)->_head
92
93// void *pbuf = ion_collection_next(ION_COLLECTION_CURSOR *pcursor)
94#define ION_COLLECTION_NEXT(pcursor, pbuf) \
95 if ((pcursor) != NULL) { \
96 *((void **)&(pbuf)) = IPCN_pNODE_TO_pDATA(pcursor); \
97 (pcursor) = (pcursor)->_next; \
98 } else { \
99 *((void **)&(pbuf)) = NULL; \
100 }
101
102// ION_COLLECTION_CURSOR *pcursor = ion_collection_close();
103#define ION_COLLECTION_CLOSE(pcursor) \
104 (pcursor) = NULL
105
106
107#ifdef __cplusplus
108}
109#endif
110
111#endif
Definition ion_collection.h:42
Definition ion_collection.h:72