diff --git a/headers/private/kernel/util/Stack.h b/headers/private/kernel/util/Stack.h index dc832aabf1..855db1fd45 100644 --- a/headers/private/kernel/util/Stack.h +++ b/headers/private/kernel/util/Stack.h @@ -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 + #include @@ -75,4 +76,33 @@ template class Stack { int32 fMax; }; +template class StackDeleter { +public: + StackDeleter(Stack* stack) + : fStack(stack) + { + } + + ~StackDeleter() + { + if (fStack == NULL) + return; + + T item; + while (fStack->Pop(&item)) { + delete item; + } + + delete fStack; + } + + void Detach() + { + fStack = NULL; + } + +private: + Stack* fStack; +}; + #endif /* KERNEL_UTIL_STACK_H */