vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / translators / rtf / Stack.h
blob837f0ed56ac258459ef74c96e7a28f4c74fb9290
1 /* Stack - a template stack class
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 STACK_H
7 #define STACK_H
10 #include <stdlib.h>
12 #include <SupportDefs.h>
15 template<class T> class Stack {
16 public:
17 Stack()
19 fArray(NULL),
20 fUsed(0),
21 fMax(0)
25 ~Stack()
27 free(fArray);
30 bool IsEmpty() const
32 return fUsed == 0;
35 void MakeEmpty()
37 // could also free the memory
38 fUsed = 0;
41 status_t Push(T value)
43 if (fUsed >= fMax) {
44 fMax += 16;
45 T *newArray = (T *)realloc(fArray, fMax * sizeof(T));
46 if (newArray == NULL)
47 return B_NO_MEMORY;
49 fArray = newArray;
51 fArray[fUsed++] = value;
52 return B_OK;
55 bool Pop(T *value)
57 if (fUsed == 0)
58 return false;
60 *value = fArray[--fUsed];
61 return true;
64 private:
65 T *fArray;
66 int32 fUsed;
67 int32 fMax;
70 #endif /* STACK_H */