diff --git a/gtsam/discrete/AlgebraicDecisionTree.h b/gtsam/discrete/AlgebraicDecisionTree.h index 7e046199a..637f56066 100644 --- a/gtsam/discrete/AlgebraicDecisionTree.h +++ b/gtsam/discrete/AlgebraicDecisionTree.h @@ -29,6 +29,18 @@ namespace gtsam { */ template class GTSAM_EXPORT AlgebraicDecisionTree: public DecisionTree { + /** + * @brief Default method used by `labelFormatter` or `valueFormatter` when printing. + * + * @param x The value passed to format. + * @return std::string + */ + static std::string DefaultFormatter(const L& x) { + std::stringstream ss; + ss << x; + return ss.str(); + } + public: using Base = DecisionTree; @@ -149,7 +161,7 @@ namespace gtsam { /// print method customized to node type `double`. void print(const std::string& s, const typename Base::LabelFormatter& labelFormatter = - &Base::DefaultFormatter) const { + &DefaultFormatter) const { auto valueFormatter = [](const double& v) { return (boost::format("%4.2g") % v).str(); }; diff --git a/gtsam/discrete/DecisionTree.h b/gtsam/discrete/DecisionTree.h index 0717405dd..6aa97d8ac 100644 --- a/gtsam/discrete/DecisionTree.h +++ b/gtsam/discrete/DecisionTree.h @@ -45,18 +45,6 @@ namespace gtsam { return a == b; } - /** - * @brief Default method used by `labelFormatter` or `valueFormatter` when printing. - * - * @param x The value passed to format. - * @return std::string - */ - static std::string DefaultFormatter(const L& x) { - std::stringstream ss; - ss << x; - return ss.str(); - } - public: using LabelFormatter = std::function; @@ -101,14 +89,12 @@ namespace gtsam { const void* id() const { return this; } // everything else is virtual, no documentation here as internal - virtual void print( - const std::string& s, - const LabelFormatter& labelFormatter = &DefaultFormatter, - const ValueFormatter& valueFormatter = &DefaultFormatter) const = 0; - virtual void dot(std::ostream& os, - const LabelFormatter& labelFormatter = &DefaultFormatter, - const ValueFormatter& valueFormatter = &DefaultFormatter, - bool showZero = true) const = 0; + virtual void print(const std::string& s, + const LabelFormatter& labelFormatter, + const ValueFormatter& valueFormatter) const = 0; + virtual void dot(std::ostream& os, const LabelFormatter& labelFormatter, + const ValueFormatter& valueFormatter, + bool showZero) const = 0; virtual bool sameLeaf(const Leaf& q) const = 0; virtual bool sameLeaf(const Node& q) const = 0; virtual bool equals(const Node& other, const CompareFunc& compare = @@ -219,9 +205,8 @@ namespace gtsam { * @param labelFormatter Functor to format the node label. * @param valueFormatter Functor to format the node value. */ - void print(const std::string& s, - const LabelFormatter& labelFormatter = &DefaultFormatter, - const ValueFormatter& valueFormatter = &DefaultFormatter) const; + void print(const std::string& s, const LabelFormatter& labelFormatter, + const ValueFormatter& valueFormatter) const; // Testable bool equals(const DecisionTree& other, @@ -266,20 +251,16 @@ namespace gtsam { } /** output to graphviz format, stream version */ - void dot(std::ostream& os, - const LabelFormatter& labelFormatter = &DefaultFormatter, - const ValueFormatter& valueFormatter = &DefaultFormatter, - bool showZero = true) const; + void dot(std::ostream& os, const LabelFormatter& labelFormatter, + const ValueFormatter& valueFormatter, bool showZero = true) const; /** output to graphviz format, open a file */ - void dot(const std::string& name, - const LabelFormatter& labelFormatter = &DefaultFormatter, - const ValueFormatter& valueFormatter = &DefaultFormatter, - bool showZero = true) const; + void dot(const std::string& name, const LabelFormatter& labelFormatter, + const ValueFormatter& valueFormatter, bool showZero = true) const; /** output to graphviz format string */ - std::string dot(const LabelFormatter& labelFormatter = &DefaultFormatter, - const ValueFormatter& valueFormatter = &DefaultFormatter, + std::string dot(const LabelFormatter& labelFormatter, + const ValueFormatter& valueFormatter, bool showZero = true) const; /// @name Advanced Interface