00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef freecloth_resmgt_rcShdPtr_inline_h
00020 #define freecloth_resmgt_rcShdPtr_inline_h
00021
00022 #ifndef freecloth_resmgt_rcBase_h
00023 #include <freecloth/resmgt/rcBase.h>
00024 #endif
00025
00026 FREECLOTH_NAMESPACE_START
00027
00028
00029
00030
00031
00032
00033 inline bool RCShdPtrBase::operator==( const RCBase* rhs ) const
00034 {
00035 return _ptr == rhs;
00036 }
00037
00038
00039
00040 inline bool RCShdPtrBase::operator!=( const RCBase* rhs ) const
00041 {
00042 return _ptr != rhs;
00043 }
00044
00045
00046
00047 inline RCShdPtrBase::RCShdPtrBase()
00048 : _ptr( 0 )
00049 {
00050 }
00051
00052
00053
00054 inline void RCShdPtrBase::acquire( RCBase* ptr )
00055 {
00056 #if RCSHDPTR_DEBUG
00057 DGFX_TRACE_ENTER( "RCShdPtrBase::acquire" );
00058 DGFX_TRACE( "this = " << this );
00059 DGFX_TRACE( "ptr = " << static_cast<void *>( ptr ) );
00060 DGFX_TRACE( "count = " << (ptr ? ptr->_rcCount : 0 ) );
00061 #endif
00062 _ptr = ptr;
00063 if ( 0 != _ptr ) {
00064 ++_ptr->_rcCount;
00065 }
00066 }
00067
00068
00069
00070 inline void RCShdPtrBase::release()
00071 {
00072 #if RCSHDPTR_DEBUG
00073 DGFX_TRACE_ENTER( "RCShdPtrBase::release" );
00074 DGFX_TRACE( "this = " << this );
00075 DGFX_TRACE( "ptr = " << static_cast<void *>( _ptr ) );
00076 DGFX_TRACE( "count = " << ( _ptr ? _ptr->_rcCount : 0 ) );
00077 #endif
00078 if ( _ptr ) {
00079 if ( _ptr->_rcCount == 1 ) {
00080 delete _ptr;
00081 }
00082 else {
00083 --_ptr->_rcCount;
00084 }
00085
00086 _ptr = 0;
00087 }
00088 }
00089
00090
00091
00092 inline bool operator==( const RCBase* lhs, const RCShdPtrBase& rhs )
00093 {
00094 return rhs == lhs;
00095 }
00096
00097
00098
00099 inline bool operator!=( const RCBase* lhs, const RCShdPtrBase& rhs )
00100 {
00101 return rhs != lhs;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110 template <class T>
00111 inline RCShdPtr<T>::RCShdPtr( T* ptr )
00112 {
00113 #if RCSHDPTR_DEBUG
00114 DGFX_TRACE_ENTER( "RCShdPtr<" << typeid(T).name() << "> ctor" );
00115 DGFX_TRACE( "ptr = " << static_cast<void *>( ptr ) );
00116 DGFX_TRACE( "this = " << this );
00117 #endif
00118 acquire( ptr );
00119
00120 }
00121
00122
00123
00124 template <class T>
00125 inline RCShdPtr<T>::RCShdPtr( const RCShdPtr& rhs )
00126 {
00127 #if RCSHDPTR_DEBUG
00128 DGFX_TRACE_ENTER( "RCShdPtr<" << typeid(T).name() << "> copy ctor" );
00129 DGFX_TRACE( "rhs = " << &rhs );
00130 #endif
00131 acquire( rhs._ptr );
00132 }
00133
00134
00135
00136 template <class T>
00137 inline RCShdPtr<T>::~RCShdPtr()
00138 {
00139 #if RCSHDPTR_DEBUG
00140 DGFX_TRACE_ENTER( "RCShdPtr<" << typeid(T).name() << "> dtor" );
00141 DGFX_TRACE( "this = " << this );
00142 #endif
00143 release();
00144 }
00145
00146
00147
00148 template <class T>
00149 inline RCShdPtr<T>&
00150 RCShdPtr<T>::operator=( const RCShdPtr<T>& rhs )
00151 {
00152 #if RCSHDPTR_DEBUG
00153 DGFX_TRACE_ENTER( "RCShdPtr<" << typeid(T).name() << ">::operator=" );
00154 DGFX_TRACE( "this = " << this );
00155 DGFX_TRACE( "rhs = " << &rhs );
00156 #endif
00157 if ( this != &rhs ) {
00158 release();
00159 acquire( rhs._ptr );
00160 }
00161 return *this;
00162 }
00163
00164
00165
00166 template <class T>
00167 inline bool RCShdPtr<T>::operator==( const RCShdPtr<T>& rhs ) const
00168 {
00169 return _ptr == rhs._ptr;
00170 }
00171
00172
00173
00174 template <class T>
00175 inline bool RCShdPtr<T>::operator!=( const RCShdPtr<T>& rhs ) const
00176 {
00177 return _ptr != rhs._ptr;
00178 }
00179
00180
00181
00182 template <class T>
00183 inline bool RCShdPtr<T>::operator==( const RCBase* rhs ) const
00184 {
00185 return _ptr == rhs;
00186 }
00187
00188
00189
00190 template <class T>
00191 inline bool RCShdPtr<T>::operator!=( const RCBase* rhs ) const
00192 {
00193 return _ptr != rhs;
00194 }
00195
00196
00197
00198 template <class T>
00199 inline bool RCShdPtr<T>::isNull() const
00200 {
00201 return _ptr == 0;
00202 }
00203
00204
00205
00206 template <class T>
00207 inline T& RCShdPtr<T>::operator*() const
00208 {
00209 DGFX_ASSERT( ! isNull() );
00210 #if RCSHDPTR_DEBUG
00211 DGFX_ASSERT( 0 != _ptr );
00212 #endif
00213
00214 return *reinterpret_cast<T*>( _ptr );
00215 }
00216
00217
00218
00219 template <class T>
00220 inline T* RCShdPtr<T>::operator->() const
00221 {
00222 DGFX_ASSERT( ! isNull() );
00223 #if RCSHDPTR_DEBUG
00224 DGFX_ASSERT( 0 != _ptr );
00225 #endif
00226 return reinterpret_cast<T*>( _ptr );
00227 }
00228
00229
00230
00231 template <class T>
00232 inline T* RCShdPtr<T>::get() const
00233 {
00234 return reinterpret_cast<T*>( _ptr );
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244 template <class T>
00245 inline std::ostream& operator<<( std::ostream& out, const RCShdPtr<T>& ptr )
00246 {
00247 if ( ptr.isNull() ) {
00248 out << "(null)";
00249 }
00250 else {
00251 out << *ptr;
00252 }
00253 return out;
00254 }
00255
00256 FREECLOTH_NAMESPACE_END
00257
00258 #endif