2 * Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de.
3 * This file may be used under the terms of the MIT License.
5 #ifndef KERNEL_UTIL_STACK_H
6 #define KERNEL_UTIL_STACK_H
11 #include <SupportDefs.h>
13 #include <AutoDeleter.h>
16 template<class T
> class Stack
{
38 // could also free the memory
42 status_t
Push(T value
)
46 T
*newArray
= (T
*)realloc(fArray
, fMax
* sizeof(T
));
52 fArray
[fUsed
++] = value
;
61 *value
= fArray
[--fUsed
];
70 int32
CountItems() const
82 template<typename T
> class StackDelete
{
84 inline void operator()(Stack
<T
>* stack
)
90 while (stack
->Pop(&item
)) {
98 template<typename T
> class StackDeleter
99 : public BPrivate::AutoDeleter
<Stack
<T
>, StackDelete
<T
> > {
105 StackDeleter(Stack
<T
>* stack
)
106 : BPrivate::AutoDeleter
<Stack
<T
>, StackDelete
<T
> >(stack
)
111 #endif /* KERNEL_UTIL_STACK_H */