vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / print / drivers / gutenprint / GPArray.cpp
blobaab29cbff9185e14ceb249fe404392fd7354d343
1 /*
2 * Copyright 2010, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Michael Pfeiffer
7 */
8 #include<Debug.h>
10 template<typename TYPE>
11 GPArray<TYPE>::GPArray()
13 fArray(NULL),
14 fSize(0)
19 template<typename TYPE>
20 GPArray<TYPE>::~GPArray()
22 if (fArray != NULL) {
23 for (int i = 0; i < fSize; i ++)
24 delete fArray[i];
25 delete[] fArray;
26 fArray = NULL;
31 template<typename TYPE>
32 void
33 GPArray<TYPE>::SetSize(int size)
35 ASSERT(fSize == NULL);
36 fArray = new PointerType[size];
37 if (fArray == NULL)
38 return;
40 fSize = size;
41 for (int i = 0; i < size; i ++) {
42 fArray[i] = NULL;
47 template<typename TYPE>
48 int
49 GPArray<TYPE>::Size() const
51 return fSize;
55 template<typename TYPE>
56 void
57 GPArray<TYPE>::DecreaseSize()
59 ASSERT(fArray != NULL);
60 ASSERT(fArray[fSize-1] == NULL);
61 fSize --;
64 template<typename TYPE>
65 TYPE**
66 GPArray<TYPE>::Array()
68 return fArray;
72 template<typename TYPE>
73 TYPE **
74 GPArray<TYPE>::Array() const
76 return fArray;
79 template<typename TYPE>
80 bool
81 GPArray<TYPE>::IsEmpty() const
83 return fSize == 0;