summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test-graph.c26
-rw-r--r--ufo/ufo-graph.c22
-rw-r--r--ufo/ufo-graph.h18
3 files changed, 59 insertions, 7 deletions
diff --git a/tests/test-graph.c b/tests/test-graph.c
index 1184a0a..d50857e 100644
--- a/tests/test-graph.c
+++ b/tests/test-graph.c
@@ -124,6 +124,28 @@ test_get_num_edges (Fixture *fixture, gconstpointer data)
}
static void
+test_get_edges (Fixture *fixture, gconstpointer data)
+{
+ GList *edges;
+ UfoEdge *edge;
+
+ edges = ufo_graph_get_edges (fixture->graph);
+ g_assert (g_list_length (edges) == 2);
+
+ edge = g_list_nth_data (edges, 0);
+ g_assert (edge->source == fixture->root);
+ g_assert (edge->target == fixture->target1 ||
+ edge->target == fixture->target2);
+
+ edge = g_list_nth_data (edges, 1);
+ g_assert (edge->source == fixture->root);
+ g_assert (edge->target == fixture->target1 ||
+ edge->target == fixture->target2);
+
+ g_list_free (edges);
+}
+
+static void
test_get_successors (Fixture *fixture, gconstpointer data)
{
GList *successors;
@@ -231,6 +253,10 @@ test_add_graph (void)
Fixture, NULL,
fixture_setup, test_get_num_edges, fixture_teardown);
+ g_test_add ("/graph/edges/get",
+ Fixture, NULL,
+ fixture_setup, test_get_edges, fixture_teardown);
+
g_test_add ("/graph/get-successors",
Fixture, NULL,
fixture_setup, test_get_successors, fixture_teardown);
diff --git a/ufo/ufo-graph.c b/ufo/ufo-graph.c
index fe6644d..826f13f 100644
--- a/ufo/ufo-graph.c
+++ b/ufo/ufo-graph.c
@@ -31,12 +31,6 @@ G_DEFINE_TYPE (UfoGraph, ufo_graph, G_TYPE_OBJECT)
#define UFO_GRAPH_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UFO_TYPE_GRAPH, UfoGraphPrivate))
-typedef struct {
- UfoNode *source;
- UfoNode *target;
- gpointer label;
-} UfoEdge;
-
struct _UfoGraphPrivate {
GList *node_types;
GList *nodes;
@@ -220,6 +214,22 @@ ufo_graph_get_num_edges (UfoGraph *graph)
}
/**
+ * ufo_graph_get_edges:
+ * @graph: A #UfoGraph
+ *
+ * Get all edges contained in @graph.
+ *
+ * Returns: (element-type UfoEdge): a list of #UfoEdge elements or %NULL on
+ * error. Release the list with g_list_free().
+ */
+GList *
+ufo_graph_get_edges (UfoGraph *graph)
+{
+ g_return_val_if_fail (UFO_IS_GRAPH (graph), NULL);
+ return g_list_copy (graph->priv->edges);
+}
+
+/**
* ufo_graph_get_nodes:
* @graph: A #UfoGraph
*
diff --git a/ufo/ufo-graph.h b/ufo/ufo-graph.h
index b39c31c..4e1a0d9 100644
--- a/ufo/ufo-graph.h
+++ b/ufo/ufo-graph.h
@@ -38,10 +38,25 @@ G_BEGIN_DECLS
typedef struct _UfoGraph UfoGraph;
typedef struct _UfoGraphClass UfoGraphClass;
typedef struct _UfoGraphPrivate UfoGraphPrivate;
+typedef struct _UfoEdge UfoEdge;
typedef gboolean (*UfoFilterPredicate) (UfoNode *node, gpointer user_data);
/**
+ * UfoEdge:
+ * @source: source node
+ * @target: target node
+ * @label: label
+ *
+ * An edge in a #UfoGraph.
+ */
+struct _UfoEdge {
+ UfoNode *source;
+ UfoNode *target;
+ gpointer label;
+};
+
+/**
* UfoGraph:
*
* Main object for organizing filters. The contents of the #UfoGraph structure
@@ -83,11 +98,12 @@ gpointer ufo_graph_get_edge_label (UfoGraph *graph,
UfoNode *source,
UfoNode *target);
guint ufo_graph_get_num_nodes (UfoGraph *graph);
-guint ufo_graph_get_num_edges (UfoGraph *graph);
GList *ufo_graph_get_nodes (UfoGraph *graph);
GList *ufo_graph_get_nodes_filtered (UfoGraph *graph,
UfoFilterPredicate func,
gpointer user_data);
+guint ufo_graph_get_num_edges (UfoGraph *graph);
+GList *ufo_graph_get_edges (UfoGraph *graph);
GList *ufo_graph_get_roots (UfoGraph *graph);
GList *ufo_graph_get_leaves (UfoGraph *graph);
GList *ufo_graph_get_predecessors (UfoGraph *graph,