1 /* This file is part of GEGL
2  *
3  * GEGL is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 3 of the License, or (at your option) any later version.
7  *
8  * GEGL is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with GEGL; if not, see <https://www.gnu.org/licenses/>.
15  *
16  * Copyright 2017 Ell
17  */
18 
19 #include "config.h"
20 
21 #include <glib-object.h>
22 
23 #include "gegl-types-internal.h"
24 
25 #include "gegl.h"
26 #include "gegl-connection.h"
27 #include "gegl-node-output-visitable.h"
28 #include "gegl-node-private.h"
29 #include "gegl-pad.h"
30 #include "gegl-visitable.h"
31 #include "gegl-visitor.h"
32 
33 
34 static void       gegl_node_output_visitable_class_init           (GeglNodeOutputVisitableClass *klass);
35 static void       gegl_node_output_visitable_init                 (GeglNodeOutputVisitable      *self);
36 static void       gegl_node_output_visitable_visitable_iface_init (gpointer                      ginterface,
37                                                                    gpointer                      interface_data);
38 static gboolean   gegl_node_output_visitable_visitable_accept     (GeglVisitable                *visitable,
39                                                                    GeglVisitor                  *visitor);
40 static GSList   * gegl_node_output_visitable_visitable_depends_on (GeglVisitable                *visitable);
41 
42 
G_DEFINE_TYPE_WITH_CODE(GeglNodeOutputVisitable,gegl_node_output_visitable,G_TYPE_OBJECT,G_IMPLEMENT_INTERFACE (GEGL_TYPE_VISITABLE,gegl_node_output_visitable_visitable_iface_init))43 G_DEFINE_TYPE_WITH_CODE (GeglNodeOutputVisitable, gegl_node_output_visitable, G_TYPE_OBJECT,
44                          G_IMPLEMENT_INTERFACE (GEGL_TYPE_VISITABLE,
45                                                 gegl_node_output_visitable_visitable_iface_init))
46 
47 
48 static void
49 gegl_node_output_visitable_class_init (GeglNodeOutputVisitableClass *klass)
50 {
51 }
52 
53 static void
gegl_node_output_visitable_init(GeglNodeOutputVisitable * self)54 gegl_node_output_visitable_init (GeglNodeOutputVisitable *self)
55 {
56   self->node = NULL;
57 }
58 
59 static void
gegl_node_output_visitable_visitable_iface_init(gpointer ginterface,gpointer interface_data)60 gegl_node_output_visitable_visitable_iface_init (gpointer ginterface,
61                                                  gpointer interface_data)
62 {
63   GeglVisitableClass *visitable_class = ginterface;
64 
65   visitable_class->accept     = gegl_node_output_visitable_visitable_accept;
66   visitable_class->depends_on = gegl_node_output_visitable_visitable_depends_on;
67 }
68 
69 static gboolean
gegl_node_output_visitable_visitable_accept(GeglVisitable * visitable,GeglVisitor * visitor)70 gegl_node_output_visitable_visitable_accept (GeglVisitable *visitable,
71                                              GeglVisitor   *visitor)
72 {
73   GeglNodeOutputVisitable *self = GEGL_NODE_OUTPUT_VISITABLE (visitable);
74 
75   return gegl_visitor_visit_node (visitor, self->node);
76 }
77 
78 static GSList *
gegl_node_output_visitable_visitable_depends_on(GeglVisitable * visitable)79 gegl_node_output_visitable_visitable_depends_on (GeglVisitable *visitable)
80 {
81   GeglNodeOutputVisitable *self         = GEGL_NODE_OUTPUT_VISITABLE (visitable);
82   GSList                  *dependencies = NULL;
83   GSList                  *iter;
84 
85   for (iter = gegl_node_get_sinks (self->node); iter; iter = g_slist_next (iter))
86     {
87       GeglConnection *connection = iter->data;
88       GeglNode       *sink_node;
89       GeglVisitable  *sink_visitable;
90 
91       sink_node      = gegl_connection_get_sink_node (connection);
92       sink_visitable = gegl_node_get_output_visitable (sink_node);
93 
94       dependencies = g_slist_prepend (dependencies, sink_visitable);
95     }
96 
97   return dependencies;
98 }
99 
100 GeglVisitable *
gegl_node_output_visitable_new(GeglNode * node)101 gegl_node_output_visitable_new (GeglNode *node)
102 {
103   GeglNodeOutputVisitable *self;
104 
105   g_return_val_if_fail (GEGL_IS_NODE (node), NULL);
106 
107   self = g_object_new (GEGL_TYPE_NODE_OUTPUT_VISITABLE, NULL);
108 
109   self->node = node;
110 
111   return GEGL_VISITABLE (self);
112 }
113