Permalink
Browse files

Make pretty tree printing optional (configure option)

  • Loading branch information...
1 parent 4abca71 commit 1bff742744b0573f0211cd0efa5765b3289cf172 @hyperair committed Apr 8, 2012
Showing with 49 additions and 0 deletions.
  1. +11 −0 configure.ac
  2. +38 −0 src/fptree.cc
View
@@ -3,6 +3,7 @@
AC_INIT([fptree], [0.1], [hyperair@gmail.com])
AC_CONFIG_SRCDIR([src/transactions.hh])
+AC_CONFIG_HEADERS([config.h])
AC_CANONICAL_HOST
AM_INIT_AUTOMAKE([foreign dist-zip])
@@ -20,5 +21,15 @@ esac
AM_CONDITIONAL([WINDOWS], [test "$is_windows" = "yes"])
+AC_ARG_ENABLE([pretty-tree-printing],
+ [AS_HELP_STRING([--enable-pretty-tree-printing],
+ [Use alternative tree dumping format])],,
+ [enable_pretty_tree_printing=no])
+
+if test "$enable_pretty_tree_printing" = "yes"; then
+ AC_DEFINE([WITH_PRETTY_TREE_PRINTING], [1],
+ [Define to Use alternative tree dumping format])
+fi
+
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
View
@@ -5,6 +5,10 @@
#include <memory>
#include <sstream>
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
using fpt::fptree;
class fptree::node : public std::enable_shared_from_this<node>
@@ -129,6 +133,8 @@ fptree::stats::stats () :
{}
+#ifdef WITH_PRETTY_TREE_PRINTING
+
std::ostream &fpt::operator<< (std::ostream &out, const fptree::node &node)
{
out << node.item << " (f=" << node.counter << ")" << std::endl;
@@ -170,3 +176,35 @@ std::ostream &fpt::operator<< (std::ostream &out, const fptree &tree)
return out;
}
+
+#else
+
+std::ostream &fpt::operator<< (std::ostream &out, const fptree::node &node)
+{
+ for (const auto &i : node.item_order) {
+ auto j = node.children.find (i.item);
+
+ if (j != node.children.end ()) {
+ assert (j->second);
+ out << *j->second;
+ }
+ }
+
+ return out << node.item << " " << node.counter << std::endl;
+}
+
+std::ostream &fpt::operator<< (std::ostream &out, const fptree &tree)
+{
+ for (const auto &i : tree.item_order) {
+ auto j = tree.roots.find (i.item);
+
+ if (j != tree.roots.end ()) {
+ assert (j->second);
+ out << *j->second;
+ }
+ }
+
+ return out;
+}
+
+#endif // WITH_PRETTY_TREE_PRINTING

0 comments on commit 1bff742

Please sign in to comment.