From fd48028f24ca5b2193c880b7be26a7a99a010491 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sun, 9 Jan 2022 15:06:57 -0500 Subject: [PATCH] Make free versions and wrap --- gtsam/discrete/DiscreteValues.cpp | 15 +++++++++++++-- gtsam/discrete/DiscreteValues.h | 19 ++++++++++++++++--- gtsam/discrete/discrete.i | 12 ++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/gtsam/discrete/DiscreteValues.cpp b/gtsam/discrete/DiscreteValues.cpp index 9bd0572bd..8a09de742 100644 --- a/gtsam/discrete/DiscreteValues.cpp +++ b/gtsam/discrete/DiscreteValues.cpp @@ -60,8 +60,8 @@ string DiscreteValues::markdown(const KeyFormatter& keyFormatter, return ss.str(); } -std::string DiscreteValues::html(const KeyFormatter& keyFormatter, - const Names& names) const { +string DiscreteValues::html(const KeyFormatter& keyFormatter, + const Names& names) const { stringstream ss; // Print out preamble. @@ -83,4 +83,15 @@ std::string DiscreteValues::html(const KeyFormatter& keyFormatter, ss << " \n\n"; return ss.str(); } + +string markdown(const DiscreteValues& values, const KeyFormatter& keyFormatter, + const DiscreteValues::Names& names) { + return values.markdown(keyFormatter, names); +} + +string html(const DiscreteValues& values, const KeyFormatter& keyFormatter, + const DiscreteValues::Names& names) { + return values.html(keyFormatter, names); +} + } // namespace gtsam diff --git a/gtsam/discrete/DiscreteValues.h b/gtsam/discrete/DiscreteValues.h index 3d0c54ab6..81997a783 100644 --- a/gtsam/discrete/DiscreteValues.h +++ b/gtsam/discrete/DiscreteValues.h @@ -21,7 +21,9 @@ #include #include +#include #include +#include namespace gtsam { @@ -71,8 +73,8 @@ class DiscreteValues : public Assignment { * @param names translation table for values. * @return string markdown output. */ - std::string markdown(const KeyFormatter& keyFormatter, - const Names& names) const; + std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter, + const Names& names = {}) const; /** * @brief Output as a html table. @@ -81,11 +83,22 @@ class DiscreteValues : public Assignment { * @param names translation table for values. * @return string html output. */ - std::string html(const KeyFormatter& keyFormatter, const Names& names) const; + std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter, + const Names& names = {}) const; /// @} }; +/// Free version of markdown. +std::string markdown(const DiscreteValues& values, + const KeyFormatter& keyFormatter = DefaultKeyFormatter, + const DiscreteValues::Names& names = {}); + +/// Free version of html. +std::string html(const DiscreteValues& values, + const KeyFormatter& keyFormatter = DefaultKeyFormatter, + const DiscreteValues::Names& names = {}); + // traits template <> struct traits : public Testable {}; diff --git a/gtsam/discrete/discrete.i b/gtsam/discrete/discrete.i index 9bf324fd3..218b790e8 100644 --- a/gtsam/discrete/discrete.i +++ b/gtsam/discrete/discrete.i @@ -17,6 +17,18 @@ class DiscreteKeys { }; // DiscreteValues is added in specializations/discrete.h as a std::map +string markdown( + const gtsam::DiscreteValues& values, + const gtsam::KeyFormatter& keyFormatter = gtsam::DefaultKeyFormatter); +string markdown(const gtsam::DiscreteValues& values, + const gtsam::KeyFormatter& keyFormatter, + std::map> names); +string html( + const gtsam::DiscreteValues& values, + const gtsam::KeyFormatter& keyFormatter = gtsam::DefaultKeyFormatter); +string html(const gtsam::DiscreteValues& values, + const gtsam::KeyFormatter& keyFormatter, + std::map> names); #include class DiscreteFactor {