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