X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5200ca361e9edef8b7c075f8989b2dbe9c4c7ad8..49a63afbad7646668df343d29edd88458bc7e0a9:/include/wx/ptr_shrd.h?ds=sidebyside diff --git a/include/wx/ptr_shrd.h b/include/wx/ptr_shrd.h index f90f4ec8b1..e32351fe79 100644 --- a/include/wx/ptr_shrd.h +++ b/include/wx/ptr_shrd.h @@ -1,133 +1,12 @@ -///////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // Name: wx/ptr_shrd.h -// Purpose: Shared pointer based on the counted_ptr<> template, which -// is in the public domain -// Author: Robert Roebling, Yonat Sharon -// RCS-ID: $Id: object.h 47254 2007-07-09 10:09:52Z VS $ -// Copyright: Robert Roebling +// Purpose: compatibility wrapper for wx/sharedptr.h +// Author: Vadim Zeitlin +// Created: 2009-02-03 +// RCS-ID: $Id$ +// Copyright: (c) 2009 Vadim Zeitlin // Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// -#ifndef _WX_SHARED_PTRH__ -#define _WX_SHARED_PTRH__ - -#include "wx/defs.h" -#include "wx/atomic.h" - -// ---------------------------------------------------------------------------- -// wxSharedPtr: A smart pointer with non-intrusive reference counting. -// ---------------------------------------------------------------------------- - -template -class wxSharedPtr -{ -public: - typedef T element_type; - - wxEXPLICIT wxSharedPtr( T* ptr = NULL ) - : m_ref(NULL) - { - if (ptr) - m_ref = new reftype(ptr); - } - - ~wxSharedPtr() { Release(); } - wxSharedPtr(const wxSharedPtr& tocopy) { Acquire(tocopy.m_ref); } - - wxSharedPtr& operator=( const wxSharedPtr& tocopy ) - { - if (this != &tocopy) - { - Release(); - Acquire(tocopy.m_ref); - } - return *this; - } - - wxSharedPtr& operator=( T* ptr ) - { - if (get() != ptr) - { - Release(); - if (ptr) - m_ref = new reftype(ptr); - } - return *this; - } - - T& operator*() const - { - wxASSERT(m_ref != NULL); - wxASSERT(m_ref->m_ptr != NULL); - return *(m_ref->m_ptr); - } - - T* operator->() const - { - wxASSERT(m_ref != NULL); - wxASSERT(m_ref->m_ptr != NULL); - return m_ref->m_ptr; - } - - T* get() const - { - return m_ref ? m_ref->m_ptr : NULL; - } - - void reset( T* ptr = NULL ) - { - Release(); - if (ptr) - m_ref = new reftype(ptr); - } - - bool unique() const { return (m_ref ? m_ref->m_count == 1 : true); } - long use_count() const { return (m_ref ? (long)m_ref->m_count : 0); } - operator bool() const { return (get() != NULL); } - -private: - - struct reftype - { - reftype( T* ptr = NULL, unsigned count = 1 ) : m_ptr(ptr), m_count(count) {} - T* m_ptr; - wxAtomicInt m_count; - }* m_ref; - - void Acquire(reftype* ref) - { - m_ref = ref; - if (ref) - wxAtomicInc( ref->m_count ); - } - - void Release() - { - if (m_ref) - { - wxAtomicDec( m_ref->m_count ); - if (m_ref->m_count == 0) - { - delete m_ref->m_ptr; - delete m_ref; - } - m_ref = NULL; - } - } -}; - -template -bool operator == (wxSharedPtr const &a, wxSharedPtr const &b ) -{ - return a.get() == b.get(); -} - -template -bool operator != (wxSharedPtr const &a, wxSharedPtr const &b ) -{ - return a.get() != b.get(); -} - - - -#endif // _WX_SHARED_PTRH__ +// do not include this file in any new code, include wx/sharedptr.h instead +#include "wx/sharedptr.h"