1 /* 2 * Copyright 2010, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Michael Pfeiffer 7 */ 8 #include<Debug.h> 9 10 template<typename TYPE> 11 GPArray<TYPE>::GPArray() 12 : 13 fArray(NULL), 14 fSize(0) 15 { 16 17 } 18 19 template<typename TYPE> 20 GPArray<TYPE>::~GPArray() 21 { 22 if (fArray != NULL) { 23 for (int i = 0; i < fSize; i ++) 24 delete fArray[i]; 25 delete[] fArray; 26 fArray = NULL; 27 } 28 } 29 30 31 template<typename TYPE> 32 void 33 GPArray<TYPE>::SetSize(int size) 34 { 35 ASSERT(fSize == 0); 36 fArray = new PointerType[size]; 37 if (fArray == NULL) 38 return; 39 40 fSize = size; 41 for (int i = 0; i < size; i ++) { 42 fArray[i] = NULL; 43 } 44 } 45 46 47 template<typename TYPE> 48 int 49 GPArray<TYPE>::Size() const 50 { 51 return fSize; 52 } 53 54 55 template<typename TYPE> 56 void 57 GPArray<TYPE>::DecreaseSize() 58 { 59 ASSERT(fArray != NULL); 60 ASSERT(fArray[fSize-1] == NULL); 61 fSize --; 62 } 63 64 template<typename TYPE> 65 TYPE** 66 GPArray<TYPE>::Array() 67 { 68 return fArray; 69 } 70 71 72 template<typename TYPE> 73 TYPE ** 74 GPArray<TYPE>::Array() const 75 { 76 return fArray; 77 } 78 79 template<typename TYPE> 80 bool 81 GPArray<TYPE>::IsEmpty() const 82 { 83 return fSize == 0; 84 } 85