Removed the clone method

release/4.3a0
Paul Furgale 2014-09-27 15:01:02 +02:00
parent 9eed7e10fe
commit 768c7f00e1
1 changed files with 10 additions and 15 deletions

View File

@ -44,9 +44,11 @@ class ExpressionNode {
virtual void getKeys(std::set<Key>& keys) const = 0; virtual void getKeys(std::set<Key>& keys) const = 0;
virtual T value(const Values& values, virtual T value(const Values& values,
boost::optional<std::map<Key, Matrix>&> = boost::none) const = 0; boost::optional<std::map<Key, Matrix>&> = boost::none) const = 0;
virtual ExpressionNode<T>* clone() const = 0;
}; };
template<typename T>
class Expression;
/// Constant Expression /// Constant Expression
template<class T> template<class T>
class ConstantExpression : public ExpressionNode<T> { class ConstantExpression : public ExpressionNode<T> {
@ -68,7 +70,6 @@ class ConstantExpression : public ExpressionNode<T> {
boost::optional<std::map<Key, Matrix>&> jacobians = boost::none) const { boost::optional<std::map<Key, Matrix>&> jacobians = boost::none) const {
return value_; return value_;
} }
virtual ExpressionNode<T>* clone() const { return new ConstantExpression(*this); }
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -103,7 +104,6 @@ class LeafExpression : public ExpressionNode<T> {
return value; return value;
} }
virtual ExpressionNode<T>* clone() const { return new LeafExpression(*this); }
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -125,8 +125,8 @@ class UnaryExpression : public ExpressionNode<T> {
typedef T type; typedef T type;
/// Constructor with a single key /// Constructor with a single key
UnaryExpression(function f, const ExpressionNode<E>& expression) : UnaryExpression(function f, const Expression<E>& expression) :
expression_(expression.clone()), f_(f) { expression_(expression.root()), f_(f) {
} }
virtual ~UnaryExpression(){} virtual ~UnaryExpression(){}
@ -148,7 +148,6 @@ class UnaryExpression : public ExpressionNode<T> {
return value; return value;
} }
virtual ExpressionNode<T>* clone() const { return new UnaryExpression(*this); }
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -173,8 +172,8 @@ class BinaryExpression : public ExpressionNode<T> {
typedef T type; typedef T type;
/// Constructor with a single key /// Constructor with a single key
BinaryExpression(function f, const ExpressionNode<E1>& expression1, const ExpressionNode<E2>& expression2) : BinaryExpression(function f, const Expression<E1>& expression1, const Expression<E2>& expression2) :
expression1_(expression1.clone()), expression2_(expression2.clone()), f_(f) { expression1_(expression1.root()), expression2_(expression2.root()), f_(f) {
} }
virtual ~BinaryExpression(){} virtual ~BinaryExpression(){}
@ -216,15 +215,11 @@ class BinaryExpression : public ExpressionNode<T> {
return val; return val;
} }
virtual ExpressionNode<T>* clone() const { return new BinaryExpression(*this); }
}; };
template<typename T> template<typename T>
class Expression { class Expression {
public: public:
Expression(const ExpressionNode<T>& root) {
root_.reset(root.clone());
}
// Initialize a constant expression // Initialize a constant expression
Expression(const T& value) : Expression(const T& value) :
@ -239,7 +234,7 @@ class Expression {
Expression(typename UnaryExpression<T,E>::function f, Expression(typename UnaryExpression<T,E>::function f,
const Expression<E>& expression) { const Expression<E>& expression) {
// TODO Assert that root of expression is not null. // TODO Assert that root of expression is not null.
root_.reset(new UnaryExpression<T,E>(f, *expression.root())); root_.reset(new UnaryExpression<T,E>(f, expression));
} }
/// Initialize a binary expression /// Initialize a binary expression
@ -248,8 +243,8 @@ class Expression {
const Expression<E1>& expression1, const Expression<E1>& expression1,
const Expression<E2>& expression2) { const Expression<E2>& expression2) {
// TODO Assert that root of expressions 1 and 2 are not null. // TODO Assert that root of expressions 1 and 2 are not null.
root_.reset(new BinaryExpression<T,E1,E2>(f, *expression1.root(), root_.reset(new BinaryExpression<T,E1,E2>(f, expression1,
*expression2.root())); expression2));
} }
void getKeys(std::set<Key>& keys) const { root_->getKeys(keys); } void getKeys(std::set<Key>& keys) const { root_->getKeys(keys); }