Files
Upsilon/apps/calculation/calculation_store.cpp
Émilie Feral 71284311bb [escher] [apps] Implement app snapshot
Change-Id: I24d7eed7cef964af8be1c85222e758c297dc0da1
2017-05-18 14:16:41 +02:00

71 lines
1.6 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++;
}
}
void CalculationStore::tidy() {
for (int i = 0; i < k_maxNumberOfCalculations; i++) {
m_calculations[i].tidy();
}
}
}