[Scummvm-cvs-logs] SF.net SVN: scummvm: [31299] scummvm/trunk
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Sat Mar 29 01:08:56 CET 2008
Revision: 31299
http://scummvm.svn.sourceforge.net/scummvm/?rev=31299&view=rev
Author: fingolfin
Date: 2008-03-28 17:08:56 -0700 (Fri, 28 Mar 2008)
Log Message:
-----------
Document SharedPtr bool conversion operator; added test cases for it; also added two test cases for the comparision operators, which currently fail
Modified Paths:
--------------
scummvm/trunk/common/ptr.h
scummvm/trunk/test/common/ptr.h
Modified: scummvm/trunk/common/ptr.h
===================================================================
--- scummvm/trunk/common/ptr.h 2008-03-29 00:04:33 UTC (rev 31298)
+++ scummvm/trunk/common/ptr.h 2008-03-29 00:08:56 UTC (rev 31299)
@@ -62,7 +62,7 @@
* The class has implicit upcast support, so if you got a class B derived
* from class A, you can assign a pointer to B without any problems to a
* SharedPtr object with template parameter A. The very same applies to
- * assigment of a SharedPtr<B> object to a SharedPtr<A> object.
+ * assignment of a SharedPtr<B> object to a SharedPtr<A> object.
*
* There are also operators != and == to compare two SharedPtr objects
* with compatible pointers.
@@ -116,6 +116,10 @@
*/
Pointer get() const { return _pointer; }
+ /**
+ * Implicit conversion operator to bool for convenience, to make
+ * checks like "if (sharePtr) ..." possible.
+ */
operator bool() const { return _pointer != 0; }
/**
Modified: scummvm/trunk/test/common/ptr.h
===================================================================
--- scummvm/trunk/test/common/ptr.h 2008-03-29 00:04:33 UTC (rev 31298)
+++ scummvm/trunk/test/common/ptr.h 2008-03-29 00:08:56 UTC (rev 31299)
@@ -33,4 +33,20 @@
TS_ASSERT_EQUALS(*p1, 0);
TS_ASSERT(p1.unique());
}
+
+ void test_compare() {
+ Common::SharedPtr<int> p1(new int(1));
+ Common::SharedPtr<int> p2;
+
+ TS_ASSERT(p1);
+ TS_ASSERT(!p2);
+
+ TS_ASSERT(p1 != 0);
+ TS_ASSERT(p2 == 0);
+
+ // Note: The following two currently do *not* work, contrary to
+ // what the Doxygen comments of SharedPtr claim.
+ TS_ASSERT(p1 != (int *)0);
+ TS_ASSERT(p2 == (int *)0);
+ }
};
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