[gegl] graph: add GeglCallbackVisitor
- From: N/A <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] graph: add GeglCallbackVisitor
- Date: Thu, 9 Nov 2017 23:34:35 +0000 (UTC)
commit b1458e0d1e211ffbc885e916ec723f90b17d9c90
Author: Ell <ell_se yahoo com>
Date: Thu Nov 9 14:36:52 2017 -0500
graph: add GeglCallbackVisitor
Add GeglCallbackVisitor -- a GeglVisitor subclass, taking a custom
callback, and using it to visit the nodes. Useful for traversing
the graph without the fuss of defining a dedicated GObject.
gegl/graph/Makefile.am | 2 +
gegl/graph/gegl-callback-visitor.c | 73 ++++++++++++++++++++++++++++++++++++
gegl/graph/gegl-callback-visitor.h | 63 +++++++++++++++++++++++++++++++
3 files changed, 138 insertions(+), 0 deletions(-)
---
diff --git a/gegl/graph/Makefile.am b/gegl/graph/Makefile.am
index 9cbfc2b..9992065 100644
--- a/gegl/graph/Makefile.am
+++ b/gegl/graph/Makefile.am
@@ -28,6 +28,7 @@ libgraph_la_SOURCES = \
gegl-node.c \
gegl-pad.c \
gegl-visitor.c \
+ gegl-callback-visitor.c \
gegl-visitable.c \
\
gegl-connection.h \
@@ -35,6 +36,7 @@ libgraph_la_SOURCES = \
gegl-node-private.h \
gegl-pad.h \
gegl-visitor.h \
+ gegl-callback-visitor.h \
gegl-visitable.h
#libgraph_la_SOURCES = $(libgraph_sources) $(libgraph_public_HEADERS)
diff --git a/gegl/graph/gegl-callback-visitor.c b/gegl/graph/gegl-callback-visitor.c
new file mode 100644
index 0000000..c8ab737
--- /dev/null
+++ b/gegl/graph/gegl-callback-visitor.c
@@ -0,0 +1,73 @@
+/* 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 2017 Ell
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+
+#include "gegl.h"
+#include "gegl-types-internal.h"
+#include "gegl-callback-visitor.h"
+
+
+static void gegl_callback_visitor_class_init (GeglCallbackVisitorClass *klass);
+static void gegl_callback_visitor_init (GeglCallbackVisitor *self);
+static gboolean gegl_callback_visitor_visit_node (GeglVisitor *visitor,
+ GeglNode *node);
+
+
+G_DEFINE_TYPE (GeglCallbackVisitor, gegl_callback_visitor, GEGL_TYPE_VISITOR)
+
+
+static void
+gegl_callback_visitor_class_init (GeglCallbackVisitorClass *klass)
+{
+ GeglVisitorClass *visitor_class = GEGL_VISITOR_CLASS (klass);
+
+ visitor_class->visit_node = gegl_callback_visitor_visit_node;
+}
+
+static void
+gegl_callback_visitor_init (GeglCallbackVisitor *self)
+{
+}
+
+static gboolean
+gegl_callback_visitor_visit_node (GeglVisitor *visitor,
+ GeglNode *node)
+{
+ GeglCallbackVisitor *self = GEGL_CALLBACK_VISITOR (visitor);
+
+ return self->callback (node, self->data);
+}
+
+GeglVisitor *
+gegl_callback_visitor_new (GeglCallbackVisitorCallback callback,
+ gpointer data)
+{
+ GeglCallbackVisitor *self;
+
+ g_return_val_if_fail (callback != NULL, NULL);
+
+ self = g_object_new (GEGL_TYPE_CALLBACK_VISITOR, NULL);
+
+ self->callback = callback;
+ self->data = data;
+
+ return GEGL_VISITOR (self);
+}
diff --git a/gegl/graph/gegl-callback-visitor.h b/gegl/graph/gegl-callback-visitor.h
new file mode 100644
index 0000000..32c9cc5
--- /dev/null
+++ b/gegl/graph/gegl-callback-visitor.h
@@ -0,0 +1,63 @@
+/* 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 2017 Ell
+ */
+
+#ifndef __GEGL_CALLBACK_VISITOR_H__
+#define __GEGL_CALLBACK_VISITOR_H__
+
+#include "gegl-visitor.h"
+
+G_BEGIN_DECLS
+
+
+#define GEGL_TYPE_CALLBACK_VISITOR (gegl_callback_visitor_get_type ())
+#define GEGL_CALLBACK_VISITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GEGL_TYPE_CALLBACK_VISITOR, GeglCallbackVisitor))
+#define GEGL_CALLBACK_VISITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GEGL_TYPE_CALLBACK_VISITOR, GeglCallbackVisitorClass))
+#define GEGL_IS_CALLBACK_VISITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GEGL_TYPE_CALLBACK_VISITOR))
+#define GEGL_IS_CALLBACK_VISITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GEGL_TYPE_CALLBACK_VISITOR))
+#define GEGL_CALLBACK_VISITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GEGL_TYPE_CALLBACK_VISITOR, GeglCallbackVisitorClass))
+
+
+typedef gboolean (* GeglCallbackVisitorCallback) (GeglNode *node,
+ gpointer data);
+
+
+typedef struct _GeglCallbackVisitor GeglCallbackVisitor;
+typedef struct _GeglCallbackVisitorClass GeglCallbackVisitorClass;
+
+struct _GeglCallbackVisitor
+{
+ GeglVisitor parent_instance;
+
+ GeglCallbackVisitorCallback callback;
+ gpointer data;
+};
+
+struct _GeglCallbackVisitorClass
+{
+ GeglVisitorClass parent_class;
+};
+
+
+GType gegl_callback_visitor_get_type (void) G_GNUC_CONST;
+
+GeglVisitor * gegl_callback_visitor_new (GeglCallbackVisitorCallback callback,
+ gpointer data);
+
+G_END_DECLS
+
+#endif /* __GEGL_CALLBACK_VISITOR_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]