Panda3D
|
00001 // Filename: threadSafePointerTo.I 00002 // Created by: drose (28Apr06) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: ThreadSafePointerTo::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 template<class T> 00022 INLINE ThreadSafePointerTo<T>:: 00023 ThreadSafePointerTo(To *ptr) : ThreadSafePointerToBase<T>(ptr) { 00024 } 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: ThreadSafePointerTo::Copy Constructor 00028 // Access: Public 00029 // Description: 00030 //////////////////////////////////////////////////////////////////// 00031 template<class T> 00032 INLINE ThreadSafePointerTo<T>:: 00033 ThreadSafePointerTo(const ThreadSafePointerTo<T> ©) : 00034 ThreadSafePointerToBase<T>((const ThreadSafePointerToBase<T> &)copy) 00035 { 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: ThreadSafePointerTo::Destructor 00040 // Access: Public 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 template<class T> 00044 INLINE ThreadSafePointerTo<T>:: 00045 ~ThreadSafePointerTo() { 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: ThreadSafePointerTo::Dereference operator 00050 // Access: Public 00051 // Description: 00052 //////////////////////////////////////////////////////////////////// 00053 template<class T> 00054 INLINE TYPENAME ThreadSafePointerTo<T>::To &ThreadSafePointerTo<T>:: 00055 operator *() const { 00056 return *((To *)AtomicAdjust::get_ptr(this->_void_ptr)); 00057 } 00058 00059 //////////////////////////////////////////////////////////////////// 00060 // Function: ThreadSafePointerTo::Member access operator 00061 // Access: Public 00062 // Description: 00063 //////////////////////////////////////////////////////////////////// 00064 template<class T> 00065 INLINE TYPENAME ThreadSafePointerTo<T>::To *ThreadSafePointerTo<T>:: 00066 operator -> () const { 00067 return (To *)AtomicAdjust::get_ptr(this->_void_ptr); 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: ThreadSafePointerTo::Typecast operator 00072 // Access: Public 00073 // Description: We also have the typecast operator to automatically 00074 // convert ThreadSafePointerTo's to the required kind of actual 00075 // pointer. This introduces ambiguities which the 00076 // compiler will resolve one way or the other, but we 00077 // don't care which way it goes because either will be 00078 // correct. 00079 //////////////////////////////////////////////////////////////////// 00080 template<class T> 00081 INLINE ThreadSafePointerTo<T>:: 00082 operator T * () const { 00083 return (To *)AtomicAdjust::get_ptr(this->_void_ptr); 00084 } 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: ThreadSafePointerTo::p 00088 // Access: Published 00089 // Description: Returns an ordinary pointer instead of a ThreadSafePointerTo. 00090 // Useful to work around compiler problems, particularly 00091 // for implicit upcasts. 00092 //////////////////////////////////////////////////////////////////// 00093 template<class T> 00094 INLINE TYPENAME ThreadSafePointerTo<T>::To *ThreadSafePointerTo<T>:: 00095 p() const { 00096 return (To *)AtomicAdjust::get_ptr(this->_void_ptr); 00097 } 00098 00099 //////////////////////////////////////////////////////////////////// 00100 // Function: ThreadSafePointerTo::Assignment operator 00101 // Access: Published 00102 // Description: 00103 //////////////////////////////////////////////////////////////////// 00104 template<class T> 00105 INLINE ThreadSafePointerTo<T> &ThreadSafePointerTo<T>:: 00106 operator = (To *ptr) { 00107 reassign(ptr); 00108 return *this; 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: ThreadSafePointerTo::Assignment operator 00113 // Access: Published 00114 // Description: 00115 //////////////////////////////////////////////////////////////////// 00116 template<class T> 00117 INLINE ThreadSafePointerTo<T> &ThreadSafePointerTo<T>:: 00118 operator = (const ThreadSafePointerTo<T> ©) { 00119 reassign((const ThreadSafePointerToBase<T> &)copy); 00120 return *this; 00121 } 00122 00123 //////////////////////////////////////////////////////////////////// 00124 // Function: ThreadSafeConstPointerTo::Constructor 00125 // Access: Public 00126 // Description: 00127 //////////////////////////////////////////////////////////////////// 00128 template<class T> 00129 INLINE ThreadSafeConstPointerTo<T>:: 00130 ThreadSafeConstPointerTo(const TYPENAME ThreadSafeConstPointerTo<T>::To *ptr) : 00131 ThreadSafePointerToBase<T>((TYPENAME ThreadSafeConstPointerTo<T>::To *)ptr) 00132 { 00133 } 00134 00135 //////////////////////////////////////////////////////////////////// 00136 // Function: ThreadSafeConstPointerTo::Copy Constructor 00137 // Access: Public 00138 // Description: 00139 //////////////////////////////////////////////////////////////////// 00140 template<class T> 00141 INLINE ThreadSafeConstPointerTo<T>:: 00142 ThreadSafeConstPointerTo(const ThreadSafePointerTo<T> ©) : 00143 ThreadSafePointerToBase<T>((const ThreadSafePointerToBase<T> &)copy) 00144 { 00145 } 00146 00147 //////////////////////////////////////////////////////////////////// 00148 // Function: ThreadSafeConstPointerTo::Destructor 00149 // Access: Public 00150 // Description: 00151 //////////////////////////////////////////////////////////////////// 00152 template<class T> 00153 INLINE ThreadSafeConstPointerTo<T>:: 00154 ~ThreadSafeConstPointerTo() { 00155 } 00156 00157 //////////////////////////////////////////////////////////////////// 00158 // Function: ThreadSafeConstPointerTo::Copy Constructor 00159 // Access: Public 00160 // Description: 00161 //////////////////////////////////////////////////////////////////// 00162 template<class T> 00163 INLINE ThreadSafeConstPointerTo<T>:: 00164 ThreadSafeConstPointerTo(const ThreadSafeConstPointerTo<T> ©) : 00165 ThreadSafePointerToBase<T>((const ThreadSafePointerToBase<T> &)copy) 00166 { 00167 } 00168 00169 //////////////////////////////////////////////////////////////////// 00170 // Function: ThreadSafeConstPointerTo::Dereference operator 00171 // Access: Public 00172 // Description: 00173 //////////////////////////////////////////////////////////////////// 00174 template<class T> 00175 INLINE const TYPENAME ThreadSafeConstPointerTo<T>::To &ThreadSafeConstPointerTo<T>:: 00176 operator *() const { 00177 return *((To *)AtomicAdjust::get_ptr(this->_void_ptr)); 00178 } 00179 00180 //////////////////////////////////////////////////////////////////// 00181 // Function: ThreadSafeConstPointerTo::Member access operator 00182 // Access: Public 00183 // Description: 00184 //////////////////////////////////////////////////////////////////// 00185 template<class T> 00186 INLINE const TYPENAME ThreadSafeConstPointerTo<T>::To *ThreadSafeConstPointerTo<T>:: 00187 operator -> () const { 00188 return (To *)AtomicAdjust::get_ptr(this->_void_ptr); 00189 } 00190 00191 //////////////////////////////////////////////////////////////////// 00192 // Function: ThreadSafeConstPointerTo::Typecast operator 00193 // Access: Public 00194 // Description: We also have the typecast operator to automatically 00195 // convert ThreadSafeConstPointerTo's to the required kind of actual 00196 // pointer. This introduces ambiguities which the 00197 // compiler will resolve one way or the other, but we 00198 // don't care which way it goes because either will be 00199 // correct. 00200 //////////////////////////////////////////////////////////////////// 00201 00202 template<class T> 00203 INLINE ThreadSafeConstPointerTo<T>:: 00204 operator const T * () const { 00205 return (To *)AtomicAdjust::get_ptr(this->_void_ptr); 00206 } 00207 00208 //////////////////////////////////////////////////////////////////// 00209 // Function: ThreadSafeConstPointerTo::p 00210 // Access: Published 00211 // Description: Returns an ordinary pointer instead of a ThreadSafeConstPointerTo. 00212 // Useful to work around compiler problems, particularly 00213 // for implicit upcasts. 00214 //////////////////////////////////////////////////////////////////// 00215 template<class T> 00216 INLINE const TYPENAME ThreadSafeConstPointerTo<T>::To *ThreadSafeConstPointerTo<T>:: 00217 p() const { 00218 return (To *)AtomicAdjust::get_ptr(this->_void_ptr); 00219 } 00220 00221 //////////////////////////////////////////////////////////////////// 00222 // Function: ThreadSafeConstPointerTo::Assignment operator 00223 // Access: Published 00224 // Description: 00225 //////////////////////////////////////////////////////////////////// 00226 template<class T> 00227 INLINE ThreadSafeConstPointerTo<T> &ThreadSafeConstPointerTo<T>:: 00228 operator = (const To *ptr) { 00229 reassign((To *)ptr); 00230 return *this; 00231 } 00232 00233 //////////////////////////////////////////////////////////////////// 00234 // Function: ThreadSafeConstPointerTo::Assignment operator 00235 // Access: Published 00236 // Description: 00237 //////////////////////////////////////////////////////////////////// 00238 template<class T> 00239 INLINE ThreadSafeConstPointerTo<T> &ThreadSafeConstPointerTo<T>:: 00240 operator = (const ThreadSafePointerTo<T> ©) { 00241 reassign((const ThreadSafePointerToBase<T> &)copy); 00242 return *this; 00243 } 00244 00245 //////////////////////////////////////////////////////////////////// 00246 // Function: ThreadSafeConstPointerTo::Assignment operator 00247 // Access: Published 00248 // Description: 00249 //////////////////////////////////////////////////////////////////// 00250 template<class T> 00251 INLINE ThreadSafeConstPointerTo<T> &ThreadSafeConstPointerTo<T>:: 00252 operator = (const ThreadSafeConstPointerTo<T> ©) { 00253 reassign((const ThreadSafePointerToBase<T> &)copy); 00254 return *this; 00255 }