All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::RefObj< T > Class Template Reference

Smart object reference. More...

#include <Radiant/RefObj.hpp>

Public Member Functions

void deepCopy (const RefObj &that)
 Create a deep copy of the object Instead of sharing a link to an object, this method creates a real copy of the object. More...
 
T & operator* ()
 An operator to get a reference to the object. More...
 
const T & operator* () const
 An operator to get a constant reference to the object. More...
 
RefObjoperator= (const RefObj &that)
 Link to the source object. More...
 
T & ref ()
 Get a reference to the object. More...
 
const T & ref () const
 Get a constant reference to the object. More...
 
 RefObj ()
 Constructor.
 
 RefObj (const T &obj)
 Creates a RefObj that copies the argument object. More...
 
 RefObj (const RefObj< T > &that)
 Share the object pointer with another RefObj. More...
 
 ~RefObj ()
 Deletes the RefObj, potentially deleting the object.
 

Detailed Description

template<typename T>
class Radiant::RefObj< T >

Smart object reference.

This class can be used to share an object between several holders, using reference counters.

Typical use cases for RefObj are situations where one wants to avoid copying objects, instead sharing them inside the application. RefObj implements a basic reference- counter for these situations.

The RefObj class is not fully thread-safe. You can access the objects from multiple threads, but the reference count changes are not thread-safe. Thus you should not do the link/unlink actions without implementing thread-locks yourself. Functions that are affected by this limitation are the consttructors, destructor, and equality operators.

class Big
{
public:
int m_data[1000000];
};
RefObj<Big> a; // Creates a reference object
(*a).m_data[0] = 100;
RefObj<Big> b(a); // b and a share data

Constructor & Destructor Documentation

template<typename T >
Radiant::RefObj< T >::RefObj ( const T &  obj)
inline

Creates a RefObj that copies the argument object.

Parameters
objObject to copy
template<typename T >
Radiant::RefObj< T >::RefObj ( const RefObj< T > &  that)
inline

Share the object pointer with another RefObj.

Parameters
thatObject that is being copied

Member Function Documentation

template<typename T >
void Radiant::RefObj< T >::deepCopy ( const RefObj< T > &  that)
inline

Create a deep copy of the object Instead of sharing a link to an object, this method creates a real copy of the object.

Parameters
thatobject to copy
template<typename T >
T& Radiant::RefObj< T >::operator* ( )
inline

An operator to get a reference to the object.

Returns
Reference to the object
template<typename T >
const T& Radiant::RefObj< T >::operator* ( ) const
inline

An operator to get a constant reference to the object.

Returns
Constatnt reference to the object
template<typename T >
RefObj& Radiant::RefObj< T >::operator= ( const RefObj< T > &  that)
inline

Link to the source object.

Parameters
thatObject to point to from this objecct
Returns
Reference to self
template<typename T >
T& Radiant::RefObj< T >::ref ( )
inline

Get a reference to the object.

Returns
Reference to the object
template<typename T >
const T& Radiant::RefObj< T >::ref ( ) const
inline

Get a constant reference to the object.

Returns
Constant reference to the object