> > How does this relate to G_DECLARE_DERIVABLE_TYPE/G_DECLARE_FINAL_TYPE? > Similar but for any type, kind of declare version for G_DEFINE_TYPE. Why did I choose a GOBJECT_ prefix I don't know... Frediano > On Mon, Sep 04, 2017 at 05:09:22PM +0100, Frediano Ziglio wrote: > > The macro will implement most of the boilerplate needed > > to declare an object. > > > > Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> > > --- > > server/red-common.h | 34 ++++++++++++++++++++++++++++++++++ > > 1 file changed, 34 insertions(+) > > > > diff --git a/server/red-common.h b/server/red-common.h > > index 9ff1fd9b..7f60e228 100644 > > --- a/server/red-common.h > > +++ b/server/red-common.h > > @@ -93,4 +93,38 @@ typedef struct GListIter { > > #define GLIST_FOREACH_REVERSED(_list, _type, _data) \ > > GLIST_FOREACH_GENERIC(_list, G_PASTE(_iter_, __LINE__), _type, _data, > > prev) > > > > +/* Helper to declare a GObject type > > + * > > + * @_type type identifier like MyObject > > + * @_prefix method prefix like my_object (no need to add the > > + * underscore) > > + * @_macro macro common part like MY_OBJECT > > + * @_struct used to specify the structure type in case is not > > + * the same as the @_type. For instance can be > > + * "struct MyOjectDefinition" > > + */ > > +#define GOBJECT_DECLARE_TYPE_STRUCT(_type, _prefix, _macro, _struct) \ > > + typedef _struct _type; \ > > + typedef struct _type ## Class _type ## Class; \ > > + typedef struct _type ## Private _type ## Private; \ > > + GType _prefix ## _get_type(void) G_GNUC_CONST; \ > > + static inline _type *_macro(void *obj) \ > > + { return G_TYPE_CHECK_INSTANCE_CAST(obj, _prefix ## _get_type(), > > _type); } \ > > + static inline _type ## Class *_macro ## _CLASS(void *klass) \ > > + { return G_TYPE_CHECK_CLASS_CAST(klass, _prefix ## _get_type(), _type > > ## Class); } \ > > + static inline gboolean IS_ ## _macro(void *obj) \ > > + { return G_TYPE_CHECK_INSTANCE_TYPE(obj, _prefix ## _get_type()); } \ > > + static inline gboolean IS_ ## _macro ## _CLASS(void *klass) \ > > + { return G_TYPE_CHECK_CLASS_TYPE((klass), _prefix ## _get_type()); } \ > > + static inline _type ## Class *_macro ## _GET_CLASS(void *obj) \ > > + { return G_TYPE_INSTANCE_GET_CLASS(obj, _prefix ## _get_type(), _type > > ## Class); } > > + > > +/* Helper to declare a GObject type > > + * > > + * Same as GOBJECT_DECLARE_TYPE_STRUCT but the structure is the same > > + * as the type, most declarations use this convention. > > + */ > > +#define GOBJECT_DECLARE_TYPE(_type, _prefix, _macro) \ > > + GOBJECT_DECLARE_TYPE_STRUCT(_type, _prefix, _macro, struct _type) > > + > > #endif /* RED_COMMON_H_ */ _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel