[apps/shared] Functions cache clears on change

Added several triggers to clear the cache when the function's type,
range or content is changed.

Change-Id: I4f49a90bb6571e335a4a601723d7715b8de1e25e
This commit is contained in:
Gabriel Ozouf
2020-06-09 14:00:11 +02:00
committed by Émilie Feral
parent 552dca9494
commit a9c633a540
3 changed files with 11 additions and 1 deletions

View File

@@ -125,6 +125,8 @@ void ContinuousFunction::setPlotType(PlotType newPlotType, Poincare::Preferences
recordData()->setPlotType(newPlotType);
cache()->clear();
// Recompute the layouts
m_model.tidy();
@@ -251,10 +253,12 @@ float ContinuousFunction::tMax() const {
void ContinuousFunction::setTMin(float tMin) {
recordData()->setTMin(tMin);
cache()->clear();
}
void ContinuousFunction::setTMax(float tMax) {
recordData()->setTMax(tMax);
cache()->clear();
}
void * ContinuousFunction::Model::expressionAddress(const Ion::Storage::Record * record) const {
@@ -347,6 +351,11 @@ Poincare::Expression ContinuousFunction::sumBetweenBounds(double start, double e
* the derivative table. */
}
Ion::Storage::Record::ErrorStatus ContinuousFunction::setContent(const char * c, Poincare::Context * context) {
cache()->clear();
return ExpressionModelHandle::setContent(c, context);
}
template Coordinate2D<float> ContinuousFunction::templatedApproximateAtParameter<float>(float, Poincare::Context *) const;
template Coordinate2D<double> ContinuousFunction::templatedApproximateAtParameter<double>(double, Poincare::Context *) const;

View File

@@ -80,6 +80,7 @@ public:
// Cache
ContinuousFunctionCache * cache() const { return const_cast<ContinuousFunctionCache *>(&m_cache); }
Ion::Storage::Record::ErrorStatus setContent(const char * c, Poincare::Context * context) override;
private:
constexpr static float k_polarParamRangeSearchNumberOfPoints = 100.0f; // This is ad hoc, no special justification
typedef Poincare::Coordinate2D<double> (*ComputePointOfInterest)(Poincare::Expression e, char * symbol, double start, double step, double max, Poincare::Context * context);

View File

@@ -30,7 +30,7 @@ public:
* behaviour but it is not true for its child classes (for example, in
* Sequence). */
virtual void tidy() { model()->tidy(); }
Ion::Storage::Record::ErrorStatus setContent(const char * c, Poincare::Context * context) { return editableModel()->setContent(this, c, context, symbol()); }
virtual Ion::Storage::Record::ErrorStatus setContent(const char * c, Poincare::Context * context) { return editableModel()->setContent(this, c, context, symbol()); }
Ion::Storage::Record::ErrorStatus setExpressionContent(const Poincare::Expression & e) { return editableModel()->setExpressionContent(this, e); }
protected:
ExpressionModel * editableModel() { return const_cast<ExpressionModel *>(model()); }