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:
@@ -1,12 +1,13 @@
|
|||||||
/* Stack - a template stack class (plus some handy methods)
|
/*
|
||||||
*
|
* Copyright 2001-2008, Axel Dörfler, [email protected].
|
||||||
* Copyright 2001-2005, Axel Dörfler, [email protected].
|
|
||||||
* This file may be used under the terms of the MIT License.
|
* This file may be used under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef KERNEL_UTIL_STACK_H
|
#ifndef KERNEL_UTIL_STACK_H
|
||||||
#define KERNEL_UTIL_STACK_H
|
#define KERNEL_UTIL_STACK_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -75,4 +76,33 @@ template<class T> class Stack {
|
|||||||
int32 fMax;
|
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 */
|
#endif /* KERNEL_UTIL_STACK_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user