Game Development Reference
In-Depth Information
How to do it...
1.
The implementation of our intrusive smart pointer class is as follows:
template <class T> class clPtr
{
public:
clPtr(): FObject( 0 ) {}
clPtr( const clPtr& Ptr ): FObject( Ptr.FObject )
{
2.
Here, we call a helper to do the atomic increment of an intrusive counter. This allows
us to use this smart pointer with incomplete types:
LPtr::IncRef( FObject );
}
template <typename U>
clPtr( const clPtr<U>& Ptr ): FObject( Ptr.GetInternalPtr() )
{
LPtr::IncRef( FObject );
}
~clPtr()
{
3.
The same trick is applied to the atomic decrement operation:
LPtr::DecRef( FObject );
}
4.
We need a constructor for an implicit type conversion from T* :
clPtr( T* const Object ): FObject( Object )
{
LPtr::IncRef( FObject );
}
5.
We also need an assignment operator:
clPtr& operator = ( const clPtr& Ptr )
{
T* Temp = FObject;
FObject = Ptr.FObject;
LPtr::IncRef( Ptr.FObject );
LPtr::DecRef( Temp );
return *this;
}
 
Search WWH ::




Custom Search