78 template <
typename ReturnPo
inter,
typename OriginalPo
inter, CountedPo
interCastingState>
class CountedPtrCastImpl;
85 template <
typename ReturnPo
inter,
typename OriginalPo
inter> ReturnPointer*
CountedPtrInternalCast(
const OriginalPointer* Original);
100 TypePointedTo* Target;
110 : Target(InitialPointer), RefCount(InitialCount)
120 {
return ++RefCount; }
125 {
return --RefCount; }
161 {
return ++RefCount; }
166 {
return --RefCount; }
205 template <
typename T>
206 class ReferenceCountTraits
250 template <
typename CurrentReferenceCountType,
typename OtherReferenceCountType>
251 class ReferenceCountAdjuster
257 static void Acquire(CurrentReferenceCountType* & UpdateCounter, OtherReferenceCountType* & OtherCounter)
258 { UpdateCounter = CountedPtrInternalCast<CurrentReferenceCountType>(OtherCounter->GetMostDerived()); }
263 template <
typename InternalReferenceCount>
264 class ReferenceCountAdjuster<InternalReferenceCount,InternalReferenceCount>
270 static void Acquire(InternalReferenceCount* & UpdateCounter, InternalReferenceCount* & OtherCounter)
271 { UpdateCounter = OtherCounter; }
287 template <
typename TypePo
intedTo>
310 template <
typename AnyReferenceCountType>
311 void Acquire(AnyReferenceCountType* CounterToAcquire)
throw()
313 ReferenceCountAdjuster<RefCountType, AnyReferenceCountType>::Acquire(_ReferenceCounter, CounterToAcquire);
314 if (_ReferenceCounter)
321 if (_ReferenceCounter)
326 _ReferenceCounter = 0;
346 explicit CountedPtr(TypePointedTo* PointerTarget = 0) throw()
351 { _ReferenceCounter = NULL; }
362 {
Acquire( Original._ReferenceCounter ); }
367 template <
typename OtherPo
inter>
371 Acquire( Original._ReferenceCounter );
378 _ReferenceCounter = NULL;
390 if (
this != &Other) {
392 Acquire(Other._ReferenceCounter);
403 void Reset(TypePointedTo* PointerTarget)
408 { _ReferenceCounter = NULL; }
413 void reset(TypePointedTo* PointerTarget)
414 {
Reset (PointerTarget); }
435 if (
this != &Other) {
437 Acquire(Other._ReferenceCounter);
452 {
return CountedPtrInternalCast<TypePointedTo>(_ReferenceCounter->
GetMostDerived()); }
458 TypePointedTo*
Get()
const throw()
459 {
return CountedPtrInternalCast<TypePointedTo>(_ReferenceCounter->
GetMostDerived()); }
463 TypePointedTo*
get()
const throw()
515 template <
typename ReturnPo
inter,
typename OriginalPo
inter, CountedPo
interCastingState>
516 class CountedPtrCastImpl
523 static ReturnPointer
Cast(OriginalPointer)
527 return ReturnPointer(0);
535 template <
typename OriginalPo
inter>
542 static OriginalPointer
Cast(OriginalPointer Original)
550 template <
typename ReturnPo
inter,
typename OriginalPo
inter>
557 static ReturnPointer
Cast(OriginalPointer)
558 {
return ReturnPointer(0); }
565 template <
typename ReturnPo
inter,
typename OriginalPo
inter>
574 static ReturnPointer
Cast(OriginalPointer Original)
575 {
return static_cast<ReturnPointer
>(Original); }
582 template <
typename ReturnPo
inter,
typename OriginalPo
inter>
591 static ReturnPointer
Cast(OriginalPointer Original)
592 {
return dynamic_cast<ReturnPointer
>(Original); }
599 template <
typename ReturnPo
inter,
typename OriginalPo
inter>
608 static ReturnPointer
Cast(OriginalPointer Original)
609 {
return dynamic_cast<ReturnPointer
>(Original); }
619 template <
typename ReturnPo
inter,
typename OriginalPo
inter>
631 const_cast<OriginalPointer*>(Original)
642 template <
typename Po
inter>
651 template <
typename ReturnType,
typename OtherPo
interTargetType>
660 template <
typename ReturnType,
typename OtherPo
interTargetType>
669 template <
typename ReturnType,
typename OtherPo
interTargetType>
676 #endif // _smartptr_h
This exists once per object managed by a group of shared pointer to track items in memory...
virtual IntrusiveRefCount * GetMostDerived()
Get a pointer to the most Derived type of this class.
ReferenceCountTraits< TypePointedTo >::RefCountType RefCountType
The non pointer version of PtrType.
Whole IncrementReferenceCount()
Increase the reference count by one and return the updated count.
static RefCountType * ConstructionPointer(RefCountType *Target)
Because The reference count is allocated when the caller created the target this does not need to all...
virtual ~ReferenceCount()
Destructor, cleans up the object when the last reference deletes this.
Boole unique() const
Is this the only pointer to the managed object.
bool Boole
Generally acts a single bit, true or false.
TypePointedTo & operator*() const
Dereference operator.
A sample class that implements a minimal intrusive reference counting scheme.
void Acquire(AnyReferenceCountType *CounterToAcquire)
Have this pointer point at the same thing another pointer points to,.
Whole UseCount() const
Get the current count of references.
static RefCountType * ConstructionPointer(T *Target)
This will somehow return a pointer to the reference count.
Boole operator==(const CountedPtr &Other) const
A comparision of two CountedPtr instances.
No Casting, any cast attempt results in a compilation Error.
TypePointedTo * GetReferenceCountTargetAsPointer()
Gets the actual pointer to the target.
All the definitions for datatypes as well as some basic conversion functions are defined here...
A simple reference counting pointer.
Whole IncrementReferenceCount()
Increase the reference count by one and return the updated count.
void Reset(TypePointedTo *PointerTarget)
Take ownership of the passed pointer.
Boole Unique() const
Is this the only pointer to the managed object.
Whole GetReferenceCount()
Get the current amount of references.
static OriginalPointer Cast(OriginalPointer Original)
This literally does nothing and returns the value passed, so simple all but the dumbest compilers wil...
virtual ~IntrusiveRefCount()
Virtual Deconstructor to prevent issues with deletion with incomplete type information.
CountedPtr(const CountedPtr &Original)
Copy constructor.
void Release()
This decrements the reference count and deletes the managed items if there are no remaining reference...
CountedPtr< ReturnType > CountedPtrStaticCast(CountedPtr< OtherPointerTargetType > &Original)
A compile time cast that uses static casting conversion of the underlying raw pointers but only works...
Whole use_count() const
Get the current count of references.
A dynamic cast from the pointer as provided with no attempt to calls functions on the pointer target...
Whole GetReferenceCount() const
Get the current amount of references.
CountedPtr(TypePointedTo *PointerTarget=0)
Initializing Constructor.
Whole DecrementReferenceCount()
Decrease the reference count by one and return the updated count.
CountedPtr< ReturnType > CountedPtrCast(CountedPtr< OtherPointerTargetType > &Original)
A compile time cast that uses only the implicit conversion of the underlying raw pointers.
This is used to deduce at compile if a specific class has built-in reference counting or needs an ext...
TypePointedTo * Get() const
Get the raw pointer to the managed object.
void reset(TypePointedTo *PointerTarget)
Take ownership of the passed pointer.
static ReturnPointer Cast(OriginalPointer Original)
Simply static cast the passed pointer.
void reset(const CountedPtr< TypePointedTo > &Other)
Reset this to point at the same as another CountedPtr of the same type.
IntrusiveRefCount * GetReferenceCountTargetAsPointer()
Gets the actual pointer to the target.
A static cast from the pointer as provided with no attempt to calls functions on the pointer target...
No Casting, 0 is returned. Useful when types are unknown and dynamic casts are already used and check...
TypePointedTo element_type
This makes referencing the type of the pointer object easier for external classes.
CountedPtr & operator=(const CountedPtr &Other)
Assignement operator.
static ReturnPointer Cast(OriginalPointer Original)
Simply dynamic cast the passed pointer.
Whole DecrementReferenceCount()
Decrease the reference count by one and return the updated count.
CountedPtr< ReturnType > CountedPtrDynamicCast(CountedPtr< OtherPointerTargetType > &Original)
A Runtime cast that uses dynamic casting conversion of the underlying raw pointers but only works on ...
ReferenceCount< T > RefCountType
This is type of the ReferenceCounter, The type of the class if reference counting is instrusive...
static ReturnPointer Cast(OriginalPointer Original)
Simply static cast the passed pointer.
RefCountType * GetReferenceCount() const
Get the internal Reference count.
ReferenceCount(TypePointedTo *InitialPointer=0, unsigned InitialCount=0)
Constructor.
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
friend CountedPtr< ReturnType > CountedPtrStaticCast(CountedPtr< OtherPointerTargetType > &Original)
Static casting can access internals also.
TypePointedTo * operator->() const
The Structure dereference operator.
void FirstAcquire(TypePointedTo *PointerTarget)
If required create a reference counter and point this at the passed pointer.
RefCountType * _ReferenceCounter
This is the only data on this class, a pointer to the counter and the managed object.
void Reset(const CountedPtr< TypePointedTo > &Other)
Reset this to point at the same as another CountedPtr of the same type.
virtual TypePointedTo * GetMostDerived()
Get a pointer to the Target as a The most derived type in of this object*.
Does no casting, but keeps types distinct. This should allow implicit casts to more base types...
void Reset()
Reset this to point at nothing.
static ReturnPointer Cast(OriginalPointer)
Do not cast, rather fail.
IntrusiveRefCount()
Constructor for instatiating the Reference Count.
CountedPtr(const CountedPtr< OtherPointer > &Original)
Casting copy constructor.
IntrusiveRefCount RefCountType
The sample internal reference count needs to indicate that the managed type is the same as the Refere...
void reset()
Reset this to point at nothing.
CountedPointerCastingState
CountedPointer casting implementation states.
static ReturnPointer Cast(OriginalPointer)
This accepts a parameter solely for compatibility with other templates and always returns 0...
Pointer * CountedPtrInternalCast(Pointer *Original)
Used internally by CounterPtr to abstract away casts in the case where the return type would match th...
~CountedPtr()
Deconstructor, Just calls Release().
This is used as to determine how a CountedPtr performs castin between pointer types internally...