NAME
OTC_CResPtr -
Const version of a smart pointer to help manage a resource.
SYNOPSIS
#include <OTC/refcnt/cresptr.hh>
template<class T>
class OTC_CResPtr
{
public:
OTC_CResPtr();
OTC_CResPtr(T const* theItem);
OTC_CResPtr(OTC_CResPtr<T> const& theRP);
~OTC_CResPtr();
inline T const* item() const;
inline T const* operator->() const;
inline operator T const*() const;
inline T const& operator*() const;
inline OTC_Boolean operator!() const;
inline OTC_Boolean operator==(int theItem) const;
inline OTC_Boolean operator!=(int theItem) const;
inline OTC_Boolean operator==(T const* theItem) const;
inline OTC_Boolean operator!=(T const* theItem) const;
void setItem(OTC_CResPtr<T> const& theRP);
void setItem(T const* theItem);
OTC_CResPtr<T>& operator=(OTC_CResPtr<T> const& theRP);
OTC_CResPtr<T>& operator=(T const* theItem);
u_int numRefs() const;
protected:
inline T* _item() const;
T* _itemNoNull() const;
};
CLASS TYPE
Concrete
DESCRIPTION
Designed to manage classes which contain the ability to keep a
reference count, such as classes derived from OTC_Resource.
CONSTRUCTION
OTC_CResPtr();
Creates a nil pointer class.
OTC_CResPtr(T const* theItem);
Creates a pointer class for theItem.
OTC_CResPtr(OTC_CResPtr<T> const& theRP);
Creates a pointer class for the object
pointed to by theRP.
DESTRUCTION
~OTC_CResPtr();
Decrements the reference count associated
with the object. If the object is no
longer required, it will be deleted.
ACCESS
inline T const* item() const;
Returns the object being pointed at.
inline T const* operator->() const;
Returns the object being pointed at. An
exception is generated if no item is held.
inline operator T const*() const;
Returns the object being pointed at.
inline T const& operator*() const;
Returns a reference to the object being
pointed at. An exception is generated if
no item is held.
inline OTC_Boolean operator!() const;
inline OTC_Boolean operator==(int theItem) const;
inline OTC_Boolean operator!=(int theItem) const;
inline OTC_Boolean operator==(T const* theItem) const;
inline OTC_Boolean operator!=(T const* theItem) const;
ASSIGNMENT
With all the following, the object being assigned to this class
will have its reference count incremented, the count on the
currently held object will be decremented and if it is no longer
required, it will be deleted.
void setItem(OTC_CResPtr<T> const& theRP);
Sets this class to point at the object
held by theRP.
void setItem(T const* theItem);
Sets this class to point at theItem.
OTC_CResPtr<T>& operator=(OTC_CResPtr<T> const& theRP);
Sets this class to point at the object
held by theRP.
OTC_CResPtr<T>& operator=(T const* theItem);
Sets this class to point at theItem.
QUERY
u_int numRefs() const;
Returns the number of references to the
object held by this class, or 0 if this
class does not reference an object.
SEE ALSO
OTC_Resource
LIBRARY
OTC
AUTHOR(S)
Graham Dumpleton
COPYRIGHT
Copyright 1991 OTC LIMITED
Copyright 1994 DUMPLETON SOFTWARE CONSULTING PTY LIMITED