From 186afcc95ef7286bfa3c1c514417e494781a43dc Mon Sep 17 00:00:00 2001 From: dellaert Date: Sat, 27 Sep 2014 15:58:34 +0200 Subject: [PATCH] Made constructors private --- gtsam_unstable/base/tests/testBAD.cpp | 44 ++++++++++++++++++--------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/gtsam_unstable/base/tests/testBAD.cpp b/gtsam_unstable/base/tests/testBAD.cpp index 9e3bd80fb..8443114cc 100644 --- a/gtsam_unstable/base/tests/testBAD.cpp +++ b/gtsam_unstable/base/tests/testBAD.cpp @@ -38,9 +38,10 @@ namespace gtsam { /// http://loki-lib.sourceforge.net/html/a00652.html template class ExpressionNode { -public: +protected: ExpressionNode() { } +public: virtual ~ExpressionNode() { } virtual void getKeys(std::set& keys) const = 0; @@ -57,12 +58,15 @@ class ConstantExpression: public ExpressionNode { T value_; -public: - /// Constructor with a value, yielding a constant ConstantExpression(const T& value) : value_(value) { } + + friend class Expression ; + +public: + virtual ~ConstantExpression() { } @@ -81,12 +85,15 @@ class LeafExpression: public ExpressionNode { Key key_; -public: - /// Constructor with a single key LeafExpression(Key key) : key_(key) { } + + friend class Expression ; + +public: + virtual ~LeafExpression() { } @@ -124,12 +131,15 @@ private: boost::shared_ptr > expression_; function f_; + /// Constructor with a unary function f, and input argument e + UnaryExpression(function f, const Expression& e) : + expression_(e.root()), f_(f) { + } + + friend class Expression ; + public: - /// Constructor with a single key - UnaryExpression(function f, const Expression& expression) : - expression_(expression.root()), f_(f) { - } virtual ~UnaryExpression() { } @@ -172,13 +182,16 @@ private: boost::shared_ptr > expression2_; function f_; + /// Constructor with a binary function f, and two input arguments + BinaryExpression(function f, // + const Expression& e1, const Expression& e2) : + expression1_(e1.root()), expression2_(e2.root()), f_(f) { + } + + friend class Expression ; + public: - /// Constructor with a single key - BinaryExpression(function f, const Expression& expression1, - const Expression& expression2) : - expression1_(expression1.root()), expression2_(expression2.root()), f_(f) { - } virtual ~BinaryExpression() { } @@ -371,6 +384,9 @@ TEST(BAD, test) { double expected_error = old.error(values); GaussianFactor::shared_ptr expected = old.linearize(values); + // Test Constant expression + Expression c(0); + // Create leaves Expression x(1); Expression p(2);