Panda3D

weakPointerTo.I

00001 // Filename: weakPointerTo.I
00002 // Created by:  drose (27Sep04)
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: WeakPointerTo::Constructor
00018 //       Access: Public
00019 //  Description:
00020 ////////////////////////////////////////////////////////////////////
00021 template<class T>
00022 INLINE WeakPointerTo<T>::
00023 WeakPointerTo(To *ptr) : WeakPointerToBase<T>(ptr) {
00024 }
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: WeakPointerTo::Copy Constructor
00028 //       Access: Public
00029 //  Description:
00030 ////////////////////////////////////////////////////////////////////
00031 template<class T>
00032 INLINE WeakPointerTo<T>::
00033 WeakPointerTo(const PointerTo<T> &copy) :
00034   WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
00035 {
00036 }
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //     Function: WeakPointerTo::Copy Constructor
00040 //       Access: Public
00041 //  Description:
00042 ////////////////////////////////////////////////////////////////////
00043 template<class T>
00044 INLINE WeakPointerTo<T>::
00045 WeakPointerTo(const WeakPointerTo<T> &copy) :
00046   WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
00047 {
00048 }
00049 
00050 ////////////////////////////////////////////////////////////////////
00051 //     Function: WeakPointerTo::Dereference operator
00052 //       Access: Public
00053 //  Description:
00054 ////////////////////////////////////////////////////////////////////
00055 template<class T>
00056 INLINE TYPENAME WeakPointerTo<T>::To &WeakPointerTo<T>::
00057 operator *() const {
00058   nassertr(!this->was_deleted(), *((To *)NULL));
00059   return *((To *)WeakPointerToBase<T>::_void_ptr);
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //     Function: WeakPointerTo::Member access operator
00064 //       Access: Public
00065 //  Description:
00066 ////////////////////////////////////////////////////////////////////
00067 template<class T>
00068 INLINE TYPENAME WeakPointerTo<T>::To *WeakPointerTo<T>::
00069 operator -> () const {
00070   nassertr(!this->was_deleted(), (To *)NULL);
00071   return (To *)WeakPointerToBase<T>::_void_ptr;
00072 }
00073 
00074 ////////////////////////////////////////////////////////////////////
00075 //     Function: WeakPointerTo::Typecast operator
00076 //       Access: Public
00077 //  Description: We also have the typecast operator to automatically
00078 //               convert WeakPointerTo's to the required kind of actual
00079 //               pointer.  This introduces ambiguities which the
00080 //               compiler will resolve one way or the other, but we
00081 //               don't care which way it goes because either will be
00082 //               correct.
00083 ////////////////////////////////////////////////////////////////////
00084 template<class T>
00085 INLINE WeakPointerTo<T>::
00086 operator T * () const {
00087   nassertr(!this->was_deleted(), (To *)NULL);
00088   return (To *)WeakPointerToBase<T>::_void_ptr;
00089 }
00090 
00091 ////////////////////////////////////////////////////////////////////
00092 //     Function: WeakPointerTo::p
00093 //       Access: Public
00094 //  Description: Returns an ordinary pointer instead of a WeakPointerTo.
00095 //               Useful to work around compiler problems, particularly
00096 //               for implicit upcasts.
00097 ////////////////////////////////////////////////////////////////////
00098 template<class T>
00099 INLINE TYPENAME WeakPointerTo<T>::To *WeakPointerTo<T>::
00100 p() const {
00101   nassertr(!this->was_deleted(), (To *)NULL);
00102   return (To *)WeakPointerToBase<T>::_void_ptr;
00103 }
00104 
00105 ////////////////////////////////////////////////////////////////////
00106 //     Function: WeakPointerTo::get_orig
00107 //       Access: Public
00108 //  Description: Returns the original pointer value, even if the
00109 //               object has since been deleted.
00110 ////////////////////////////////////////////////////////////////////
00111 template<class T>
00112 INLINE TYPENAME WeakPointerTo<T>::To *WeakPointerTo<T>::
00113 get_orig() const {
00114   return (To *)WeakPointerToBase<T>::_void_ptr;
00115 }
00116 
00117 ////////////////////////////////////////////////////////////////////
00118 //     Function: WeakPointerTo::Assignment operator
00119 //       Access: Public
00120 //  Description:
00121 ////////////////////////////////////////////////////////////////////
00122 template<class T>
00123 INLINE WeakPointerTo<T> &WeakPointerTo<T>::
00124 operator = (To *ptr) {
00125   ((WeakPointerTo<T> *)this)->reassign(ptr);
00126   return *this;
00127 }
00128 
00129 ////////////////////////////////////////////////////////////////////
00130 //     Function: WeakPointerTo::Assignment operator
00131 //       Access: Public
00132 //  Description:
00133 ////////////////////////////////////////////////////////////////////
00134 template<class T>
00135 INLINE WeakPointerTo<T> &WeakPointerTo<T>::
00136 operator = (const PointerTo<T> &copy) {
00137   ((WeakPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
00138   return *this;
00139 }
00140 
00141 ////////////////////////////////////////////////////////////////////
00142 //     Function: WeakPointerTo::Assignment operator
00143 //       Access: Public
00144 //  Description:
00145 ////////////////////////////////////////////////////////////////////
00146 template<class T>
00147 INLINE WeakPointerTo<T> &WeakPointerTo<T>::
00148 operator = (const WeakPointerTo<T> &copy) {
00149   ((WeakPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
00150   return *this;
00151 }
00152 
00153 ////////////////////////////////////////////////////////////////////
00154 //     Function: WeakConstPointerTo::Constructor
00155 //       Access: Public
00156 //  Description:
00157 ////////////////////////////////////////////////////////////////////
00158 template<class T>
00159 INLINE WeakConstPointerTo<T>::
00160 WeakConstPointerTo(const To *ptr) :
00161   WeakPointerToBase<T>((TYPENAME WeakConstPointerTo<T>::To *)ptr)
00162 {
00163 }
00164 
00165 ////////////////////////////////////////////////////////////////////
00166 //     Function: WeakConstPointerTo::Copy Constructor
00167 //       Access: Public
00168 //  Description:
00169 ////////////////////////////////////////////////////////////////////
00170 template<class T>
00171 INLINE WeakConstPointerTo<T>::
00172 WeakConstPointerTo(const PointerTo<T> &copy) :
00173   WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
00174 {
00175 }
00176 
00177 ////////////////////////////////////////////////////////////////////
00178 //     Function: WeakConstPointerTo::Copy Constructor
00179 //       Access: Public
00180 //  Description:
00181 ////////////////////////////////////////////////////////////////////
00182 template<class T>
00183 INLINE WeakConstPointerTo<T>::
00184 WeakConstPointerTo(const ConstPointerTo<T> &copy) :
00185   WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
00186 {
00187 }
00188 
00189 ////////////////////////////////////////////////////////////////////
00190 //     Function: WeakConstPointerTo::Copy Constructor
00191 //       Access: Public
00192 //  Description:
00193 ////////////////////////////////////////////////////////////////////
00194 template<class T>
00195 INLINE WeakConstPointerTo<T>::
00196 WeakConstPointerTo(const WeakPointerTo<T> &copy) :
00197   WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
00198 {
00199 }
00200 
00201 ////////////////////////////////////////////////////////////////////
00202 //     Function: WeakConstPointerTo::Copy Constructor
00203 //       Access: Public
00204 //  Description:
00205 ////////////////////////////////////////////////////////////////////
00206 template<class T>
00207 INLINE WeakConstPointerTo<T>::
00208 WeakConstPointerTo(const WeakConstPointerTo<T> &copy) :
00209   WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
00210 {
00211 }
00212 
00213 ////////////////////////////////////////////////////////////////////
00214 //     Function: WeakConstPointerTo::Dereference operator
00215 //       Access: Public
00216 //  Description:
00217 ////////////////////////////////////////////////////////////////////
00218 template<class T>
00219 INLINE const TYPENAME WeakConstPointerTo<T>::To &WeakConstPointerTo<T>::
00220 operator *() const {
00221   nassertr(!this->was_deleted(), *((To *)NULL));
00222   return *((To *)WeakPointerToBase<T>::_void_ptr);
00223 }
00224 
00225 ////////////////////////////////////////////////////////////////////
00226 //     Function: WeakConstPointerTo::Member access operator
00227 //       Access: Public
00228 //  Description:
00229 ////////////////////////////////////////////////////////////////////
00230 template<class T>
00231 INLINE const TYPENAME WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
00232 operator -> () const {
00233   nassertr(!this->was_deleted(), (To *)NULL);
00234   return (To *)WeakPointerToBase<T>::_void_ptr;
00235 }
00236 
00237 ////////////////////////////////////////////////////////////////////
00238 //     Function: WeakConstPointerTo::Typecast operator
00239 //       Access: Public
00240 //  Description: We also have the typecast operator to automatically
00241 //               convert WeakConstPointerTo's to the required kind of actual
00242 //               pointer.  This introduces ambiguities which the
00243 //               compiler will resolve one way or the other, but we
00244 //               don't care which way it goes because either will be
00245 //               correct.
00246 ////////////////////////////////////////////////////////////////////
00247 
00248 template<class T>
00249 INLINE WeakConstPointerTo<T>::
00250 operator const T * () const {
00251   nassertr(!this->was_deleted(), (To *)NULL);
00252   return (To *)WeakPointerToBase<T>::_void_ptr;
00253 }
00254 
00255 ////////////////////////////////////////////////////////////////////
00256 //     Function: WeakConstPointerTo::p
00257 //       Access: Public
00258 //  Description: Returns an ordinary pointer instead of a WeakConstPointerTo.
00259 //               Useful to work around compiler problems, particularly
00260 //               for implicit upcasts.
00261 ////////////////////////////////////////////////////////////////////
00262 template<class T>
00263 INLINE const TYPENAME WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
00264 p() const {
00265   nassertr(!this->was_deleted(), (To *)NULL);
00266   return (To *)WeakPointerToBase<T>::_void_ptr;
00267 }
00268 
00269 ////////////////////////////////////////////////////////////////////
00270 //     Function: WeakConstPointerTo::get_orig
00271 //       Access: Public
00272 //  Description: Returns the original pointer value, even if the
00273 //               object has since been deleted.
00274 ////////////////////////////////////////////////////////////////////
00275 template<class T>
00276 INLINE const TYPENAME WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
00277 get_orig() const {
00278   return (To *)WeakPointerToBase<T>::_void_ptr;
00279 }
00280 
00281 ////////////////////////////////////////////////////////////////////
00282 //     Function: WeakConstPointerTo::Assignment operator
00283 //       Access: Public
00284 //  Description:
00285 ////////////////////////////////////////////////////////////////////
00286 template<class T>
00287 INLINE WeakConstPointerTo<T> &WeakConstPointerTo<T>::
00288 operator = (const To *ptr) {
00289   ((WeakConstPointerTo<T> *)this)->reassign((To *)ptr);
00290   return *this;
00291 }
00292 
00293 ////////////////////////////////////////////////////////////////////
00294 //     Function: WeakConstPointerTo::Assignment operator
00295 //       Access: Public
00296 //  Description:
00297 ////////////////////////////////////////////////////////////////////
00298 template<class T>
00299 INLINE WeakConstPointerTo<T> &WeakConstPointerTo<T>::
00300 operator = (const PointerTo<T> &copy) {
00301   ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
00302   return *this;
00303 }
00304 
00305 ////////////////////////////////////////////////////////////////////
00306 //     Function: WeakConstPointerTo::Assignment operator
00307 //       Access: Public
00308 //  Description:
00309 ////////////////////////////////////////////////////////////////////
00310 template<class T>
00311 INLINE WeakConstPointerTo<T> &WeakConstPointerTo<T>::
00312 operator = (const ConstPointerTo<T> &copy) {
00313   ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
00314   return *this;
00315 }
00316 
00317 ////////////////////////////////////////////////////////////////////
00318 //     Function: WeakConstPointerTo::Assignment operator
00319 //       Access: Public
00320 //  Description:
00321 ////////////////////////////////////////////////////////////////////
00322 template<class T>
00323 INLINE WeakConstPointerTo<T> &WeakConstPointerTo<T>::
00324 operator = (const WeakPointerTo<T> &copy) {
00325   ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
00326   return *this;
00327 }
00328 
00329 ////////////////////////////////////////////////////////////////////
00330 //     Function: WeakConstPointerTo::Assignment operator
00331 //       Access: Public
00332 //  Description:
00333 ////////////////////////////////////////////////////////////////////
00334 template<class T>
00335 INLINE WeakConstPointerTo<T> &WeakConstPointerTo<T>::
00336 operator = (const WeakConstPointerTo<T> &copy) {
00337   ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
00338   return *this;
00339 }
 All Classes Functions Variables Enumerations