From 044ba1ed95558edaadbbdffff5030775dd3b6be6 Mon Sep 17 00:00:00 2001 From: beveloper Date: Thu, 3 Oct 2002 21:45:43 +0000 Subject: [PATCH] We need a stack. Using the one from bfs. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1356 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/media/TStack.h | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 headers/private/media/TStack.h diff --git a/headers/private/media/TStack.h b/headers/private/media/TStack.h new file mode 100644 index 0000000000..9793eb2491 --- /dev/null +++ b/headers/private/media/TStack.h @@ -0,0 +1,58 @@ +#ifndef STACK_H +#define STACK_H +/* Stack - a template stack class +** +** Copyright 2001 pinc Software. All Rights Reserved. +** This file may be used under the terms of the OpenBeOS License. +*/ + + +#include + + +template class Stack { + public: + Stack() + : + fArray(NULL), + fUsed(0), + fMax(0) + { + } + + ~Stack() + { + if (fArray) + free(fArray); + } + + status_t Push(T value) + { + if (fUsed >= fMax) { + fMax += 16; + T *newArray = (T *)realloc(fArray,fMax * sizeof(T)); + if (newArray == NULL) + return B_NO_MEMORY; + + fArray = newArray; + } + fArray[fUsed++] = value; + return B_OK; + } + + bool Pop(T *value) + { + if (fUsed == 0) + return false; + + *value = fArray[--fUsed]; + return true; + } + + private: + T *fArray; + int32 fUsed; + int32 fMax; +}; + +#endif /* STACK_H */