[vala/staging] libvaladoc: Prevent WITH_CGRAPH conditional having an impact on generated sources



commit 09390407f5b4e467e700bad9ad25a669e0a38722
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Dec 10 09:35:24 2017 +0100

    libvaladoc: Prevent WITH_CGRAPH conditional having an impact on generated sources

 libvaladoc/Makefile.am                    |    1 +
 libvaladoc/charts/chart.vala              |    6 ++--
 libvaladoc/charts/chartfactory.vala       |    8 ++---
 libvaladoc/charts/simplechartfactory.vala |   10 ++----
 libvaladoc/gvc-compat.c                   |   53 +++++++++++++++++++++++++++++
 5 files changed, 63 insertions(+), 15 deletions(-)
---
diff --git a/libvaladoc/Makefile.am b/libvaladoc/Makefile.am
index 271c88a..384292f 100644
--- a/libvaladoc/Makefile.am
+++ b/libvaladoc/Makefile.am
@@ -166,6 +166,7 @@ libvaladoc_la_VALASOURCES = \
 libvaladoc@PACKAGE_SUFFIX@_la_SOURCES = \
        libvaladoc.vala.stamp \
        $(libvaladoc_la_VALASOURCES:.vala=.c) \
+       gvc-compat.c \
        $(NULL)
 
 valadoc@PACKAGE_SUFFIX@.vapi valadoc.h: libvaladoc.vala.stamp
diff --git a/libvaladoc/charts/chart.vala b/libvaladoc/charts/chart.vala
index a6307d7..4e642d1 100644
--- a/libvaladoc/charts/chart.vala
+++ b/libvaladoc/charts/chart.vala
@@ -20,6 +20,8 @@
  *     Florian Brosch <flo brosch gmail com>
  */
 
+[CCode (cname = "valadoc_compat_gvc_init")]
+extern void valadoc_gvc_init ();
 
 public class Valadoc.Charts.Chart : Api.Visitor {
        protected Gvc.Context context;
@@ -27,9 +29,7 @@ public class Valadoc.Charts.Chart : Api.Visitor {
        protected Factory factory;
 
        static construct {
-               #if !WITH_CGRAPH
-               Gvc.init ();
-               #endif
+               valadoc_gvc_init ();
        }
 
        public Chart (Factory factory, Api.Node node) {
diff --git a/libvaladoc/charts/chartfactory.vala b/libvaladoc/charts/chartfactory.vala
index ab1ea73..4fee009 100644
--- a/libvaladoc/charts/chartfactory.vala
+++ b/libvaladoc/charts/chartfactory.vala
@@ -20,14 +20,12 @@
  *     Florian Brosch <flo brosch gmail com>
  */
 
+[CCode (cname = "valadoc_compat_gvc_graph_create_node")]
+extern Gvc.Node valadoc_gvc_graph_create_node (Gvc.Graph graph, string name);
 
 public abstract class Valadoc.Charts.Factory : Object {
        protected Gvc.Node create_type (Gvc.Graph graph, Api.Node item) {
-#if WITH_CGRAPH
-               return graph.create_node (item.get_full_name (), 1);
-#else
-               return graph.create_node (item.get_full_name ());
-#endif
+               return valadoc_gvc_graph_create_node (graph, item.get_full_name ());
        }
 
        public abstract Gvc.Graph create_graph (Api.Node item);
diff --git a/libvaladoc/charts/simplechartfactory.vala b/libvaladoc/charts/simplechartfactory.vala
index a1d080f..ddacbf0 100644
--- a/libvaladoc/charts/simplechartfactory.vala
+++ b/libvaladoc/charts/simplechartfactory.vala
@@ -20,7 +20,8 @@
  *     Florian Brosch <flo brosch gmail com>
  */
 
-
+[CCode (cname = "valadoc_compat_gvc_graph_new")]
+extern Gvc.Graph valadoc_gvc_graph_new (string name);
 
 public class Valadoc.Charts.SimpleFactory : Charts.Factory {
        protected virtual Gvc.Node configure_type (Gvc.Node node, Api.Node item) {
@@ -31,12 +32,7 @@ public class Valadoc.Charts.SimpleFactory : Charts.Factory {
        }
 
        public override Gvc.Graph create_graph (Api.Node item) {
-#if WITH_CGRAPH
-               var graph = new Gvc.Graph (item.get_full_name (), Gvc.Agdirected, 0);
-#else
-               var graph = new Gvc.Graph (item.get_full_name (), Gvc.GraphKind.AGDIGRAPH);
-#endif
-               return graph;
+               return valadoc_gvc_graph_new (item.get_full_name ());
        }
 
        public override Gvc.Context create_context (Gvc.Graph graph) {
diff --git a/libvaladoc/gvc-compat.c b/libvaladoc/gvc-compat.c
new file mode 100644
index 0000000..9ec37e6
--- /dev/null
+++ b/libvaladoc/gvc-compat.c
@@ -0,0 +1,53 @@
+/* gvc-compat.c
+ *
+ * Copyright (C) 2017  Rico Tzschichholz
+ *
+ * This library 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 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *  Rico Tzschichholz <ricotz ubuntu com>
+ */
+
+#include <gvc.h>
+
+/* Compat-layer for Graphviz with/without cgraph support */
+
+void
+valadoc_compat_gvc_init ()
+{
+#ifndef WITH_CGRAPH
+       aginit ();
+#endif
+}
+
+Agnode_t*
+valadoc_compat_gvc_graph_create_node (Agraph_t* graph, const char *name)
+{
+#ifdef WITH_CGRAPH
+       return agnode (graph, (char*) name, TRUE);
+#else
+       return agnode (graph, (char*) name);
+#endif
+}
+
+Agraph_t*
+valadoc_compat_gvc_graph_new (const char *name)
+{
+#ifdef WITH_CGRAPH
+       return agopen ((char*) name, Agdirected, NULL);
+#else
+       return agopen ((char*) name, AGDIGRAPH);
+#endif
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]