From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- Src/Wasabi/bfc/stack.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Src/Wasabi/bfc/stack.h (limited to 'Src/Wasabi/bfc/stack.h') 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 +#include + +// 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 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(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 -- cgit