Optimize the common cases (init == NULL or init == "") a bit. replace uses
[platform/upstream/glib.git] / gobject / gparam.h
index 370fb4f..3fbea4b 100644 (file)
@@ -1,5 +1,5 @@
 /* GObject - GLib Type, Object, Parameter and Signal Library
- * Copyright (C) 1997, 1998, 1999, 2000 Tim Janik and Red Hat, Inc.
+ * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  *
  * gparam.h: GParamSpec base class implementation
  */
+#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
+#error "Only <glib-object.h> can be included directly."
+#endif
+
 #ifndef __G_PARAM_H__
 #define __G_PARAM_H__
 
-
 #include       <gobject/gvalue.h>
 
+G_BEGIN_DECLS
 
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-
-/* --- type macros --- */
+/* --- standard type macros --- */
 #define G_TYPE_IS_PARAM(type)          (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
-#define G_PARAM_SPEC_TYPE(pspec)       (G_TYPE_FROM_INSTANCE (pspec))
-#define G_PARAM_SPEC_TYPE_NAME(pspec)  (g_type_name (G_PARAM_SPEC_TYPE (pspec)))
 #define G_PARAM_SPEC(pspec)            (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM, GParamSpec))
 #define G_IS_PARAM_SPEC(pspec)         (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM))
+#define G_PARAM_SPEC_CLASS(pclass)      (G_TYPE_CHECK_CLASS_CAST ((pclass), G_TYPE_PARAM, GParamSpecClass))
+#define G_IS_PARAM_SPEC_CLASS(pclass)   (G_TYPE_CHECK_CLASS_TYPE ((pclass), G_TYPE_PARAM))
 #define G_PARAM_SPEC_GET_CLASS(pspec)  (G_TYPE_INSTANCE_GET_CLASS ((pspec), G_TYPE_PARAM, GParamSpecClass))
-#define        G_IS_PARAM_VALUE(pspec, value)  (g_type_is_a (G_VALUE_TYPE (value), G_PARAM_SPEC_VALUE_TYPE (pspec))) /* FIXME */
-#define        G_PARAM_SPEC_VALUE_TYPE(pspec)  (G_PARAM_SPEC_GET_CLASS (pspec)->value_type)
 
 
+/* --- convenience macros --- */
+#define G_PARAM_SPEC_TYPE(pspec)       (G_TYPE_FROM_INSTANCE (pspec))
+#define G_PARAM_SPEC_TYPE_NAME(pspec)  (g_type_name (G_PARAM_SPEC_TYPE (pspec)))
+#define        G_PARAM_SPEC_VALUE_TYPE(pspec)  (G_PARAM_SPEC (pspec)->value_type)
+#define G_VALUE_HOLDS_PARAM(value)     (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_PARAM))
+       
+
 /* --- flags --- */
 typedef enum
 {
   G_PARAM_READABLE            = 1 << 0,
   G_PARAM_WRITABLE            = 1 << 1,
-  G_PARAM_MASK                = 0x000f,
-  /* bits in the range 0xfff0 are reserved for 3rd party usage */
-  G_PARAM_USER_MASK           = 0xfff0
+  G_PARAM_CONSTRUCT          = 1 << 2,
+  G_PARAM_CONSTRUCT_ONLY      = 1 << 3,
+  G_PARAM_LAX_VALIDATION      = 1 << 4,
+  G_PARAM_PRIVATE            = 1 << 5
 } GParamFlags;
+#define        G_PARAM_READWRITE       (G_PARAM_READABLE | G_PARAM_WRITABLE)
+#define        G_PARAM_MASK            (0x000000ff)
+/* bits in the range 0xffffff00 are reserved for 3rd party usage */
+#define        G_PARAM_USER_SHIFT      (8)
 
 
 /* --- typedefs & structures --- */
-typedef struct _GParamSpecClass GParamSpecClass;
 typedef struct _GParamSpec      GParamSpec;
