Overture
Version 25
|
MY smart pointer class (not yours!) More...
#include <kk_ptr.hh>
Public Member Functions | |
sptr (T *d_=0) | |
initialize the pointer using a regular pointer (or null if none is provided) | |
sptr (const sptr< T > &p) | |
make a new reference a pointer of the same type (be carefull if the pointer is assigned to itself) | |
~sptr () | |
decrement and destroy the pointer | |
sptr< T > & | operator= (const sptr< T > &p) |
assignment operator, this will make the reference and increment the reference count | |
bool | operator== (const sptr< T > &p) const |
boolean equals; two sptrs are the same if this->data==p.data && this->gid==p.gid | |
bool | operator!= (const sptr< T > &p) const |
boolean not equals; two sptrs are the same if this->data==p.data && this->gid==p.gid | |
T * | operator-> () |
dereferencing operator for the pointer; an error is thrown if the pointer is null | |
const T * | operator-> () const |
const dereferencing operator for the pointer; an error is thrown if the pointer is null | |
T & | operator* () |
dereferencing operator for the pointer; an error is thrown if the pointer is null | |
const T & | operator* () const |
const dereferencing operator for the pointer; an error is thrown if the pointer is null | |
const T * | raw () const |
return the raw pointer; use it wisely! | |
operator bool () const | |
conversion to bool; the result is true if data!=0 && gid>=-1 | |
long int | GID () const |
return the global id | |
int | nRefs () const |
return the number of references | |
Protected Member Functions | |
sptr (T *rp, int *start_count, long int gid_) | |
a "special" constructor used by sptr_cast that takes a raw pointer and reference count | |
int | increment () |
increment the reference count after checking to see if the pointer makes sense | |
int | decrement () |
decrement the reference count after checking to see if the pointer makes sense | |
void | destroy () |
Friends | |
template<typename TO , typename FROM > | |
sptr< TO > | sptr_cast (sptr< FROM > &p) |
cast from one pointer type to another; return a null ptr if the dynamic cast is invalid | |
template<typename TO , typename FROM > | |
sptr< TO > | sptr_static_cast (sptr< FROM > &p) |
template<typename TO , typename FROM > | |
sptr< TO > | sptr_dynamic_cast (sptr< FROM > &p) |
MY smart pointer class (not yours!)
KK::sptr is a smart pointer class implemented using reference counting (heap allocated int). The object pointed to is destructed when the reference count goes to zero. A dynamic_cast mechanism is provided; most of the methods throw sptr_Err in the event of an unrecoverable error. Invalid casts return a null sptr (count==0, data==0)
initialize the pointer using a regular pointer (or null if none is provided)
References KK::acquire_gid(), KK::sptr< T >::increment(), and KK_PTR_OUT.
make a new reference a pointer of the same type (be carefull if the pointer is assigned to itself)
References KK::sptr< T >::increment(), and KK_PTR_OUT.
decrement and destroy the pointer
References KK::sptr< T >::decrement(), KK::sptr< T >::destroy(), and KK_PTR_OUT.
|
inlineprotected |
a "special" constructor used by sptr_cast that takes a raw pointer and reference count
References KK::Assert(), and KK::sptr< T >::increment().
|
inlineprotected |
decrement the reference count after checking to see if the pointer makes sense
References KK_PTR_OUT.
Referenced by KK::sptr< T >::operator=(), and KK::sptr< T >::~sptr().
|
inlineprotected |
References KK::release_gid().
Referenced by KK::sptr< T >::operator=(), and KK::sptr< T >::~sptr().
|
inline |
return the global id
|
inlineprotected |
increment the reference count after checking to see if the pointer makes sense
References KK_PTR_OUT.
Referenced by KK::sptr< T >::operator=(), and KK::sptr< T >::sptr().
|
inline |
return the number of references
|
inline |
conversion to bool; the result is true if data!=0 && gid>=-1
boolean not equals; two sptrs are the same if this->data==p.data && this->gid==p.gid
boolean not equals; two sptrs are the same if this->data==p.data && this->gid==p.gid. An error is thrown if (this->data==p.data && this->gid!=p.gid) or (this->data!=p.data && this->gid==p.gid)
|
inline |
dereferencing operator for the pointer; an error is thrown if the pointer is null
|
inline |
const dereferencing operator for the pointer; an error is thrown if the pointer is null
|
inline |
dereferencing operator for the pointer; an error is thrown if the pointer is null
|
inline |
const dereferencing operator for the pointer; an error is thrown if the pointer is null
assignment operator, this will make the reference and increment the reference count
References KK::sptr< T >::decrement(), KK::sptr< T >::destroy(), KK::sptr< T >::increment(), and KK_PTR_OUT.
boolean equals; two sptrs are the same if this->data==p.data && this->gid==p.gid
boolean equals; two sptrs are the same if this->data==p.data && this->gid==p.gid. An error is thrown if (this->data==p.data && this->gid!=p.gid) or (this->data!=p.data && this->gid==p.gid)
References KK_PTR_OUT.
|
inline |
return the raw pointer; use it wisely!
Referenced by KK::sptr_cast(), and KK::sptr_dynamic_cast().
|
friend |
cast from one pointer type to another; return a null ptr if the dynamic cast is invalid
|
friend |
|
friend |