From 62986df7c49c29adccb3abbeabc615415ccf3c98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 12 Dec 2004 20:48:40 +0000 Subject: [PATCH] Added a MakeEmpty() method. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10402 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/bfs/Stack.h | 29 ++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Stack.h b/src/add-ons/kernel/file_systems/bfs/Stack.h index 9793eb2491..4790204470 100644 --- a/src/add-ons/kernel/file_systems/bfs/Stack.h +++ b/src/add-ons/kernel/file_systems/bfs/Stack.h @@ -1,10 +1,10 @@ +/* Stack - a template stack class + * + * Copyright 2001-2004, Axel Dörfler, axeld@pinc-software.de. + * This file may be used under the terms of the MIT License. + */ #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 @@ -19,18 +19,23 @@ template class Stack { fMax(0) { } - + ~Stack() { - if (fArray) - free(fArray); + free(fArray); } - + + void MakeEmpty() + { + // could also free the memory + fUsed = 0; + } + status_t Push(T value) { if (fUsed >= fMax) { fMax += 16; - T *newArray = (T *)realloc(fArray,fMax * sizeof(T)); + T *newArray = (T *)realloc(fArray, fMax * sizeof(T)); if (newArray == NULL) return B_NO_MEMORY; @@ -39,7 +44,7 @@ template class Stack { fArray[fUsed++] = value; return B_OK; } - + bool Pop(T *value) { if (fUsed == 0) @@ -48,7 +53,7 @@ template class Stack { *value = fArray[--fUsed]; return true; } - + private: T *fArray; int32 fUsed;