[gegl/pippin/property-keys: 1/16] operation: add property-key API



commit cd9689954637d6c5f7499a76357db2f7c367b3a9
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed May 14 05:11:32 2014 +0200

    operation: add property-key API
    
    API to set and query string based key/value meta data for properties on GEGL
    operations.

 gegl/gegl-operations-util.h                   |   34 +++++-
 gegl/operation/Makefile.am                    |    2 +
 gegl/operation/gegl-operation-property-keys.c |  174 +++++++++++++++++++++++++
 gegl/operation/gegl-operation-property-keys.h |   36 +++++
 4 files changed, 245 insertions(+), 1 deletions(-)
---
diff --git a/gegl/gegl-operations-util.h b/gegl/gegl-operations-util.h
index e2d734d..9437525 100644
--- a/gegl/gegl-operations-util.h
+++ b/gegl/gegl-operations-util.h
@@ -77,6 +77,38 @@ gboolean       gegl_has_operation           (const gchar *operation_type);
 GParamSpec** gegl_operation_list_properties (const gchar   *operation_type,
                                              guint         *n_properties_p);
 
+
+/**
+ * gegl_operation_get_property_key:
+ * @operation_type: the name of the operation type we want to query to property keys for.
+ * @property_name: the property to query a key for.
+ * @property_key_name: the property mata data key to query
+ *
+ * Return value: NULL or a string with the meta-data value for the operation
+ * key.
+ */
+const gchar *
+gegl_operation_get_property_key (const gchar *operation_type,
+                                 const gchar *property_name,
+                                 const gchar *property_key_name);
+
+/**
+ * gegl_operation_list_property_keys:
+ * @operation_type: the name of the operation type we want to query to property keys for.
+ * @property_name: the property to query a key for.
+ * @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.
+ */
+gchar **
+gegl_operation_list_property_keys (const gchar *operation_type,
+                                   const gchar *property_name,
+                                   guint       *n_keys);
+
+
+
+
 G_END_DECLS
 
-#endif /* __GEGL_OPERATIONS_UTIL_H__ */
\ No newline at end of file
+#endif /* __GEGL_OPERATIONS_UTIL_H__ */
diff --git a/gegl/operation/Makefile.am b/gegl/operation/Makefile.am
index 6482d92..e9eb1a6 100644
--- a/gegl/operation/Makefile.am
+++ b/gegl/operation/Makefile.am
@@ -32,6 +32,7 @@ liboperation_public_HEADERS = \
        gegl-operation-point-composer3.h \
        gegl-operation-point-filter.h    \
        gegl-operation-point-render.h    \
+       gegl-operation-property-keys.h \
        gegl-operation-sink.h            \
        gegl-operation-source.h          \
        gegl-operation-temporal.h
@@ -49,6 +50,7 @@ liboperation_sources = \
        gegl-operation-point-composer3.c        \
        gegl-operation-point-filter.c           \
        gegl-operation-point-render.c           \
+       gegl-operation-property-keys.c \
        gegl-operation-sink.c                   \
        gegl-operation-source.c                 \
        gegl-operation-temporal.c               \
