SharedPtr now has referenceCount() member fn

This commit is contained in:
Guenter Obiltschnig 2008-09-26 13:36:51 +00:00
parent c60067167f
commit 6ea765969d
2 changed files with 17 additions and 2 deletions

View File

@ -1,7 +1,7 @@
//
// SharedPtr.h
//
// $Id: //poco/1.3/Foundation/include/Poco/SharedPtr.h#5 $
// $Id: //poco/1.3/Foundation/include/Poco/SharedPtr.h#6 $
//
// Library: Foundation
// Package: Core
@ -68,6 +68,11 @@ public:
FastMutex::ScopedLock lock(_mutex);
return --_cnt;
}
int referenceCount() const
{
return _cnt;
}
private:
FastMutex _mutex;
@ -364,6 +369,11 @@ public:
{
return get() >= ptr;
}
int referenceCount() const
{
return _pCounter->referenceCount();
}
private:
C* deref() const

View File

@ -1,7 +1,7 @@
//
// SharedPtrTest.cpp
//
// $Id: //poco/svn/Foundation/testsuite/src/SharedPtrTest.cpp#2 $
// $Id: //poco/1.3/Foundation/testsuite/src/SharedPtrTest.cpp#3 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
@ -84,6 +84,7 @@ namespace
{
return _number;
}
private:
int _number;
};
@ -114,8 +115,10 @@ void SharedPtrTest::testSharedPtr()
}
assert (pTO1 < pTO2);
ptr1 = pTO1;
assert (ptr1.referenceCount() == 1);
SharedPtr<TestObject> ptr2 = pTO2;
SharedPtr<TestObject> ptr3 = ptr1;
assert (ptr1.referenceCount() == 2);
SharedPtr<TestObject> ptr4;
assert (ptr1.get() == pTO1);
assert (ptr1 == pTO1);
@ -198,6 +201,7 @@ void SharedPtrTest::testImplicitCast()
assert (TestObject::count() == 0);
}
void SharedPtrTest::testExplicitCast()
{
SharedPtr<TestObject> ptr1 = new DerivedObject("test", 666);
@ -212,6 +216,7 @@ void SharedPtrTest::testExplicitCast()
assert (ptr2.get() == 0);
}
void SharedPtrTest::setUp()
{
}