[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/2] object: recommend a few type check macros
From: |
Eduardo Habkost |
Subject: |
Re: [Qemu-devel] [PATCH 1/2] object: recommend a few type check macros |
Date: |
Tue, 25 Sep 2018 16:49:44 -0300 |
User-agent: |
Mutt/1.9.2 (2017-12-15) |
On Fri, Sep 21, 2018 at 03:13:31PM +0400, Marc-André Lureau wrote:
> I sometime regret that we have to resort to long
> object{_class}_dynamic_cast() calls instead of having a shorter and
> more readable macros available, similar to the one recommended by
> GObject (https://developer.gnome.org/gobject/stable/gtype-conventions.html).
>
> Signed-off-by: Marc-André Lureau <address@hidden>
Nice addition.
Reviewed-by: Eduardo Habkost <address@hidden>
I wonder if we could provide a tool to help us generate and/or
validate all this boilerplate code for new and/or existing types.
> ---
> include/qom/object.h | 25 ++++++++++++++++---------
> 1 file changed, 16 insertions(+), 9 deletions(-)
>
> diff --git a/include/qom/object.h b/include/qom/object.h
> index f0b0bf39cc..c16e0bc91e 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -101,24 +101,31 @@ typedef struct InterfaceInfo InterfaceInfo;
> * </programlisting>
> * </example>
> *
> - * Every type has an #ObjectClass associated with it. #ObjectClass
> derivatives
> - * are instantiated dynamically but there is only ever one instance for any
> - * given type. The #ObjectClass typically holds a table of function pointers
> - * for the virtual methods implemented by this type.
> + * Every type has an #ObjectClass associated with it. #ObjectClass
> + * derivatives are instantiated dynamically but there is only ever one
> + * instance for any given type. The #ObjectClass typically holds a
> + * table of function pointers for the virtual methods implemented by
> + * this type. You can cast an #ObjectClass to a subclass (or
> + * base-class) type using object_class_dynamic_cast().
> *
> - * Using object_new(), a new #Object derivative will be instantiated. You
> can
> - * cast an #Object to a subclass (or base-class) type using
> - * object_dynamic_cast(). You typically want to define macro wrappers around
> - * OBJECT_CHECK() and OBJECT_CLASS_CHECK() to make it easier to convert to a
> - * specific type:
> + * Using object_new(), a new #Object derivative will be instantiated.
> + * You can cast an #Object to a subclass (or base-class) type using
> + * object_dynamic_cast().
> + *
> + * You typically want to define macro wrappers to make it easier to
> + * handle casting:
> *
> * <example>
> * <title>Typecasting macros</title>
> * <programlisting>
> * #define MY_DEVICE_GET_CLASS(obj) \
> * OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE)
> + * #define IS_MY_DEVICE_CLASS(klass) \
> + * object_class_dynamic_cast(OBJECT_CLASS(klass), TYPE_MY_DEVICE)
> * #define MY_DEVICE_CLASS(klass) \
> * OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE)
> + * #define IS_MY_DEVICE(obj) \
> + * object_dynamic_cast(OBJECT(obj), TYPE_MY_DEVICE)
> * #define MY_DEVICE(obj) \
> * OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE)
> * </programlisting>
> --
> 2.19.0
>
--
Eduardo