1 /* 2 * Copyright (C) 2007 The Android Open Source Project 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 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /** 18 * A pointer array which intelligently expands its capacity ad needed. 19 */ 20 21 #ifndef __ARRAY_H 22 #define __ARRAY_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #include <stdlib.h> 29 30 /** An array. */ 31 typedef struct Array Array; 32 33 /** Constructs a new array. Returns NULL if we ran out of memory. */ 34 Array* arrayCreate(); 35 36 /** Frees an array. Does not free elements themselves. */ 37 void arrayFree(Array* array); 38 39 /** Adds a pointer. Returns 0 is successful, < 0 otherwise. */ 40 int arrayAdd(Array* array, void* pointer); 41 42 /** Gets the pointer at the specified index. */ 43 void* arrayGet(Array* array, int index); 44 45 /** Removes the pointer at the given index and returns it. */ 46 void* arrayRemove(Array* array, int index); 47 48 /** Sets pointer at the given index. Returns old pointer. */ 49 void* arraySet(Array* array, int index, void* pointer); 50 51 /** Sets the array size. Sets new pointers to NULL. Returns 0 if successful, < 0 otherwise . */ 52 int arraySetSize(Array* array, int size); 53 54 /** Returns the size of the given array. */ 55 int arraySize(Array* array); 56 57 /** 58 * Returns a pointer to a C-style array which will be valid until this array 59 * changes. 60 */ 61 const void** arrayUnwrap(Array* array); 62 63 #ifdef __cplusplus 64 } 65 #endif 66 67 #endif /* __ARRAY_H */ 68