grim/guifications3

added a recursive option to GfTypeQueryContext
org.guifications.gf3
2009-10-15, Gary Kramlich
3fc7fc6529e8
Parents 3ddd8914fd81
Children 6aa03b22e94f
added a recursive option to GfTypeQueryContext
--- a/gflib/gflib/gf_type.c Thu Oct 15 03:57:19 2009 -0500
+++ b/gflib/gflib/gf_type.c Thu Oct 15 04:12:14 2009 -0500
@@ -27,6 +27,7 @@
*****************************************************************************/
typedef struct {
GfTypeQuery *query;
+ gboolean recursive;
gpointer data;
GDestroyNotify destroy_notify;
@@ -38,6 +39,7 @@
enum {
PROP_ZERO,
PROP_QUERY,
+ PROP_RECURSIVE,
PROP_DATA,
PROP_DESTROY_NOTIFY,
PROP_LAST,
@@ -90,7 +92,6 @@
GType type)
{
GObjectClass *klass = NULL;
- GType *types = NULL;
GTypeQuery query;
guint t = 0;
@@ -118,20 +119,24 @@
if(priv->query->end_object)
priv->query->end_object(&query);
- /* now dig through the children */
- types = g_type_children(type, NULL);
- for(t = 0; types[t]; t++) {
- GObjectClass *child = NULL;
+ /* now dig through the children if we're recursive */
+ if(priv->recursive) {
+ GType *types = g_type_children(type, NULL);
+
+ for(t = 0; types[t]; t++) {
+ GObjectClass *child = NULL;
- child = g_type_class_ref(types[t]);
+ child = g_type_class_ref(types[t]);
+
+ gf_type_query_context_real_query_object(priv, types[t]);
- gf_type_query_context_real_query_object(priv, types[t]);
+ g_type_class_unref(child);
+ }
- g_type_class_unref(child);
+ g_free(types);
}
g_type_class_unref(klass);
- g_free(types);
}
static void
@@ -182,6 +187,10 @@
case PROP_QUERY:
g_value_set_pointer(value, gf_type_query_context_get_query(ctx));
break;
+ case PROP_RECURSIVE:
+ g_value_set_boolean(value,
+ gf_type_query_context_is_recursive(ctx));
+ break;
case PROP_DATA:
g_value_set_pointer(value,
gf_type_query_context_get_user_data(ctx));
@@ -206,6 +215,10 @@
case PROP_QUERY:
gf_type_query_context_set_query(ctx, g_value_get_pointer(value));
break;
+ case PROP_RECURSIVE:
+ gf_type_query_context_set_recursive(ctx,
+ g_value_get_boolean(value));
+ break;
case PROP_DATA:
gf_type_query_context_set_data(ctx, g_value_get_pointer(value));
break;
@@ -248,6 +261,11 @@
P_("The GfTypeQuery to use."),
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property(obj_class, PROP_RECURSIVE,
+ g_param_spec_boolean("recursive", P_("recursive"),
+ P_("Whether or not to recurse into children"),
+ TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
g_object_class_install_property(obj_class, PROP_DATA,
g_param_spec_pointer("data", P_("data"),
P_("The user data to use while parsing."),
@@ -291,6 +309,7 @@
/**
* gf_type_query_context_new:
* @query: A #GfTypeQuery.
+ * @recursive: Whether or not to recurse into children.
* @data: user data to pass to the #GfTypeQuery functions.
* @destroy_notify: A function to free @data.
*
@@ -299,13 +318,14 @@
* Return Value: The new #GfTypeQueryContext.
*/
GfTypeQueryContext *
-gf_type_query_context_new(GfTypeQuery *query, gpointer data,
- GDestroyNotify destroy_notify)
+gf_type_query_context_new(GfTypeQuery *query, gboolean recursive,
+ gpointer data, GDestroyNotify destroy_notify)
{
g_return_val_if_fail(query, NULL);
return g_object_new(GF_TYPE_TYPE_QUERY_CONTEXT,
"query", query,
+ "recursive", recursive,
"data", data,
"destroy-notify", destroy_notify,
NULL);
@@ -388,6 +408,49 @@
return priv->destroy_notify;
}
+/**
+ * gf_type_query_context_is_recursive:
+ * @ctx: The #GfTypeQueryContext instance.
+ *
+ * Gets whether or not @ctx will recurse into children.
+ *
+ * Return Value: TRUE if recursive, FALSE otherwise.
+ */
+gboolean
+gf_type_query_context_is_recursive(const GfTypeQueryContext *ctx) {
+ GfTypeQueryContextPrivate *priv = NULL;
+
+ g_return_val_if_fail(GF_IS_TYPE_QUERY_CONTEXT(ctx), FALSE);
+
+ priv = GF_TYPE_QUERY_CONTEXT_GET_PRIVATE(ctx);
+
+ return priv->recursive;
+}
+
+/**
+ * gf_type_query_set_recursive:
+ * @ctx: The #GfTypeQueryContext instance.
+ * @recursive: Whether or not to recurse into children.
+ *
+ * Set's whether or not @ctx will recurse into children.
+ */
+void
+gf_type_query_context_set_recursive(GfTypeQueryContext *ctx,
+ gboolean recursive)
+{
+ GfTypeQueryContextPrivate *priv = NULL;
+
+ g_return_if_fail(GF_IS_TYPE_QUERY_CONTEXT(ctx));
+
+ priv = GF_TYPE_QUERY_CONTEXT_GET_PRIVATE(ctx);
+
+ if(priv->recursive != recursive) {
+ priv->recursive = recursive;
+
+ g_object_notify(G_OBJECT(ctx), "recursive");
+ }
+}
+
/******************************************************************************
* Introspection API
*****************************************************************************/
--- a/gflib/gflib/gf_type.h Thu Oct 15 03:57:19 2009 -0500
+++ b/gflib/gflib/gf_type.h Thu Oct 15 04:12:14 2009 -0500
@@ -76,10 +76,14 @@
GType gf_type_query_context_get_type(void);
-GfTypeQueryContext *gf_type_query_context_new(GfTypeQuery *query, gpointer data, GDestroyNotify destroy_notify);
+GfTypeQueryContext *gf_type_query_context_new(GfTypeQuery *query, gboolean recursive, gpointer data, GDestroyNotify destroy_notify);
void gf_type_query_context_run(GfTypeQueryContext *ctx, GType type);
GfTypeQuery *gf_type_query_context_get_query(const GfTypeQueryContext *ctx);
+
+gboolean gf_type_query_context_is_recursive(const GfTypeQueryContext *ctx);
+void gf_type_query_context_set_recursive(GfTypeQueryContext *ctx, gboolean recursive);
+
gpointer gf_type_query_context_get_user_data(const GfTypeQueryContext *ctx);
GDestroyNotify gf_type_query_context_get_destroy_notify(const GfTypeQueryContext *ctx);