diff options
author | Max Horn | 2006-12-25 23:13:13 +0000 |
---|---|---|
committer | Max Horn | 2006-12-25 23:13:13 +0000 |
commit | f54b9355002ea9e5c66e4f2c3b036fde044be163 (patch) | |
tree | e8995db83876d936dd2edca9051facb4023bbaae | |
parent | ae4ea4d98944b9add05fac5f0efb053657fe82c3 (diff) | |
download | scummvm-rg350-f54b9355002ea9e5c66e4f2c3b036fde044be163.tar.gz scummvm-rg350-f54b9355002ea9e5c66e4f2c3b036fde044be163.tar.bz2 scummvm-rg350-f54b9355002ea9e5c66e4f2c3b036fde044be163.zip |
Tweaked the FixedStack class a bit
svn-id: r24926
-rw-r--r-- | common/stack.h | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/common/stack.h b/common/stack.h index ce438b6174..123cacd6cb 100644 --- a/common/stack.h +++ b/common/stack.h @@ -49,23 +49,27 @@ public: assert(_size < MAX_SIZE); _stack[_size++] = x; } - T top() const { - if (_size > 0) - return _stack[_size - 1]; - else - return 0; + const T& top() const { + assert(_size > 0); + return _stack[_size - 1]; } - T pop() { - T tmp; + T& top() { assert(_size > 0); - tmp = _stack[_size - 1]; - _stack[--_size] = 0; + return _stack[_size - 1]; + } + T pop() { + T tmp = top(); + --_size; return tmp; } int size() const { return _size; } - T operator [](int i) { + T& operator [](int i) { + assert(0 <= i && i < MAX_SIZE); + return _stack[i]; + } + const T& operator [](int i) const { assert(0 <= i && i < MAX_SIZE); return _stack[i]; } |