2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2009-02-03 07:01:46 -05:00
|
|
|
// Name: sharedptr.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxSharedPtr<T>
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
2009-02-03 07:01:46 -05:00
|
|
|
A smart pointer with non-intrusive reference counting.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-02-03 07:01:46 -05:00
|
|
|
It is modeled after @c boost::shared_ptr<> and can be used with STL
|
|
|
|
containers and wxVector<T> unlike @c std::auto_ptr<> and wxScopedPtr<T>.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-03-21 10:36:04 -04:00
|
|
|
@category{smartpointers}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-07 06:37:32 -04:00
|
|
|
@see wxScopedPtr<T>, wxWeakRef<T>, wxObjectDataPtr<T>
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-21 10:36:04 -04:00
|
|
|
template<typename T>
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxSharedPtr<T>
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-03-21 10:36:04 -04:00
|
|
|
Constructor.
|
|
|
|
|
|
|
|
Creates shared pointer from the raw pointer @a ptr and takes ownership
|
|
|
|
of it.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-04-10 17:16:38 -04:00
|
|
|
wxEXPLICIT wxSharedPtr(T* ptr = NULL);
|
2008-03-21 10:36:04 -04:00
|
|
|
|
2008-04-10 17:16:38 -04:00
|
|
|
/**
|
|
|
|
Copy constructor.
|
|
|
|
*/
|
2008-03-21 10:36:04 -04:00
|
|
|
wxSharedPtr(const wxSharedPtr<T>& tocopy);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-04-06 20:17:06 -04:00
|
|
|
~wxSharedPtr();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns pointer to its object or @NULL.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
T* get() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Conversion to a boolean expression (in a variant which is not
|
2009-02-03 07:01:46 -05:00
|
|
|
convertible to anything but a boolean expression).
|
2008-04-10 17:16:38 -04:00
|
|
|
|
|
|
|
If this class contains a valid pointer it will return @true, if it contains
|
|
|
|
a @NULL pointer it will return @false.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
operator unspecified_bool_type() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-10 17:16:38 -04:00
|
|
|
Returns a reference to the object.
|
|
|
|
|
|
|
|
If the internal pointer is @NULL this method will cause an assert in debug mode.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
T operator*() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2010-07-25 15:45:24 -04:00
|
|
|
Smart pointer member access. Returns pointer to its object.
|
|
|
|
|
|
|
|
If the internal pointer is @NULL this method will cause an assert in debug mode.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-04-10 17:16:38 -04:00
|
|
|
T* operator->() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-10 17:16:38 -04:00
|
|
|
Assignment operator.
|
|
|
|
|
|
|
|
Releases any previously held pointer and creates a reference to @a ptr.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-04-10 17:16:38 -04:00
|
|
|
wxSharedPtr<T>& operator=(T* ptr);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-10 17:16:38 -04:00
|
|
|
Assignment operator.
|
|
|
|
|
|
|
|
Releases any previously held pointer and creates a reference to the
|
|
|
|
same object as @a topcopy.
|
|
|
|
*/
|
2008-10-30 07:11:00 -04:00
|
|
|
wxSharedPtr<T>& operator=(const wxSharedPtr<T>& tocopy);
|
2008-04-10 17:16:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Reset pointer to @a ptr.
|
|
|
|
|
|
|
|
If the reference count of the previously owned pointer was 1 it will be deleted.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
void reset(T* ptr = NULL);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if this is the only pointer pointing to its object.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool unique() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the number of pointers pointing to its object.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
long use_count() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|