[gegl/property-keys: 2/4] add utility paramspec factories with varargs
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/property-keys: 2/4] add utility paramspec factories with varargs
- Date: Wed, 14 May 2014 12:57:15 +0000 (UTC)
commit 3008098e6ae5eca0d36826326e3c7e9bac41b9ae
Author: Øyvind Kolås <pippin gimp org>
Date: Wed May 14 05:56:26 2014 +0200
add utility paramspec factories with varargs
These functions makes a key/value based chanting API possible.
gegl/gegl-operations-util.h | 2 +-
gegl/property-types/gegl-paramspecs.c | 432 +++++++++++++++++++++++++++++++++
gegl/property-types/gegl-paramspecs.h | 15 ++
3 files changed, 448 insertions(+), 1 deletions(-)
---
diff --git a/gegl/gegl-operations-util.h b/gegl/gegl-operations-util.h
index 9437525..27e4635 100644
--- a/gegl/gegl-operations-util.h
+++ b/gegl/gegl-operations-util.h
@@ -99,7 +99,7 @@ gegl_operation_get_property_key (const gchar *operation_type,
* @n_keys: (out caller-allocates): return location for number of property
* keys.
*
- * Return value: (transfer container) (array length=n_properties_p): An allocated NULL terminated array of
property-key names. The list should be freed with g_free after use.
+ * Return value: (transfer container) (array length=n_keys): An allocated NULL terminated array of
property-key names. The list should be freed with g_free after use.
*/
gchar **
gegl_operation_list_property_keys (const gchar *operation_type,
diff --git a/gegl/property-types/gegl-paramspecs.c b/gegl/property-types/gegl-paramspecs.c
index 2438306..8713fd4 100644
--- a/gegl/property-types/gegl-paramspecs.c
+++ b/gegl/property-types/gegl-paramspecs.c
@@ -25,6 +25,9 @@
#include <glib.h>
#include <glib-object.h>
#include "gegl-paramspecs.h"
+#include "gegl-types.h"
+#include <babl/babl.h>
+#include "gegl-color.h"
static void gegl_param_double_class_init (GParamSpecClass *klass);
static void gegl_param_double_init (GParamSpec *pspec);
@@ -740,3 +743,432 @@ gegl_param_spec_format (const gchar *name,
return G_PARAM_SPEC (pspec);
}
+
+GParamSpec *
+gegl_param_spec_double_from_vararg (const char *name, ...)
+{
+ const gchar *nick = name,
+ *blurb = "";
+ gdouble min_value = DBL_MIN,
+ max_value = DBL_MAX,
+ default_value = 0.0;
+
+ GParamSpec *pspec;
+ GHashTable *ht;
+
+ va_list var_args;
+ const gchar *key;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ va_start (var_args, name);
+ key = va_arg (var_args, const char*);
+ while (key)
+ {
+ if (g_str_equal (key, "min"))
+ min_value = va_arg (var_args, double);
+ else if (g_str_equal (key, "max"))
+ max_value = va_arg (var_args, double);
+ else if (g_str_equal (key, "default"))
+ default_value = va_arg (var_args, double);
+ else if (g_str_equal (key, "blurb"))
+ blurb = va_arg (var_args, const gchar *);
+ else if (g_str_equal (key, "nick"))
+ nick = va_arg (var_args, const gchar *);
+ else
+ {
+ const char *value = va_arg (var_args, const gchar*);
+ g_hash_table_insert (ht, g_strdup (key), g_strdup (value));
+ }
+ key = va_arg (var_args, const char*);
+ }
+ va_end (var_args);
+ pspec = g_param_spec_double (name, nick, blurb,
+ min_value, max_value, default_value,
+ (GParamFlags) (
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ GEGL_PARAM_PAD_INPUT));
+ g_param_spec_set_qdata_full (pspec, g_quark_from_static_string ("meta"),
+ ht, (GDestroyNotify)g_hash_table_destroy);
+ return pspec;
+}
+
+GParamSpec *
+gegl_param_spec_int_from_vararg (const char *name, ...)
+{
+ const gchar *nick = name,
+ *blurb = "";
+ gint min_value = G_MININT32,
+ max_value = G_MAXINT32,
+ default_value = 0;
+
+ GParamSpec *pspec;
+ GHashTable *ht;
+
+ va_list var_args;
+ const gchar *key;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ va_start (var_args, name);
+ key = va_arg (var_args, const char*);
+ while (key)
+ {
+ if (g_str_equal (key, "min"))
+ min_value = va_arg (var_args, int);
+ else if (g_str_equal (key, "max"))
+ max_value = va_arg (var_args, int);
+ else if (g_str_equal (key, "default"))
+ default_value = va_arg (var_args, int);
+ else if (g_str_equal (key, "blurb"))
+ blurb = va_arg (var_args, const gchar *);
+ else if (g_str_equal (key, "nick"))
+ nick = va_arg (var_args, const gchar *);
+ else
+ {
+ const char *value = va_arg (var_args, const gchar*);
+ g_hash_table_insert (ht, g_strdup (key), g_strdup (value));
+ }
+ key = va_arg (var_args, const char*);
+ }
+ va_end (var_args);
+ pspec = g_param_spec_int (name, nick, blurb,
+ min_value, max_value, default_value,
+ (GParamFlags) (
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ GEGL_PARAM_PAD_INPUT));
+ g_param_spec_set_qdata_full (pspec, g_quark_from_static_string ("meta"),
+ ht, (GDestroyNotify)g_hash_table_destroy);
+ return pspec;
+}
+
+GParamSpec *
+gegl_param_spec_boolean_from_vararg (const char *name, ...)
+{
+ const gchar *nick = name,
+ *blurb = "";
+ gboolean default_value = FALSE;
+
+ GParamSpec *pspec;
+ GHashTable *ht;
+
+ va_list var_args;
+ const gchar *key;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ va_start (var_args, name);
+ key = va_arg (var_args, const char*);
+ while (key)
+ {
+ if (g_str_equal (key, "default"))
+ default_value = va_arg (var_args, gboolean);
+ else if (g_str_equal (key, "blurb"))
+ blurb = va_arg (var_args, const gchar *);
+ else if (g_str_equal (key, "nick"))
+ nick = va_arg (var_args, const gchar *);
+ else
+ {
+ const char *value = va_arg (var_args, const gchar*);
+ g_hash_table_insert (ht, g_strdup (key), g_strdup (value));
+ }
+ key = va_arg (var_args, const char*);
+ }
+ va_end (var_args);
+ pspec = g_param_spec_boolean (name, nick, blurb,
+ default_value,
+ (GParamFlags) (
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ GEGL_PARAM_PAD_INPUT));
+ g_param_spec_set_qdata_full (pspec, g_quark_from_static_string ("meta"),
+ ht, (GDestroyNotify)g_hash_table_destroy);
+ return pspec;
+}
+
+GParamSpec *
+gegl_param_spec_string_from_vararg (const char *name, ...)
+{
+ const gchar *nick = name,
+ *blurb = "";
+ const gchar *default_value = "";
+
+ GParamSpec *pspec;
+ GHashTable *ht;
+
+ va_list var_args;
+ const gchar *key;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ va_start (var_args, name);
+ key = va_arg (var_args, const char*);
+ while (key)
+ {
+ if (g_str_equal (key, "default"))
+ default_value = va_arg (var_args, const gchar *);
+ else if (g_str_equal (key, "blurb"))
+ blurb = va_arg (var_args, const gchar *);
+ else if (g_str_equal (key, "nick"))
+ nick = va_arg (var_args, const gchar *);
+ else
+ {
+ const char *value = va_arg (var_args, const gchar*);
+ g_hash_table_insert (ht, g_strdup (key), g_strdup (value));
+ }
+ key = va_arg (var_args, const char*);
+ }
+ va_end (var_args);
+ pspec = g_param_spec_string (name, nick, blurb,
+ default_value,
+ (GParamFlags) (
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ GEGL_PARAM_PAD_INPUT));
+ g_param_spec_set_qdata_full (pspec, g_quark_from_static_string ("meta"),
+ ht, (GDestroyNotify)g_hash_table_destroy);
+ return pspec;
+}
+
+GParamSpec *
+gegl_param_spec_enum_from_vararg (const char *name, GType enum_type, ...)
+{
+ const gchar *nick = name,
+ *blurb = "";
+ int default_value = 0;
+
+ GParamSpec *pspec;
+ GHashTable *ht;
+
+ va_list var_args;
+ const gchar *key;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ va_start (var_args, enum_type);
+ key = va_arg (var_args, const char*);
+ while (key)
+ {
+ if (g_str_equal (key, "default"))
+ default_value = va_arg (var_args, int);
+ else if (g_str_equal (key, "blurb"))
+ blurb = va_arg (var_args, const gchar *);
+ else if (g_str_equal (key, "nick"))
+ nick = va_arg (var_args, const gchar *);
+ else
+ {
+ const char *value = va_arg (var_args, const gchar*);
+ g_hash_table_insert (ht, g_strdup (key), g_strdup (value));
+ }
+ key = va_arg (var_args, const char*);
+ }
+ va_end (var_args);
+
+ pspec = g_param_spec_enum (name, nick, blurb,
+ enum_type,
+ default_value,
+ (GParamFlags) (
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ GEGL_PARAM_PAD_INPUT));
+ g_param_spec_set_qdata_full (pspec, g_quark_from_static_string ("meta"),
+ ht, (GDestroyNotify)g_hash_table_destroy);
+ return pspec;
+}
+
+GParamSpec *
+gegl_param_spec_pointer_from_vararg (const char *name, ...)
+{
+ const gchar *nick = name,
+ *blurb = "";
+
+ GParamSpec *pspec;
+ GHashTable *ht;
+
+ va_list var_args;
+ const gchar *key;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ va_start (var_args, name);
+ key = va_arg (var_args, const char*);
+ while (key)
+ {
+ if (g_str_equal (key, "blurb"))
+ blurb = va_arg (var_args, const gchar *);
+ else if (g_str_equal (key, "nick"))
+ nick = va_arg (var_args, const gchar *);
+ else
+ {
+ const char *value = va_arg (var_args, const gchar*);
+ g_hash_table_insert (ht, g_strdup (key), g_strdup (value));
+ }
+ key = va_arg (var_args, const char*);
+ }
+ va_end (var_args);
+ pspec = g_param_spec_pointer (name, nick, blurb,
+ (GParamFlags) (
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ GEGL_PARAM_PAD_INPUT));
+ g_param_spec_set_qdata_full (pspec, g_quark_from_static_string ("meta"),
+ ht, (GDestroyNotify)g_hash_table_destroy);
+ return pspec;
+}
+
+GParamSpec *
+gegl_param_spec_object_from_vararg (const char *name, ...)
+{
+ const gchar *nick = name,
+ *blurb = "";
+
+ GParamSpec *pspec;
+ GHashTable *ht;
+
+ va_list var_args;
+ const gchar *key;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ va_start (var_args, name);
+ key = va_arg (var_args, const char*);
+ while (key)
+ {
+ if (g_str_equal (key, "blurb"))
+ blurb = va_arg (var_args, const gchar *);
+ else if (g_str_equal (key, "nick"))
+ nick = va_arg (var_args, const gchar *);
+ else
+ {
+ const char *value = va_arg (var_args, const gchar*);
+ g_hash_table_insert (ht, g_strdup (key), g_strdup (value));
+ }
+ key = va_arg (var_args, const char*);
+ }
+ va_end (var_args);
+ pspec = g_param_spec_object (name, nick, blurb,
+ G_TYPE_OBJECT,
+ (GParamFlags) (
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ GEGL_PARAM_PAD_INPUT));
+ g_param_spec_set_qdata_full (pspec, g_quark_from_static_string ("meta"),
+ ht, (GDestroyNotify)g_hash_table_destroy);
+ return pspec;
+}
+
+GParamSpec *
+gegl_param_spec_format_from_vararg (const char *name, ...)
+{
+ const gchar *nick = name,
+ *blurb = "";
+
+ GParamSpec *pspec;
+ GHashTable *ht;
+
+ va_list var_args;
+ const gchar *key;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ va_start (var_args, name);
+ key = va_arg (var_args, const char*);
+ while (key)
+ {
+ if (g_str_equal (key, "blurb"))
+ blurb = va_arg (var_args, const gchar *);
+ else if (g_str_equal (key, "nick"))
+ nick = va_arg (var_args, const gchar *);
+ else
+ {
+ const char *value = va_arg (var_args, const gchar*);
+ g_hash_table_insert (ht, g_strdup (key), g_strdup (value));
+ }
+ key = va_arg (var_args, const char*);
+ }
+ va_end (var_args);
+ pspec = gegl_param_spec_format (name, nick, blurb,
+ (GParamFlags) (
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ GEGL_PARAM_PAD_INPUT));
+ g_param_spec_set_qdata_full (pspec, g_quark_from_static_string ("meta"),
+ ht, (GDestroyNotify)g_hash_table_destroy);
+ return pspec;
+}
+
+GParamSpec *
+gegl_param_spec_color_from_vararg (const char *name, ...)
+{
+ const gchar *nick = name,
+ *blurb = "";
+ const gchar *default_value = "";
+
+ GParamSpec *pspec;
+ GHashTable *ht;
+
+ va_list var_args;
+ const gchar *key;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ va_start (var_args, name);
+ key = va_arg (var_args, const char*);
+ while (key)
+ {
+ if (g_str_equal (key, "default"))
+ default_value = va_arg (var_args, const gchar *);
+ else if (g_str_equal (key, "blurb"))
+ blurb = va_arg (var_args, const gchar *);
+ else if (g_str_equal (key, "nick"))
+ nick = va_arg (var_args, const gchar *);
+ else
+ {
+ const char *value = va_arg (var_args, const gchar*);
+ g_hash_table_insert (ht, g_strdup (key), g_strdup (value));
+ }
+ key = va_arg (var_args, const char*);
+ }
+ va_end (var_args);
+ pspec = gegl_param_spec_color_from_string (name, nick, blurb,
+ default_value,
+ (GParamFlags) (
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ GEGL_PARAM_PAD_INPUT));
+ g_param_spec_set_qdata_full (pspec, g_quark_from_static_string ("meta"),
+ ht, (GDestroyNotify)g_hash_table_destroy);
+ return pspec;
+}
+
+GParamSpec *
+gegl_param_spec_seed_from_vararg (const char *name, ...)
+{
+ const gchar *nick = name,
+ *blurb = "";
+
+ GParamSpec *pspec;
+ GHashTable *ht;
+
+ va_list var_args;
+ const gchar *key;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ va_start (var_args, name);
+ key = va_arg (var_args, const char*);
+ while (key)
+ {
+ if (g_str_equal (key, "blurb"))
+ blurb = va_arg (var_args, const gchar *);
+ else if (g_str_equal (key, "nick"))
+ nick = va_arg (var_args, const gchar *);
+ else
+ {
+ const char *value = va_arg (var_args, const gchar*);
+ g_hash_table_insert (ht, g_strdup (key), g_strdup (value));
+ }
+ key = va_arg (var_args, const char*);
+ }
+ va_end (var_args);
+ pspec = gegl_param_spec_seed (name, nick, blurb,
+ (GParamFlags) (
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ GEGL_PARAM_PAD_INPUT));
+ g_param_spec_set_qdata_full (pspec, g_quark_from_static_string ("meta"),
+ ht, (GDestroyNotify)g_hash_table_destroy);
+ return pspec;
+}
diff --git a/gegl/property-types/gegl-paramspecs.h b/gegl/property-types/gegl-paramspecs.h
index 6142e46..1d3eeb3 100644
--- a/gegl/property-types/gegl-paramspecs.h
+++ b/gegl/property-types/gegl-paramspecs.h
@@ -374,5 +374,20 @@ GParamSpec * gegl_param_spec_format (const gchar *name,
const gchar *blurb,
GParamFlags flags);
+
+
+GParamSpec * gegl_param_spec_double_from_vararg (const char *name, ...);
+GParamSpec * gegl_param_spec_int_from_vararg (const char *name, ...);
+GParamSpec * gegl_param_spec_string_from_vararg (const char *name, ...);
+GParamSpec * gegl_param_spec_boolean_from_vararg (const char *name, ...);
+GParamSpec * gegl_param_spec_pointer_from_vararg (const char *name, ...);
+GParamSpec * gegl_param_spec_enum_from_vararg (const char *name, GType enum_type, ...);
+GParamSpec * gegl_param_spec_color_from_vararg (const char *name, ...);
+GParamSpec * gegl_param_spec_seed_from_vararg (const char *name, ...);
+GParamSpec * gegl_param_spec_object_from_vararg (const char *name, ...);
+GParamSpec *
+gegl_param_spec_format_from_vararg (const char *name, ...);
+
+
G_END_DECLS
#endif /* __GEGL_PARAM_SPECS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]