diff --git a/gtsam/nonlinear/Expression.h b/gtsam/nonlinear/Expression.h index afbc5e93a..d24a568f5 100644 --- a/gtsam/nonlinear/Expression.h +++ b/gtsam/nonlinear/Expression.h @@ -60,7 +60,9 @@ private: public: // Expressions wrap trees of functions that can evaluate their own derivatives. - // The meta-functions below provide a handy to specify the type of those functions + // The meta-functions below are useful to specify the type of those functions. + // Example, a function taking a camera and a 3D point and yielding a 2D point: + // Expression::BinaryFunction::type template struct UnaryFunction { typedef boost::function< @@ -135,6 +137,10 @@ public: typename MakeOptionalJacobian::type) const, const Expression& expression2, const Expression& expression3); + /// Destructor + virtual ~Expression() { + } + /// Return keys that play in this expression std::set keys() const; diff --git a/gtsam/nonlinear/internal/ExpressionNode.h b/gtsam/nonlinear/internal/ExpressionNode.h index 6e47adef0..e7aa34db0 100644 --- a/gtsam/nonlinear/internal/ExpressionNode.h +++ b/gtsam/nonlinear/internal/ExpressionNode.h @@ -129,6 +129,10 @@ class ConstantExpression: public ExpressionNode { public: + /// Destructor + virtual ~ConstantExpression() { + } + /// Return value virtual T value(const Values& values) const { return constant_; @@ -154,12 +158,15 @@ class LeafExpression: public ExpressionNode { LeafExpression(Key key) : key_(key) { } - // todo: do we need a virtual destructor here too? friend class Expression ; public: + /// Destructor + virtual ~LeafExpression() { + } + /// Return keys that play in this expression virtual std::set keys() const { std::set keys; @@ -205,18 +212,23 @@ class UnaryExpression: public ExpressionNode { boost::shared_ptr > expression1_; Function function_; -public: - /// Constructor with a unary function f, and input argument e1 UnaryExpression(Function f, const Expression& e1) : expression1_(e1.root()), function_(f) { ExpressionNode::traceSize_ = upAligned(sizeof(Record)) + e1.traceSize(); } + friend class Expression ; + +public: + + /// Destructor + virtual ~UnaryExpression() { + } + /// Return value virtual T value(const Values& values) const { - using boost::none; - return function_(expression1_->value(values), none); + return function_(expression1_->value(values), boost::none); } /// Return keys that play in this expression @@ -300,8 +312,6 @@ class BinaryExpression: public ExpressionNode { boost::shared_ptr > expression2_; Function function_; -public: - /// Constructor with a binary function f, and two input arguments BinaryExpression(Function f, const Expression& e1, const Expression& e2) : @@ -310,8 +320,15 @@ public: upAligned(sizeof(Record)) + e1.traceSize() + e2.traceSize(); } + friend class Expression ; friend class ::ExpressionFactorBinaryTest; +public: + + /// Destructor + virtual ~BinaryExpression() { + } + /// Return value virtual T value(const Values& values) const { using boost::none; @@ -394,8 +411,6 @@ class TernaryExpression: public ExpressionNode { boost::shared_ptr > expression3_; Function function_; -public: - /// Constructor with a ternary function f, and two input arguments TernaryExpression(Function f, const Expression& e1, const Expression& e2, const Expression& e3) : @@ -405,6 +420,14 @@ public: e1.traceSize() + e2.traceSize() + e3.traceSize(); } + friend class Expression ; + +public: + + /// Destructor + virtual ~TernaryExpression() { + } + /// Return value virtual T value(const Values& values) const { using boost::none;