Make BReference and BWeakReference behave more like a normal pointer.

* Casts like BReference<Derived> to BReference<Base> are now possible.
* This cast for BWeakReference is, because of the underlying structure, not automatically type safe. I used a simple hack to make the compiler complain if the cast
is not type safe. Please take a look if that can be done better.
* Smaller style and bug fixes.
This commit is contained in:
czeidler
2012-01-05 13:42:45 +13:00
parent dafbb16406
commit 32951c4e63
2 changed files with 82 additions and 10 deletions
+28 -3
View File
@@ -41,22 +41,34 @@ template<typename Type = BReferenceable>
class BReference {
public:
BReference()
: fObject(NULL)
:
fObject(NULL)
{
}
BReference(Type* object, bool alreadyHasReference = false)
: fObject(NULL)
:
fObject(NULL)
{
SetTo(object, alreadyHasReference);
}
BReference(const BReference<Type>& other)
: fObject(NULL)
:
fObject(NULL)
{
SetTo(other.fObject);
}
template <typename OtherType>
BReference(const BReference<OtherType>& other)
:
fObject(NULL)
{
SetTo(other.Get());
}
~BReference()
{
Unset();
@@ -113,6 +125,19 @@ public:
return *this;
}
BReference& operator=(Type* other)
{
SetTo(other);
return *this;
}
template <typename OtherType>
BReference& operator=(const BReference<OtherType>& other)
{
SetTo(other.Get());
return *this;
}
bool operator==(const BReference<Type>& other) const
{
return (fObject == other.fObject);