Home | C-Bits Package Documentation | Project Page |
00001 /* ==================================================================== 00002 * The CBITS Software License, Version 1.0 00003 * 00004 * Copyright (c) 2002-2003 Bruce Lowery 00005 * All rights reserved 00006 * 00007 * Redistribution and use of this software, in source and binary forms, 00008 * with or without modification, are permitted provided that the above 00009 * copyright notice, this paragraph, and the following paragraph are 00010 * retained in each source code file. 00011 * 00012 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00013 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00014 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00015 * DISCLAIMED. IN NO EVENT SHALL BRUCE LOWERY OR OTHER CONTRIBUTORS 00016 * TO THE CBITS LIBRARY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00017 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00018 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00019 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00020 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00021 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00022 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00023 * SUCH DAMAGE. 00024 * ==================================================================== 00025 */ 00026 00027 #ifndef __SAFE_PTR_H__ 00028 #define __SAFE_PTR_H__ 00029 00030 #ifdef USE_PTHREAD 00031 #include <pthread.h> 00032 #elif defined WIN32 00033 #include <winnt.h> 00034 #endif 00035 00036 #include <cbits/ref_ptr.h> 00037 #include <cbits/sync_ptr.h> 00038 00039 namespace cbits 00040 { 00041 00059 template< typename T > 00060 class safe_ptr : public ref_ptr<T> 00061 { 00062 public: 00063 00069 safe_ptr<T>( T* t ) : ref_ptr<T>(t) 00070 { 00071 } 00072 00073 00079 safe_ptr<T>( const safe_ptr<T>& r ) 00080 : ref_ptr<T>(r) 00081 { 00082 } 00083 00084 00090 safe_ptr<T>& operator=( const safe_ptr<T>& r ) 00091 { 00092 ref_ptr<T>::operator=(r); 00093 return *this; 00094 } 00095 00096 00102 bool operator==( const safe_ptr<T>& r ) 00103 { 00104 return ref_ptr<T>::operator==(r); 00105 } 00106 00107 00113 sync_ptr<T> operator->() 00114 { 00115 return sync_ptr<T>(_t); 00116 } 00117 00118 00124 T& operator*() 00125 { 00126 return sync_ptr<T>(_t); 00127 } 00128 00129 00137 virtual ~safe_ptr<T>() 00138 { 00139 } 00140 }; 00141 00142 }; 00143 00144 #endif 00145 00146 /* 00147 * $Id: safe_ptr.h,v 1.2 2002/10/14 01:21:04 brulow Exp $ 00148 * 00149 * History: (Add nothing manually below) 00150 * ----------------------------------------------------------------------- 00151 * 00152 * $Log: safe_ptr.h,v $ 00153 * Revision 1.2 2002/10/14 01:21:04 brulow 00154 * Add unit tests for pointer pkg 00155 * 00156 * Revision 1.1 2002/10/13 20:11:05 brulow 00157 * Add t-safe, ref-counting ptr 00158 * 00159 * 00160 */
|
|