BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / ramfs / Stack.h
blobdc832aabf1d1eca4e1791e6fae47455c216b7996
1 /* Stack - a template stack class (plus some handy methods)
3 * Copyright 2001-2005, Axel Dörfler, axeld@pinc-software.de.
4 * This file may be used under the terms of the MIT License.
5 */
6 #ifndef KERNEL_UTIL_STACK_H
7 #define KERNEL_UTIL_STACK_H
10 #include <SupportDefs.h>
13 template<class T> class Stack {
14 public:
15 Stack()
17 fArray(NULL),
18 fUsed(0),
19 fMax(0)
23 ~Stack()
25 free(fArray);
28 bool IsEmpty() const
30 return fUsed == 0;
33 void MakeEmpty()
35 // could also free the memory
36 fUsed = 0;
39 status_t Push(T value)
41 if (fUsed >= fMax) {
42 fMax += 16;
43 T *newArray = (T *)realloc(fArray, fMax * sizeof(T));
44 if (newArray == NULL)
45 return B_NO_MEMORY;
47 fArray = newArray;
49 fArray[fUsed++] = value;
50 return B_OK;
53 bool Pop(T *value)
55 if (fUsed == 0)
56 return false;
58 *value = fArray[--fUsed];
59 return true;
62 T *Array()
64 return fArray;
67 int32 CountItems() const
69 return fUsed;
72 private:
73 T *fArray;
74 int32 fUsed;
75 int32 fMax;
78 #endif /* KERNEL_UTIL_STACK_H */