sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description: Dynamic pointer array
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
#ifndef __M3G_ARRAY_H__
|
sl@0
|
19 |
#define __M3G_ARRAY_H__
|
sl@0
|
20 |
|
sl@0
|
21 |
/*!
|
sl@0
|
22 |
* \internal
|
sl@0
|
23 |
* \file
|
sl@0
|
24 |
* \brief Dynamic pointer array
|
sl@0
|
25 |
*/
|
sl@0
|
26 |
|
sl@0
|
27 |
/*!
|
sl@0
|
28 |
* \internal
|
sl@0
|
29 |
* \brief Dynamic array structure
|
sl@0
|
30 |
*
|
sl@0
|
31 |
* Prior to using an array, the structure must be initialized by
|
sl@0
|
32 |
* either calling \c m3gInitArray or explicitly clearing the structure
|
sl@0
|
33 |
* to all zeros.
|
sl@0
|
34 |
*/
|
sl@0
|
35 |
typedef struct
|
sl@0
|
36 |
{
|
sl@0
|
37 |
M3Gsizei size, capacity;
|
sl@0
|
38 |
void **items;
|
sl@0
|
39 |
} PointerArray;
|
sl@0
|
40 |
|
sl@0
|
41 |
/*----------------------------------------------------------------------
|
sl@0
|
42 |
* Internal functions
|
sl@0
|
43 |
*--------------------------------------------------------------------*/
|
sl@0
|
44 |
|
sl@0
|
45 |
static M3Gint m3gArrayAppend (PointerArray *array,
|
sl@0
|
46 |
void *item,
|
sl@0
|
47 |
Interface *m3g);
|
sl@0
|
48 |
static void m3gArrayDelete (PointerArray *array, M3Gint idx);
|
sl@0
|
49 |
static M3Gint m3gArrayInsert (PointerArray *array,
|
sl@0
|
50 |
M3Gint idx,
|
sl@0
|
51 |
void *item,
|
sl@0
|
52 |
Interface *m3g);
|
sl@0
|
53 |
static M3Gint m3gArrayFind (const PointerArray *array, void *item);
|
sl@0
|
54 |
#if 0 /* currently disabled, but available if needed */
|
sl@0
|
55 |
static M3Gbool m3gArrayRemove (PointerArray *array, void *item);
|
sl@0
|
56 |
#endif
|
sl@0
|
57 |
static M3Gsizei m3gArraySize (const PointerArray *array);
|
sl@0
|
58 |
static void m3gClearArray (PointerArray *array);
|
sl@0
|
59 |
static void m3gDestroyArray (PointerArray *array, Interface *m3g);
|
sl@0
|
60 |
static M3Gbool m3gEnsureArrayCapacity(PointerArray *array,
|
sl@0
|
61 |
M3Gsizei capacity,
|
sl@0
|
62 |
Interface *m3g);
|
sl@0
|
63 |
static void* m3gGetArrayElement(const PointerArray *array, M3Gint idx);
|
sl@0
|
64 |
static void m3gInitArray (PointerArray *array);
|
sl@0
|
65 |
#if defined(M3G_NATIVE_LOADER) /* currently only used in loader */
|
sl@0
|
66 |
static void m3gSetArrayElement(PointerArray *array,
|
sl@0
|
67 |
M3Gint idx,
|
sl@0
|
68 |
void *item);
|
sl@0
|
69 |
#endif
|
sl@0
|
70 |
#if 0 /* currently unused, but available here */
|
sl@0
|
71 |
static M3Gbool m3gTrimArray (PointerArray *array, Interface *m3g);
|
sl@0
|
72 |
#endif
|
sl@0
|
73 |
|
sl@0
|
74 |
/*----------------------------------------------------------------------
|
sl@0
|
75 |
* Inline functions
|
sl@0
|
76 |
*--------------------------------------------------------------------*/
|
sl@0
|
77 |
|
sl@0
|
78 |
/*!
|
sl@0
|
79 |
* \internal
|
sl@0
|
80 |
* \brief Returns the number of elements in the array
|
sl@0
|
81 |
*/
|
sl@0
|
82 |
static M3G_INLINE M3Gsizei m3gArraySize(const PointerArray *array)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
M3G_ASSERT_PTR(array);
|
sl@0
|
85 |
M3G_ASSERT(array->size <= array->capacity);
|
sl@0
|
86 |
return array->size;
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
/*!
|
sl@0
|
90 |
* \internal
|
sl@0
|
91 |
* \brief Returns the array element at \c index
|
sl@0
|
92 |
*/
|
sl@0
|
93 |
static M3G_INLINE void *m3gGetArrayElement(const PointerArray *array,
|
sl@0
|
94 |
M3Gint idx)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
M3G_ASSERT_PTR(array);
|
sl@0
|
97 |
M3G_ASSERT(idx >= 0 && idx < array->size);
|
sl@0
|
98 |
return array->items[idx];
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
#if defined(M3G_NATIVE_LOADER) /* currently only used in loader */
|
sl@0
|
102 |
/*!
|
sl@0
|
103 |
* \internal
|
sl@0
|
104 |
* \brief Sets the value of the array element at \c index
|
sl@0
|
105 |
*/
|
sl@0
|
106 |
static M3G_INLINE void m3gSetArrayElement(PointerArray *array,
|
sl@0
|
107 |
M3Gint idx,
|
sl@0
|
108 |
void *item)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
M3G_ASSERT_PTR(array);
|
sl@0
|
111 |
M3G_ASSERT(idx >= 0 && idx < array->size);
|
sl@0
|
112 |
array->items[idx] = item;
|
sl@0
|
113 |
}
|
sl@0
|
114 |
#endif
|
sl@0
|
115 |
|
sl@0
|
116 |
#endif /*__M3G_ARRAY_H__*/
|