18 template <
class T>
class WeakPtr;
19 template <
class T>
class RefMan;
128 void unRefDontInvalidate();
131 od_int32 count()
const {
return count_.load(); }
135 void clearAllObservers();
136 void addObserver(WeakPtrBase* obj);
137 void removeObserver(WeakPtrBase* obj);
140 Counter(
const Counter& a);
162 void unRefNoDelete()
const;
167 Referenced(
const Referenced&);
168 Referenced& operator =(
const Referenced&);
169 virtual ~Referenced();
172 friend class WeakPtrBase;
173 virtual void refNotify()
const {}
174 virtual void unRefNotify()
const {}
175 virtual void unRefNoDeleteNotify()
const {}
176 virtual void prepareForDelete() {}
179 mutable Counter refcount_;
185 bool refIfReffed()
const;
190 void addObserver(WeakPtrBase* obs);
192 void removeObserver(WeakPtrBase* obs);
194 static bool isSane(
const Referenced*);
200 const od_uint64 magicnumber_ = 0x123456789abcdef;
206 inline void refIfObjIsReffed(
const T* obj )
217 inline void unRefIfObjIsReffed(
const T* obj )
227 template <
class T>
inline void refIfObjIsReffed(
const T& obj )
228 { refIfObjIsReffed( &obj ); }
229 template <
class T>
inline void unRefIfObjIsReffed(
const T& obj )
230 { unRefIfObjIsReffed( &obj ); }
237 operator bool()
const;
238 bool operator!()
const;
240 {
return ptr_==r.ptr_; }
243 void set(Referenced*);
245 friend class Counter;
258 CleanupBlocker( WeakPtrSetBase& base )
261 base_.blockCleanup();
264 ~CleanupBlocker() { base_.unblockCleanup(); }
266 WeakPtrSetBase& base_;
273 friend class CleanupBlocker;
275 void unblockCleanup();
289 WeakPtr(RefCount::Referenced* p = 0) {
set(p); }
296 {
set(p.
ptr());
return p; }
298 {
set(p);
return p; }
307 mClass(Basic) WeakPtrSet : public RefCount::WeakPtrSetBase
329 mGlobal(Basic) void unRefPtr( const RefCount::Referenced* ptr );
332 mGlobal(Basic)
void unRefNoDeletePtr( const RefCount::Referenced* ptr );
335 mGlobal(Basic) const RefCount::Referenced*
336 refPtr( const RefCount::Referenced* ptr );
339 template <class T> inline
340 void unRefAndZeroPtr( T*& ptr )
341 { unRefPtr( static_cast<RefCount::Referenced*>( ptr ) ); ptr = 0; }
343 template <
class T>
inline 344 void unRefAndZeroPtr(
const T*& ptr )
345 { unRefPtr( static_cast<const RefCount::Referenced*>( ptr ) ); ptr = 0; }
371 if ( ptr_ && ptr_->tryRef() )
384 template <
class T>
inline 385 bool WeakPtrSet<T>::operator+=(
RefMan<T>& n)
388 return WeakPtrSet<T>::operator+=(
WeakPtr<T>( ptr ) );
391 template <
class T>
inline 392 bool WeakPtrSet<T>::operator+=(
const WeakPtr<T>& n)
396 const bool cleanup = blockcleanup_.setIfValueIs( 0, -1 );
398 for (
int idx=ptrs_.size()-1; idx>=0; idx-- )
400 if ( cleanup && !ptrs_[idx] )
402 ptrs_.removeSingle( idx );
408 if ( cleanup ) blockcleanup_ = 0;
414 if ( cleanup ) blockcleanup_ = 0;
423 template <
class T>
inline 424 int WeakPtrSet<T>::size()
const 427 const int res = ptrs_.size();
433 template <
class T>
inline 434 RefMan<T> WeakPtrSet<T>::operator[](
int idx )
444 template <
class T>
inline 447 return const_cast<WeakPtrSet<T>*
>( this )->
operator[](idx);
#define mExpClass(module)
Definition: commondefs.h:157
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:51
void setNoDelete(bool yn)
Definition: ptrman.h:489
#define mGlobal(module)
Definition: commondefs.h:160
ObjectSet< T >::size_type indexOf(const ObjectSet< T > &os, const S &val)
Locate object in set.
Definition: objectset.h:173
Set of pointers to objects.
Definition: commontypes.h:28
Set of (small) copyable elements.
Definition: commontypes.h:26
Is an alternative to Mutex. It is a lock which causes a thread trying to acquire it to simply wait in...
Definition: atomic.h:130
static void unRef(T *p)
Definition: ptrman.h:500
#define mDynamicCastGet(typ, out, in)
Definition: commondefs.h:123
#define od_uint64
Definition: plftypes.h:35
#define od_int32
Definition: plftypes.h:29
#define mObjectSetApplyToAllFunc(fn, op, extra)
Definition: objectset.h:112
#define mClass(module)
Definition: commondefs.h:161
const T * ptr() const
Definition: ptrman.h:95