Added a StackDeleter class that also empties the stack and deletes the items.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25381 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2008-05-08 16:43:59 +00:00
parent 9623534399
commit b1429e2a05
1 changed files with 33 additions and 3 deletions

View File

@ -1,12 +1,13 @@
/* Stack - a template stack class (plus some handy methods)
*
* Copyright 2001-2005, Axel Dörfler, axeld@pinc-software.de.
/*
* Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de.
* This file may be used under the terms of the MIT License.
*/
#ifndef KERNEL_UTIL_STACK_H
#define KERNEL_UTIL_STACK_H
#include <stdlib.h>
#include <SupportDefs.h>
@ -75,4 +76,33 @@ template<class T> class Stack {
int32 fMax;
};
template<typename T> class StackDeleter {
public:
StackDeleter(Stack<T>* stack)
: fStack(stack)
{
}
~StackDeleter()
{
if (fStack == NULL)
return;
T item;
while (fStack->Pop(&item)) {
delete item;
}
delete fStack;
}
void Detach()
{
fStack = NULL;
}
private:
Stack<T>* fStack;
};
#endif /* KERNEL_UTIL_STACK_H */