--- a/gplate/gplate-errors.h Thu Feb 07 19:01:28 2008 -0600
+++ b/gplate/gplate-errors.h Fri Feb 08 00:11:26 2008 -0600
@@ -39,6 +39,8 @@
GPLATE_ERROR_LIBRARY_FUNCTION_BOUND,
GPLATE_ERROR_LIBRARY_FUNCTION_NOT_BOUND,
GPLATE_ERROR_LIBRARY_FUNCTION_NOT_BOUND_TO_TAG,
+ GPLATE_ERROR_LIBRARY_TAG_EXISTS = 450, + GPLATE_ERROR_LIBRARY_TAG_NOT_FOUND, GPLATE_ERROR_UNKNOWN = 1 << 31,
--- a/gplate/gplate-library.c Thu Feb 07 19:01:28 2008 -0600
+++ b/gplate/gplate-library.c Fri Feb 08 00:11:26 2008 -0600
@@ -35,7 +35,8 @@
/******************************************************************************
*****************************************************************************/
-static GHashTable *library = NULL;
+static GHashTable *functions = NULL; +static GHashTable *tags = NULL; /******************************************************************************
@@ -60,11 +61,15 @@
*****************************************************************************/
gplate_library_lazy_init(void) {
- if(G_UNLIKELY(library == NULL)) {
+ if(G_UNLIKELY(functions == NULL)) { g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
(GDestroyNotify)gplate_library_data_free);
+ if(G_UNLIKELY(tags == NULL)) { + tags = g_hash_table_new(g_direct_hash, g_direct_equal); @@ -121,7 +126,7 @@
if(!gplate_library_check_type(function, GPLATE_TYPE_FUNCTION, error))
- data = g_hash_table_lookup(library, name);
+ data = g_hash_table_lookup(functions, name); /* if the function is already registered with the same name and
* function, return TRUE and jump out.
@@ -142,7 +147,7 @@
data = gplate_library_data_new(function, G_TYPE_INVALID);
- g_hash_table_insert(library, g_strdup(name), data);
+ g_hash_table_insert(functions, g_strdup(name), data); @@ -162,7 +167,7 @@
g_return_val_if_fail(name, FALSE);
- ret = g_hash_table_remove(library, name);
+ ret = g_hash_table_remove(functions, name); *error = g_error_new(GPLATE_DOMAIN,
@@ -175,6 +180,72 @@
+ * gplate_library_add_tag: + * @tag: The #GPlateTag's GType to add. + * @error: The return address for any errors. + * Adds a tag to the library. + * Tags must be added to the library via this function for a template to + * Return Value: TRUE on success, FALSE on failure with @error set. +gplate_library_add_tag(GType tag, GError **error) { + gplate_library_lazy_init(); + if(!gplate_library_check_type(tag, GPLATE_TYPE_TAG, error)) + data = g_hash_table_lookup(tags, GSIZE_TO_POINTER(tag)); + *error = g_error_new(GPLATE_DOMAIN, + GPLATE_ERROR_LIBRARY_TAG_EXISTS, + "Tag '%s' is already in the library", + data = GSIZE_TO_POINTER(tag); + g_hash_table_insert(tags, data, data); +gplate_library_remove_tag(GType tag, GError **error) { + gplate_library_lazy_init(); + if(!gplate_library_check_type(tag, GPLATE_TYPE_TAG, error)) + data = g_hash_table_lookup(tags, GSIZE_TO_POINTER(tag)); + *error = g_error_new(GPLATE_DOMAIN, + GPLATE_ERROR_LIBRARY_TAG_NOT_FOUND, + "Tag '%s' is not in the library.", + g_hash_table_remove(tags, GSIZE_TO_POINTER(tag)); * gplate_library_bind_function:
* @name: The name of the function.
* @tag: The #GType of the tag.
@@ -195,7 +266,7 @@
if(!gplate_library_check_type(tag, GPLATE_TYPE_TAG, error))
- data = g_hash_table_lookup(library, name);
+ data = g_hash_table_lookup(functions, name); *error = g_error_new(GPLATE_DOMAIN,
@@ -233,7 +304,7 @@
gplate_library_lazy_init();
- data = g_hash_table_lookup(library, name);
+ data = g_hash_table_lookup(functions, name); *error = g_error_new(GPLATE_DOMAIN,
@@ -318,7 +389,7 @@
g_return_val_if_fail(name, FALSE);
- data = g_hash_table_lookup(library, name);
+ data = g_hash_table_lookup(functions, name); *error = g_error_new(GPLATE_DOMAIN,
--- a/gplate/gplate-library.h Thu Feb 07 19:01:28 2008 -0600
+++ b/gplate/gplate-library.h Fri Feb 08 00:11:26 2008 -0600
@@ -29,13 +29,15 @@
gboolean gplate_library_add_function(const gchar *name, GType function, GError **error);
gboolean gplate_library_remove_function(const gchar *name, GError **error);
+gboolean gplate_library_add_tag(GType tag, GError **error); +gboolean gplate_library_remove_tag(GType tag, GError **error); gboolean gplate_library_bind_function(const gchar *name, GType tag, GError **error);
gboolean gplate_library_unbind_function(const gchar *name, GError **error);
gboolean gplate_library_add_bound_function(const gchar *name, GType function, GType tag, GError **error);
gboolean gplate_library_lookup_function(const gchar *name, GType *function, GType *tag, GError **error);
GType gplate_library_lookup_function_for_tag(const gchar *name, GType tag, GError **error);