diff --git a/gegl/operation/gegl-operation-property-keys.c b/gegl/operation/gegl-operation-property-keys.c
new file mode 100644
index 0000000..32152fb
--- /dev/null
+++ b/gegl/operation/gegl-operation-property-keys.c
@@ -0,0 +1,174 @@
+/* This file is part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2014 Øyvind Kolås
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+#include <string.h>
+
+#include "gegl.h"
+#include "gegl-operation.h"
+#include "gegl-operations.h"
+#include "gegl-operation-property-keys.h"
+
+static GHashTable *
+gegl_paramspec_get_property_key_ht (GParamSpec  *pspec,
+                                    gboolean     create)
+{
+  GHashTable *ret = NULL;
+  if (pspec)
+    {
+      GQuark quark = g_quark_from_static_string ("meta");
+      ret = g_param_spec_get_qdata (pspec, quark);
+      if (!ret && create)
+      {
+        ret = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+        g_param_spec_set_qdata_full (pspec, quark, ret, 
+                                     (GDestroyNotify)g_hash_table_destroy);
+      }
+    }
+  return ret;
+}
+
+const gchar *
+gegl_paramspec_get_property_key (GParamSpec  *pspec,
+                                 const gchar *key_name)
+{
+  GHashTable *ht;
+  ht = gegl_paramspec_get_property_key_ht (pspec, FALSE);
+  if (ht)
+    return g_hash_table_lookup (ht, key_name);
+  return NULL;
+}
+
+const gchar *
+gegl_paramspec_set_property_key (GParamSpec  *pspec,
+                                 const gchar *key_name,
+                                 const gchar *value)
+{
+  GHashTable *ht;
+  ht = gegl_paramspec_get_property_key_ht (pspec, TRUE);
+  if (ht)
+    g_hash_table_insert (ht, g_strdup (key_name), g_strdup (value));
+  return NULL;
+}
+
+static GHashTable *
+gegl_operation_class_get_property_key_ht (GeglOperationClass *operation_class,
+                                          const gchar        *property_name,
+                                          gboolean            create)
+{
+  GParamSpec *pspec;
+  pspec = g_object_class_find_property (G_OBJECT_CLASS (operation_class),
+                                        property_name);
+  if (pspec)
+    return gegl_paramspec_get_property_key_ht (pspec, create);
+  return NULL;
+}
+
+gchar **
+gegl_operation_list_property_keys (const gchar *operation_name,
+                                   const gchar *property_name,
+                                   guint       *n_keys)
+{
+  GType         type;
+  GObjectClass *klass;
+  GHashTable   *ht = NULL;
+  GList        *list, *l;
+  gchar       **ret;
+  int count;
+  int i;
+  type = gegl_operation_gtype_from_name (operation_name);
+  if (!type)
+    {
+      if (n_keys)
+        *n_keys = 0;
+      return NULL;
+    }
+  klass  = g_type_class_ref (type);
+  ht = gegl_operation_class_get_property_key_ht (GEGL_OPERATION_CLASS (klass),
+                                                 property_name, FALSE);
+  if (!ht)
+  {
+    count = 0;
+    ret = g_malloc0 (sizeof (gpointer));;
+  }
+  else
+  {
+    count = g_hash_table_size (ht);
+    ret = g_malloc0 (sizeof (gpointer) * (count + 1));
+    list = g_hash_table_get_keys (ht);
+    for (i = 0, l = list; l; l = l->next)
+      {
+        ret[i] = l->data;
+      }
+    g_list_free (list);
+  }
+  if (n_keys)
+    *n_keys = count;
+  g_type_class_unref (klass);
+  return ret;
+}
+
+void
+gegl_operation_class_set_property_key (GeglOperationClass *operation_class,
+                                       const gchar        *property_name,
+                                       const gchar        *key_name,
+                                       const gchar        *value)
+{
+  GParamSpec *pspec;
+  pspec = g_object_class_find_property (G_OBJECT_CLASS (operation_class),
+                                        property_name);
+  if (pspec)
+    gegl_paramspec_set_property_key (pspec, key_name, value);
+}
+
+
+static const gchar *
+gegl_operation_class_get_property_key (GeglOperationClass *operation_class,
+                                       const gchar        *property_name,
+                                       const gchar        *key_name)
+{
+  GParamSpec *pspec;
+  pspec = g_object_class_find_property (G_OBJECT_CLASS (operation_class),
+                                        property_name);
+  if (pspec)
+    return gegl_paramspec_get_property_key (pspec, key_name);
+  return NULL;
+}
+
+const gchar *
+gegl_operation_get_property_key (const gchar *operation_name,
+                                 const gchar *property_name,
+                                 const gchar *property_key_name)
+{
+  GType         type;
+  GObjectClass *klass;
+  const gchar  *ret = NULL;
+  type = gegl_operation_gtype_from_name (operation_name);
+  if (!type)
+    {
+      return NULL;
+    }
+  klass  = g_type_class_ref (type);
+  ret = gegl_operation_class_get_property_key (GEGL_OPERATION_CLASS (klass), 
+                                               property_name, 
+                                               property_key_name);
+  g_type_class_unref (klass);
+  return ret;
+}
diff --git a/gegl/operation/gegl-operation-property-keys.h b/gegl/operation/gegl-operation-property-keys.h
new file mode 100644
index 0000000..f5f04da
--- /dev/null
+++ b/gegl/operation/gegl-operation-property-keys.h
@@ -0,0 +1,36 @@
+/* This file is part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2014 Øyvind Kolås
+ */
+
+#ifndef __GEGL_OPERATION_PROPERTY_KEYS_H__
+#define __GEGL_OPERATION_PROPERTY_KEYS__
+
+#include <glib-object.h>
+
+const gchar *gegl_paramspec_get_property_key (GParamSpec  *pspec,
+                                              const gchar *key_name);
+
+const gchar *gegl_paramspec_set_property_key (GParamSpec  *pspec,
+                                              const gchar *key_name,
+                                              const gchar *value);
+
+void       gegl_operation_class_set_property_key
+                                            (GeglOperationClass *klass,
+                                             const gchar        *property_name,
+                                             const gchar        *key_name,
+                                             const gchar        *value);
+#endif


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