btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / bin / bfs_tools / lib / Stack.h
blobd88961a8e3d3ddd2fc9a45e5d6e6d6e155080937
1 #ifndef STACK_H
2 #define STACK_H
3 /* Stack - a template stack class
4 **
5 ** Copyright 2001 pinc Software. All Rights Reserved.
6 ** Released under the terms of the MIT license.
7 */
10 #include <stdlib.h>
12 #include <SupportDefs.h>
15 template<class T> class Stack
17 public:
18 Stack()
20 fArray(NULL),
21 fUsed(0),
22 fMax(0)
26 ~Stack()
28 if (fArray)
29 free(fArray);
32 status_t Push(T value)
34 if (fUsed >= fMax)
36 fMax += 16;
37 fArray = (T *)realloc(fArray,fMax * sizeof(T));
38 if (fArray == NULL)
39 return B_NO_MEMORY;
41 fArray[fUsed++] = value;
42 return B_OK;
45 bool Pop(T *value)
47 if (fUsed == 0)
48 return false;
50 *value = fArray[--fUsed];
51 return true;
54 private:
55 T *fArray;
56 int32 fUsed;
57 int32 fMax;
60 #endif /* STACK_H */