MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Static Public Member Functions | List of all members
Mezzanine::ReferenceCountTraits< T > Class Template Reference

This is used to deduce at compile if a specific class has built-in reference counting or needs an external reference count. More...

#include <countedptr.h>

Public Types

enum  { IsCastable = CastStatic }
 Used to determine if the data a CountedPtr is managing can be cast. More...
 
typedef ReferenceCount< T > RefCountType
 This is type of the ReferenceCounter, The type of the class if reference counting is instrusive.
 

Static Public Member Functions

static RefCountTypeConstructionPointer (T *Target)
 This will somehow return a pointer to the reference count. More...
 

Detailed Description

template<typename T>
class Mezzanine::ReferenceCountTraits< T >

This is used to deduce at compile if a specific class has built-in reference counting or needs an external reference count.

Every class that does not implement its own reference count gets this default one. The Default reference count is not thread-safe, and requires that every dereferencing of the smart pointer has the cost of a double dereference. The double dereference is caused because the reference counter has to store a native pointer to the managed object. In benchmarks included with the Unit tests this seems to increase dereference time by about double.

Any class that provides TypePointedTo* GetReferenceCountTargetAsPointer(), Whole GetReferenceCount(), Whole IncrementReferenceCount(), Whole DecrementReferenceCount() and something* GetMostDerived() (which need to be virtual if inheritance is used to be useful) can be used as a reference counter. If it provides these then a specialization of ReferenceCountTraits should be implemented for a given class and CountedPtr will use the type defined by ReferenceCountTraits<T>::RefCountType as the counter.

The Mezzanine provides a Reference count class that can be used with any type at the cost of extra dereferences. Some types (Scripts) have their own internal reference count that when used will increase the locality (since the reference count is part of the managed object) and reduce dereferences to exactly one. Since the CountedPtr is the size of a native pointer if it is used with an internal reference count, the only signifigant overhead should be the counting itself.

Definition at line 87 of file countedptr.h.

Member Enumeration Documentation

template<typename T>
anonymous enum

Used to determine if the data a CountedPtr is managing can be cast.

This uses the CountedPointerCastingState to enter a value the Template MetaProgramming Machinery will understand.

Definition at line 221 of file countedptr.h.

Member Function Documentation

template<typename T>
static RefCountType* Mezzanine::ReferenceCountTraits< T >::ConstructionPointer ( T *  Target)
inlinestatic

This will somehow return a pointer to the reference count.

Parameters
TargetA pointer the freshly created object.
Returns
This will return a pointer to a valid reference counter.
Note
The default implemetation call new with a matching delete in CounterPtr::~CountedPtr . If no allocations are required this may simply return the passed parameter.

Definition at line 216 of file countedptr.h.


The documentation for this class was generated from the following file: