#include "cache_context.h" #include "sequence_store.h" #include using namespace Poincare; namespace Sequence { template CacheContext::CacheContext(Context * parentContext) : VariableContext("n", parentContext), m_values{{NAN, NAN}, {NAN, NAN}} { } template const Expression CacheContext::expressionForSymbol(const SymbolAbstract & symbol, bool clone) { // [u|v](n(+1)?) if (symbol.type() == ExpressionNode::Type::Symbol && (symbol.name()[0] == SequenceStore::k_sequenceNames[0][0] || symbol.name()[0] == SequenceStore::k_sequenceNames[1][0]) && (strcmp(symbol.name()+1, "(n)") == 0 || strcmp(symbol.name()+1, "(n+1)") == 0)) { Symbol s = const_cast(static_cast(symbol)); return Float::Builder(m_values[nameIndexForSymbol(s)][rankIndexForSymbol(s)]); } return VariableContext::expressionForSymbol(symbol, clone); } template void CacheContext::setValueForSymbol(T value, const Poincare::Symbol & symbol) { m_values[nameIndexForSymbol(symbol)][rankIndexForSymbol(symbol)] = value; } template int CacheContext::nameIndexForSymbol(const Poincare::Symbol & symbol) { assert(strlen(symbol.name()) == 4 || strlen(symbol.name()) == 6); // [u|v](n(+1)?) if (symbol.name()[0] == SequenceStore::k_sequenceNames[0][0]) { // u return 0; } // v return 1; } template int CacheContext::rankIndexForSymbol(const Poincare::Symbol & symbol) { assert(strlen(symbol.name()) == 4 || strlen(symbol.name()) == 6); // u(n) or u(n+1) if (symbol.name()[3] == ')') { // .(n) return 0; } // .(n+1) return 1; } template class CacheContext; template class CacheContext; }