mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-21 02:00:33 +01:00
SharedPtr now has referenceCount() member fn
This commit is contained in:
parent
c60067167f
commit
6ea765969d
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// SharedPtr.h
|
// SharedPtr.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.3/Foundation/include/Poco/SharedPtr.h#5 $
|
// $Id: //poco/1.3/Foundation/include/Poco/SharedPtr.h#6 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Core
|
// Package: Core
|
||||||
@ -68,6 +68,11 @@ public:
|
|||||||
FastMutex::ScopedLock lock(_mutex);
|
FastMutex::ScopedLock lock(_mutex);
|
||||||
return --_cnt;
|
return --_cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int referenceCount() const
|
||||||
|
{
|
||||||
|
return _cnt;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FastMutex _mutex;
|
FastMutex _mutex;
|
||||||
@ -364,6 +369,11 @@ public:
|
|||||||
{
|
{
|
||||||
return get() >= ptr;
|
return get() >= ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int referenceCount() const
|
||||||
|
{
|
||||||
|
return _pCounter->referenceCount();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
C* deref() const
|
C* deref() const
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// SharedPtrTest.cpp
|
// 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.
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
@ -84,6 +84,7 @@ namespace
|
|||||||
{
|
{
|
||||||
return _number;
|
return _number;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _number;
|
int _number;
|
||||||
};
|
};
|
||||||
@ -114,8 +115,10 @@ void SharedPtrTest::testSharedPtr()
|
|||||||
}
|
}
|
||||||
assert (pTO1 < pTO2);
|
assert (pTO1 < pTO2);
|
||||||
ptr1 = pTO1;
|
ptr1 = pTO1;
|
||||||
|
assert (ptr1.referenceCount() == 1);
|
||||||
SharedPtr<TestObject> ptr2 = pTO2;
|
SharedPtr<TestObject> ptr2 = pTO2;
|
||||||
SharedPtr<TestObject> ptr3 = ptr1;
|
SharedPtr<TestObject> ptr3 = ptr1;
|
||||||
|
assert (ptr1.referenceCount() == 2);
|
||||||
SharedPtr<TestObject> ptr4;
|
SharedPtr<TestObject> ptr4;
|
||||||
assert (ptr1.get() == pTO1);
|
assert (ptr1.get() == pTO1);
|
||||||
assert (ptr1 == pTO1);
|
assert (ptr1 == pTO1);
|
||||||
@ -198,6 +201,7 @@ void SharedPtrTest::testImplicitCast()
|
|||||||
assert (TestObject::count() == 0);
|
assert (TestObject::count() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SharedPtrTest::testExplicitCast()
|
void SharedPtrTest::testExplicitCast()
|
||||||
{
|
{
|
||||||
SharedPtr<TestObject> ptr1 = new DerivedObject("test", 666);
|
SharedPtr<TestObject> ptr1 = new DerivedObject("test", 666);
|
||||||
@ -212,6 +216,7 @@ void SharedPtrTest::testExplicitCast()
|
|||||||
assert (ptr2.get() == 0);
|
assert (ptr2.get() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SharedPtrTest::setUp()
|
void SharedPtrTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user