5 #ifndef CNOID_UTIL_REFERENCED_H 6 #define CNOID_UTIL_REFERENCED_H 8 #include <boost/version.hpp> 14 #if (BOOST_VERSION >= 105300) && !defined(NOT_USE_BOOST_ATOMIC) 15 #include <boost/atomic.hpp> 16 #define CNOID_REFERENCED_USE_ATOMIC_COUNTER 33 isObjectAlive_ =
true;
37 void add() { ++weakCount; }
48 isObjectAlive_ =
false;
55 return isObjectAlive_;
80 weakCounter_->setDestructed();
84 #ifdef CNOID_REFERENCED_USE_ATOMIC_COUNTER 86 refCount_.fetch_add(1, boost::memory_order_relaxed);
88 void releaseRef()
const {
89 if(refCount_.fetch_sub(1, boost::memory_order_release) == 1) {
90 boost::atomic_thread_fence(boost::memory_order_acquire);
95 mutable boost::atomic<int> refCount_;
98 int refCount()
const {
return refCount_.load(boost::memory_order_relaxed); }
104 if(--refCount_ == 0){
165 #if defined( BOOST_HAS_RVALUE_REFS ) 202 operator T*()
const {
232 return a.
get() == b.
get();
237 return a.
get() != b.
get();
260 template<
class T>
inline bool operator<(ref_ptr<T>
const & a,
ref_ptr<T> const & b)
262 return a.
get() < b.get();
272 return static_cast<T*
>(p.
get());
277 return const_cast<T*
>(p.
get());
282 return dynamic_cast<T*
>(p.
get());
285 template<
class Y> std::ostream & operator<< (std::ostream & os, ref_ptr<Y>
const & p)
299 void bool_type_func()
const { }
303 counter = px->weakCounter();
322 px = rhs.
lock().get();
327 #if defined( BOOST_HAS_RVALUE_REFS ) 368 if(counter && counter->isObjectAlive()){
376 return !counter || !counter->isObjectAlive();
388 counter = other.counter;
389 other.counter = counter_;
393 return counter < rhs.counter;
404 template<
class T,
class U>
inline bool operator<(weak_ref_ptr<T>
const & a,
weak_ref_ptr<U> const & b)
Definition: Referenced.h:29
bool isObjectAlive()
Definition: Referenced.h:54
void swap(weak_ref_ptr &other)
Definition: Referenced.h:383
weak_ref_ptr(weak_ref_ptr< Y > const &rhs)
Definition: Referenced.h:316
ref_ptr< T > dynamic_pointer_cast(ref_ptr< U > const &p)
Definition: Referenced.h:280
void reset(T *rhs)
Definition: Referenced.h:192
bool operator!=(ref_ptr< T > const &a, ref_ptr< U > const &b)
Definition: Referenced.h:235
ref_ptr & operator=(ref_ptr const &rhs)
Definition: Referenced.h:178
ref_ptr< T > lock() const
Definition: Referenced.h:367
ref_ptr(T *p)
Definition: Referenced.h:135
ref_ptr(ref_ptr const &rhs)
Definition: Referenced.h:148
Referenced()
Definition: Referenced.h:74
void addRef()
Definition: Referenced.h:100
Definition: Referenced.h:67
weak_ref_ptr & operator=(weak_ref_ptr< Y > const &rhs)
Definition: Referenced.h:321
Definition: Referenced.h:128
ref_ptr< T > const_pointer_cast(ref_ptr< U > const &p)
Definition: Referenced.h:275
void reset()
Definition: Referenced.h:379
T element_type
Definition: Referenced.h:131
Referenced(const Referenced &org)
Definition: Referenced.h:75
T & operator*() const
Definition: Referenced.h:206
ref_ptr< Referenced > ReferencedPtr
Definition: Referenced.h:292
void swap(ref_ptr< T > &lhs, ref_ptr< T > &rhs)
Definition: Referenced.h:265
T element_type
Definition: Referenced.h:311
Definition: Referenced.h:295
void releaseRef()
Definition: Referenced.h:103
weak_ref_ptr & operator=(ref_ptr< Y > const &rhs)
Definition: Referenced.h:359
Defines the minimum processing for performing pasing file for STL.
Definition: AbstractSceneLoader.h:9
ref_ptr & operator=(T *rhs)
Definition: Referenced.h:183
weak_ref_ptr(ref_ptr< Y > const &rhs)
Definition: Referenced.h:349
ref_ptr()
Definition: Referenced.h:133
void swap(ref_ptr &rhs)
Definition: Referenced.h:216
~ref_ptr()
Definition: Referenced.h:154
WeakCounter()
Definition: Referenced.h:32
bool operator==(ref_ptr< T > const &a, ref_ptr< U > const &b)
Definition: Referenced.h:230
weak_ref_ptr(Y *const &rhs)
Definition: Referenced.h:354
T * operator->() const
Definition: Referenced.h:211
ref_ptr< T > static_pointer_cast(ref_ptr< U > const &p)
Definition: Referenced.h:270
ref_ptr & operator=(ref_ptr< U > const &rhs)
Definition: Referenced.h:160
void reset()
Definition: Referenced.h:188
T * get() const
Definition: Referenced.h:197
weak_ref_ptr()
Definition: Referenced.h:313
ref_ptr(ref_ptr< U > const &rhs)
Definition: Referenced.h:142
void add()
Definition: Referenced.h:37
int refCount() const
Definition: Referenced.h:113
bool expired() const
Definition: Referenced.h:375
void release()
Definition: Referenced.h:39
void setDestructed()
Definition: Referenced.h:47
bool _internal_less(weak_ref_ptr< Y > const &rhs) const
Definition: Referenced.h:392
virtual ~Referenced()
Definition: Referenced.h:78