aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2006-12-25 23:13:13 +0000
committerMax Horn2006-12-25 23:13:13 +0000
commitf54b9355002ea9e5c66e4f2c3b036fde044be163 (patch)
treee8995db83876d936dd2edca9051facb4023bbaae
parentae4ea4d98944b9add05fac5f0efb053657fe82c3 (diff)
downloadscummvm-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.h24
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];
}