]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/ptr_scpd.h
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) \
92 T & operator*() const \
94 wxASSERT(m_ptr != NULL); \
98 T * operator->() const \
100 wxASSERT(m_ptr != NULL); \
109 void swap(name & ot) \
111 T * tmp = ot.m_ptr; \
117 #define wxDEFINE_SCOPED_PTR(T, name)\
120 wxCHECKED_DELETE(m_ptr) \
123 #define wxDECLARE_SCOPED_ARRAY(T, name)\
128 name(name const &); \
129 name & operator=(name const &); \
132 wxEXPLICIT name(T * p = NULL) : m_ptr(p) \
136 void reset(T * p = NULL); \
138 T & operator[](long int i) const\
140 wxASSERT(m_ptr != NULL); \
150 void swap(name & ot) \
152 T * tmp = ot.m_ptr; \
158 #define wxDEFINE_SCOPED_ARRAY(T, name) \
161 wxCHECKED_DELETE_ARRAY(m_ptr) \
163 void name::reset(T * p){ \
166 wxCHECKED_DELETE_ARRAY(m_ptr); \