Loading...
Searching...
No Matches
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.
 
 BReference (const BReference< Type > &other)
 Copy constructor.
 
 BReference (Type *object, bool alreadyHasReference=false)
 Creates and initialize a reference.
 
 ~BReference ()
 Destructor.
 
Type * Detach ()
 Detach the pointed object from the reference.
 
Type * Get () const
 Get the target object.
 
void SetTo (Type *object, bool alreadyHasReference=false)
 Sets a new target for the reference.
 
void Unset ()
 Unsets the reference.
 

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.

References BReference< Type >::SetTo().

◆ 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.

References BReference< Type >::Get(), and BReference< Type >::SetTo().

◆ ~BReference()

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

Destructor.

The reference count of the target object is decremented.

References BReference< Type >::Unset().

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.

References NULL.

◆ 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< Type >::BReference().

◆ 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.

References NULL, and BReference< Type >::Unset().

Referenced by BReference< Type >::BReference().

◆ 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.

References NULL.

Referenced by BReference< Type >::~BReference(), and BReference< Type >::SetTo().