mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/calculation] create a class evaluate context
Change-Id: Ic2aa40a00dec0ff67aeeb63edcb1776c3825cfbe
This commit is contained in:
@@ -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\
|
||||
|
||||
27
apps/calculation/evaluate_context.cpp
Normal file
27
apps/calculation/evaluate_context.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
22
apps/calculation/evaluate_context.h
Normal file
22
apps/calculation/evaluate_context.h
Normal 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
|
||||
Reference in New Issue
Block a user