169 template <
class X,
class Y>
friend struct Private::RefPointerEqualityCheck;
188 template <
class T,
class X>
friend struct Private::RefPointerEqualityCheck;
190 virtual void ref(
bool increaseRef) = 0;
191 virtual void unref() = 0;
194 inline T* object()
const;
200inline T* RefCountedObject::object()
const
202 return static_cast<T* const
>(m_object);
207inline RefPointer<T>::RefPointer()
213inline RefPointer<T>::~RefPointer()
234inline RefPointer<T>::RefPointer(
const RefPointer<T> & other)
242inline RefPointer<T> & RefPointer<T>::operator=(
const RefPointer<X> & other)
250inline RefPointer<T> & RefPointer<T>::operator=(
const RefPointer<T> & other)
259void RefPointer<T>::assign(
const RefPointer<X> & other)
262 QGLIB_STATIC_ASSERT((boost::is_base_of<T, X>::value),
263 "Cannot implicitly cast a RefPointer down the hierarchy");
265 if (!other.isNull()) {
266 m_class =
static_cast<T*
>(other.m_class);
267 static_cast<RefCountedObject*
>(m_class)->ref(
true);
275 return Private::RefPointerEqualityCheck<T, X>::check(*
this, other);
282 return !Private::RefPointerEqualityCheck<T, X>::check(*
this, other);
288template <
class T,
class X>
291typename boost::enable_if_c<
292 boost::is_pointer<X>::value &&
293 !boost::is_same<X, typename boost::add_pointer<typename T::CType>::type>::value,
298 return Private::RefPointerEqualityCheck<T, X>::check(self, other);
304template <
class T,
class X>
307typename boost::enable_if_c<
308 boost::is_pointer<X>::value &&
309 !boost::is_same<X, typename boost::add_pointer<typename T::CType>::type>::value,
314 return !Private::RefPointerEqualityCheck<T, X>::check(self, other);
331 if (nativePtr != NULL) {
333 cppObj->ref(increaseRef);
334 ptr.m_class =
dynamic_cast<T*
>(cppObj);
335 Q_ASSERT(ptr.m_class);
343 return m_class == NULL;
347inline bool RefPointer<T>::operator!()
const
349 return m_class == NULL;
353inline T *RefPointer<T>::operator->()
const
355 Q_ASSERT_X(!isNull(),
"RefPointer::operator->() const",
356 "Attempted to dereference a null pointer");
363 return m_class ?
static_cast<RefCountedObject*
>(m_class)->object<typename T::CType>() : NULL;
373 result.m_class =
static_cast<X*
>(m_class);
381template <
typename T,
typename X,
typename Enable =
void>
382struct IfaceDynamicCastImpl
384 static inline X *doCast(
typename X::CType *obj)
393template <
typename T,
typename X>
394struct IfaceDynamicCastImpl<T, X,
395 typename boost::enable_if_c<
398 (boost::is_base_of<Interface, X>::value &&
399 !boost::is_base_of<Object, X>::value &&
400 boost::is_base_of<Object, T>::value)
404 static inline X *doCast(
typename X::CType *obj)
406 X *targetClass = NULL;
410 if (Type::fromInstance(obj).isA(GetType<X>()))
412 targetClass =
dynamic_cast<X*
>(Private::wrapInterface(GetType<X>(), obj));
413 Q_ASSERT(targetClass);
422template <
typename T,
typename X>
423struct IfaceDynamicCastImpl<T, X,
424 typename boost::enable_if_c<
427 (boost::is_base_of<Interface, T>::value &&
428 !boost::is_base_of<Object, T>::value)
432 static inline X *doCast(
typename X::CType *obj)
436 RefCountedObject *cppClass = Private::wrapObject(obj);
439 X *targetClass =
dynamic_cast<X*
>(cppClass);
446 if (boost::is_base_of<Interface, X>::value &&
447 !boost::is_base_of<Object, X>::value &&
448 Type::fromInstance(obj).isA(GetType<X>()))
450 targetClass =
dynamic_cast<X*
>(Private::wrapInterface(GetType<X>(), obj));
451 Q_ASSERT(targetClass);
468 X *targetClass =
dynamic_cast<X*
>(m_class);
472 typename X::CType *obj =
static_cast<RefCountedObject*
>(m_class)->object<typename X::CType>();
473 targetClass = Private::IfaceDynamicCastImpl<T, X>::doCast(obj);
478 result.m_class = targetClass;