A simple reference counting pointer. More...
#include <countedptr.h>
Public Types | |
typedef TypePointedTo | element_type |
This makes referencing the type of the pointer object easier for external classes. | |
typedef ReferenceCountTraits< TypePointedTo >::RefCountType | RefCountType |
The non pointer version of PtrType. | |
Public Member Functions | |
CountedPtr (TypePointedTo *PointerTarget=0) throw () | |
Initializing Constructor. More... | |
CountedPtr (const CountedPtr &Original) throw () | |
Copy constructor. More... | |
template<typename OtherPointer > | |
CountedPtr (const CountedPtr< OtherPointer > &Original) throw () | |
Casting copy constructor. More... | |
~CountedPtr () throw () | |
Deconstructor, Just calls Release(). | |
TypePointedTo * | Get () const throw () |
Get the raw pointer to the managed object. More... | |
TypePointedTo * | get () const throw () |
Get the raw pointer to the managed object. More... | |
RefCountType * | GetReferenceCount () const throw () |
Get the internal Reference count. More... | |
operator Boole () const throw () | |
Returns true if this pointer points to something. More... | |
TypePointedTo & | operator* () const throw () |
Dereference operator. More... | |
TypePointedTo * | operator-> () const throw () |
The Structure dereference operator. More... | |
CountedPtr & | operator= (const CountedPtr &Other) throw () |
Assignement operator. More... | |
Boole | operator== (const CountedPtr &Other) const throw () |
A comparision of two CountedPtr instances. More... | |
void | Reset () |
Reset this to point at nothing. | |
void | reset () |
Reset this to point at nothing. More... | |
void | Reset (const CountedPtr< TypePointedTo > &Other) |
Reset this to point at the same as another CountedPtr of the same type. More... | |
void | reset (const CountedPtr< TypePointedTo > &Other) |
Reset this to point at the same as another CountedPtr of the same type. More... | |
void | Reset (TypePointedTo *PointerTarget) |
Take ownership of the passed pointer. More... | |
void | reset (TypePointedTo *PointerTarget) |
Take ownership of the passed pointer. More... | |
Boole | Unique () const throw () |
Is this the only pointer to the managed object. More... | |
Boole | unique () const throw () |
Is this the only pointer to the managed object. More... | |
Whole | use_count () const throw () |
Get the current count of references. More... | |
Whole | UseCount () const throw () |
Get the current count of references. More... | |
Protected Member Functions | |
template<typename AnyReferenceCountType > | |
void | Acquire (AnyReferenceCountType *CounterToAcquire) throw () |
Have this pointer point at the same thing another pointer points to,. More... | |
void | FirstAcquire (TypePointedTo *PointerTarget) |
If required create a reference counter and point this at the passed pointer. More... | |
void | Release () throw () |
This decrements the reference count and deletes the managed items if there are no remaining references. | |
Protected Attributes | |
RefCountType * | _ReferenceCounter |
This is the only data on this class, a pointer to the counter and the managed object. | |
Friends | |
template<typename OtherPointer > | |
class | CountedPtr |
declare all pointers as friends so they can reference eachother _ReferenceCounter. | |
template<typename ReturnType , typename OtherPointerTargetType > | |
CountedPtr< ReturnType > | CountedPtrStaticCast (CountedPtr< OtherPointerTargetType > &Original) |
Static casting can access internals also. More... | |
A simple reference counting pointer.
This is a pointer that automatically deallocates the object it manages when all CountedPtr intances managing it are destroyed or fall out of scope. This is a simpler version of std::shared_ptr.
Definition at line 70 of file countedptr.h.
|
inlineexplicit |
Initializing Constructor.
This should only be used for initial creation of a shared pointer group. This will allocate the raw pointer and the ReferenceCounter that will be used to track the pointer passed. This will only be explicitly called to prevent accidental premature deletion of the item managed.
It is quite easy to accidentally make a secondary group of counted pointers if not using the new statement inline with this constructor, and it is not recomended to use this in any other way. Here is an example of the recommended way to use new inline with this: "Mezzanine::CountedPtr<Mezzanine::Vector3> VecPtr (new Mezzanine::Vector3);"
PointerTarget | The item that will be deleted once all the pointer of this group disappear. |
Definition at line 346 of file countedptr.h.
|
inline |
Copy constructor.
Original | The pointer being copied. This fresh pointer will use the same ReferenceCounter as the original. |
Nothing | This member function does throws exceptions. |
Definition at line 361 of file countedptr.h.
|
inline |
Casting copy constructor.
Original | The CountedPtr being copied. This fresh pointer will use the same ReferenceCounter as the original. |
Nothing | This member function does throws exceptions, unless the casting mechanism throws, which it shouldn't. |
Definition at line 368 of file countedptr.h.
|
inlineprotected |
Have this pointer point at the same thing another pointer points to,.
CounterToAcquire | The ReferenceCounter that this pointer will use. |
Nothing | This member function does not throw exceptions, unless debug logging is enabled, then it can throw any exception the logger can throw. |
Definition at line 311 of file countedptr.h.
|
inlineprotected |
If required create a reference counter and point this at the passed pointer.
PointerTarget | the Pointer to take ownership of. |
Definition at line 333 of file countedptr.h.
|
inline |
Get the raw pointer to the managed object.
Nothing | This member function does not throw exceptions. |
Definition at line 458 of file countedptr.h.
|
inline |
Get the raw pointer to the managed object.
Nothing | This member function does not throw exceptions. |
Definition at line 463 of file countedptr.h.
|
inline |
Get the internal Reference count.
Definition at line 494 of file countedptr.h.
|
inline |
Returns true if this pointer points to something.
Definition at line 488 of file countedptr.h.
|
inline |
Dereference operator.
Nothing | This member function does not throw exceptions. |
Definition at line 445 of file countedptr.h.
|
inline |
The Structure dereference operator.
Nothing | This member function does not throw exceptions. |
Definition at line 451 of file countedptr.h.
|
inline |
Assignement operator.
This safely handles the semantics or release the previously assigned object and acquiring the new managed object. This performs basic checks as expected.
Other | The Item on the right hand side of the '=', which this class instance will copy. |
Definition at line 433 of file countedptr.h.
|
inline |
A comparision of two CountedPtr instances.
This is used to see if this and another CountedPtr are managing the same object and are part of the same group of CountedPtr managing that object.
Other | The CountedPtr on the right hand side of the == |
Definition at line 483 of file countedptr.h.
|
inline |
Reset this to point at nothing.
Definition at line 383 of file countedptr.h.
|
inline |
Reset this to point at the same as another CountedPtr of the same type.
Other | Another CountedPtr which will share ownership of the target. |
Definition at line 388 of file countedptr.h.
|
inline |
Reset this to point at the same as another CountedPtr of the same type.
Other | Another CountedPtr which will share ownership of the target. |
Definition at line 398 of file countedptr.h.
|
inline |
Take ownership of the passed pointer.
PointerTarget | The pointer to assume ownership of. |
Definition at line 403 of file countedptr.h.
|
inline |
Take ownership of the passed pointer.
PointerTarget | The pointer to assume ownership of. |
Definition at line 413 of file countedptr.h.
|
inline |
Is this the only pointer to the managed object.
Nothing | This member function does not throw exceptions. |
Definition at line 470 of file countedptr.h.
|
inline |
Is this the only pointer to the managed object.
Nothing | This member function does not throw exceptions. |
Definition at line 475 of file countedptr.h.
|
inline |
Get the current count of references.
Nothing | This member function does not throws exceptions. |
Definition at line 425 of file countedptr.h.
|
inline |
Get the current count of references.
Nothing | This member function does not throws exceptions. |
Definition at line 420 of file countedptr.h.
|
friend |
Static casting can access internals also.
ReturnType | The type to be returned, must be specified |
OtherPointerTargetType | The type of the provided pointer, this can be infered and should not be provided. |
Original | The pointer to convert. |
Definition at line 661 of file countedptr.h.