[Scummvm-cvs-logs] CVS: scummvm/common list.h,1.17,1.18

Max Horn fingolfin at users.sourceforge.net
Sun Dec 12 13:39:03 CET 2004


Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20698

Modified Files:
	list.h 
Log Message:
Hide iterator implementation details from client code

Index: list.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/list.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- list.h	8 May 2004 19:34:06 -0000	1.17
+++ list.h	12 Dec 2004 21:38:11 -0000	1.18
@@ -47,11 +47,13 @@
 	};
 
 	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 @@
 		}
 		// 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 @@
 		}
 		// 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 @@
 		prev->_next = next;
 		next->_prev = prev;
 		delete node;
-		return next;
+		return iterator(next);
 	}
 
 	iterator erase(iterator first, iterator last) {
@@ -195,19 +197,19 @@
 
 
 	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);
 	}
 };
 





More information about the Scummvm-git-logs mailing list