19 #ifndef LUNCHBOX_REFPTR_H
20 #define LUNCHBOX_REFPTR_H
22 #include <lunchbox/debug.h>
41 typedef T*
RefPtr::*bool_t;
49 RefPtr( T*
const ptr ) : _ptr( ptr ) { _ref(); }
60 : _ptr( from.
get( )) { _ref(); }
68 if( _ptr == rhs._ptr )
74 if( tmp ) tmp->unref(
this );
87 if( tmp ) tmp->unref(
this );
96 {
return ( _ptr == rhs._ptr ); }
103 {
return ( _ptr != rhs._ptr ); }
109 operator bool_t()
const {
return _ptr == 0 ? 0 : &RefPtr::_ptr; }
130 bool operator == (
const T* ptr )
const {
return ( _ptr == ptr ); }
136 bool operator != (
const T* ptr )
const {
return ( _ptr != ptr ); }
140 { LBASSERTINFO( _ptr,
className(
this ));
return _ptr; }
143 { LBASSERTINFO( _ptr,
className(
this ));
return _ptr; }
146 { LBASSERTINFO( _ptr,
className(
this ));
return *_ptr; }
149 { LBASSERTINFO( _ptr,
className(
this ));
return *_ptr; }
152 T*
get() {
return _ptr; }
154 const T*
get()
const {
return _ptr; }
157 bool isValid()
const {
return ( _ptr != 0 ); }
163 void _ref() {
if(_ptr) _ptr->ref(
this ); }
173 if( _ptr->unref(
this ))
182 inline std::ostream& operator << ( std::ostream& os, RefPtr< T > rp )
184 const T* p = rp.get();
186 return os <<
"RP[ 0:NULL ]";
188 os <<
disableFlush <<
"RP[" << p->getRefCount() <<
":" << *p <<
"]";
189 p->printHolders( os );
193 template<
class T >
inline std::string
className(
const RefPtr<T>& rp )
197 #include <boost/serialization/split_free.hpp>
201 namespace serialization
204 template<
class Archive,
class T >
208 const T* ptr = t.
get();
212 template<
class Archive,
class T >
221 template<
class Archive,
class T >
223 const unsigned int version )
225 boost::serialization::split_free( ar, t, version );
231 #endif //LUNCHBOX_REFPTR_H
std::ostream & enableFlush(std::ostream &os)
Re-enable flushing of the Log stream.
const T * operator->() const
Access the held object.
RefPtr & operator=(const RefPtr &rhs)
Assign another RefPtr to this reference pointer.
std::string className(const T *object)
Print the RTTI name of the given class.
RefPtr()
Construct a new, empty reference pointer.
bool operator==(const RefPtr &rhs) const
bool operator>(const RefPtr &rhs) const
T & operator*()
Access the held object.
RefPtr(const RefPtr &from)
Construct a copy of a reference pointer.
T * operator->()
Access the held object.
~RefPtr()
Destruct this reference pointer.
Abstraction layer and common utilities for multi-threaded programming.
bool operator<(const RefPtr &rhs) const
A smart reference pointer, aka boost::intrusive_ptr.
RefPtr(RefPtr< O > from)
Construct a copy of a reference pointer of a different type.
const T & operator*() const
Access the held object.
bool operator!=(const RefPtr &rhs) const
RefPtr(T *const ptr)
Construct a reference pointer from a C pointer.
std::ostream & disableFlush(std::ostream &os)
Disable flushing of the Log stream.