1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/m3g/m3gcore11/inc/m3g_array.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,116 @@
1.4 +/*
1.5 +* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description: Dynamic pointer array
1.18 +*
1.19 +*/
1.20 +
1.21 +#ifndef __M3G_ARRAY_H__
1.22 +#define __M3G_ARRAY_H__
1.23 +
1.24 +/*!
1.25 + * \internal
1.26 + * \file
1.27 + * \brief Dynamic pointer array
1.28 + */
1.29 +
1.30 +/*!
1.31 + * \internal
1.32 + * \brief Dynamic array structure
1.33 + *
1.34 + * Prior to using an array, the structure must be initialized by
1.35 + * either calling \c m3gInitArray or explicitly clearing the structure
1.36 + * to all zeros.
1.37 + */
1.38 +typedef struct
1.39 +{
1.40 + M3Gsizei size, capacity;
1.41 + void **items;
1.42 +} PointerArray;
1.43 +
1.44 +/*----------------------------------------------------------------------
1.45 + * Internal functions
1.46 + *--------------------------------------------------------------------*/
1.47 +
1.48 +static M3Gint m3gArrayAppend (PointerArray *array,
1.49 + void *item,
1.50 + Interface *m3g);
1.51 +static void m3gArrayDelete (PointerArray *array, M3Gint idx);
1.52 +static M3Gint m3gArrayInsert (PointerArray *array,
1.53 + M3Gint idx,
1.54 + void *item,
1.55 + Interface *m3g);
1.56 +static M3Gint m3gArrayFind (const PointerArray *array, void *item);
1.57 +#if 0 /* currently disabled, but available if needed */
1.58 +static M3Gbool m3gArrayRemove (PointerArray *array, void *item);
1.59 +#endif
1.60 +static M3Gsizei m3gArraySize (const PointerArray *array);
1.61 +static void m3gClearArray (PointerArray *array);
1.62 +static void m3gDestroyArray (PointerArray *array, Interface *m3g);
1.63 +static M3Gbool m3gEnsureArrayCapacity(PointerArray *array,
1.64 + M3Gsizei capacity,
1.65 + Interface *m3g);
1.66 +static void* m3gGetArrayElement(const PointerArray *array, M3Gint idx);
1.67 +static void m3gInitArray (PointerArray *array);
1.68 +#if defined(M3G_NATIVE_LOADER) /* currently only used in loader */
1.69 +static void m3gSetArrayElement(PointerArray *array,
1.70 + M3Gint idx,
1.71 + void *item);
1.72 +#endif
1.73 +#if 0 /* currently unused, but available here */
1.74 +static M3Gbool m3gTrimArray (PointerArray *array, Interface *m3g);
1.75 +#endif
1.76 +
1.77 +/*----------------------------------------------------------------------
1.78 + * Inline functions
1.79 + *--------------------------------------------------------------------*/
1.80 +
1.81 +/*!
1.82 + * \internal
1.83 + * \brief Returns the number of elements in the array
1.84 + */
1.85 +static M3G_INLINE M3Gsizei m3gArraySize(const PointerArray *array)
1.86 +{
1.87 + M3G_ASSERT_PTR(array);
1.88 + M3G_ASSERT(array->size <= array->capacity);
1.89 + return array->size;
1.90 +}
1.91 +
1.92 +/*!
1.93 + * \internal
1.94 + * \brief Returns the array element at \c index
1.95 + */
1.96 +static M3G_INLINE void *m3gGetArrayElement(const PointerArray *array,
1.97 + M3Gint idx)
1.98 +{
1.99 + M3G_ASSERT_PTR(array);
1.100 + M3G_ASSERT(idx >= 0 && idx < array->size);
1.101 + return array->items[idx];
1.102 +}
1.103 +
1.104 +#if defined(M3G_NATIVE_LOADER) /* currently only used in loader */
1.105 +/*!
1.106 + * \internal
1.107 + * \brief Sets the value of the array element at \c index
1.108 + */
1.109 +static M3G_INLINE void m3gSetArrayElement(PointerArray *array,
1.110 + M3Gint idx,
1.111 + void *item)
1.112 +{
1.113 + M3G_ASSERT_PTR(array);
1.114 + M3G_ASSERT(idx >= 0 && idx < array->size);
1.115 + array->items[idx] = item;
1.116 +}
1.117 +#endif
1.118 +
1.119 +#endif /*__M3G_ARRAY_H__*/