19 #ifndef LUNCHBOX_REFPTR_H
20 #define LUNCHBOX_REFPTR_H
22 #include <lunchbox/debug.h>
36 typedef T*
RefPtr::*bool_t;
43 RefPtr( T*
const ptr ) : _ptr( ptr ) { _ref(); }
53 : _ptr( from.
get( )) { _ref(); }
61 if( _ptr == rhs._ptr )
67 if( tmp ) tmp->unref(
this );
80 if( tmp ) tmp->unref(
this );
89 {
return ( _ptr == rhs._ptr ); }
96 {
return ( _ptr != rhs._ptr ); }
102 operator bool_t()
const {
return _ptr == 0 ? 0 : &RefPtr::_ptr; }
109 {
return ( _ptr < rhs._ptr ); }
116 {
return ( _ptr > rhs._ptr ); }
125 bool operator == (
const T* ptr )
const {
return ( _ptr == ptr ); }
131 bool operator != (
const T* ptr )
const {
return ( _ptr != ptr ); }
135 { LBASSERTINFO( _ptr,
className(
this ));
return _ptr; }
138 { LBASSERTINFO( _ptr,
className(
this ));
return _ptr; }
141 { LBASSERTINFO( _ptr,
className(
this ));
return *_ptr; }
144 { LBASSERTINFO( _ptr,
className(
this ));
return *_ptr; }
147 T*
get() {
return _ptr; }
149 const T*
get()
const {
return _ptr; }
152 bool isValid()
const {
return ( _ptr != 0 ); }
158 void _ref() {
if(_ptr) _ptr->ref(
this ); }
168 if( _ptr->unref(
this ))
177 inline std::ostream& operator << ( std::ostream& os, RefPtr< T > rp )
179 const T* p = rp.get();
181 return os <<
"RP[ 0:NULL ]";
183 os <<
disableFlush <<
"RP[" << p->getRefCount() <<
":" << *p <<
"]";
184 p->printHolders( os );
188 template<
class T >
inline std::string
className(
const RefPtr<T>& rp )
192 #include <boost/serialization/split_free.hpp>
196 namespace serialization
199 template<
class Archive,
class T >
203 const T* ptr = t.
get();
207 template<
class Archive,
class T >
216 template<
class Archive,
class T >
218 const unsigned int version )
220 boost::serialization::split_free( ar, t, version );
226 #endif //LUNCHBOX_REFPTR_H