[glib: 2/3] docs: Standardise property ID enums in examples




commit 3c14b6846d5ea9fb2b4e07fc0a8c4587d9fc2b68
Author: Philip Withnall <pwithnall endlessos org>
Date:   Fri May 20 12:56:03 2022 +0100

    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>

 gobject/gobject.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index caee34f4e3..a7a1d3032d 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -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];
  *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]