template < class T > class Sptr

Template simulates a "smart" pointer which deletes the item it is pointing to when no more references to the item exist

Public Methods

template < class T2 > Sptr& dynamicCast(const Sptr < T2 > & x)
dynamicCast works similarly to the actual dynamic_cast() operator, like so:
class A {

int* getCount()
this interface is here because it may sometimes be necessary
VMutex* getMutex()
this interface is here because it may sometimes be necessary
T* getPtr()
this interface is here because it may sometimes be necessary
template < class T2 > operator const Sptr ()
conversion operator converts pointers of this const class to class const Sptr< T2 >
template < class T2 > operator Sptr ()
conversion operator converts pointers of this class to class Sptr< T2 >
int operator!()
! operator . Returns true if ptr == 0, false otherwise.
friend int operator!=(const Sptr& x, const void* y)
compare whether a smart pointer and a pointer point to different things
int operator!=(const Sptr& x)
compare whether two smart pointers point to the different things
friend int operator!=(const void* y, const Sptr& x)
compare whether a pointer and a smart pointer point to different things
T& operator*()
dereference operator
T* operator->()
pointer operator.
Sptr& operator=(T* original)
assignment operator from plain pointer
Sptr& operator=(const Sptr& x)
assignment operator
template < class T2 > Sptr& operator=(const Sptr < T2 > & x)
assignment operator -- this is most often used to assign from a smart pointer to a derived type to a smart pointer of the base type
friend int operator==(const void* y, const Sptr& x)
compare whether a pointer and a smart pointer point to the same thing
int operator==(const Sptr& x)
compare whether two smart pointers point to the same thing
friend int operator==(const Sptr& x, const void* y)
compare whether a smart pointer and a pointer point to the same thing
Sptr(const Sptr& x)
copy constructor
Sptr(T* original, int* myCount = 0, VMutex* myMutex = 0)
constructor used most often as the constructor from a plain pointer
Sptr()
default constructor. points to NULL.
~Sptr()
destructor

Private Methods

void decrement()
decrement the reference count
void increment()
increment the reference count.

Documentation

Template simulates a "smart" pointer which deletes the item it is pointing to when no more references to the item exist. Warning: circular references will produce memory leaks.

Note that only one Sptr should be constructed from the original ptr -- Sptr will free twice (and cause havoc) if it is misused like so:

WRONG:

T* obj = new T();
Sptr p;
Sptr q;
p = obj;
q = obj;  
now both p and q think they are the only ones who will free the 
memory, so you will get an error.
void increment()
increment the reference count.

void decrement()
decrement the reference count

template < class T2 > operator Sptr ()
conversion operator converts pointers of this class to class Sptr< T2 >., where T2 is a different base class. This is most often used when attempting to call a method of the base class through a derived class pointer.

template < class T2 > operator const Sptr ()
conversion operator converts pointers of this const class to class const Sptr< T2 >., where T2 is a different base class. This is most often used when attempting to call a const method of the base class through a derived class pointer.

Sptr()
default constructor. points to NULL.

Sptr(T* original, int* myCount = 0, VMutex* myMutex = 0)
constructor used most often as the constructor from a plain pointer. Do not use this to convert a single pointer to a smart pointer multiple times -- this will result in an error (see class introduction for details).

Sptr(const Sptr& x)
copy constructor

~Sptr()
destructor

T& operator*()
dereference operator

int operator!()
! operator . Returns true if ptr == 0, false otherwise.

T* operator->()
pointer operator.

template < class T2 > Sptr& dynamicCast(const Sptr < T2 > & x)
dynamicCast works similarly to the actual dynamic_cast() operator, like so:
class A {
...
};
class B : public A {
...
};
class C {
...
};
...
int main()
{
Sptr< A > a;
Sptr< B > b;
Sptr< C > c;

a = new B;

b.dynamicCast(a);

c.dynamicCast(a);
}

template < class T2 > Sptr& operator=(const Sptr < T2 > & x)
assignment operator -- this is most often used to assign from a smart pointer to a derived type to a smart pointer of the base type

Sptr& operator=(T* original)
assignment operator from plain pointer. Do not use this to convert a single pointer to a smart pointer multiple times -- this will result in an error (see class introduction for details).

Sptr& operator=(const Sptr& x)
assignment operator

friend int operator!=(const void* y, const Sptr& x)
compare whether a pointer and a smart pointer point to different things

friend int operator!=(const Sptr& x, const void* y)
compare whether a smart pointer and a pointer point to different things

friend int operator==(const void* y, const Sptr& x)
compare whether a pointer and a smart pointer point to the same thing

friend int operator==(const Sptr& x, const void* y)
compare whether a smart pointer and a pointer point to the same thing

int operator==(const Sptr& x)
compare whether two smart pointers point to the same thing

int operator!=(const Sptr& x)
compare whether two smart pointers point to the different things

VMutex* getMutex()
this interface is here because it may sometimes be necessary. DO NOT USE unless you must use it. get the actual mutex of the smart pointer.

int* getCount()
this interface is here because it may sometimes be necessary. DO NOT USE unless you must use it. get the value of the reference count of the smart pointer.

T* getPtr()
this interface is here because it may sometimes be necessary. DO NOT USE unless you must use it. get the pointer to which the smart pointer points.


This class has no child classes.

alphabetic index hierarchy of classes


generated by doc++