docs: Standardise property ID enums in examples

Drop the redundant `PROP_0` (which isn’t a real property) and initialise
the first member of the enum instead.

Add a typedef so that the enum type can be used in `switch` statements
in `get_property()` and `set_property()` vfuncs. This allows
`-Wswitch-enum` to be used to improve type safety.

The examples here don’t have `get_property()` or `set_property()`
vfuncs, but people might copy/paste the code to somewhere which does.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2022-05-20 12:56:03 +01:00
parent 8f9c5090db
commit 3c14b6846d

View File

@ -707,9 +707,11 @@ g_object_class_install_property (GObjectClass *class,
* class initialization:
*
* |[<!-- language="C" -->
* enum {
* PROP_0, PROP_FOO, PROP_BAR, N_PROPERTIES
* };
* typedef enum {
* PROP_FOO = 1,
* PROP_BAR,
* N_PROPERTIES
* } MyObjectProperty;
*
* static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
*
@ -732,7 +734,7 @@ g_object_class_install_property (GObjectClass *class,
* gobject_class->set_property = my_object_set_property;
* gobject_class->get_property = my_object_get_property;
* g_object_class_install_properties (gobject_class,
* N_PROPERTIES,
* G_N_ELEMENTS (obj_properties),
* obj_properties);
* }
* ]|
@ -1406,12 +1408,11 @@ g_object_notify (GObject *object,
* g_object_class_install_property() inside a static array, e.g.:
*
*|[<!-- language="C" -->
* enum
* typedef enum
* {
* PROP_0,
* PROP_FOO,
* PROP_FOO = 1,
* PROP_LAST
* };
* } MyObjectProperty;
*
* static GParamSpec *properties[PROP_LAST];
*