sl@0: /* sl@0: * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: Dynamic pointer array sl@0: * sl@0: */ sl@0: sl@0: #ifndef __M3G_ARRAY_H__ sl@0: #define __M3G_ARRAY_H__ sl@0: sl@0: /*! sl@0: * \internal sl@0: * \file sl@0: * \brief Dynamic pointer array sl@0: */ sl@0: sl@0: /*! sl@0: * \internal sl@0: * \brief Dynamic array structure sl@0: * sl@0: * Prior to using an array, the structure must be initialized by sl@0: * either calling \c m3gInitArray or explicitly clearing the structure sl@0: * to all zeros. sl@0: */ sl@0: typedef struct sl@0: { sl@0: M3Gsizei size, capacity; sl@0: void **items; sl@0: } PointerArray; sl@0: sl@0: /*---------------------------------------------------------------------- sl@0: * Internal functions sl@0: *--------------------------------------------------------------------*/ sl@0: sl@0: static M3Gint m3gArrayAppend (PointerArray *array, sl@0: void *item, sl@0: Interface *m3g); sl@0: static void m3gArrayDelete (PointerArray *array, M3Gint idx); sl@0: static M3Gint m3gArrayInsert (PointerArray *array, sl@0: M3Gint idx, sl@0: void *item, sl@0: Interface *m3g); sl@0: static M3Gint m3gArrayFind (const PointerArray *array, void *item); sl@0: #if 0 /* currently disabled, but available if needed */ sl@0: static M3Gbool m3gArrayRemove (PointerArray *array, void *item); sl@0: #endif sl@0: static M3Gsizei m3gArraySize (const PointerArray *array); sl@0: static void m3gClearArray (PointerArray *array); sl@0: static void m3gDestroyArray (PointerArray *array, Interface *m3g); sl@0: static M3Gbool m3gEnsureArrayCapacity(PointerArray *array, sl@0: M3Gsizei capacity, sl@0: Interface *m3g); sl@0: static void* m3gGetArrayElement(const PointerArray *array, M3Gint idx); sl@0: static void m3gInitArray (PointerArray *array); sl@0: #if defined(M3G_NATIVE_LOADER) /* currently only used in loader */ sl@0: static void m3gSetArrayElement(PointerArray *array, sl@0: M3Gint idx, sl@0: void *item); sl@0: #endif sl@0: #if 0 /* currently unused, but available here */ sl@0: static M3Gbool m3gTrimArray (PointerArray *array, Interface *m3g); sl@0: #endif sl@0: sl@0: /*---------------------------------------------------------------------- sl@0: * Inline functions sl@0: *--------------------------------------------------------------------*/ sl@0: sl@0: /*! sl@0: * \internal sl@0: * \brief Returns the number of elements in the array sl@0: */ sl@0: static M3G_INLINE M3Gsizei m3gArraySize(const PointerArray *array) sl@0: { sl@0: M3G_ASSERT_PTR(array); sl@0: M3G_ASSERT(array->size <= array->capacity); sl@0: return array->size; sl@0: } sl@0: sl@0: /*! sl@0: * \internal sl@0: * \brief Returns the array element at \c index sl@0: */ sl@0: static M3G_INLINE void *m3gGetArrayElement(const PointerArray *array, sl@0: M3Gint idx) sl@0: { sl@0: M3G_ASSERT_PTR(array); sl@0: M3G_ASSERT(idx >= 0 && idx < array->size); sl@0: return array->items[idx]; sl@0: } sl@0: sl@0: #if defined(M3G_NATIVE_LOADER) /* currently only used in loader */ sl@0: /*! sl@0: * \internal sl@0: * \brief Sets the value of the array element at \c index sl@0: */ sl@0: static M3G_INLINE void m3gSetArrayElement(PointerArray *array, sl@0: M3Gint idx, sl@0: void *item) sl@0: { sl@0: M3G_ASSERT_PTR(array); sl@0: M3G_ASSERT(idx >= 0 && idx < array->size); sl@0: array->items[idx] = item; sl@0: } sl@0: #endif sl@0: sl@0: #endif /*__M3G_ARRAY_H__*/