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>
178 template <
class T_CastFrom>
190 template <
class T_CastFrom>
198 explicit inline RefPtr(T_CppObject *cpp_object,
int *refcount,
Mutex *refmutex);
221 T_CppObject *__cpp_object;
222 mutable int *__ref_count;
223 mutable Mutex *__ref_mutex;
231 template <
class T_CppObject>
inline
238 template <
class T_CppObject>
inline
244 template <
class T_CppObject>
inline
252 template <
class T_CppObject>
inline
255 if(__ref_count && __ref_mutex)
261 if(*__ref_count == 0)
274 __ref_mutex->unlock();
280 template <
class T_CppObject>
inline
283 __cpp_object(cpp_object),
289 __ref_count =
new int;
290 __ref_mutex =
new Mutex();
296 template <
class T_CppObject>
inline
299 __cpp_object(cpp_object),
300 __ref_count(refcount),
301 __ref_mutex(refmutex)
303 if(__cpp_object && __ref_count && __ref_mutex) {
310 template <
class T_CppObject>
inline
313 __cpp_object (src.__cpp_object),
314 __ref_count(src.__ref_count),
315 __ref_mutex(src.__ref_mutex)
317 if(__cpp_object && __ref_count && __ref_mutex)
328 template <
class T_CppObject>
329 template <
class T_CastFrom>
336 __cpp_object (src.operator->()),
337 __ref_count(src.refcount_ptr()),
338 __ref_mutex(src.refmutex_ptr())
340 if(__cpp_object && __ref_count && __ref_mutex) {
347 template <
class T_CppObject>
inline
351 T_CppObject *
const temp = __cpp_object;
352 int *temp_count = __ref_count;
353 Mutex *temp_mutex = __ref_mutex;
355 __cpp_object = other.__cpp_object;
356 __ref_count = other.__ref_count;
357 __ref_mutex = other.__ref_mutex;
359 other.__cpp_object = temp;
360 other.__ref_count = temp_count;
361 other.__ref_mutex = temp_mutex;
364 template <
class T_CppObject>
inline
397 template <
class T_CppObject>
inline
407 template <
class T_CppObject>
408 template <
class T_CastFrom>
418 template <
class T_CppObject>
inline
422 return (__cpp_object == src.__cpp_object);
425 template <
class T_CppObject>
inline
429 return (__cpp_object != src.__cpp_object);
432 template <
class T_CppObject>
inline
435 return (__cpp_object != 0);
438 template <
class T_CppObject>
inline
445 template <
class T_CppObject>
inline
452 template <
class T_CppObject>
453 template <
class T_CastFrom>
458 T_CppObject *
const cpp_object =
dynamic_cast<T_CppObject*
>(src.operator->());
466 template <
class T_CppObject>
467 template <
class T_CastFrom>
472 T_CppObject *
const cpp_object =
static_cast<T_CppObject*
>(src.operator->());
474 return RefPtr<T_CppObject>(cpp_object, src.refcount_ptr(), src.refmutex_ptr());
477 template <
class T_CppObject>
478 template <
class T_CastFrom>
483 T_CppObject *
const cpp_object =
const_cast<T_CppObject*
>(src.operator->());
485 return RefPtr<T_CppObject>(cpp_object, src.refcount_ptr(), src.refmutex_ptr());
494 template <
class T_CppObject>
inline