2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: ptr_shrd.h
|
2008-03-10 15:24:38 +00:00
|
|
|
// Purpose: interface of wxSharedPtr<T>
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxSharedPtrT
|
|
|
|
@wxheader{ptr_shrd.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
A smart pointer with non-intrusive reference counting. It is modeled
|
2008-03-08 14:43:31 +00:00
|
|
|
after @b boost::shared_ptr and can be used with STL containers
|
2008-03-10 15:24:38 +00:00
|
|
|
and wxVector() - unlike @b std::auto_ptr
|
|
|
|
and wxScopedPtr().
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{FIXME}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxScopedPtr, wxWeakRef, wxObjectDataPtr
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
class wxSharedPtr<T>
|
2008-03-08 13:52:38 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Constructors.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxSharedPtrT(T* ptr = NULL);
|
2008-03-08 14:43:31 +00:00
|
|
|
wxSharedPtrT(const wxSharedPtr<T>& tocopy);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
|
|
|
~wxSharedPtrT();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns pointer to its object or @NULL.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
T* get() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-08 14:43:31 +00:00
|
|
|
Conversion to a boolean expression (in a variant which is not
|
2008-03-08 13:52:38 +00:00
|
|
|
convertable to anything but a boolean expression). If this class
|
|
|
|
contains a valid pointer it will return @e @true, if it contains
|
|
|
|
a @NULL pointer it will return @e @false.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
operator unspecified_bool_type() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a reference to the object. If the internal pointer is @NULL this
|
|
|
|
method will cause an assert in debug mode.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
T operator*() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns pointer to its object or @NULL.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
T* operator-() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Assignment operator. Releases any previously held pointer
|
|
|
|
and creates a reference to @e ptr.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxSharedPtrT& operator operator=(T* ptr);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Reset pointer to @e ptr. If the reference count of the
|
|
|
|
previously owned pointer was 1 it will be deleted.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void reset(T* ptr = NULL);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if this is the only pointer pointing to its object.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool unique() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the number of pointers pointing to its object.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
long use_count() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
2008-03-10 15:24:38 +00:00
|
|
|
|