diff --git a/headers/os/support/Referenceable.h b/headers/os/support/Referenceable.h index 0c7b2980df..a9af8c691c 100644 --- a/headers/os/support/Referenceable.h +++ b/headers/os/support/Referenceable.h @@ -37,7 +37,7 @@ protected: // #pragma mark - BReference -template +template class BReference { public: BReference() @@ -57,7 +57,7 @@ public: : fObject(NULL) { - SetTo(other.fObject); + SetTo(other.Get()); } @@ -92,34 +92,34 @@ public: } } - Type* Get() const + ConstType* Get() const { return fObject; } - Type* Detach() + ConstType* Detach() { Type* object = fObject; fObject = NULL; return object; } - Type& operator*() const + ConstType& operator*() const { return *fObject; } - Type* operator->() const + ConstType* operator->() const { return fObject; } - operator Type*() const + operator ConstType*() const { return fObject; } - BReference& operator=(const BReference& other) + BReference& operator=(const BReference& other) { SetTo(other.fObject); return *this; @@ -131,14 +131,14 @@ public: return *this; } - template - BReference& operator=(const BReference& other) + template + BReference& operator=(const BReference& other) { SetTo(other.Get()); return *this; } - bool operator==(const BReference& other) const + bool operator==(const BReference& other) const { return fObject == other.fObject; } @@ -148,7 +148,7 @@ public: return fObject == other; } - bool operator!=(const BReference& other) const + bool operator!=(const BReference& other) const { return fObject != other.fObject; } @@ -163,4 +163,39 @@ private: }; +// #pragma mark - BReference + + +template +class BConstReference: public BReference { +public: + BConstReference() + : + BReference() + { + } + + BConstReference(Type* object, bool alreadyHasReference = false) + : + BReference(object, alreadyHasReference) + { + } + + BConstReference(const BReference& other) + : + BReference(other) + { + } + + // Allow assignment of a const reference from a mutable one (but not the + // reverse). + BConstReference& operator=(const BReference& other) + { + SetTo(other.Get()); + return *this; + } + +}; + + #endif // _REFERENCEABLE_H