///////////////////////////////////////////////////////////////////////////////
// template class refptr
//
// - Wraps C++ "dumb" pointers and provides reference counting, garbage
// collection.
// - Works for arrays, but does not bounds check
// - Very lightweight
// - Designed to limit access so the progammer cannot overwrite/corrupt/miscount
///////////////////////////////////////////////////////////////////////////////
template <class T>
class refptr
{
private:
T* ptr; // The actual object(s) being referred to
int* count; // Reference count, ptr deleted when equals 0
public:
// Constructors, Destructor
inline refptr(); // Construct empty refptr
inline refptr(const refptr<T> &orig); // Copy from another refptr
inline ~refptr(); // Destroy refptr
// Extractors to get CONST pointers out of the objects
inline operator T* () const
inline T* operator ->() const
// Assignment operator
inline refptr<T> & operator =(const refptr<T> &orig); // Assignment operator
// Methods
inline void refnew(int qty=1); // Allocate new pointer
void clear(); // Clear contents of refptr
};