diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Wasabi/bfc/stack.h | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/Wasabi/bfc/stack.h')
-rw-r--r-- | Src/Wasabi/bfc/stack.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Src/Wasabi/bfc/stack.h b/Src/Wasabi/bfc/stack.h new file mode 100644 index 00000000..39ed50a0 --- /dev/null +++ b/Src/Wasabi/bfc/stack.h @@ -0,0 +1,42 @@ +//PORTABLE +#ifndef _STACK_H +#define _STACK_H + +#include <bfc/common.h> +#include <bfc/wasabi_std.h> + +// a self-growing stack. note that it never shrinks (for now) + +class StackBase { +protected: + StackBase(); + ~StackBase(); + + int push(void *item, int sizeofT, int increment); + int peek(); + int peekAt(void *ptr, int n, int sizeofT); + int getRef(void **ptr, int n, int sizeofT); + void *top(int sizeofT); + int pop(void *ptr, int sizeofT); + int isempty(); + void purge(); + +private: + int nslots, cur; + char *stack; +}; + +template<class T> +class Stack : public StackBase { +public: + int push(T item, int increment=-1) { return StackBase::push(&item, sizeof(T), increment); } + using StackBase::peek; + T top() { return *static_cast<T*>(StackBase::top(sizeof(T))); } + int peekAt(T *ptr = NULL, int n = 0) { return StackBase::peekAt(ptr, n, sizeof(T)); } + int getRef(T **ptr = NULL, int n = 0) { if (!ptr) return peek(); return StackBase::getRef((void **)&(*ptr), n, sizeof(T)); } + int pop(T *ptr = NULL) { return StackBase::pop(ptr, sizeof(T)); } + using StackBase::isempty; + using StackBase::purge; +}; + +#endif |