diff options
author | Max Horn | 2004-12-12 21:38:11 +0000 |
---|---|---|
committer | Max Horn | 2004-12-12 21:38:11 +0000 |
commit | 9e4a529ef9b2e2760c79fd729ad67545302f7c63 (patch) | |
tree | c7f5b0699cfb105efe250503c8ef87ad1351d7e7 /common | |
parent | 74e789ce99f9929694893f23042b0607dd79dd55 (diff) | |
download | scummvm-rg350-9e4a529ef9b2e2760c79fd729ad67545302f7c63.tar.gz scummvm-rg350-9e4a529ef9b2e2760c79fd729ad67545302f7c63.tar.bz2 scummvm-rg350-9e4a529ef9b2e2760c79fd729ad67545302f7c63.zip |
Hide iterator implementation details from client code
svn-id: r16041
Diffstat (limited to 'common')
-rw-r--r-- | common/list.h | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/common/list.h b/common/list.h index 2e8403c9dc..523fd5b94c 100644 --- a/common/list.h +++ b/common/list.h @@ -47,11 +47,13 @@ protected: }; template <class T2> - struct Iterator { + class Iterator { + friend class List<T>; NodeBase *_node; + explicit Iterator<T2>(NodeBase *node) : _node(node) {} + public: Iterator<T2>() : _node(0) {} - Iterator<T2>(NodeBase *node) : _node(node) {} // Prefix inc Iterator<T2> &operator++() { @@ -61,7 +63,7 @@ protected: } // Postfix inc Iterator<T2> operator++(int) { - Iterator<T2> tmp = *this; + Iterator<T2> tmp(*this); if (_node) _node = _node->_next; return tmp; @@ -74,7 +76,7 @@ protected: } // Postfix dec Iterator<T2> operator--(int) { - Iterator<T2> tmp = *this; + Iterator<T2> tmp(*this); if (_node) _node = _node->_prev; return tmp; @@ -153,7 +155,7 @@ public: prev->_next = next; next->_prev = prev; delete node; - return next; + return iterator(next); } iterator erase(iterator first, iterator last) { @@ -195,19 +197,19 @@ public: iterator begin() { - return _anchor->_next; + return iterator(_anchor->_next); } iterator end() { - return _anchor; + return iterator(_anchor); } const_iterator begin() const { - return _anchor->_next; + return const_iterator(_anchor->_next); } const_iterator end() const { - return _anchor; + return const_iterator(_anchor); } }; |