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
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@wxheader{ptr_shrd.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-21 14:36:04 +00:00
|
|
|
A smart pointer with non-intrusive reference counting. It is modeled after
|
2008-04-10 21:16:38 +00:00
|
|
|
@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 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
2008-03-21 14:36:04 +00:00
|
|
|
@category{smartpointers}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-07 10:37:32 +00:00
|
|
|
@see wxScopedPtr<T>, wxWeakRef<T>, wxObjectDataPtr<T>
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-04-10 21:16:38 +00:00
|
|
|
|
2008-03-21 14:36:04 +00:00
|
|
|
template<typename T>
|
2008-03-08 14:43:31 +00:00
|
|
|
class wxSharedPtr<T>
|
2008-03-08 13:52:38 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-03-21 14:36:04 +00:00
|
|
|
Constructor.
|
|
|
|
|
|
|
|
Creates shared pointer from the raw pointer @a ptr and takes ownership
|
|
|
|
of it.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-04-10 21:16:38 +00:00
|
|
|
wxEXPLICIT wxSharedPtr(T* ptr = NULL);
|
2008-03-21 14:36:04 +00:00
|
|
|
|
2008-04-10 21:16:38 +00:00
|
|
|
/**
|
|
|
|
Copy constructor.
|
|
|
|
*/
|
2008-03-21 14:36:04 +00:00
|
|
|
wxSharedPtr(const wxSharedPtr<T>& tocopy);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-04-07 00:17:06 +00:00
|
|
|
~wxSharedPtr();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
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-04-10 21:16:38 +00:00
|
|
|
convertable to anything but a boolean expression).
|
|
|
|
|
|
|
|
If this class contains a valid pointer it will return @true, if it contains
|
|
|
|
a @NULL pointer it will return @false.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
operator unspecified_bool_type() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-10 21:16: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-08 13:52:38 +00:00
|
|
|
*/
|
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-04-10 21:16:38 +00:00
|
|
|
T* operator->() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-10 21:16:38 +00:00
|
|
|
Assignment operator.
|
|
|
|
|
|
|
|
Releases any previously held pointer and creates a reference to @a ptr.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-04-10 21:16:38 +00:00
|
|
|
wxSharedPtr<T>& operator=(T* ptr);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-10 21:16:38 +00:00
|
|
|
Assignment operator.
|
|
|
|
|
|
|
|
Releases any previously held pointer and creates a reference to the
|
|
|
|
same object as @a topcopy.
|
|
|
|
*/
|
|
|
|
wxSharedPtr<T>& operator=(const wxSharedPtr<T>& tocopy)
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reset pointer to @a ptr.
|
|
|
|
|
|
|
|
If the reference count of the previously owned pointer was 1 it will be deleted.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
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
|
|
|
|