diff --git a/apps/statistics/Makefile b/apps/statistics/Makefile index 17245d25d..bfafe7973 100644 --- a/apps/statistics/Makefile +++ b/apps/statistics/Makefile @@ -18,6 +18,7 @@ app_objs += $(addprefix apps/statistics/,\ multiple_data_view.o\ multiple_data_view_controller.o\ multiple_histograms_view.o\ + series_context.o\ store.o\ store_controller.o\ ) diff --git a/apps/statistics/series_context.cpp b/apps/statistics/series_context.cpp new file mode 100644 index 000000000..a63f254ea --- /dev/null +++ b/apps/statistics/series_context.cpp @@ -0,0 +1,31 @@ +#include "series_context.h" +#include +#include + +using namespace Poincare; +using namespace Shared; + +namespace Statistics { + +const Expression * SeriesContext::expressionForSymbol(const Symbol * symbol) { + assert(m_seriesPairIndex >= 0); + if (!symbol->isSeriesSymbol()) { + return nullptr; + } + const char * seriesName = Symbol::textForSpecialSymbols(symbol->name()); + assert(strlen(seriesName) == 2); + + int series = seriesName[1] - '0'; + assert(series >= 0 && series < Store::k_numberOfSeries); + + assert((seriesName[0] == 'V') || (seriesName[0] == 'N')); + int storeI = seriesName[0] == 'V' ? 0 : 1; + + assert(m_seriesPairIndex < store->numberOfPairsOfSeries(series)); + + Expression * result = new Decimal(m_store->get(series, storeI, m_seriesPairIndex)); + assert(result != nullptr); + return result; +} + +} diff --git a/apps/statistics/series_context.h b/apps/statistics/series_context.h new file mode 100644 index 000000000..1ffe4986a --- /dev/null +++ b/apps/statistics/series_context.h @@ -0,0 +1,26 @@ +#ifndef STATISTICS_SERIES_CONTEXT_H +#define STATISTICS_SERIES_CONTEXT_H + +#include +#include "../shared/float_pair_store.h" + +namespace Statistics { + +class SeriesContext : public Poincare::Context { +public: + SeriesContext(Shared::FloatPairStore * store) : + Poincare::Context(), + m_store(store), + m_seriesPairIndex(-1) + {} + void setStorePosition(int series, int i, int j); + void setExpressionForSymbolName(const Poincare::Expression * expression, const Poincare::Symbol * symbol, Poincare::Context & context) override {} + const Poincare::Expression * expressionForSymbol(const Poincare::Symbol * symbol) override; +private: + Shared::FloatPairStore * m_store; + int m_seriesPairIndex; +}; + +} + +#endif diff --git a/poincare/include/poincare/symbol.h b/poincare/include/poincare/symbol.h index d81e43743..26a89aac4 100644 --- a/poincare/include/poincare/symbol.h +++ b/poincare/include/poincare/symbol.h @@ -49,8 +49,8 @@ public: bool isApproximate(Context & context) const; float characteristicXRange(Context & context, AngleUnit angleUnit = AngleUnit::Default) const override; bool hasAnExactRepresentation(Context & context) const; + static const char * textForSpecialSymbols(char name); private: - const char * textForSpecialSymbols(char name) const; Expression * replaceSymbolWithExpression(char symbol, Expression * expression) override; /* Simplification */ Expression * shallowReduce(Context& context, AngleUnit angleUnit) override; diff --git a/poincare/src/symbol.cpp b/poincare/src/symbol.cpp index 718be60b0..63b60dd40 100644 --- a/poincare/src/symbol.cpp +++ b/poincare/src/symbol.cpp @@ -21,7 +21,7 @@ extern "C" { namespace Poincare { -const char * Symbol::textForSpecialSymbols(char name) const { +const char * Symbol::textForSpecialSymbols(char name) { switch (name) { case SpecialSymbols::Ans: return "ans";