* Removed the obsolescent [B]Reference[able] API and replaced the remaining
uses. Fixes the gcc 2 acpi build.
* Renamed WeakReferenceable::{Add,Remove}Reference() to
{Acquire,Release}Reference() for consistency.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39871 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2004-2009, Ingo Weinhold, [email protected].
|
||||
* Copyright 2004-2010, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _REFERENCEABLE_H
|
||||
@@ -9,13 +9,12 @@
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
// #pragma mark - BReferenceable
|
||||
|
||||
|
||||
class BReferenceable {
|
||||
public:
|
||||
BReferenceable(
|
||||
bool deleteWhenUnreferenced = true);
|
||||
// TODO: The parameter is deprecated.
|
||||
// Override LastReferenceReleased()
|
||||
// instead!
|
||||
BReferenceable();
|
||||
virtual ~BReferenceable();
|
||||
|
||||
void AcquireReference();
|
||||
@@ -25,35 +24,18 @@ public:
|
||||
int32 CountReferences() const
|
||||
{ return fReferenceCount; }
|
||||
|
||||
// deprecate aliases
|
||||
inline void AddReference();
|
||||
inline bool RemoveReference();
|
||||
|
||||
protected:
|
||||
virtual void FirstReferenceAcquired();
|
||||
virtual void LastReferenceReleased();
|
||||
|
||||
protected:
|
||||
vint32 fReferenceCount;
|
||||
bool fDeleteWhenUnreferenced;
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
BReferenceable::AddReference()
|
||||
{
|
||||
AcquireReference();
|
||||
}
|
||||
// #pragma mark - BReference
|
||||
|
||||
|
||||
bool
|
||||
BReferenceable::RemoveReference()
|
||||
{
|
||||
return ReleaseReference();
|
||||
}
|
||||
|
||||
|
||||
// BReference
|
||||
template<typename Type = BReferenceable>
|
||||
class BReference {
|
||||
public:
|
||||
@@ -145,107 +127,4 @@ private:
|
||||
};
|
||||
|
||||
|
||||
// #pragma mark Obsolete API
|
||||
|
||||
// TODO: To be phased out!
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
// Reference
|
||||
template<typename Type = BReferenceable>
|
||||
class Reference {
|
||||
public:
|
||||
Reference()
|
||||
: fObject(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
Reference(Type* object, bool alreadyHasReference = false)
|
||||
: fObject(NULL)
|
||||
{
|
||||
SetTo(object, alreadyHasReference);
|
||||
}
|
||||
|
||||
Reference(const Reference<Type>& other)
|
||||
: fObject(NULL)
|
||||
{
|
||||
SetTo(other.fObject);
|
||||
}
|
||||
|
||||
~Reference()
|
||||
{
|
||||
Unset();
|
||||
}
|
||||
|
||||
void SetTo(Type* object, bool alreadyHasReference = false)
|
||||
{
|
||||
if (object != NULL && !alreadyHasReference)
|
||||
object->AddReference();
|
||||
|
||||
Unset();
|
||||
|
||||
fObject = object;
|
||||
}
|
||||
|
||||
void Unset()
|
||||
{
|
||||
if (fObject) {
|
||||
fObject->RemoveReference();
|
||||
fObject = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Type* Get() const
|
||||
{
|
||||
return fObject;
|
||||
}
|
||||
|
||||
Type* Detach()
|
||||
{
|
||||
Type* object = fObject;
|
||||
fObject = NULL;
|
||||
return object;
|
||||
}
|
||||
|
||||
Type& operator*() const
|
||||
{
|
||||
return *fObject;
|
||||
}
|
||||
|
||||
Type* operator->() const
|
||||
{
|
||||
return fObject;
|
||||
}
|
||||
|
||||
Reference& operator=(const Reference<Type>& other)
|
||||
{
|
||||
SetTo(other.fObject);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Reference<Type>& other) const
|
||||
{
|
||||
return (fObject == other.fObject);
|
||||
}
|
||||
|
||||
bool operator!=(const Reference<Type>& other) const
|
||||
{
|
||||
return (fObject != other.fObject);
|
||||
}
|
||||
|
||||
private:
|
||||
Type* fObject;
|
||||
};
|
||||
|
||||
|
||||
typedef BReferenceable Referenceable;
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
using BPrivate::Referenceable;
|
||||
using BPrivate::Reference;
|
||||
|
||||
|
||||
#endif // _REFERENCEABLE_H
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace BPrivate {
|
||||
template<typename Type> class WeakReferenceable;
|
||||
|
||||
template<typename Type>
|
||||
class WeakPointer : public Referenceable {
|
||||
class WeakPointer : public BReferenceable {
|
||||
public:
|
||||
Type* Get();
|
||||
bool Put();
|
||||
@@ -41,10 +41,10 @@ public:
|
||||
WeakReferenceable(Type* object);
|
||||
~WeakReferenceable();
|
||||
|
||||
void AddReference()
|
||||
void AcquireReference()
|
||||
{ fPointer->_GetUnchecked(); }
|
||||
|
||||
bool RemoveReference()
|
||||
bool ReleaseReference()
|
||||
{ return fPointer->Put(); }
|
||||
|
||||
int32 CountReferences() const
|
||||
@@ -119,7 +119,7 @@ public:
|
||||
|
||||
if (pointer != NULL) {
|
||||
fPointer = pointer;
|
||||
fPointer->AddReference();
|
||||
fPointer->AcquireReference();
|
||||
fObject = pointer->Get();
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ public:
|
||||
fPointer->Put();
|
||||
fObject = NULL;
|
||||
}
|
||||
fPointer->RemoveReference();
|
||||
fPointer->ReleaseReference();
|
||||
fPointer = NULL;
|
||||
}
|
||||
}
|
||||
@@ -287,7 +287,7 @@ template<typename Type>
|
||||
inline
|
||||
WeakReferenceable<Type>::~WeakReferenceable()
|
||||
{
|
||||
fPointer->RemoveReference();
|
||||
fPointer->ReleaseReference();
|
||||
}
|
||||
|
||||
|
||||
@@ -295,7 +295,7 @@ template<typename Type>
|
||||
inline WeakPointer<Type>*
|
||||
WeakReferenceable<Type>::GetWeakPointer()
|
||||
{
|
||||
fPointer->AddReference();
|
||||
fPointer->AcquireReference();
|
||||
return fPointer;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user