[apps] Sequence: invalidate the context cache when the sequences are

redefined
This commit is contained in:
Émilie Feral
2017-12-13 17:49:54 +01:00
committed by EmilieNumworks
parent 31ceb5ed40
commit cb754ab6d5
12 changed files with 31 additions and 16 deletions

View File

@@ -32,6 +32,9 @@ App * App::Snapshot::unpack(Container * container) {
void App::Snapshot::reset() {
FunctionApp::Snapshot::reset();
m_graphRange.setDefault();
/* We do not need to invalidate the sequence context cache here as the
* context is not allocated yet when reset is call (from the application
* settings). */
m_sequenceStore.removeAll();
}
@@ -77,7 +80,7 @@ InputViewController * App::inputViewController() {
return &m_inputViewController;
}
Context * App::localContext() {
SequenceContext * App::localContext() {
return &m_sequenceContext;
}

View File

@@ -35,7 +35,7 @@ public:
CurveViewRange m_graphRange;
};
InputViewController * inputViewController() override;
Poincare::Context * localContext() override;
SequenceContext * localContext() override;
const char * XNT() override;
private:
App(Container * container, Snapshot * snapshot);

View File

@@ -101,6 +101,8 @@ void ListController::editExpression(Sequence * sequence, int sequenceDefinition,
}
App * myApp = (App *)app();
InputViewController * inputController = myApp->inputViewController();
// Invalidate the sequences context cache
static_cast<App *>(app())->localContext()->resetCache();
switch (sequenceDefinition) {
case 0:
inputController->edit(this, event, sequence, initialText,
@@ -137,6 +139,13 @@ void ListController::editExpression(Sequence * sequence, int sequenceDefinition,
}
}
bool ListController::removeFunctionRow(Function * function) {
m_functionStore->removeFunction(function);
// Invalidate the sequences context cache
static_cast<App *>(app())->localContext()->resetCache();
return true;
}
ListParameterController * ListController::parameterController() {
return &m_parameterController;
}
@@ -251,6 +260,8 @@ void ListController::editExpression(Shared::Function * function, Ion::Events::Ev
}
void ListController::reinitExpression(Shared::Function * function) {
// Invalidate the sequences context cache
static_cast<App *>(app())->localContext()->resetCache();
Sequence * sequence = (Sequence *)function;
switch (sequenceDefinitionForRow(selectedRow())) {
case 1:

View File

@@ -37,6 +37,7 @@ private:
int sequenceDefinitionForRow(int j);
void addEmptyFunction() override;
void editExpression(Shared::Function * function, Ion::Events::Event event) override;
bool removeFunctionRow(Shared::Function * function) override;
void reinitExpression(Shared::Function * function) override;
View * loadView() override;
void unloadView(View * view) override;

View File

@@ -1,5 +1,6 @@
#include "list_parameter_controller.h"
#include "list_controller.h"
#include "../app.h"
using namespace Poincare;
using namespace Shared;
@@ -52,6 +53,7 @@ bool ListParameterController::handleEvent(Ion::Events::Event event) {
#endif
if (m_functionStore->numberOfFunctions() > 0) {
m_functionStore->removeFunction(m_function);
static_cast<App *>(app())->localContext()->resetCache();
StackViewController * stack = (StackViewController *)(parentResponder());
stack->pop();
return true;

View File

@@ -1,5 +1,6 @@
#include "type_parameter_controller.h"
#include "list_controller.h"
#include "../app.h"
#include <assert.h>
#include "../../../poincare/src/layout/baseline_relative_layout.h"
#include "../../../poincare/src/layout/string_layout.h"
@@ -54,6 +55,8 @@ bool TypeParameterController::handleEvent(Ion::Events::Event event) {
if (m_sequence->type() != sequenceType) {
m_listController->selectPreviousNewSequenceCell();
m_sequence->setType((Sequence::Type)selectedRow());
// Invalidate sequence context cache when changing sequence type
static_cast<App *>(app())->localContext()->resetCache();
}
StackViewController * stack = stackController();
assert(stack->depth()>2);

View File

@@ -126,7 +126,6 @@ void Sequence::setType(Type type) {
}
setFirstInitialConditionContent("");
setSecondInitialConditionContent("");
//sqctx->resetCache();
}
Poincare::Expression * Sequence::firstInitialConditionExpression(Context * context) const {
@@ -173,7 +172,6 @@ Poincare::ExpressionLayout * Sequence::secondInitialConditionLayout() {
void Sequence::setContent(const char * c) {
Function::setContent(c);
//sqctx->resetCache();
}
void Sequence::setFirstInitialConditionContent(const char * c) {
@@ -186,7 +184,6 @@ void Sequence::setFirstInitialConditionContent(const char * c) {
delete m_firstInitialConditionLayout;
m_firstInitialConditionLayout = nullptr;
}
//sqctx->resetCache();
}
void Sequence::setSecondInitialConditionContent(const char * c) {
@@ -199,7 +196,6 @@ void Sequence::setSecondInitialConditionContent(const char * c) {
delete m_secondInitialConditionLayout;
m_secondInitialConditionLayout = nullptr;
}
//sqctx->resetCache();
}
char Sequence::symbol() const {

View File

@@ -22,13 +22,16 @@ public:
Sequence(Sequence&& other) = delete;
uint32_t checksum() override;
Type type();
void setType(Type type);
const char * firstInitialConditionText();
const char * secondInitialConditionText();
Poincare::Expression * firstInitialConditionExpression(Poincare::Context * context) const;
Poincare::Expression * secondInitialConditionExpression(Poincare::Context * context) const;
Poincare::ExpressionLayout * firstInitialConditionLayout();
Poincare::ExpressionLayout * secondInitialConditionLayout();
/* WARNING: after calling setType, setContent, setFirstInitialConditionContent
* or setSecondInitialConditionContent, the sequence context needs to
* invalidate the cache because the sequences evaluations might have changed. */
void setType(Type type);
void setContent(const char * c) override;
void setFirstInitialConditionContent(const char * c);
void setSecondInitialConditionContent(const char * c);

View File

@@ -56,7 +56,6 @@ void SequenceStore::removeFunction(Shared::Function * f) {
}
Sequence emptySequence("", KDColorBlack);
m_sequences[m_numberOfFunctions] = emptySequence;
//sqctx->resetCache();
}
int SequenceStore::maxNumberOfFunctions() {
@@ -105,7 +104,6 @@ void SequenceStore::removeAll() {
m_sequences[i] = emptySequence;
}
m_numberOfFunctions = 0;
//sqctx->resetCache();
}
}

View File

@@ -16,11 +16,14 @@ public:
Sequence * activeFunctionAtIndex(int i) override;
Sequence * definedFunctionAtIndex(int i) override;
Sequence * addEmptyFunction() override;
/* WARNING: after calling removeFunction or removeAll, the sequence context
* need to invalidate its cache as the sequences evaluations might have
* changed */
void removeFunction(Shared::Function * f) override;
void removeAll() override;
int maxNumberOfFunctions() override;
const char * firstAvailableName() override;
char symbol() const override;
void removeAll() override;
static constexpr const char * k_sequenceNames[MaxNumberOfSequences] = {
"u", "v"//, "w"
};

View File

@@ -292,11 +292,6 @@ void ListController::addEmptyFunction() {
selectableTableView()->reloadData();
}
bool ListController::removeFunctionRow(Function * function) {
m_functionStore->removeFunction(function);
return true;
}
View * ListController::loadView() {
m_emptyCell = new EvenOddCell();
m_addNewFunction = new NewFunctionCell(m_addNewMessage);

View File

@@ -43,7 +43,7 @@ private:
virtual int functionIndexForRow(int j);
virtual const char * textForRow(int j);
virtual void addEmptyFunction();
virtual bool removeFunctionRow(Function * function);
virtual bool removeFunctionRow(Function * function) = 0;
virtual void editExpression(Function * function, Ion::Events::Event event) = 0;
virtual ListParameterController * parameterController() = 0;
virtual int maxNumberOfRows() = 0;