Document SharedPtr bool conversion operator; added test cases for it; also added two test cases for the comparision operators, which currently fail
svn-id: r31299
This commit is contained in:
parent
1092b87cd7
commit
f93c076a7b
2 changed files with 21 additions and 1 deletions
|
@ -62,7 +62,7 @@ namespace Common {
|
||||||
* The class has implicit upcast support, so if you got a class B derived
|
* 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
|
* 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
|
* 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
|
* There are also operators != and == to compare two SharedPtr objects
|
||||||
* with compatible pointers.
|
* with compatible pointers.
|
||||||
|
@ -116,6 +116,10 @@ public:
|
||||||
*/
|
*/
|
||||||
Pointer get() const { return _pointer; }
|
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; }
|
operator bool() const { return _pointer != 0; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -33,4 +33,20 @@ class PtrTestSuite : public CxxTest::TestSuite
|
||||||
TS_ASSERT_EQUALS(*p1, 0);
|
TS_ASSERT_EQUALS(*p1, 0);
|
||||||
TS_ASSERT(p1.unique());
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue