--- a/gplate/gplate-library.c Thu Feb 14 03:48:40 2008 -0600
+++ b/gplate/gplate-library.c Sun Feb 17 03:22:52 2008 -0600
@@ -36,6 +36,7 @@
+ GType default_function; /******************************************************************************
@@ -122,6 +123,7 @@
data->prefix = (prefix) ? g_strdup(prefix) : NULL;
data->suffix = (suffix) ? g_strdup(suffix) : NULL;
+ data->default_function = G_TYPE_INVALID; g_type_class_unref(klass);
@@ -602,6 +604,94 @@
+ * gplate_library_set_default_function_for_tag: + * @name: The name of the function. + * @tag: The #GType of the tag. + * @error: The return address for any errors. + * Sets the default function of @tag to @name. + * A default function is used when the contents of a tag do not match any + * functions that are registered to the tag. + * For example, the default function of #GPlateCommentTag is + * Return Value: TRUE on success, otherwise FALSE with @error set. +gplate_library_set_default_function_for_tag(const gchar *name, GType tag, + GPlateTagData *tdata = NULL; + GType function = G_TYPE_INVALID; + g_return_val_if_fail(name, FALSE); + gplate_library_lazy_init(); + tdata = 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 registered", + function = gplate_library_lookup_function_for_tag(name, tag, error); + if(function == G_TYPE_INVALID) { + /* error should already be set from + * gplate_library_lookup_function_for_tag + tdata->default_function = function; + * gplate_library_get_default_function_for_tag: + * @tag: The #GPlateTag. + * @error: The return address for any errors. + * Get's the default function for @tag. + * Return Value: On success, the #GType of the function is returned. + * On failure, #G_TYPE_INVALID is returned and @error is set. + * However, if a tag does not have a default function, + * #G_TYPE_INVALID will be returned. So it is recommended to + * pass @error and check if it's set before assuming a return + * value of #G_TYPE_INVALID is an error. +gplate_library_get_default_function_for_tag(GType tag, GError **error) { + GPlateTagData *tdata = NULL; + gplate_library_lazy_init(); + tdata = 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 registered", + return tdata->default_function; /******************************************************************************
*****************************************************************************/
--- a/gplate/gplate-library.h Thu Feb 14 03:48:40 2008 -0600
+++ b/gplate/gplate-library.h Sun Feb 17 03:22:52 2008 -0600
@@ -44,6 +44,9 @@
gboolean gplate_library_lookup_tag(GType tag, gchar **prefix, gchar **suffix, GError **error);
GType gplate_library_get_default_tag(void);
+gboolean gplate_library_set_default_function_for_tag(const gchar *name, GType tag, GError **error); +GType gplate_library_get_default_function_for_tag(GType tag, GError **error); void gplate_library_tags_foreach(GPlateLibraryTagsForeachFunc func, gpointer data);