[Scummvm-cvs-logs] CVS: scummvm/common list.h,1.1,1.2

Max Horn fingolfin at users.sourceforge.net
Tue Oct 15 08:33:03 CEST 2002


Update of /cvsroot/scummvm/scummvm/common
In directory usw-pr-cvs1:/tmp/cvs-serv24587

Modified Files:
	list.h 
Log Message:
added insert_at method to List template

Index: list.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/list.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- list.h	8 Sep 2002 01:08:11 -0000	1.1
+++ list.h	15 Oct 2002 15:32:32 -0000	1.2
@@ -49,11 +49,26 @@
 			delete [] _data;
 	}
 	
-	void push_back(const T& str)
+	void push_back(const T& element)
 	{
 		ensureCapacity(_size + 1);
-		_data[_size++] = str;
+		_data[_size++] = element;
 	}
+	
+	void insert_at(int idx, const T& element)
+	{
+		assert(idx >= 0 && idx <= _size);
+		ensureCapacity(_size + 1);
+		// The following loop is not efficient if you can just memcpy things around.
+		// e.g. if you have a list of ints. But for real objects (String...), memcpy
+		// is *not* usually a good idea!
+		for (int i = _size; i > idx; i--) {
+			_data[i] = _data[i-1];
+		}
+		_data[idx] = element;
+		_size++;
+	}
+
 	
 	// TODO: insert, remove, ...
 	





More information about the Scummvm-git-logs mailing list