Public Member Functions | List of all members
BReference< Type > Class Template Reference

A reference to a BReferenceable object. More...

Public Member Functions

 BReference ()
 Creates a reference without initializing it. More...
 
 BReference (Type *object, bool alreadyHasReference=false)
 Creates and initialize a reference. More...
 
 BReference (const BReference< Type > &other)
 Copy constructor. More...
 
 ~BReference ()
 Destructor. More...
 
Type * Detach ()
 Detach the pointed object from the reference. More...
 
Type * Get () const
 Get the target object. More...
 
void SetTo (Type *object, bool alreadyHasReference=false)
 Sets a new target for the reference. More...
 
void Unset ()
 Unsets the reference. More...
 

Detailed Description

template<typename Type = BReferenceable>
class BReference< Type >

A reference to a BReferenceable object.

BReference simplifies the use of BReferenceable and makes it more transparent. It automatically acquires and release references to the pointed objects. It provides an API similar to a standard C++ pointer, allowing use of assignment and comparison operators and direct access to the object with -> and *.

Constructor & Destructor Documentation

◆ BReference() [1/3]

template<typename Type = BReferenceable>
BReference< Type >::BReference ( )
inline

Creates a reference without initializing it.

An uninitialized references behaves similarly to a NULL pointer.

◆ BReference() [2/3]

template<typename Type = BReferenceable>
BReference< Type >::BReference ( Type *  object,
bool  alreadyHasReference = false 
)
inline

Creates and initialize a reference.

The reference is set to the pointed object. If the parameter is set to true, the reference count is not incremented, this should only be used when referencing a freshly constructed object.

◆ BReference() [3/3]

template<typename Type = BReferenceable>
BReference< Type >::BReference ( const BReference< Type > &  other)
inline

Copy constructor.

The reference is set to the same object as the source. The reference count of the target object is incremented.

◆ ~BReference()

template<typename Type = BReferenceable>
BReference< Type >::~BReference ( )
inline

Destructor.

The reference count of the target object is decremented.

Member Function Documentation

◆ Detach()

template<typename Type = BReferenceable>
ConstType * BReference< Type >::Detach ( )
inline

Detach the pointed object from the reference.

Returns
a raw pointer to the target object.

This returns the pointed object and unsets the reference, without decrementing the object reference count. It is used to transfer ownership of the reference to something else.

Referenced by BReference< BUrlContext >::Detach().

◆ Get()

template<typename Type = BReferenceable>
ConstType * BReference< Type >::Get ( ) const
inline

Get the target object.

Returns
a raw pointer to the target object.

Referenced by BReference< BUrlContext >::BReference(), and BReference< BUrlContext >::Detach().

◆ SetTo()

template<typename Type = BReferenceable>
void BReference< Type >::SetTo ( Type *  object,
bool  alreadyHasReference = false 
)
inline

Sets a new target for the reference.

The reference to the previously targetted object is released. A reference to the new object is acquired only if alreadyHasReference is false.

◆ Unset()

template<typename Type = BReferenceable>
void BReference< Type >::Unset ( )
inline

Unsets the reference.

The targetted object is released. The reference is unset and can't be used to access it anymore.