Files
Upsilon/apps/calculation/calculation_store.cpp
Émilie Feral 65235d0551 [apps/calculation] Fix bug with ans
Change-Id: I8691c7901783e61518eae2cdb33632f2eb3e9247
2017-03-31 16:59:43 +02:00

65 lines
1.5 KiB
C++

#include "calculation_store.h"
#include <assert.h>
using namespace Poincare;
namespace Calculation {
CalculationStore::CalculationStore() :
m_start(m_calculations)
{
}
Calculation * CalculationStore::push(const char * text, Context * context) {
Calculation * result = m_start;
m_start->setContent(text, context);
m_start++;
if (m_start >= m_calculations + k_maxNumberOfCalculations) {
m_start = m_calculations;
}
return result;
}
Calculation * CalculationStore::calculationAtIndex(int i) {
int j = 0;
Calculation * currentCalc = m_start;
Calculation * previousCalc = nullptr;
while (j <= i) {
if (!currentCalc++->isEmpty()) {
previousCalc = currentCalc - 1;
j++;
}
if (currentCalc >= m_calculations + k_maxNumberOfCalculations) {
currentCalc = m_calculations;
}
}
return previousCalc;
}
int CalculationStore::numberOfCalculations() {
Calculation * currentCalc= m_calculations;
int numberOfCalculations = 0;
while (currentCalc < m_calculations + k_maxNumberOfCalculations) {
if (!currentCalc++->isEmpty()) {
numberOfCalculations++;
}
}
return numberOfCalculations;
}
void CalculationStore::deleteCalculationAtIndex(int i) {
calculationAtIndex(i)->reset();
}
void CalculationStore::deleteAll() {
m_start = m_calculations;
Calculation * currentCalc= m_start;
while (currentCalc < m_calculations + k_maxNumberOfCalculations) {
if (!currentCalc->isEmpty()) {
currentCalc->reset();
}
currentCalc++;
}
}
}