aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/bfc/stack.h
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Wasabi/bfc/stack.h
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/Wasabi/bfc/stack.h')
-rw-r--r--Src/Wasabi/bfc/stack.h42
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