+typedef struct _GParamSpecClass GParamSpecClass;
+typedef struct _GParameter     GParameter;
+typedef struct _GParamSpecPool  GParamSpecPool;
+struct _GParamSpec
+{
+  GTypeInstance  g_type_instance;
+
+  gchar         *name;
+  GParamFlags    flags;
+  GType                 value_type;
+  GType                 owner_type;    /* class using this property */
+
+  /*< private >*/
+  gchar         *_nick;
+  gchar         *_blurb;
+  GData                *qdata;
+  guint          ref_count;
+  guint                 param_id;      /* sort-criteria */
+};
 struct _GParamSpecClass
 {
   GTypeClass      g_type_class;
@@ -71,26 +98,19 @@ struct _GParamSpecClass
   gint          (*values_cmp)           (GParamSpec   *pspec,
                                         const GValue *value1,
                                         const GValue *value2);
+  gpointer       dummy[4];
 };
-struct _GParamSpec
+struct _GParameter /* auxillary structure for _setv() variants */
 {
-  GTypeInstance  g_instance;
-
-  gchar         *name;
-  gchar         *nick;
-  gchar         *blurb;
-  GParamFlags    flags;
-
-  /*< private >*/
-  GType                 owner_type;
-  GData                *qdata;
-  guint          ref_count;
+  const gchar *name;
+  GValue       value;
 };
 
 
 /* --- prototypes --- */
 GParamSpec*    g_param_spec_ref                (GParamSpec    *pspec);
 void           g_param_spec_unref              (GParamSpec    *pspec);
