26 #ifndef __CORE_UTILS_REFPTR_H_ 27 #define __CORE_UTILS_REFPTR_H_ 29 #include <core/threading/mutex.h> 48 template <
class T_CppObject>
67 explicit inline RefPtr(T_CppObject* cpp_object);
79 template <
class T_CastFrom>
101 template <
class T_CastFrom>
145 inline operator bool()
const;
166 template <
class T_CastFrom>
169 T_CppObject *
const cpp_object =
dynamic_cast<T_CppObject*
>(src.operator->());
186 template <
class T_CastFrom>
189 T_CppObject *
const cpp_object =
static_cast<T_CppObject*
>(src.operator->());
203 template <
class T_CastFrom>
206 T_CppObject *
const cpp_object =
const_cast<T_CppObject*
>(src.operator->());
216 explicit inline RefPtr(T_CppObject *cpp_object,
int *refcount,
Mutex *refmutex);
239 T_CppObject *__cpp_object;
240 mutable int *__ref_count;
241 mutable Mutex *__ref_mutex;
249 template <
class T_CppObject>
inline 256 template <
class T_CppObject>
inline 262 template <
class T_CppObject>
inline 270 template <
class T_CppObject>
inline 273 if(__ref_count && __ref_mutex)
279 if(*__ref_count == 0)
292 __ref_mutex->unlock();
298 template <
class T_CppObject>
inline 301 __cpp_object(cpp_object),
307 __ref_count =
new int;
308 __ref_mutex =
new Mutex();
314 template <
class T_CppObject>
inline 317 __cpp_object(cpp_object),
318 __ref_count(refcount),
319 __ref_mutex(refmutex)
321 if(__cpp_object && __ref_count && __ref_mutex) {
324 __ref_mutex->unlock();
328 template <
class T_CppObject>
inline 331 __cpp_object (src.__cpp_object),
332 __ref_count(src.__ref_count),
333 __ref_mutex(src.__ref_mutex)
335 if(__cpp_object && __ref_count && __ref_mutex)
339 __ref_mutex->unlock();
346 template <
class T_CppObject>
347 template <
class T_CastFrom>
354 __cpp_object (src.operator->()),
355 __ref_count(src.refcount_ptr()),
356 __ref_mutex(src.refmutex_ptr())
358 if(__cpp_object && __ref_count && __ref_mutex) {
361 __ref_mutex->unlock();
365 template <
class T_CppObject>
inline 369 T_CppObject *
const temp = __cpp_object;
370 int *temp_count = __ref_count;
371 Mutex *temp_mutex = __ref_mutex;
373 __cpp_object = other.__cpp_object;
374 __ref_count = other.__ref_count;
375 __ref_mutex = other.__ref_mutex;
377 other.__cpp_object = temp;
378 other.__ref_count = temp_count;
379 other.__ref_mutex = temp_mutex;
382 template <
class T_CppObject>
inline 415 template <
class T_CppObject>
inline 425 template <
class T_CppObject>
426 template <
class T_CastFrom>
436 template <
class T_CppObject>
inline 440 return (__cpp_object == src.__cpp_object);
443 template <
class T_CppObject>
inline 447 return (__cpp_object != src.__cpp_object);
450 template <
class T_CppObject>
inline 453 return (__cpp_object != 0);
456 template <
class T_CppObject>
inline 463 template <
class T_CppObject>
inline 476 template <
class T_CppObject>
inline static RefPtr< T_CppObject > cast_dynamic(const RefPtr< T_CastFrom > &src)
Dynamic cast to derived class.
void swap(RefPtr< T_CppObject > &lrp, RefPtr< T_CppObject > &rrp)
Swap refptr instances.
int * refcount_ptr() const
For use only in the internal implementation of sharedptr.
Fawkes library namespace.
T_CppObject * operator*() const
Get underlying pointer.
RefPtr< T_CppObject > & operator=(const RefPtr< T_CppObject > &src)
Copy from another RefPtr.
Mutex * refmutex_ptr() const
For use only in the internal implementation of sharedptr.
void reset()
Reset pointer.
void clear()
Set underlying instance to 0, decrementing reference count of existing instance appropriately.
void swap(RefPtr< T_CppObject > &other)
Swap the contents of two RefPtr<>.
static RefPtr< T_CppObject > cast_const(const RefPtr< T_CastFrom > &src)
Cast to non-const.
int use_count() const
Get current reference count.
~RefPtr()
Destructor - decrements reference count.
bool operator!=(const RefPtr< T_CppObject > &src) const
Tests whether the RefPtr<> do not point to the same underlying instance.
RefPtr<> is a reference-counting shared smartpointer.
T_CppObject * operator->() const
Dereferencing.
Mutex mutual exclusion lock.
bool operator==(const RefPtr< T_CppObject > &src) const
Tests whether the RefPtr<> point to the same underlying instance.
RefPtr()
Default constructor.
static RefPtr< T_CppObject > cast_static(const RefPtr< T_CastFrom > &src)
Static cast to derived class.