]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/ptr_scpd.h
b574491359fbcdfe7e245f6a23640d107b2facf0
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: scoped smart pointer class
4 // Author: Jesse Lovelace <jllovela@eos.ncsu.edu>
8 // Copyright: (c) Jesse Lovelace and original Boost authors (see below)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // This class closely follows the implementation of the boost
13 // library scoped_ptr and is an adaption for c++ macro's in
14 // the wxWindows project. The original authors of the boost
15 // scoped_ptr are given below with their respective copyrights.
17 // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
18 // Copyright (c) 2001, 2002 Peter Dimov
20 // Permission to copy, use, modify, sell and distribute this software
21 // is granted provided this copyright notice appears in all copies.
22 // This software is provided "as is" without express or implied
23 // warranty, and with no claim as to its suitability for any purpose.
25 // See http://www.boost.org/libs/smart_ptr/scoped_ptr.htm for documentation.
28 #ifndef __WX_SCOPED_POINTER__
29 #define __WX_SCOPED_POINTER__
33 /* checked deleters are used to make sure that the
34 type being deleted is really a complete type.
35 - Jesse Lovelace <jllovela@eos.ncsu.edu>
38 #define wxCHECKED_DELETE(ptr) \
40 typedef char complete[sizeof(*ptr)]; \
44 #define wxCHECKED_DELETE_ARRAY(ptr) \
46 typedef char complete[sizeof(*ptr)]; \
50 /* These scoped pointers are *not* assignable and cannot be used
51 within a container. Look for wxDECLARE_SHARED_PTR for this
54 In addition, the type being used *must* be complete at the time
55 that wxDEFINE_SCOPED_* is called or a compiler error will result.
56 This is because the class checks for the completeness of the type
61 #define wxDECLARE_SCOPED_PTR(T, name) \
68 name & operator=(name const &); \
71 wxEXPLICIT name(T * ptr = NULL) \
76 void reset(T * ptr = NULL) \
85 T & operator*() const \
87 wxASSERT(m_ptr != NULL); \
91 T * operator->() const \
93 wxASSERT(m_ptr != NULL); \
102 void swap(name & ot) \
104 T * tmp = ot.m_ptr; \
110 #define wxDEFINE_SCOPED_PTR(T, name)\
113 wxCHECKED_DELETE(m_ptr) \
116 #define wxDECLARE_SCOPED_ARRAY(T, name)\
121 name(name const &); \
122 name & operator=(name const &); \
125 wxEXPLICIT name(T * p = NULL) : m_ptr(p) \
129 void reset(T * p = NULL); \
131 T & operator[](long int i) const\
133 wxASSERT(m_ptr != NULL); \
143 void swap(name & ot) \
145 T * tmp = ot.m_ptr; \
151 #define wxDEFINE_SCOPED_ARRAY(T, name) \
154 wxCHECKED_DELETE_ARRAY(m_ptr) \
156 void name::reset(T * p){ \
159 wxCHECKED_DELETE_ARRAY(m_ptr); \