+void           g_param_spec_sink               (GParamSpec    *pspec);
 gpointer        g_param_spec_get_qdata         (GParamSpec    *pspec,
                                                 GQuark         quark);
 void            g_param_spec_set_qdata         (GParamSpec    *pspec,
@@ -108,74 +128,96 @@ gboolean  g_param_value_defaults          (GParamSpec    *pspec,
                                                 GValue        *value);
 gboolean       g_param_value_validate          (GParamSpec    *pspec,
                                                 GValue        *value);
+gboolean       g_param_value_convert           (GParamSpec    *pspec,
+                                                const GValue  *src_value,
+                                                GValue        *dest_value,
+                                                gboolean       strict_validation);
 gint           g_param_values_cmp              (GParamSpec    *pspec,
                                                 const GValue  *value1,
                                                 const GValue  *value2);
+G_CONST_RETURN gchar*  g_param_spec_get_name   (GParamSpec    *pspec);
+G_CONST_RETURN gchar*  g_param_spec_get_nick   (GParamSpec    *pspec);
+G_CONST_RETURN gchar*  g_param_spec_get_blurb  (GParamSpec    *pspec);
+void            g_value_set_param               (GValue               *value,
+                                                GParamSpec    *param);
+GParamSpec*     g_value_get_param               (const GValue  *value);
+GParamSpec*     g_value_dup_param               (const GValue  *value);
+
+
+/* --- marshaller specific --- */
+void           g_value_set_param_take_ownership (GValue        *value,
+                                                GParamSpec    *param);
+
+
+/* --- convenience functions --- */
+typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
+struct _GParamSpecTypeInfo
+{
+  /* type system portion */
+  guint16         instance_size;                               /* obligatory */
+  guint16         n_preallocs;                                 /* optional */
+  void         (*instance_init)        (GParamSpec   *pspec); /* optional */
+
+  /* class portion */
+  GType           value_type;                                 /* obligatory */
+  void          (*finalize)             (GParamSpec   *pspec); /* optional */
+  void          (*value_set_default)    (GParamSpec   *pspec,  /* recommended */
+                                        GValue       *value);
+  gboolean      (*value_validate)       (GParamSpec   *pspec,  /* optional */
+                                        GValue       *value);
+  gint          (*values_cmp)           (GParamSpec   *pspec,  /* recommended */
+                                        const GValue *value1,
+                                        const GValue *value2);
+};
+GType  g_param_type_register_static    (const gchar              *name,
+                                        const GParamSpecTypeInfo *pspec_info);
+
+/* For registering builting types */
+GType  _g_param_type_register_static_constant (const gchar              *name,
+                                              const GParamSpecTypeInfo *pspec_info,
+                                              GType                     opt_type);
 
 
-/* --- private --- */
+/* --- protected --- */
 gpointer       g_param_spec_internal           (GType          param_type,
                                                 const gchar   *name,
                                                 const gchar   *nick,
                                                 const gchar   *blurb,
                                                 GParamFlags    flags);
-GHashTable*    g_param_spec_hash_table_new     (void);
-void           g_param_spec_hash_table_insert  (GHashTable    *hash_table,
-                                                GParamSpec    *pspec,
-                                                GType          owner_type);
-void           g_param_spec_hash_table_remove  (GHashTable    *hash_table,
-                                                GParamSpec    *pspec);
-GParamSpec*    g_param_spec_hash_table_lookup  (GHashTable    *hash_table,
-                                                const gchar   *param_name,
-                                                GType          owner_type,
-                                                gboolean       try_ancestors,
-                                                const gchar  **trailer);
+GParamSpecPool* g_param_spec_pool_new          (gboolean       type_prefixing);
+void           g_param_spec_pool_insert        (GParamSpecPool *pool,
+                                                GParamSpec     *pspec,
+                                                GType           owner_type);
+void           g_param_spec_pool_remove        (GParamSpecPool *pool,
+                                                GParamSpec     *pspec);
+GParamSpec*    g_param_spec_pool_lookup        (GParamSpecPool *pool,
+                                                const gchar    *param_name,
+                                                GType           owner_type,
+                                                gboolean        walk_ancestors);
+GList*         g_param_spec_pool_list_owned    (GParamSpecPool *pool,
+                                                GType           owner_type);
+GParamSpec**   g_param_spec_pool_list          (GParamSpecPool *pool,
+                                                GType           owner_type,
+                                                guint          *n_pspecs_p);
+
 
 
 /* contracts:
  *
- * +++ OUTDATED +++
- *
- * class functions may not evaluate param->pspec directly,
- * instead, pspec will be passed as argument if required.
- *
- * void        param_init (GParam *param, GParamSpec *pspec):
- *     initialize param's value to default if pspec is given,
- *     and to zero-equivalent (a value that doesn't need to be
- *     free()ed later on) otherwise.
- *
- * void param_free_value (GParam *param):
- *     free param's value if required, zero-reinitialization
- *     of the value is not required. (this class function
- *     may be NULL for param types that don't need to free
- *     values, such as ints or floats).
- *
- * gboolean param_validate (GParam *param, GParamSpec *pspec):
- *     modify param's value in the least destructive way, so
+ * gboolean value_validate (GParamSpec *pspec,
+ *                          GValue     *value):
+ *     modify value contents in the least destructive way, so
  *     that it complies with pspec's requirements (i.e.
  *     according to minimum/maximum ranges etc...). return
  *     whether modification was necessary.
  *
- * gint param_values_cmp (GParam *param1, GParam *param2, GParamSpec*):
- *     return param1 - param2, i.e. <0 if param1 < param2,
- *     >0 if param1 > param2, and 0 if they are equal
- *     (passing pspec is optional, but recommended)
- *
- * void param_copy_value (GParam *param_src, GParam *param_dest):
- *     copy value from param_src to param_dest, param_dest is
- *     already free()d and zero-initialized, so its value can
- *     simply be overwritten. (may be NULL for memcpy)
- *
- * gchar* param_collect_value ():
- *     class function may be NULL.
- *
- * gchar* param_lcopy_value ():
- *     class function may be NULL.
- *
+ * gint values_cmp (GParamSpec   *pspec,
+ *                  const GValue *value1,
+ *                  const GValue *value2):
+ *     return value1 - value2, i.e. (-1) if value1 < value2,
+ *     (+1) if value1 > value2, and (0) otherwise (equality)
  */
 
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+G_END_DECLS
 
 #endif /* __G_PARAM_H__ */