[Scummvm-cvs-logs] SF.net SVN: scummvm: [31357] scummvm/trunk
lordhoto at users.sourceforge.net
lordhoto at users.sourceforge.net
Wed Apr 2 04:15:00 CEST 2008
Revision: 31357
http://scummvm.svn.sourceforge.net/scummvm/?rev=31357&view=rev
Author: lordhoto
Date: 2008-04-01 19:15:00 -0700 (Tue, 01 Apr 2008)
Log Message:
-----------
Implemented transparent List::iterator to List::const_iterator conversion and updated our tests accordingly.
Modified Paths:
--------------
scummvm/trunk/common/list.h
scummvm/trunk/test/common/list.h
Modified: scummvm/trunk/common/list.h
===================================================================
--- scummvm/trunk/common/list.h 2008-04-02 02:01:31 UTC (rev 31356)
+++ scummvm/trunk/common/list.h 2008-04-02 02:15:00 UTC (rev 31357)
@@ -54,6 +54,7 @@
template <class t_T2>
class Iterator {
+ //template<class T> friend class Iterator;
friend class List<t_T>;
NodeBase *_node;
@@ -65,7 +66,15 @@
public:
Iterator() : _node(0) {}
+ template<class T>
+ Iterator(const Iterator<T> &c) : _node(c._node) {}
+ template<class T>
+ Iterator<t_T2> &operator =(const Iterator<T> &c) {
+ _node = c._node;
+ return *this;
+ }
+
// Prefix inc
Iterator<t_T2> &operator++() {
if (_node)
@@ -90,7 +99,7 @@
--(*this);
return tmp;
}
- t_T2& operator*() const {
+ t_T2 &operator*() const {
assert(_node);
#if (__GNUC__ == 2) && (__GNUC_MINOR__ >= 95)
return static_cast<List<t_T>::Node<t_T2> *>(_node)->_data;
@@ -98,15 +107,17 @@
return static_cast<Node<t_T2>*>(_node)->_data;
#endif
}
- t_T2* operator->() const {
+ t_T2 *operator->() const {
return &(operator*());
}
- bool operator==(const Iterator<t_T2>& x) const {
+ template<class T>
+ bool operator==(const Iterator<T> &x) const {
return _node == x._node;
}
- bool operator!=(const Iterator<t_T2>& x) const {
+ template<class T>
+ bool operator!=(const Iterator<T> &x) const {
return _node != x._node;
}
};
Modified: scummvm/trunk/test/common/list.h
===================================================================
--- scummvm/trunk/test/common/list.h 2008-04-02 02:01:31 UTC (rev 31356)
+++ scummvm/trunk/test/common/list.h 2008-04-02 02:15:00 UTC (rev 31357)
@@ -36,6 +36,7 @@
{
Common::List<int> container;
Common::List<int>::iterator iter;
+ Common::List<int>::const_iterator cIter;
// Fill the container with some random data
container.push_back(17);
@@ -46,19 +47,34 @@
// the order we expect them to be.
iter = container.begin();
+ cIter = container.begin();
+ TS_ASSERT( iter == cIter );
+
TS_ASSERT( *iter == 17 );
++iter;
+ ++cIter;
TS_ASSERT( iter != container.end() );
+ TS_ASSERT( cIter != container.end() );
+ TS_ASSERT( iter == cIter );
TS_ASSERT( *iter == 33 );
++iter;
+ ++cIter;
TS_ASSERT( iter != container.end() );
+ TS_ASSERT( cIter != container.end() );
+ TS_ASSERT( iter == cIter );
// Also test the postinc
TS_ASSERT( *iter == -11 );
iter++;
+ cIter++;
TS_ASSERT( iter == container.end() );
+ TS_ASSERT( cIter == container.end() );
+ TS_ASSERT( iter == cIter );
+
+ cIter = iter;
+ TS_ASSERT( iter == cIter );
}
void test_insert( void )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list