diff options
author | George Kiagiadakis <george.kiagiadakis@collabora.co.uk> | 2010-12-26 20:43:18 +0200 |
---|---|---|
committer | George Kiagiadakis <george.kiagiadakis@collabora.co.uk> | 2010-12-26 20:43:18 +0200 |
commit | caf21765eaf2204e8eac49b6e3aa98054c9bfc37 (patch) | |
tree | 525bcc2ee2fff69b83d50c6c36b3d24f47f60228 /src | |
parent | ba14fbb8227852fecd93b325c5b0b5ade4cfb004 (diff) |
Improve a bit the API of QGlib::Type.
* Make fundamental() return a Type.
* Rename qname() to nameQuark().
* Add an isA<T>() overload, as the usage of isA(GetType<T>())
seems to be quite popular.
* Remove the useless fromInstance(const RefPointer<T> &) overload.
RefPointer can be cast to void* implicitly.
Diffstat (limited to 'src')
-rw-r--r-- | src/QGlib/type.cpp | 6 | ||||
-rw-r--r-- | src/QGlib/type.h | 18 | ||||
-rw-r--r-- | src/QGst/global.h | 2 |
3 files changed, 15 insertions, 11 deletions
diff --git a/src/QGlib/type.cpp b/src/QGlib/type.cpp index abd25d1..9910fc5 100644 --- a/src/QGlib/type.cpp +++ b/src/QGlib/type.cpp @@ -41,7 +41,7 @@ QString Type::name() const return QString::fromUtf8(g_type_name(m_type)); } -Quark Type::qname() const +Quark Type::nameQuark() const { return g_type_qname(m_type); } @@ -96,9 +96,9 @@ bool Type::isInterface() const return G_TYPE_IS_INTERFACE(m_type); } -Type::FundamentalType Type::fundamental() const +Type Type::fundamental() const { - return static_cast<Type::FundamentalType>(G_TYPE_FUNDAMENTAL(m_type)); + return G_TYPE_FUNDAMENTAL(m_type); } Type Type::parent() const diff --git a/src/QGlib/type.h b/src/QGlib/type.h index f974cf0..2dd4906 100644 --- a/src/QGlib/type.h +++ b/src/QGlib/type.h @@ -96,13 +96,11 @@ public: inline bool operator==(Type other) const; inline operator Private::GType() const { return m_type; } - template<class T> - static Type fromInstance(const RefPointer<T> & instance); static Type fromInstance(void *nativeInstance); static Type fromName(const char *name); QString name() const; - Quark qname() const; + Quark nameQuark() const; bool isAbstract() const; bool isDerived() const; @@ -115,12 +113,15 @@ public: bool isDeepDerivable() const; bool isInterface() const; - FundamentalType fundamental() const; + Type fundamental() const; Type parent() const; uint depth() const; Type nextBase(Type rootType) const; bool isA(Type is_a_type) const; + template <typename T> + inline bool isA() const; + QList<Type> children() const; QList<Type> interfaces() const; QList<Type> interfacePrerequisites() const; @@ -144,9 +145,12 @@ inline bool Type::operator==(Type other) const } template <class T> -Type Type::fromInstance(const RefPointer<T> & instance) +inline Type GetType(); //forward-declaration, defined below + +template <typename T> +inline bool Type::isA() const { - return fromInstance(static_cast<void*>(static_cast<typename T::CType*>(instance))); + return isA(GetType<T>()); } //*************** @@ -242,7 +246,7 @@ struct CanConvertTo { static inline bool from(void *instance) { - return Type::fromInstance(instance).isA(GetType<T>()); + return Type::fromInstance(instance).isA<T>(); } }; diff --git a/src/QGst/global.h b/src/QGst/global.h index adbe94a..bbf36de 100644 --- a/src/QGst/global.h +++ b/src/QGst/global.h @@ -42,7 +42,7 @@ { \ static inline bool from(void *instance) \ { \ - return (Type::fromInstance(instance).isA(GetType<QGst::BASECLASS>()) && \ + return (Type::fromInstance(instance).isA<QGst::BASECLASS>() && \ QGst::BASECLASS##Ptr::wrap(static_cast<Gst##BASECLASS *>(instance))->type() \ == QGst::BASECLASS##TYPE); \ } \ |