From 758b41cea56c232079fc9a817c1729f6600c472c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 6 Sep 2018 14:04:18 +0200 Subject: [PATCH] [sequence] Fix cache_context and sequence_context with new Poincare API --- apps/sequence/cache_context.cpp | 26 +++++++++++++------------- apps/sequence/cache_context.h | 12 ++++++------ apps/sequence/sequence_context.h | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/apps/sequence/cache_context.cpp b/apps/sequence/cache_context.cpp index c6439d7a3..cda8b28c7 100644 --- a/apps/sequence/cache_context.cpp +++ b/apps/sequence/cache_context.cpp @@ -8,28 +8,28 @@ namespace Sequence { template CacheContext::CacheContext(Context * parentContext) : VariableContext('n', parentContext), - m_values{{Approximation(NAN), Approximation(NAN)}, - {Approximation(NAN), Approximation(NAN)}} + m_values{{NAN, NAN}, + {NAN, NAN}} { } template -const Expression * CacheContext::expressionForSymbol(const Symbol * symbol) { - if (symbol->name() == Symbol::SpecialSymbols::un || symbol->name() == Symbol::SpecialSymbols::un1 || - symbol->name() == Symbol::SpecialSymbols::vn || symbol->name() == Symbol::SpecialSymbols::vn1) { - return &m_values[nameIndexForSymbol(symbol)][rankIndexForSymbol(symbol)]; +const Expression CacheContext::expressionForSymbol(const Symbol & symbol) { + if (symbol.name() == Symbol::SpecialSymbols::un || symbol.name() == Symbol::SpecialSymbols::un1 || + symbol.name() == Symbol::SpecialSymbols::vn || symbol.name() == Symbol::SpecialSymbols::vn1) { + return Float(m_values[nameIndexForSymbol(symbol)][rankIndexForSymbol(symbol)]); } return VariableContext::expressionForSymbol(symbol); } template -void CacheContext::setValueForSymbol(T value, const Poincare::Symbol * symbol) { - m_values[nameIndexForSymbol(symbol)][rankIndexForSymbol(symbol)] = Approximation(value); +void CacheContext::setValueForSymbol(T value, const Poincare::Symbol & symbol) { + m_values[nameIndexForSymbol(symbol)][rankIndexForSymbol(symbol)] = value; } template -int CacheContext::nameIndexForSymbol(const Poincare::Symbol * symbol) { - switch (symbol->name()) { +int CacheContext::nameIndexForSymbol(const Poincare::Symbol & symbol) { + switch (symbol.name()) { case Symbol::SpecialSymbols::un: return 0; case Symbol::SpecialSymbols::un1: @@ -44,8 +44,8 @@ int CacheContext::nameIndexForSymbol(const Poincare::Symbol * symbol) { } template -int CacheContext::rankIndexForSymbol(const Poincare::Symbol * symbol) { - switch (symbol->name()) { +int CacheContext::rankIndexForSymbol(const Poincare::Symbol & symbol) { + switch (symbol.name()) { case Symbol::SpecialSymbols::un: return 0; case Symbol::SpecialSymbols::un1: @@ -62,4 +62,4 @@ int CacheContext::rankIndexForSymbol(const Poincare::Symbol * symbol) { template class CacheContext; template class CacheContext; -} \ No newline at end of file +} diff --git a/apps/sequence/cache_context.h b/apps/sequence/cache_context.h index 31f80b385..69a989d44 100644 --- a/apps/sequence/cache_context.h +++ b/apps/sequence/cache_context.h @@ -10,14 +10,14 @@ template class CacheContext : public Poincare::VariableContext { public: CacheContext(Poincare::Context * parentContext); - const Poincare::Expression * expressionForSymbol(const Poincare::Symbol * symbol) override; - void setValueForSymbol(T value, const Poincare::Symbol * symbol); + const Poincare::Expression expressionForSymbol(const Poincare::Symbol & symbol) override; + void setValueForSymbol(T value, const Poincare::Symbol & symbol); private: - int nameIndexForSymbol(const Poincare::Symbol * symbol); - int rankIndexForSymbol(const Poincare::Symbol * symbol); - Poincare::Approximation m_values[MaxNumberOfSequences][MaxRecurrenceDepth]; + int nameIndexForSymbol(const Poincare::Symbol & symbol); + int rankIndexForSymbol(const Poincare::Symbol & symbol); + T m_values[MaxNumberOfSequences][MaxRecurrenceDepth]; }; } -#endif \ No newline at end of file +#endif diff --git a/apps/sequence/sequence_context.h b/apps/sequence/sequence_context.h index c1fefdc3c..9056b8558 100644 --- a/apps/sequence/sequence_context.h +++ b/apps/sequence/sequence_context.h @@ -43,10 +43,10 @@ public: * context respective methods. Indeed, special chars like n, u(n), u(n+1), * v(n), v(n+1) are taken into accound only when evaluating sequences which * is done in another context. */ - const Poincare::Expression * expressionForSymbol(const Poincare::Symbol * symbol) override { + const Poincare::Expression expressionForSymbol(const Poincare::Symbol & symbol) override { return m_parentContext->expressionForSymbol(symbol); } - void setExpressionForSymbolName(const Poincare::Expression * expression, const Poincare::Symbol * symbol, Poincare::Context & context) override { + void setExpressionForSymbolName(const Poincare::Expression & expression, const Poincare::Symbol & symbol, Poincare::Context & context) override { m_parentContext->setExpressionForSymbolName(expression, symbol, context); } template T valueOfSequenceAtPreviousRank(int sequenceIndex, int rank) const {