[apps/calculation] create a class evaluate context

Change-Id: Ic2aa40a00dec0ff67aeeb63edcb1776c3825cfbe
This commit is contained in:
Émilie Feral
2016-11-03 17:18:54 +01:00
parent 89cae4db30
commit 99af9b8692
3 changed files with 50 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ app_objs += $(addprefix apps/calculation/,\
app.o\
calculation.o\
calculation_store.o\
evaluate_context.o\
selectable_table_view.o\
history_view_cell.o\
history_controller.o\

View File

@@ -0,0 +1,27 @@
#include "evaluate_context.h"
#include <string.h>
namespace Calculation {
EvaluateContext::EvaluateContext(::Context * parentContext, CalculationStore * calculationStore) :
m_ansValue(Float(0.0f)),
m_calculationStore(calculationStore),
m_context(parentContext)
{
}
Float * EvaluateContext::ansValue() {
Calculation * lastCalculation = m_calculationStore->calculationAtIndex(m_calculationStore->numberOfCalculations()-1);
m_ansValue = Float(lastCalculation->evaluation());
return &m_ansValue;
}
const Expression * EvaluateContext::expressionForSymbol(const Symbol * symbol) {
if (symbol->name() == Symbol::SpecialSymbols::Ans) {
return ansValue();
} else {
return m_context->expressionForSymbol(symbol);
}
}
}

View File

@@ -0,0 +1,22 @@
#ifndef CALCULATION_EVALUATECONTEXT_H
#define CALCULATION_EVALUATECONTEXT_H
#include <poincare.h>
#include "calculation_store.h"
namespace Calculation {
class EvaluateContext : public ::Context {
public:
EvaluateContext(Context * parentContext, CalculationStore * calculationStore);
Float * ansValue();
const Expression * expressionForSymbol(const Symbol * symbol) override;
private:
Float m_ansValue;
CalculationStore * m_calculationStore;
::Context * m_context;
};
}
#endif