19#ifdef OSG_USE_REF_PTR_SAFE_DEREFERENCE
27template<
typename T>
class observer_ptr;
37 ref_ptr(T* ptr) : _ptr(ptr) {
if (_ptr) _ptr->ref(); }
41 ~ref_ptr() {
if (_ptr) _ptr->unref(); _ptr = 0; }
57 if (_ptr==ptr)
return *
this;
60 if (_ptr) _ptr->ref();
64 if (tmp_ptr) tmp_ptr->unref();
68#ifdef OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION
70 operator T*()
const {
return _ptr; }
89 typedef T*
ref_ptr::*unspecified_bool_type;
93 operator unspecified_bool_type()
const {
return valid()? &ref_ptr::_ptr : 0; }
98#ifdef OSG_USE_REF_PTR_SAFE_DEREFERENCE
101 throw std::runtime_error(std::string(
"could not dereference invalid osg pointer ") + std::string(
typeid(T).name()));
108#ifdef OSG_USE_REF_PTR_SAFE_DEREFERENCE
111 throw std::runtime_error(std::string(
"could not call invalid osg pointer ") + std::string(
typeid(T).name()));
117 T*
get()
const {
return _ptr; }
120 bool valid()
const {
return _ptr!=0; }
126 T*
release() { T* tmp=_ptr;
if (_ptr) _ptr->unref_nodelete(); _ptr=0;
return tmp; }
128 void swap(
ref_ptr& rp) { T* tmp=_ptr; _ptr=rp._ptr; rp._ptr=tmp; }
134 if (_ptr==rp._ptr)
return;
137 if (_ptr) _ptr->ref();
141 if (tmp_ptr) tmp_ptr->unref();
150template<
class T>
inline
153template<
class T>
inline
156template<
class T,
class Y>
inline
159template<
class T,
class Y>
inline
162template<
class T,
class Y>
inline
Definition observer_ptr:39
bool lock(ref_ptr< T > &rptr) const
Definition observer_ptr:100
friend class ref_ptr
Definition ref_ptr:144
bool operator<(const ref_ptr &rp) const
Definition ref_ptr:81
T * get() const
Definition ref_ptr:117
bool operator!() const
Definition ref_ptr:119
void swap(ref_ptr &rp)
Definition ref_ptr:128
T * operator->() const
Definition ref_ptr:106
ref_ptr(const ref_ptr< Other > &rp)
Definition ref_ptr:39
ref_ptr(const ref_ptr &rp)
Definition ref_ptr:38
ref_ptr(T *ptr)
Definition ref_ptr:37
ref_ptr()
Definition ref_ptr:36
ref_ptr & operator=(const ref_ptr &rp)
Definition ref_ptr:43
T element_type
Definition ref_ptr:34
~ref_ptr()
Definition ref_ptr:41
T * release()
Definition ref_ptr:126
friend bool operator==(const T *ptr, const ref_ptr &rp)
Definition ref_ptr:75
friend bool operator!=(const T *ptr, const ref_ptr &rp)
Definition ref_ptr:79
ref_ptr(observer_ptr< T > &optr)
Definition ref_ptr:40
T & operator*() const
Definition ref_ptr:96
bool valid() const
Definition ref_ptr:120
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
ref_ptr< T > static_pointer_cast(const ref_ptr< Y > &rp)
Definition ref_ptr:157
T * get_pointer(const ref_ptr< T > &rp)
Definition ref_ptr:154
void swap(MixinVector< ValueT > &left, MixinVector< ValueT > &right)
Definition MixinVector:174
ref_ptr< T > const_pointer_cast(const ref_ptr< Y > &rp)
Definition ref_ptr:163
ref_ptr< T > dynamic_pointer_cast(const ref_ptr< Y > &rp)
Definition ref_ptr:160