[Scummvm-cvs-logs] SF.net SVN: scummvm:[45247] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Mon Oct 19 19:46:50 CEST 2009


Revision: 45247
          http://scummvm.svn.sourceforge.net/scummvm/?rev=45247&view=rev
Author:   fingolfin
Date:     2009-10-19 17:46:50 +0000 (Mon, 19 Oct 2009)

Log Message:
-----------
Added operator== and != to Common::Array

Modified Paths:
--------------
    scummvm/trunk/common/array.h
    scummvm/trunk/test/common/array.h

Modified: scummvm/trunk/common/array.h
===================================================================
--- scummvm/trunk/common/array.h	2009-10-19 16:06:32 UTC (rev 45246)
+++ scummvm/trunk/common/array.h	2009-10-19 17:46:50 UTC (rev 45247)
@@ -199,7 +199,22 @@
 		return (_size == 0);
 	}
 
+	bool operator==(const Array<T> &other) const {
+		if (this == &other)
+			return true;
+		if (_size != other._size)
+			return false;
+		for (uint i = 0; i < _size; ++i) {
+			if (_storage[i] != other._storage[i])
+				return false;
+		}
+		return true;
+	}
+	bool operator!=(const Array<T> &other) const {
+		return !(*this == other);
+	}
 
+
 	iterator		begin() {
 		return _storage;
 	}

Modified: scummvm/trunk/test/common/array.h
===================================================================
--- scummvm/trunk/test/common/array.h	2009-10-19 16:06:32 UTC (rev 45246)
+++ scummvm/trunk/test/common/array.h	2009-10-19 17:46:50 UTC (rev 45247)
@@ -164,6 +164,23 @@
 		TS_ASSERT_EQUALS(array2.size(), (unsigned int)3);
 	}
 
+	void test_equals() {
+		Common::Array<int> array1;
+
+		// Some data for both
+		array1.push_back(-3);
+		array1.push_back(5);
+		array1.push_back(9);
+
+		Common::Array<int> array2(array1);
+
+		TS_ASSERT(array1 == array2);
+		array1.push_back(42);
+		TS_ASSERT(array1 != array2);
+		array2.push_back(42);
+		TS_ASSERT(array1 == array2);
+	}
+
 	void test_array_constructor() {
 		const int array1[] = { -3, 5, 9 };
 


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