|
|
|
|
Documentation |
|
Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages Search
NLMISC::CRefPtr Template Class ReferenceCRefPtr: an handle on a ptr.
More...
#include <smart_ptr.h>
Collaboration diagram for NLMISC::CRefPtr:
[legend]List of all members.
Public Methods |
| CRefPtr () |
| Init a NULL Ptr. More...
|
| CRefPtr (T *v) |
| Attach a ptr to a RefPtr. More...
|
| CRefPtr (const CRefPtr ©) |
| Copy constructor. More...
|
| ~CRefPtr (void) |
| Release the RefPtr. More...
|
| operator T * () const |
| Cast operator. Check if the object has been deleted somewhere, and return NULL if this is the case. More...
|
T& | operator * (void) const |
| Indirection operator. Doesn't test if ptr has been deleted somewhere, and doesn't check NULL. More...
|
T* | operator-> (void) const |
| Selection operator. Doesn't test if ptr has been deleted somewhere, and doesn't check NULL. More...
|
CRefPtr& | operator= (T *v) |
| operator=. Giving a NULL pointer is a valid operation. More...
|
CRefPtr& | operator= (const CRefPtr ©) |
| operator=. Giving a NULL pointer is a valid operation. More...
|
void | kill () |
| kill/delete the object pointed by the pointer, and inform the other RefPtr of this. More...
|
Private Methods |
void | unRef () const |
Private Attributes |
CRefCount::CPtrInfo* | pinfo |
T* | Ptr |
Detailed Description
template<class T> template class NLMISC::CRefPtr
CRefPtr: an handle on a ptr.
T Must derive from CRefCount. If you use CRefPtr, you can kill the object simply by calling delete (T*)RefPtr, or the kill() method. All other CRefPtr which point to it can know if it has been deleted. (but you must be sure that this ptr is not handle by a SmartPtr, of course...)
SmartPtr are compatible with RefPtr. A ptr may be link to a CRefPtr and a CSmartPtr. As example, when the CSmartPtr will destroy him, CRefPtr will be informed... Sample: void foo()
{
A *p;
CSmartPtr<A> sp;
CRefPtr<A> rp;
p= new A;
sp= p;
rp= p;
sp= NULL;
if(rp==NULL)
thisIsGood();
}
PERFORMANCE WARNING! operator=() are about 10 times slower than normal pointers. So use them wisely. For local use, prefer cast the refptr to a normal Ptr. Also, an object used with a CRefPtr will allocate a small PtrInfo (one only per object, not per ptr). -
See also:
-
CSmartPtr
Definition at line 243 of file smart_ptr.h.
Constructor & Destructor Documentation
template<classT> |
NLMISC::CRefPtr< T >::CRefPtr<T> (
|
) [inline]
|
|
template<classT> |
NLMISC::CRefPtr< T >::CRefPtr<T> (
|
T * v ) [inline]
|
|
template<classT> |
NLMISC::CRefPtr< T >::CRefPtr<T> (
|
const CRefPtr<T> & copy ) [inline]
|
|
template<classT> |
NLMISC::CRefPtr< T >::~CRefPtr<T> (
|
void ) [inline]
|
|
Member Function Documentation
template<classT> |
void NLMISC::CRefPtr< T >::kill (
|
)
|
|
|
kill/delete the object pointed by the pointer, and inform the other RefPtr of this.
"rp.kill()" and "delete (T*)rp" do the same thing, except that rp NULLity is updated with kill(). RefPtr which point to the same object could know if the object is valid, by just testing it ( by an implicit call to the cast operator to T*). But any calls to operator->() or operator *() will have unpredictible effects (may crash... :) ).
Definition at line 240 of file smart_ptr_inline.h. |
template<classT> |
T & NLMISC::CRefPtr< T >::operator * (
|
void ) const [inline]
|
|
|
Indirection operator. Doesn't test if ptr has been deleted somewhere, and doesn't check NULL.
Definition at line 271 of file smart_ptr_inline.h. |
template<classT> |
NLMISC::CRefPtr< T >::operator T * (
|
) const [inline]
|
|
|
Cast operator. Check if the object has been deleted somewhere, and return NULL if this is the case.
Definition at line 259 of file smart_ptr_inline.h. |
template<classT> |
T * NLMISC::CRefPtr< T >::operator-> (
|
void ) const [inline]
|
|
|
Selection operator. Doesn't test if ptr has been deleted somewhere, and doesn't check NULL.
Definition at line 276 of file smart_ptr_inline.h. |
template<classT> |
CRefPtr< T >& NLMISC::CRefPtr< T >::operator= (
|
const CRefPtr<T> & copy )
|
|
|
operator=. Giving a NULL pointer is a valid operation.
Definition at line 222 of file smart_ptr_inline.h. |
template<classT> |
CRefPtr< T >& NLMISC::CRefPtr< T >::operator= (
|
T * v )
|
|
|
operator=. Giving a NULL pointer is a valid operation.
Definition at line 195 of file smart_ptr_inline.h. |
template<classT> |
SMART_INLINE void NLMISC::CRefPtr< T >::unRef (
|
) const [private]
|
|
Member Data Documentation
template<classT> |
T * NLMISC::CRefPtr<T>::Ptr [mutable, private]
|
|
The documentation for this class was generated from the following files:
|
|