Updates the addition code to use attributes.

We use a left and right attribtes instead of a children table.

Change-Id: Ic11846bcf0763c717834124d626cb352a30e1045
This commit is contained in:
Felix Raimundo
2016-03-16 11:55:29 +01:00
committed by Félix Raimundo
parent b33eb99067
commit 0059fe78fa
2 changed files with 8 additions and 7 deletions

View File

@@ -10,7 +10,8 @@ class Addition : public Expression {
ExpressionLayout * createLayout(ExpressionLayout * parent) override;
float approximate(Context& context) override;
private:
Expression * m_children[2];
Expression * m_left;
Expression * m_right;
};
#endif

View File

@@ -2,19 +2,19 @@
#include "layout/horizontal_layout.h"
Addition::Addition(Expression * first_operand, Expression * second_operand) {
m_children[0] = first_operand;
m_children[1] = second_operand;
m_left = first_operand;
m_right = second_operand;
}
Addition::~Addition() {
delete m_children[1];
delete m_children[0];
delete m_left;
delete m_right;
}
float Addition::approximate(Context& context) {
return m_children[0]->approximate(context) + m_children[1]->approximate(context);
return m_left->approximate(context) + m_right->approximate(context);
}
ExpressionLayout * Addition::createLayout(ExpressionLayout * parent) {
return new HorizontalLayout(parent, m_children[0], '+', m_children[1]);
return new HorizontalLayout(parent, m_left, '+', m_right);
}