mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps] Calculation: move implementation of ansExpression() from
Calculation to CalculationStore
This commit is contained in:
committed by
EmilieNumworks
parent
d43fc1b6eb
commit
36a3108309
@@ -64,10 +64,10 @@ void Calculation::reset() {
|
||||
tidy();
|
||||
}
|
||||
|
||||
void Calculation::setContent(const char * c, Context * context, CalculationStore * calculationStore) {
|
||||
void Calculation::setContent(const char * c, Context * context, Expression * ansExpression) {
|
||||
reset();
|
||||
m_input = Expression::parse(c);
|
||||
Expression::ReplaceSymbolWithExpression(&m_input, Symbol::SpecialSymbols::Ans, ansExpression(calculationStore, context));
|
||||
Expression::ReplaceSymbolWithExpression(&m_input, Symbol::SpecialSymbols::Ans, ansExpression);
|
||||
/* We do not store directly the text enter by the user but its serialization
|
||||
* to be able to compare it to the exact ouput text. */
|
||||
m_input->writeTextInBuffer(m_inputText, sizeof(m_inputText));
|
||||
@@ -192,16 +192,4 @@ bool Calculation::shouldDisplayApproximateOutput(Context * context) {
|
||||
return input()->isApproximate(*context);
|
||||
}
|
||||
|
||||
Expression * Calculation::ansExpression(CalculationStore * calculationStore, Context * context) {
|
||||
if (calculationStore->numberOfCalculations() == 0) {
|
||||
static Rational defaultExpression(0);
|
||||
return &defaultExpression;
|
||||
}
|
||||
Calculation * lastCalculation = calculationStore->calculationAtIndex(calculationStore->numberOfCalculations()-1);
|
||||
if (lastCalculation->input()->isApproximate(*context)) {
|
||||
return lastCalculation->approximateOutput(context);
|
||||
}
|
||||
return lastCalculation->exactOutput(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
Calculation& operator=(Calculation&& other) = delete;
|
||||
/* c.reset() is the equivalent of c = Calculation() without copy assingment. */
|
||||
void reset();
|
||||
void setContent(const char * c, Poincare::Context * context, CalculationStore * calculationStore);
|
||||
void setContent(const char * c, Poincare::Context * context, Poincare::Expression * ansExpression);
|
||||
const char * inputText();
|
||||
const char * exactOutputText();
|
||||
const char * approximateOutputText();
|
||||
@@ -33,7 +33,6 @@ public:
|
||||
bool shouldDisplayApproximateOutput(Poincare::Context * context);
|
||||
constexpr static int k_printedExpressionSize = 2*::TextField::maxBufferSize();
|
||||
private:
|
||||
Poincare::Expression * ansExpression(CalculationStore * calculationStore, Poincare::Context * context);
|
||||
/* Buffers holding text expressions have to be longer than the text written
|
||||
* by user (of maximum length TextField::maxBufferSize()) because when we
|
||||
* print an expression we add omitted signs (multiplications, parenthesis...) */
|
||||
|
||||
@@ -11,7 +11,7 @@ CalculationStore::CalculationStore() :
|
||||
|
||||
Calculation * CalculationStore::push(const char * text, Context * context) {
|
||||
Calculation * result = &m_calculations[m_startIndex];
|
||||
result->setContent(text, context, this);
|
||||
result->setContent(text, context, ansExpression(context));
|
||||
m_startIndex++;
|
||||
if (m_startIndex >= k_maxNumberOfCalculations) {
|
||||
m_startIndex = 0;
|
||||
@@ -89,4 +89,16 @@ void CalculationStore::tidy() {
|
||||
}
|
||||
}
|
||||
|
||||
Expression * CalculationStore::ansExpression(Context * context) {
|
||||
if (numberOfCalculations() == 0) {
|
||||
static Rational defaultExpression(0);
|
||||
return &defaultExpression;
|
||||
}
|
||||
Calculation * lastCalculation = calculationAtIndex(numberOfCalculations()-1);
|
||||
if (lastCalculation->input()->isApproximate(*context)) {
|
||||
return lastCalculation->approximateOutput(context);
|
||||
}
|
||||
return lastCalculation->exactOutput(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
void deleteAll();
|
||||
int numberOfCalculations();
|
||||
void tidy();
|
||||
Poincare::Expression * ansExpression(Poincare::Context * context);
|
||||
static constexpr int k_maxNumberOfCalculations = 10;
|
||||
private:
|
||||
int m_startIndex;
|
||||
|
||||
Reference in New Issue
Block a user