diff options
author | Max Horn | 2004-05-05 01:19:42 +0000 |
---|---|---|
committer | Max Horn | 2004-05-05 01:19:42 +0000 |
commit | 5d0f0ea0c6afd7defaba3df69b39879a63256776 (patch) | |
tree | 237c6fa267e033fc24089fbfbda66324deee0816 | |
parent | 163dc349b6c9110cfb497266b246b9b8806a7012 (diff) | |
download | scummvm-rg350-5d0f0ea0c6afd7defaba3df69b39879a63256776.tar.gz scummvm-rg350-5d0f0ea0c6afd7defaba3df69b39879a63256776.tar.bz2 scummvm-rg350-5d0f0ea0c6afd7defaba3df69b39879a63256776.zip |
Added generic variable size stack class - COMPLETELY UNTESTED. Really should add some unit tests for this...
svn-id: r13776
-rw-r--r-- | common/stack.h | 48 | ||||
-rw-r--r-- | gui/newgui.h | 2 |
2 files changed, 46 insertions, 4 deletions
diff --git a/common/stack.h b/common/stack.h index 926c61f592..acc8ae6c89 100644 --- a/common/stack.h +++ b/common/stack.h @@ -23,6 +23,7 @@ #include "common/scummsys.h" #include <assert.h> +#include "common/array.h" namespace Common { @@ -30,17 +31,20 @@ namespace Common { * Extremly simple fixed size stack class. */ template <class T, int MAX_SIZE = 10> -class Stack { +class FixedStack { protected: T _stack[MAX_SIZE]; int _size; public: - Stack<T, MAX_SIZE>() : _size(0) {} + FixedStack<T, MAX_SIZE>() : _size(0) {} bool empty() const { return _size <= 0; } - void push(T x) { + void clear() { + _size = 0; + } + void push(const T& x) { assert(_size < MAX_SIZE); _stack[_size++] = x; } @@ -63,6 +67,44 @@ public: } }; + +/** + * Variable size stack class, implemented using our Array class. + */ +template <class T> +class Stack { +protected: + Array<T> _stack; +public: + Stack<T>() {} + + bool empty() const { + return _stack.isEmpty(); + } + void clear() { + _stack.clear(); + } + void push(const T& x) { + _stack.push_back(x); + } + T top() const { + const int s = size(); + if (s > 0) + return _stack[s - 1]; + else + return 0; + } + void pop() { + _stack.remove_at(size() - 1); + } + int size() const { + return _stack.size(); + } + T operator [](int i) { + return _stack[i]; + } +}; + } // End of namespace Common #endif diff --git a/gui/newgui.h b/gui/newgui.h index 7a08e7dbfa..13872db69f 100644 --- a/gui/newgui.h +++ b/gui/newgui.h @@ -56,7 +56,7 @@ using Graphics::kTextAlignRight; // Simple dialog stack class // Anybody nesting dialogs deeper than 4 is mad anyway -typedef Common::Stack<Dialog *> DialogStack; +typedef Common::FixedStack<Dialog *> DialogStack; /** |