From 3c1e35ec048b4fb681e0f68c2bc884f689d869d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 11 Mar 2019 17:32:00 +0100 Subject: [PATCH] [shared] Rename classes: ExpressionModelHandle --> ExpressionModel SingleExpressionModelHandle --> ExpressionModelHandle StorageFunction --> Function StorageCartesianFunction --> CartesianFunction StorageFunctionApp --> FunctionApp --- apps/graph/app.cpp | 4 +- apps/graph/app.h | 8 +- .../graph/calculation_graph_controller.cpp | 2 +- .../graph/calculation_graph_controller.h | 2 +- .../graph/curve_parameter_controller.cpp | 4 +- apps/graph/graph/curve_parameter_controller.h | 6 +- apps/graph/graph/graph_controller.cpp | 12 +- apps/graph/graph/graph_controller.h | 4 +- apps/graph/graph/graph_controller_helper.cpp | 8 +- apps/graph/graph/graph_view.cpp | 12 +- apps/graph/graph/graph_view.h | 2 +- .../graph/graph/integral_graph_controller.cpp | 4 +- apps/graph/graph/integral_graph_controller.h | 2 +- .../graph/intersection_graph_controller.cpp | 12 +- apps/graph/graph/tangent_graph_controller.cpp | 6 +- apps/graph/graph/tangent_graph_controller.h | 2 +- apps/graph/list/storage_list_controller.cpp | 32 ++--- apps/graph/list/storage_list_controller.h | 4 +- .../list/text_field_function_title_cell.cpp | 2 +- .../list/text_field_function_title_cell.h | 4 +- .../storage_cartesian_function_store.cpp | 6 +- apps/graph/storage_cartesian_function_store.h | 12 +- ...torage_derivative_parameter_controller.cpp | 2 +- .../storage_derivative_parameter_controller.h | 2 +- .../storage_function_parameter_controller.cpp | 18 +-- .../storage_function_parameter_controller.h | 8 +- .../values/storage_values_controller.cpp | 18 +-- apps/graph/values/storage_values_controller.h | 4 +- apps/sequence/app.cpp | 6 +- apps/sequence/app.h | 8 +- .../graph/curve_parameter_controller.cpp | 2 +- .../graph/curve_parameter_controller.h | 2 +- .../graph/go_to_parameter_controller.cpp | 2 +- .../graph/go_to_parameter_controller.h | 4 +- apps/sequence/graph/graph_controller.cpp | 8 +- apps/sequence/graph/graph_controller.h | 4 +- apps/sequence/graph/graph_view.cpp | 4 +- apps/sequence/graph/graph_view.h | 2 +- apps/sequence/graph/term_sum_controller.cpp | 2 +- apps/sequence/graph/term_sum_controller.h | 2 +- apps/sequence/list/list_controller.cpp | 8 +- apps/sequence/list/list_controller.h | 6 +- apps/sequence/sequence.cpp | 14 +- apps/sequence/sequence.h | 12 +- apps/sequence/sequence_store.cpp | 2 +- apps/sequence/sequence_store.h | 6 +- apps/shared/Makefile | 8 +- ...an_function.cpp => cartesian_function.cpp} | 38 ++--- ...tesian_function.h => cartesian_function.h} | 20 +-- apps/shared/expression_model.cpp | 131 ++++++++++++++++++ apps/shared/expression_model.h | 42 ++++++ apps/shared/expression_model_handle.cpp | 114 +-------------- apps/shared/expression_model_handle.h | 55 ++++---- .../{storage_function.cpp => function.cpp} | 22 +-- .../shared/{storage_function.h => function.h} | 10 +- ...rage_function_app.cpp => function_app.cpp} | 12 +- ...{storage_function_app.h => function_app.h} | 10 +- apps/shared/global_context.cpp | 8 +- .../shared/single_expression_model_handle.cpp | 27 ---- apps/shared/single_expression_model_handle.h | 43 ------ ...orage_expression_model_list_controller.cpp | 12 +- ...storage_expression_model_list_controller.h | 2 +- .../shared/storage_expression_model_store.cpp | 8 +- apps/shared/storage_expression_model_store.h | 14 +- .../storage_function_banner_delegate.cpp | 4 +- .../shared/storage_function_banner_delegate.h | 4 +- ...ge_function_curve_parameter_controller.cpp | 12 +- ...rage_function_curve_parameter_controller.h | 6 +- ...ge_function_go_to_parameter_controller.cpp | 16 +-- ...rage_function_go_to_parameter_controller.h | 6 +- .../storage_function_graph_controller.cpp | 62 ++++----- .../storage_function_graph_controller.h | 10 +- apps/shared/storage_function_graph_view.cpp | 18 +-- apps/shared/storage_function_graph_view.h | 6 +- .../storage_function_list_controller.cpp | 78 +++++------ .../shared/storage_function_list_controller.h | 6 +- apps/shared/storage_function_store.cpp | 4 +- apps/shared/storage_function_store.h | 12 +- .../storage_list_parameter_controller.cpp | 8 +- .../storage_list_parameter_controller.h | 4 +- apps/shared/storage_sum_graph_controller.cpp | 12 +- apps/shared/storage_sum_graph_controller.h | 8 +- apps/shared/storage_values_controller.cpp | 8 +- apps/shared/storage_values_controller.h | 2 +- ...e_values_function_parameter_controller.cpp | 6 +- ...age_values_function_parameter_controller.h | 4 +- apps/solver/equation.cpp | 4 +- apps/solver/equation.h | 8 +- apps/solver/equation_store.cpp | 2 +- apps/solver/equation_store.h | 2 +- apps/variable_box_controller.cpp | 20 +-- 91 files changed, 602 insertions(+), 602 deletions(-) rename apps/shared/{storage_cartesian_function.cpp => cartesian_function.cpp} (72%) rename apps/shared/{storage_cartesian_function.h => cartesian_function.h} (80%) create mode 100644 apps/shared/expression_model.cpp create mode 100644 apps/shared/expression_model.h rename apps/shared/{storage_function.cpp => function.cpp} (73%) rename apps/shared/{storage_function.h => function.h} (89%) rename apps/shared/{storage_function_app.cpp => function_app.cpp} (73%) rename apps/shared/{storage_function_app.h => function_app.h} (77%) delete mode 100644 apps/shared/single_expression_model_handle.cpp delete mode 100644 apps/shared/single_expression_model_handle.h diff --git a/apps/graph/app.cpp b/apps/graph/app.cpp index 9b873e3a8..138383411 100644 --- a/apps/graph/app.cpp +++ b/apps/graph/app.cpp @@ -21,7 +21,7 @@ const Image * App::Descriptor::icon() { } App::Snapshot::Snapshot() : - Shared::StorageFunctionApp::Snapshot::Snapshot(), + Shared::FunctionApp::Snapshot::Snapshot(), m_functionStore(), m_graphRange(&m_cursor) { @@ -50,7 +50,7 @@ void App::Snapshot::tidy() { } App::App(Container * container, Snapshot * snapshot) : - StorageFunctionApp(container, snapshot, &m_inputViewController), + FunctionApp(container, snapshot, &m_inputViewController), m_listController(&m_listFooter, &m_listHeader, &m_listFooter), m_listFooter(&m_listHeader, &m_listController, &m_listController, ButtonRowController::Position::Bottom, ButtonRowController::Style::EmbossedGrey), m_listHeader(&m_listStackViewController, &m_listFooter, &m_listController), diff --git a/apps/graph/app.h b/apps/graph/app.h index a38715e72..5dfeb4db7 100644 --- a/apps/graph/app.h +++ b/apps/graph/app.h @@ -6,11 +6,11 @@ #include "graph/graph_controller.h" #include "list/storage_list_controller.h" #include "values/storage_values_controller.h" -#include "../shared/storage_function_app.h" +#include "../shared/function_app.h" namespace Graph { -class App : public Shared::StorageFunctionApp { +class App : public Shared::FunctionApp { public: class Descriptor : public ::App::Descriptor { public: @@ -18,7 +18,7 @@ public: I18n::Message upperName() override; const Image * icon() override; }; - class Snapshot : public Shared::StorageFunctionApp::Snapshot { + class Snapshot : public Shared::FunctionApp::Snapshot { public: Snapshot(); App * unpack(Container * container) override; @@ -33,7 +33,7 @@ public: InputViewController * inputViewController() override; char XNT() override; NestedMenuController * variableBoxForInputEventHandler(InputEventHandler * textInput) override; - StorageCartesianFunctionStore * functionStore() override { return static_cast(Shared::StorageFunctionApp::functionStore()); } + StorageCartesianFunctionStore * functionStore() override { return static_cast(Shared::FunctionApp::functionStore()); } private: App(Container * container, Snapshot * snapshot); StorageListController m_listController; diff --git a/apps/graph/graph/calculation_graph_controller.cpp b/apps/graph/graph/calculation_graph_controller.cpp index 7bb84d4a8..3c9ea8328 100644 --- a/apps/graph/graph/calculation_graph_controller.cpp +++ b/apps/graph/graph/calculation_graph_controller.cpp @@ -63,7 +63,7 @@ void CalculationGraphController::setRecord(Ion::Storage::Record record) { void CalculationGraphController::reloadBannerView() { m_bannerView->setNumberOfSubviews(2); - reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), StorageCartesianFunction::Symbol()); + reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), CartesianFunction::Symbol()); } bool CalculationGraphController::moveCursor(int direction) { diff --git a/apps/graph/graph/calculation_graph_controller.h b/apps/graph/graph/calculation_graph_controller.h index 90e973df5..01d748f9b 100644 --- a/apps/graph/graph/calculation_graph_controller.h +++ b/apps/graph/graph/calculation_graph_controller.h @@ -12,7 +12,7 @@ namespace Graph { class App; -class CalculationGraphController : public ViewController, public Shared::StorageFunctionBannerDelegate { +class CalculationGraphController : public ViewController, public Shared::FunctionBannerDelegate { public: CalculationGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, I18n::Message defaultMessage); View * view() override; diff --git a/apps/graph/graph/curve_parameter_controller.cpp b/apps/graph/graph/curve_parameter_controller.cpp index 2361724e5..154070b51 100644 --- a/apps/graph/graph/curve_parameter_controller.cpp +++ b/apps/graph/graph/curve_parameter_controller.cpp @@ -8,7 +8,7 @@ using namespace Shared; namespace Graph { CurveParameterController::CurveParameterController(InputEventHandlerDelegate * inputEventHandlerDelegate, InteractiveCurveViewRange * graphRange, BannerView * bannerView, CurveViewCursor * cursor, GraphView * graphView, GraphController * graphController) : - StorageFunctionCurveParameterController(graphRange, cursor), + FunctionCurveParameterController(graphRange, cursor), m_goToParameterController(this, inputEventHandlerDelegate, graphRange, cursor, I18n::Message::X), m_graphController(graphController), m_calculationCell(I18n::Message::Compute), @@ -68,7 +68,7 @@ int CurveParameterController::reusableCellCount() { return k_totalNumberOfCells; } -StorageFunctionGoToParameterController * CurveParameterController::goToParameterController() { +FunctionGoToParameterController * CurveParameterController::goToParameterController() { return &m_goToParameterController; } diff --git a/apps/graph/graph/curve_parameter_controller.h b/apps/graph/graph/curve_parameter_controller.h index 1588a2b30..06be4cb71 100644 --- a/apps/graph/graph/curve_parameter_controller.h +++ b/apps/graph/graph/curve_parameter_controller.h @@ -9,7 +9,7 @@ namespace Graph { class GraphController; -class CurveParameterController : public Shared::StorageFunctionCurveParameterController { +class CurveParameterController : public Shared::FunctionCurveParameterController { public: CurveParameterController(InputEventHandlerDelegate * inputEventHandlerDelegate, Shared::InteractiveCurveViewRange * graphRange, BannerView * bannerView, Shared::CurveViewCursor * cursor, GraphView * graphView, GraphController * graphController); const char * title() override; @@ -19,8 +19,8 @@ public: int reusableCellCount() override; void willDisplayCellForIndex(HighlightCell * cell, int index) override; private: - Shared::StorageFunctionGoToParameterController * goToParameterController() override; - Shared::StorageFunctionGoToParameterController m_goToParameterController; + Shared::FunctionGoToParameterController * goToParameterController() override; + Shared::FunctionGoToParameterController m_goToParameterController; GraphController * m_graphController; constexpr static int k_totalNumberOfCells = 3; MessageTableCellWithChevron m_calculationCell; diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 5c680b50f..2431d5222 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -8,7 +8,7 @@ namespace Graph { static inline float maxFloat(float x, float y) { return x > y ? x : y; } GraphController::GraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, StorageCartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) : - StorageFunctionGraphController(parentResponder, inputEventHandlerDelegate, header, curveViewRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion), + FunctionGraphController(parentResponder, inputEventHandlerDelegate, header, curveViewRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion), m_bannerView(), m_view(functionStore, curveViewRange, m_cursor, &m_bannerView, &m_cursorView), m_graphRange(curveViewRange), @@ -27,7 +27,7 @@ I18n::Message GraphController::emptyMessage() { void GraphController::viewWillAppear() { m_view.drawTangent(false); - StorageFunctionGraphController::viewWillAppear(); + FunctionGraphController::viewWillAppear(); selectFunctionWithCursor(indexFunctionSelectedByCursor()); // update the color of the cursor } @@ -43,7 +43,7 @@ float GraphController::interestingXHalfRange() const { float characteristicRange = 0.0f; TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) { - ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i)); + ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i)); float fRange = f->expressionReduced(myApp->localContext()).characteristicXRange(*(myApp->localContext()), Poincare::Preferences::sharedPreferences()->angleUnit()); if (!std::isnan(fRange)) { characteristicRange = maxFloat(fRange, characteristicRange); @@ -57,8 +57,8 @@ int GraphController::estimatedBannerNumberOfLines() const { } void GraphController::selectFunctionWithCursor(int functionIndex) { - StorageFunctionGraphController::selectFunctionWithCursor(functionIndex); - ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor())); + FunctionGraphController::selectFunctionWithCursor(functionIndex); + ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor())); m_cursorView.setColor(f->color()); } @@ -67,7 +67,7 @@ BannerView * GraphController::bannerView() { } void GraphController::reloadBannerView() { - StorageFunctionGraphController::reloadBannerView(); + FunctionGraphController::reloadBannerView(); m_bannerView.setNumberOfSubviews(2+m_displayDerivativeInBanner); if (functionStore()->numberOfActiveFunctions() == 0 || !m_displayDerivativeInBanner) { return; diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index 58586d727..e7206a470 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -13,7 +13,7 @@ namespace Graph { -class GraphController : public Shared::StorageFunctionGraphController, public GraphControllerHelper { +class GraphController : public Shared::FunctionGraphController, public GraphControllerHelper { public: GraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, StorageCartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header); I18n::Message emptyMessage() override; @@ -33,7 +33,7 @@ private: return &m_cursorView; } CurveParameterController * curveParameterController() override; - StorageCartesianFunctionStore * functionStore() const override { return static_cast(Shared::StorageFunctionGraphController::functionStore()); } + StorageCartesianFunctionStore * functionStore() const override { return static_cast(Shared::FunctionGraphController::functionStore()); } Shared::RoundCursorView m_cursorView; BannerView m_bannerView; GraphView m_view; diff --git a/apps/graph/graph/graph_controller_helper.cpp b/apps/graph/graph/graph_controller_helper.cpp index 7f59b3cf3..b4cdd4465 100644 --- a/apps/graph/graph/graph_controller_helper.cpp +++ b/apps/graph/graph/graph_controller_helper.cpp @@ -10,7 +10,7 @@ using namespace Poincare; namespace Graph { bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Ion::Storage::Record record, App * app, float cursorTopMarginRatio, float cursorRightMarginRatio, float cursorBottomMarginRatio, float cursorLeftMarginRatio) { - ExpiringPointer function = app->functionStore()->modelForRecord(record); + ExpiringPointer function = app->functionStore()->modelForRecord(record); double xCursorPosition = cursor->x(); double x = direction > 0 ? xCursorPosition + range->xGridUnit()/numberOfStepsInGradUnit : xCursorPosition - range->xGridUnit()/numberOfStepsInGradUnit; double y = function->evaluateAtAbscissa(x, app->localContext()); @@ -20,11 +20,11 @@ bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCurso } void GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, Ion::Storage::Record record, App * app) { - ExpiringPointer function = app->functionStore()->modelForRecord(record); - constexpr size_t bufferSize = StorageFunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); + ExpiringPointer function = app->functionStore()->modelForRecord(record); + constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); char buffer[bufferSize]; const char * space = " "; - int numberOfChar = function->derivativeNameWithArgument(buffer, bufferSize, StorageCartesianFunction::Symbol()); + int numberOfChar = function->derivativeNameWithArgument(buffer, bufferSize, CartesianFunction::Symbol()); const char * legend = "="; numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar); double y = function->approximateDerivative(cursor->x(), app->localContext()); diff --git a/apps/graph/graph/graph_view.cpp b/apps/graph/graph/graph_view.cpp index be44101ab..96f084c2c 100644 --- a/apps/graph/graph/graph_view.cpp +++ b/apps/graph/graph/graph_view.cpp @@ -7,7 +7,7 @@ namespace Graph { GraphView::GraphView(StorageCartesianFunctionStore * functionStore, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) : - StorageFunctionGraphView(graphRange, cursor, bannerView, cursorView), + FunctionGraphView(graphRange, cursor, bannerView, cursorView), m_functionStore(functionStore), m_tangent(false) { @@ -18,25 +18,25 @@ void GraphView::reload() { KDRect dirtyZone(KDRect(0, 0, bounds().width(), bounds().height()-m_bannerView->bounds().height())); markRectAsDirty(dirtyZone); } - return StorageFunctionGraphView::reload(); + return FunctionGraphView::reload(); } void GraphView::drawRect(KDContext * ctx, KDRect rect) const { - StorageFunctionGraphView::drawRect(ctx, rect); + FunctionGraphView::drawRect(ctx, rect); for (int i = 0; i < m_functionStore->numberOfActiveFunctions(); i++) { Ion::Storage::Record record = m_functionStore->activeRecordAtIndex(i); - ExpiringPointer f = m_functionStore->modelForRecord(record);; + ExpiringPointer f = m_functionStore->modelForRecord(record);; /* Draw function (color the area under curve of the selected function) */ if (record == m_selectedRecord) { drawCurve(ctx, rect, [](float t, void * model, void * context) { - StorageCartesianFunction * f = (StorageCartesianFunction *)model; + CartesianFunction * f = (CartesianFunction *)model; Poincare::Context * c = (Poincare::Context *)context; return f->evaluateAtAbscissa(t, c); }, f.operator->(), context(), f->color(), true, m_highlightedStart, m_highlightedEnd); } else { drawCurve(ctx, rect, [](float t, void * model, void * context) { - StorageCartesianFunction * f = (StorageCartesianFunction *)model; + CartesianFunction * f = (CartesianFunction *)model; Poincare::Context * c = (Poincare::Context *)context; return f->evaluateAtAbscissa(t, c); }, f.operator->(), context(), f->color()); diff --git a/apps/graph/graph/graph_view.h b/apps/graph/graph/graph_view.h index e43bc9143..965da1fa0 100644 --- a/apps/graph/graph/graph_view.h +++ b/apps/graph/graph/graph_view.h @@ -6,7 +6,7 @@ namespace Graph { -class GraphView : public Shared::StorageFunctionGraphView { +class GraphView : public Shared::FunctionGraphView { public: GraphView(StorageCartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * graphRange, diff --git a/apps/graph/graph/integral_graph_controller.cpp b/apps/graph/graph/integral_graph_controller.cpp index c8e948f72..041807c0b 100644 --- a/apps/graph/graph/integral_graph_controller.cpp +++ b/apps/graph/graph/integral_graph_controller.cpp @@ -36,11 +36,11 @@ double IntegralGraphController::cursorNextStep(double x, int direction) { return (direction > 0 ? x + m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit : x - m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit); } -Layout IntegralGraphController::createFunctionLayout(ExpiringPointer function) { +Layout IntegralGraphController::createFunctionLayout(ExpiringPointer function) { constexpr size_t bufferSize = SymbolAbstract::k_maxNameSize+5; // f(x)dx char buffer[bufferSize]; const char * dx = "dx"; - int numberOfChars = function->nameWithArgument(buffer, bufferSize-strlen(dx), StorageCartesianFunction::Symbol()); + int numberOfChars = function->nameWithArgument(buffer, bufferSize-strlen(dx), CartesianFunction::Symbol()); strlcpy(buffer+numberOfChars, dx, bufferSize-numberOfChars); return LayoutHelper::String(buffer, strlen(buffer), KDFont::SmallFont); } diff --git a/apps/graph/graph/integral_graph_controller.h b/apps/graph/graph/integral_graph_controller.h index cc0d6f663..29af61b60 100644 --- a/apps/graph/graph/integral_graph_controller.h +++ b/apps/graph/graph/integral_graph_controller.h @@ -14,7 +14,7 @@ public: private: I18n::Message legendMessageAtStep(Step step) override; double cursorNextStep(double position, int direction) override; - Poincare::Layout createFunctionLayout(Shared::ExpiringPointer function) override; + Poincare::Layout createFunctionLayout(Shared::ExpiringPointer function) override; }; } diff --git a/apps/graph/graph/intersection_graph_controller.cpp b/apps/graph/graph/intersection_graph_controller.cpp index 0d45ff805..bb28f6076 100644 --- a/apps/graph/graph/intersection_graph_controller.cpp +++ b/apps/graph/graph/intersection_graph_controller.cpp @@ -18,18 +18,18 @@ const char * IntersectionGraphController::title() { void IntersectionGraphController::reloadBannerView() { m_bannerView->setNumberOfSubviews(2); - reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), StorageCartesianFunction::Symbol()); - constexpr size_t bufferSize = StorageFunctionBannerDelegate::k_maxNumberOfCharacters+Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); + reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), CartesianFunction::Symbol()); + constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); char buffer[bufferSize]; const char * space = " "; const char * legend = "="; // 'f(x)=g(x)=', keep 2 chars for '=' - ExpiringPointer f = functionStore()->modelForRecord(m_record); - int numberOfChar = f->nameWithArgument(buffer, bufferSize-2, StorageCartesianFunction::Symbol()); + ExpiringPointer f = functionStore()->modelForRecord(m_record); + int numberOfChar = f->nameWithArgument(buffer, bufferSize-2, CartesianFunction::Symbol()); numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar); // keep 1 char for '='; - ExpiringPointer g = functionStore()->modelForRecord(m_intersectedRecord); - numberOfChar += g->nameWithArgument(buffer+numberOfChar, bufferSize-numberOfChar-1, StorageCartesianFunction::Symbol()); + ExpiringPointer g = functionStore()->modelForRecord(m_intersectedRecord); + numberOfChar += g->nameWithArgument(buffer+numberOfChar, bufferSize-numberOfChar-1, CartesianFunction::Symbol()); numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar); numberOfChar += PoincareHelpers::ConvertFloatToText(m_cursor->y(), buffer+numberOfChar, bufferSize-numberOfChar, Constant::MediumNumberOfSignificantDigits); strlcpy(buffer+numberOfChar, space, bufferSize-numberOfChar); diff --git a/apps/graph/graph/tangent_graph_controller.cpp b/apps/graph/graph/tangent_graph_controller.cpp index 197a69938..7032cc726 100644 --- a/apps/graph/graph/tangent_graph_controller.cpp +++ b/apps/graph/graph/tangent_graph_controller.cpp @@ -40,13 +40,13 @@ void TangentGraphController::reloadBannerView() { return; } App * myApp = static_cast(app()); - StorageFunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_record, myApp->functionStore(), StorageCartesianFunction::Symbol()); + FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_record, myApp->functionStore(), CartesianFunction::Symbol()); GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, m_record, myApp); - constexpr size_t bufferSize = StorageFunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); + constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); char buffer[bufferSize]; const char * legend = "a="; int legendLength = strlcpy(buffer, legend, bufferSize); - ExpiringPointer function = myApp->functionStore()->modelForRecord(m_record); + ExpiringPointer function = myApp->functionStore()->modelForRecord(m_record); double y = function->approximateDerivative(m_cursor->x(), myApp->localContext()); PoincareHelpers::ConvertFloatToText(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); m_bannerView->setLegendAtIndex(buffer, 4); diff --git a/apps/graph/graph/tangent_graph_controller.h b/apps/graph/graph/tangent_graph_controller.h index 9c62f94bc..aedf9f259 100644 --- a/apps/graph/graph/tangent_graph_controller.h +++ b/apps/graph/graph/tangent_graph_controller.h @@ -10,7 +10,7 @@ namespace Graph { -class TangentGraphController : public Shared::SimpleInteractiveCurveViewController, public Shared::StorageFunctionBannerDelegate, public GraphControllerHelper { +class TangentGraphController : public Shared::SimpleInteractiveCurveViewController, public Shared::FunctionBannerDelegate, public GraphControllerHelper { public: TangentGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor); const char * title() override; diff --git a/apps/graph/list/storage_list_controller.cpp b/apps/graph/list/storage_list_controller.cpp index 6beb1cd82..9734af536 100644 --- a/apps/graph/list/storage_list_controller.cpp +++ b/apps/graph/list/storage_list_controller.cpp @@ -10,7 +10,7 @@ using namespace Shared; namespace Graph { StorageListController::StorageListController(Responder * parentResponder, ButtonRowController * header, ButtonRowController * footer) : - Shared::StorageFunctionListController(parentResponder, header, footer, I18n::Message::AddFunction), + Shared::FunctionListController(parentResponder, header, footer, I18n::Message::AddFunction), m_functionTitleCells{ //TODO find better initialization TextFieldFunctionTitleCell(this), TextFieldFunctionTitleCell(this), @@ -49,14 +49,14 @@ bool StorageListController::textFieldDidFinishEditing(TextField * textField, con assert(textField != nullptr); // Compute the new name size_t textLength = strlen(text); - size_t argumentLength = StorageFunction::k_parenthesedArgumentLength; - constexpr int maxBaseNameSize = StorageFunction::k_maxNameWithArgumentSize; + size_t argumentLength = Function::k_parenthesedArgumentLength; + constexpr int maxBaseNameSize = Function::k_maxNameWithArgumentSize; char baseName[maxBaseNameSize]; if (textLength <= argumentLength) { // The user entered an empty name. Use a default function name. - StorageCartesianFunction::DefaultName(baseName, maxBaseNameSize); + CartesianFunction::DefaultName(baseName, maxBaseNameSize); size_t defaultNameLength = strlen(baseName); - strlcpy(baseName + defaultNameLength, StorageFunction::k_parenthesedArgument, maxBaseNameSize - defaultNameLength); + strlcpy(baseName + defaultNameLength, Function::k_parenthesedArgument, maxBaseNameSize - defaultNameLength); textField->setText(baseName); baseName[defaultNameLength] = 0; } else { @@ -67,8 +67,8 @@ bool StorageListController::textFieldDidFinishEditing(TextField * textField, con GlobalContext::DestroyRecordsBaseNamedWithoutExtension(baseName, Ion::Storage::funcExtension); // Set the name - StorageFunction::NameNotCompliantError nameError = StorageFunction::NameNotCompliantError::None; - Ion::Storage::Record::ErrorStatus error = StorageFunction::BaseNameCompliant(baseName, &nameError) ? modelStore()->recordAtIndex(m_selectableTableView.selectedRow()).setBaseNameWithExtension(baseName, Ion::Storage::funcExtension) : Ion::Storage::Record::ErrorStatus::NonCompliantName; + Function::NameNotCompliantError nameError = Function::NameNotCompliantError::None; + Ion::Storage::Record::ErrorStatus error = Function::BaseNameCompliant(baseName, &nameError) ? modelStore()->recordAtIndex(m_selectableTableView.selectedRow()).setBaseNameWithExtension(baseName, Ion::Storage::funcExtension) : Ion::Storage::Record::ErrorStatus::NonCompliantName; // Handle any error if (error == Ion::Storage::Record::ErrorStatus::None) { @@ -96,13 +96,13 @@ bool StorageListController::textFieldDidFinishEditing(TextField * textField, con } else if (error == Ion::Storage::Record::ErrorStatus::NameTaken) { app()->displayWarning(I18n::Message::NameTaken); } else if (error == Ion::Storage::Record::ErrorStatus::NonCompliantName) { - assert(nameError != StorageFunction::NameNotCompliantError::None); - if (nameError == StorageFunction::NameNotCompliantError::CharacterNotAllowed) { + assert(nameError != Function::NameNotCompliantError::None); + if (nameError == Function::NameNotCompliantError::CharacterNotAllowed) { app()->displayWarning(I18n::Message::AllowedCharactersAZaz09); - } else if (nameError == StorageFunction::NameNotCompliantError::NameCannotStartWithNumber) { + } else if (nameError == Function::NameNotCompliantError::NameCannotStartWithNumber) { app()->displayWarning(I18n::Message::NameCannotStartWithNumber); } else { - assert(nameError == StorageFunction::NameNotCompliantError::ReservedName); + assert(nameError == Function::NameNotCompliantError::ReservedName); app()->displayWarning(I18n::Message::ReservedName); } } else { @@ -118,7 +118,7 @@ bool StorageListController::textFieldDidAbortEditing(TextField * textField) { // Put the name column back to normal size computeTitlesColumnWidth(); selectableTableView()->reloadData(); - ExpiringPointer function = modelStore()->modelForRecord(modelStore()->recordAtIndex(selectedRow())); + ExpiringPointer function = modelStore()->modelForRecord(modelStore()->recordAtIndex(selectedRow())); setFunctionNameInTextField(function, textField); m_selectableTableView.selectedCell()->setHighlighted(true); app()->setFirstResponder(&m_selectableTableView); @@ -165,7 +165,7 @@ void StorageListController::willDisplayTitleCellAtIndex(HighlightCell * cell, in titleCell->setBaseline(baseline(j)); if (!titleCell->isEditing()) { // Set name and color if the name is not being edited - ExpiringPointer function = modelStore()->modelForRecord(modelStore()->recordAtIndex(j)); + ExpiringPointer function = modelStore()->modelForRecord(modelStore()->recordAtIndex(j)); setFunctionNameInTextField(function, titleCell->textField()); KDColor functionNameColor = function->isActive() ? function->color() : Palette::GreyDark; titleCell->setColor(functionNameColor); @@ -175,14 +175,14 @@ void StorageListController::willDisplayTitleCellAtIndex(HighlightCell * cell, in void StorageListController::willDisplayExpressionCellAtIndex(HighlightCell * cell, int j) { assert(cell != nullptr); assert(j >= 0 && j < modelStore()->numberOfModels()); - Shared::StorageFunctionListController::willDisplayExpressionCellAtIndex(cell, j); + Shared::FunctionListController::willDisplayExpressionCellAtIndex(cell, j); FunctionExpressionCell * myCell = (FunctionExpressionCell *)cell; - ExpiringPointer f = modelStore()->modelForRecord(modelStore()->recordAtIndex(j)); + ExpiringPointer f = modelStore()->modelForRecord(modelStore()->recordAtIndex(j)); KDColor textColor = f->isActive() ? KDColorBlack : Palette::GreyDark; myCell->setTextColor(textColor); } -void StorageListController::setFunctionNameInTextField(ExpiringPointer function, TextField * textField) { +void StorageListController::setFunctionNameInTextField(ExpiringPointer function, TextField * textField) { assert(textField != nullptr); char bufferName[BufferTextView::k_maxNumberOfChar]; function->nameWithArgument(bufferName, BufferTextView::k_maxNumberOfChar, modelStore()->symbol()); diff --git a/apps/graph/list/storage_list_controller.h b/apps/graph/list/storage_list_controller.h index eabe0c52f..85c35bbb3 100644 --- a/apps/graph/list/storage_list_controller.h +++ b/apps/graph/list/storage_list_controller.h @@ -11,7 +11,7 @@ namespace Graph { -class StorageListController : public Shared::StorageFunctionListController, public Shared::TextFieldDelegate { +class StorageListController : public Shared::FunctionListController, public Shared::TextFieldDelegate { public: StorageListController(Responder * parentResponder, ButtonRowController * header, ButtonRowController * footer); const char * title() override; @@ -32,7 +32,7 @@ private: Shared::TextFieldDelegateApp * textFieldDelegateApp() override { return static_cast(app()); } - void setFunctionNameInTextField(Shared::ExpiringPointer function, TextField * textField); + void setFunctionNameInTextField(Shared::ExpiringPointer function, TextField * textField); TextFieldFunctionTitleCell m_functionTitleCells[k_maxNumberOfDisplayableRows]; Shared::FunctionExpressionCell m_expressionCells[k_maxNumberOfDisplayableRows]; ListParameterController m_parameterController; diff --git a/apps/graph/list/text_field_function_title_cell.cpp b/apps/graph/list/text_field_function_title_cell.cpp index 12c2df521..e3301b258 100644 --- a/apps/graph/list/text_field_function_title_cell.cpp +++ b/apps/graph/list/text_field_function_title_cell.cpp @@ -10,7 +10,7 @@ static inline float maxFloat(float x, float y) { return x > y ? x : y; } TextFieldFunctionTitleCell::TextFieldFunctionTitleCell(StorageListController * listController, Orientation orientation, const KDFont * font) : Shared::FunctionTitleCell(orientation), Responder(listController), - m_textField(Shared::StorageFunction::k_parenthesedArgumentLength, this, m_textFieldBuffer, m_textFieldBuffer, k_textFieldBufferSize, nullptr, listController, false, font, 1.0f, 0.5f) + m_textField(Shared::Function::k_parenthesedArgumentLength, this, m_textFieldBuffer, m_textFieldBuffer, k_textFieldBufferSize, nullptr, listController, false, font, 1.0f, 0.5f) { } diff --git a/apps/graph/list/text_field_function_title_cell.h b/apps/graph/list/text_field_function_title_cell.h index 3a8771ba2..421a96d6c 100644 --- a/apps/graph/list/text_field_function_title_cell.h +++ b/apps/graph/list/text_field_function_title_cell.h @@ -2,7 +2,7 @@ #define GRAPH_LIST_TEXT_FIELD_FUNCTION_TITLE_CELL_H #include -#include +#include #include namespace Graph { @@ -41,7 +41,7 @@ public: void didBecomeFirstResponder() override; private: constexpr static KDCoordinate k_textFieldRightMargin = 4; - constexpr static int k_textFieldBufferSize = Shared::StorageFunction::k_maxNameWithArgumentSize; + constexpr static int k_textFieldBufferSize = Shared::Function::k_maxNameWithArgumentSize; float verticalAlignmentGivenExpressionBaselineAndRowHeight(KDCoordinate expressionBaseline, KDCoordinate rowHeight) const override; Shared::TextFieldWithExtension m_textField; char m_textFieldBuffer[k_textFieldBufferSize]; diff --git a/apps/graph/storage_cartesian_function_store.cpp b/apps/graph/storage_cartesian_function_store.cpp index 57a0721bd..ac73f7ae5 100644 --- a/apps/graph/storage_cartesian_function_store.cpp +++ b/apps/graph/storage_cartesian_function_store.cpp @@ -11,16 +11,16 @@ namespace Graph { Ion::Storage::Record::ErrorStatus StorageCartesianFunctionStore::addEmptyModel() { Ion::Storage::Record::ErrorStatus error; - StorageCartesianFunction newModel = StorageCartesianFunction::NewModel(&error); + CartesianFunction newModel = CartesianFunction::NewModel(&error); return error; } void StorageCartesianFunctionStore::setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record record) const { assert(cacheIndex >= 0 && cacheIndex < maxNumberOfMemoizedModels()); - m_functions[cacheIndex] = StorageCartesianFunction(record); + m_functions[cacheIndex] = CartesianFunction(record); } -SingleExpressionModelHandle * StorageCartesianFunctionStore::memoizedModelAtIndex(int cacheIndex) const { +ExpressionModelHandle * StorageCartesianFunctionStore::memoizedModelAtIndex(int cacheIndex) const { assert(cacheIndex >= 0 && cacheIndex < maxNumberOfMemoizedModels()); return &m_functions[cacheIndex]; } diff --git a/apps/graph/storage_cartesian_function_store.h b/apps/graph/storage_cartesian_function_store.h index 0f21a9cf1..7a4c02151 100644 --- a/apps/graph/storage_cartesian_function_store.h +++ b/apps/graph/storage_cartesian_function_store.h @@ -1,24 +1,24 @@ #ifndef GRAPH_STORAGE_CARTESIAN_FUNCTION_STORE_H #define GRAPH_STORAGE_CARTESIAN_FUNCTION_STORE_H -#include "../shared/storage_cartesian_function.h" +#include "../shared/cartesian_function.h" #include "../shared/storage_function_store.h" #include #include namespace Graph { -class StorageCartesianFunctionStore : public Shared::StorageFunctionStore { +class StorageCartesianFunctionStore : public Shared::FunctionStore { public: - Shared::ExpiringPointer modelForRecord(Ion::Storage::Record record) const { return Shared::ExpiringPointer(static_cast(privateModelForRecord(record))); } - char symbol() const override { return Shared::StorageCartesianFunction::Symbol(); } + Shared::ExpiringPointer modelForRecord(Ion::Storage::Record record) const { return Shared::ExpiringPointer(static_cast(privateModelForRecord(record))); } + char symbol() const override { return Shared::CartesianFunction::Symbol(); } char unknownSymbol() const override { return Poincare::Symbol::SpecialSymbols::UnknownX; } private: Ion::Storage::Record::ErrorStatus addEmptyModel() override; const char * modelExtension() const override { return Ion::Storage::funcExtension; } void setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record record) const override; - Shared::SingleExpressionModelHandle * memoizedModelAtIndex(int cacheIndex) const override; - mutable Shared::StorageCartesianFunction m_functions[k_maxNumberOfMemoizedModels]; + Shared::ExpressionModelHandle * memoizedModelAtIndex(int cacheIndex) const override; + mutable Shared::CartesianFunction m_functions[k_maxNumberOfMemoizedModels]; }; } diff --git a/apps/graph/values/storage_derivative_parameter_controller.cpp b/apps/graph/values/storage_derivative_parameter_controller.cpp index 51be4d2fc..91bef595a 100644 --- a/apps/graph/values/storage_derivative_parameter_controller.cpp +++ b/apps/graph/values/storage_derivative_parameter_controller.cpp @@ -18,7 +18,7 @@ StorageDerivativeParameterController::StorageDerivativeParameterController(Stora } void StorageDerivativeParameterController::viewWillAppear() { - functionStore()->modelForRecord(m_record)->derivativeNameWithArgument(m_pageTitle, k_maxNumberOfCharsInTitle, Shared::StorageCartesianFunction::Symbol()); + functionStore()->modelForRecord(m_record)->derivativeNameWithArgument(m_pageTitle, k_maxNumberOfCharsInTitle, Shared::CartesianFunction::Symbol()); } const char * StorageDerivativeParameterController::title() { diff --git a/apps/graph/values/storage_derivative_parameter_controller.h b/apps/graph/values/storage_derivative_parameter_controller.h index 30675d06a..5680aff98 100644 --- a/apps/graph/values/storage_derivative_parameter_controller.h +++ b/apps/graph/values/storage_derivative_parameter_controller.h @@ -31,7 +31,7 @@ private: #else constexpr static int k_totalNumberOfCell = 1; #endif - constexpr static int k_maxNumberOfCharsInTitle = Shared::StorageFunction::k_maxNameWithArgumentSize + 1; // +1 for the ' of the derivative + constexpr static int k_maxNumberOfCharsInTitle = Shared::Function::k_maxNameWithArgumentSize + 1; // +1 for the ' of the derivative char m_pageTitle[k_maxNumberOfCharsInTitle]; MessageTableCell m_hideColumn; #if COPY_COLUMN diff --git a/apps/graph/values/storage_function_parameter_controller.cpp b/apps/graph/values/storage_function_parameter_controller.cpp index 915344785..a9371be7c 100644 --- a/apps/graph/values/storage_function_parameter_controller.cpp +++ b/apps/graph/values/storage_function_parameter_controller.cpp @@ -7,14 +7,14 @@ using namespace Shared; namespace Graph { -StorageFunctionParameterController::StorageFunctionParameterController(StorageValuesController * valuesController) : - StorageValuesFunctionParameterController(StorageCartesianFunction::Symbol()), +FunctionParameterController::FunctionParameterController(StorageValuesController * valuesController) : + StorageValuesFunctionParameterController(CartesianFunction::Symbol()), m_displayDerivativeColumn(I18n::Message::DerivativeFunctionColumn), m_valuesController(valuesController) { } -bool StorageFunctionParameterController::handleEvent(Ion::Events::Event event) { +bool FunctionParameterController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::OK || event == Ion::Events::EXE) { switch (selectedRow()) { case 0: @@ -38,11 +38,11 @@ bool StorageFunctionParameterController::handleEvent(Ion::Events::Event event) { return false; } -int StorageFunctionParameterController::numberOfRows() { +int FunctionParameterController::numberOfRows() { return k_totalNumberOfCell; }; -HighlightCell * StorageFunctionParameterController::reusableCell(int index) { +HighlightCell * FunctionParameterController::reusableCell(int index) { assert(index >= 0); assert(index < k_totalNumberOfCell); #if COPY_COLUMN @@ -53,23 +53,23 @@ HighlightCell * StorageFunctionParameterController::reusableCell(int index) { return cells[index]; } -int StorageFunctionParameterController::reusableCellCount() { +int FunctionParameterController::reusableCellCount() { return k_totalNumberOfCell; } -void StorageFunctionParameterController::viewWillAppear() { +void FunctionParameterController::viewWillAppear() { StorageValuesFunctionParameterController::viewWillAppear(); m_selectedFunctionColumn = m_valuesController->selectedColumn(); } -void StorageFunctionParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) { +void FunctionParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) { if (cell == &m_displayDerivativeColumn) { SwitchView * switchView = (SwitchView *)m_displayDerivativeColumn.accessoryView(); switchView->setState(function()->displayDerivative()); } } -ExpiringPointer StorageFunctionParameterController::function() { +ExpiringPointer FunctionParameterController::function() { App * a = static_cast(app()); return a->functionStore()->modelForRecord(m_record); } diff --git a/apps/graph/values/storage_function_parameter_controller.h b/apps/graph/values/storage_function_parameter_controller.h index c629c73b6..5e652566f 100644 --- a/apps/graph/values/storage_function_parameter_controller.h +++ b/apps/graph/values/storage_function_parameter_controller.h @@ -2,16 +2,16 @@ #define GRAPH_STORAGE_FUNCTION_PARAM_CONTROLLER_H #include "../../shared/expiring_pointer.h" -#include "../../shared/storage_cartesian_function.h" +#include "../../shared/cartesian_function.h" #include "../../shared/storage_values_function_parameter_controller.h" namespace Graph { class StorageValuesController; -class StorageFunctionParameterController : public Shared::StorageValuesFunctionParameterController { +class FunctionParameterController : public Shared::StorageValuesFunctionParameterController { public: - StorageFunctionParameterController(StorageValuesController * valuesController); + FunctionParameterController(StorageValuesController * valuesController); bool handleEvent(Ion::Events::Event event) override; int numberOfRows() override; HighlightCell * reusableCell(int index) override; @@ -19,7 +19,7 @@ public: void willDisplayCellForIndex(HighlightCell * cell, int index) override; void viewWillAppear() override; private: - Shared::ExpiringPointer function(); + Shared::ExpiringPointer function(); #if COPY_COLUMN constexpr static int k_totalNumberOfCell = 2; #else diff --git a/apps/graph/values/storage_values_controller.cpp b/apps/graph/values/storage_values_controller.cpp index 764c990e8..c2ca320e7 100644 --- a/apps/graph/values/storage_values_controller.cpp +++ b/apps/graph/values/storage_values_controller.cpp @@ -41,16 +41,16 @@ void StorageValuesController::willDisplayCellAtLocation(HighlightCell * cell, in // The cell is a function title cell: if (j == 0 && i > 0) { Shared::BufferFunctionTitleCell * myFunctionCell = (Shared::BufferFunctionTitleCell *)cell; - const size_t bufferNameSize = Shared::StorageFunction::k_maxNameWithArgumentSize + 1; + const size_t bufferNameSize = Shared::Function::k_maxNameWithArgumentSize + 1; char bufferName[bufferNameSize]; bool isDerivative = isDerivativeColumn(i); /* isDerivativeColumn uses expiring pointers, so "function" must be created * after the isDerivativeColumn call, else it will expire. */ - Shared::ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(i)); + Shared::ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(i)); if (isDerivative) { - function->derivativeNameWithArgument(bufferName, bufferNameSize, StorageCartesianFunction::Symbol()); + function->derivativeNameWithArgument(bufferName, bufferNameSize, CartesianFunction::Symbol()); } else { - function->nameWithArgument(bufferName, bufferNameSize, StorageCartesianFunction::Symbol()); + function->nameWithArgument(bufferName, bufferNameSize, CartesianFunction::Symbol()); } myFunctionCell->setText(bufferName); myFunctionCell->setColor(function->color()); @@ -73,7 +73,7 @@ Ion::Storage::Record StorageValuesController::recordAtColumn(int i) { int index = 1; for (int k = 0; k < functionStore()->numberOfDefinedModels(); k++) { Ion::Storage::Record record = functionStore()->definedRecordAtIndex(k); - ExpiringPointer f = functionStore()->modelForRecord(record); + ExpiringPointer f = functionStore()->modelForRecord(record); if (f->isActive()) { if (i == index) { return record; @@ -95,7 +95,7 @@ bool StorageValuesController::isDerivativeColumn(int i) { assert(i >= 1); int index = 1; for (int k = 0; k < functionStore()->numberOfDefinedModels(); k++) { - ExpiringPointer f = functionStore()->modelForRecord(functionStore()->definedRecordAtIndex(k)); + ExpiringPointer f = functionStore()->modelForRecord(functionStore()->definedRecordAtIndex(k)); if (f->isActive()) { if (i == index) { return false; @@ -137,7 +137,7 @@ EvenOddBufferTextCell * StorageValuesController::floatCells(int j) { return &m_floatCells[j]; } -StorageFunctionParameterController * StorageValuesController::functionParameterController() { +FunctionParameterController * StorageValuesController::functionParameterController() { return &m_functionParameterController; } @@ -146,7 +146,7 @@ double StorageValuesController::evaluationOfAbscissaAtColumn(double abscissa, in bool isDerivative = isDerivativeColumn(columnIndex); /* isDerivativeColumn uses expiring pointers, so "function" must be created * after the isDerivativeColumn call, else it will expire. */ - Shared::ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(columnIndex)); + Shared::ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(columnIndex)); if (isDerivative) { return function->approximateDerivative(abscissa, myApp->localContext()); } @@ -156,7 +156,7 @@ double StorageValuesController::evaluationOfAbscissaAtColumn(double abscissa, in void StorageValuesController::updateNumberOfColumns() { int result = 1; for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) { - ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i)); + ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i)); if (f->isActive()) { result += 1 + f->displayDerivative(); } diff --git a/apps/graph/values/storage_values_controller.h b/apps/graph/values/storage_values_controller.h index e97a53fe7..3233e70d0 100644 --- a/apps/graph/values/storage_values_controller.h +++ b/apps/graph/values/storage_values_controller.h @@ -30,11 +30,11 @@ private: StorageCartesianFunctionStore * functionStore() const override { return static_cast(Shared::StorageValuesController::functionStore()); } Shared::BufferFunctionTitleCell * functionTitleCells(int j) override; EvenOddBufferTextCell * floatCells(int j) override; - StorageFunctionParameterController * functionParameterController() override; + FunctionParameterController * functionParameterController() override; Shared::BufferFunctionTitleCell m_functionTitleCells[k_maxNumberOfFunctions]; EvenOddBufferTextCell m_floatCells[k_maxNumberOfCells]; - StorageFunctionParameterController m_functionParameterController; + FunctionParameterController m_functionParameterController; Shared::IntervalParameterController m_intervalParameterController; StorageDerivativeParameterController m_derivativeParameterController; }; diff --git a/apps/sequence/app.cpp b/apps/sequence/app.cpp index 93fea6e6e..f2e1f42c2 100644 --- a/apps/sequence/app.cpp +++ b/apps/sequence/app.cpp @@ -19,7 +19,7 @@ const Image * App::Descriptor::icon() { } App::Snapshot::Snapshot() : - Shared::StorageFunctionApp::Snapshot::Snapshot(), + Shared::FunctionApp::Snapshot::Snapshot(), m_sequenceStore(), m_graphRange(&m_cursor) { @@ -30,7 +30,7 @@ App * App::Snapshot::unpack(Container * container) { } void App::Snapshot::reset() { - StorageFunctionApp::Snapshot::reset(); + FunctionApp::Snapshot::reset(); /* reset might be called when activating the exam mode from the settings or * when a memory exception occurs. In both cases, we do not want to * computeYAuto in GraphRange::setDefault, so we need to set its delegate to @@ -54,7 +54,7 @@ void App::Snapshot::tidy() { } App::App(Container * container, Snapshot * snapshot) : - StorageFunctionApp(container, snapshot, &m_inputViewController), + FunctionApp(container, snapshot, &m_inputViewController), m_sequenceContext(((AppsContainer *)container)->globalContext(), snapshot->functionStore()), m_listController(&m_listFooter, this, &m_listHeader, &m_listFooter), m_listFooter(&m_listHeader, &m_listController, &m_listController, ButtonRowController::Position::Bottom, ButtonRowController::Style::EmbossedGrey), diff --git a/apps/sequence/app.h b/apps/sequence/app.h index c63f24f30..f514839e8 100644 --- a/apps/sequence/app.h +++ b/apps/sequence/app.h @@ -8,11 +8,11 @@ #include "graph/curve_view_range.h" #include "list/list_controller.h" #include "values/values_controller.h" -#include "../shared/storage_function_app.h" +#include "../shared/function_app.h" namespace Sequence { -class App : public Shared::StorageFunctionApp { +class App : public Shared::FunctionApp { public: class Descriptor : public ::App::Descriptor { public: @@ -20,7 +20,7 @@ public: I18n::Message upperName() override; const Image * icon() override; }; - class Snapshot : public Shared::StorageFunctionApp::Snapshot { + class Snapshot : public Shared::FunctionApp::Snapshot { public: Snapshot(); App * unpack(Container * container) override; @@ -38,7 +38,7 @@ public: // NestedMenuController * variableBoxForInputEventHandler(InputEventHandler * textInput) override; char XNT() override; SequenceContext * localContext() override; - SequenceStore * functionStore() override { return static_cast(Shared::StorageFunctionApp::functionStore()); } + SequenceStore * functionStore() override { return static_cast(Shared::FunctionApp::functionStore()); } private: App(Container * container, Snapshot * snapshot); SequenceContext m_sequenceContext; diff --git a/apps/sequence/graph/curve_parameter_controller.cpp b/apps/sequence/graph/curve_parameter_controller.cpp index 9ba0be189..6521148ec 100644 --- a/apps/sequence/graph/curve_parameter_controller.cpp +++ b/apps/sequence/graph/curve_parameter_controller.cpp @@ -7,7 +7,7 @@ using namespace Shared; namespace Sequence { CurveParameterController::CurveParameterController(InputEventHandlerDelegate * inputEventHandlerDelegate, GraphController * graphController, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor) : - StorageFunctionCurveParameterController(graphRange, cursor), + FunctionCurveParameterController(graphRange, cursor), m_goToParameterController(this, inputEventHandlerDelegate, graphRange, cursor, I18n::Message::N), m_sumCell(I18n::Message::TermSum), m_graphController(graphController) diff --git a/apps/sequence/graph/curve_parameter_controller.h b/apps/sequence/graph/curve_parameter_controller.h index 7a5bf923a..d3cf4e728 100644 --- a/apps/sequence/graph/curve_parameter_controller.h +++ b/apps/sequence/graph/curve_parameter_controller.h @@ -9,7 +9,7 @@ namespace Sequence { class GraphController; -class CurveParameterController : public Shared::StorageFunctionCurveParameterController { +class CurveParameterController : public Shared::FunctionCurveParameterController { public: CurveParameterController(InputEventHandlerDelegate * inputEventHandlerDelegate, GraphController * graphController, Shared::InteractiveCurveViewRange * graphRange, Shared::CurveViewCursor * cursor); const char * title() override; diff --git a/apps/sequence/graph/go_to_parameter_controller.cpp b/apps/sequence/graph/go_to_parameter_controller.cpp index e373e15fb..93d97f983 100644 --- a/apps/sequence/graph/go_to_parameter_controller.cpp +++ b/apps/sequence/graph/go_to_parameter_controller.cpp @@ -6,7 +6,7 @@ namespace Sequence { bool GoToParameterController::setParameterAtIndex(int parameterIndex, double f) { assert(parameterIndex == 0); - return Shared::StorageFunctionGoToParameterController::setParameterAtIndex(parameterIndex, std::round(f)); + return Shared::FunctionGoToParameterController::setParameterAtIndex(parameterIndex, std::round(f)); } } diff --git a/apps/sequence/graph/go_to_parameter_controller.h b/apps/sequence/graph/go_to_parameter_controller.h index d7424d184..2021aa018 100644 --- a/apps/sequence/graph/go_to_parameter_controller.h +++ b/apps/sequence/graph/go_to_parameter_controller.h @@ -5,9 +5,9 @@ namespace Sequence { -class GoToParameterController : public Shared::StorageFunctionGoToParameterController { +class GoToParameterController : public Shared::FunctionGoToParameterController { public: - using Shared::StorageFunctionGoToParameterController::StorageFunctionGoToParameterController; + using Shared::FunctionGoToParameterController::FunctionGoToParameterController; private: bool setParameterAtIndex(int parameterIndex, double f) override; }; diff --git a/apps/sequence/graph/graph_controller.cpp b/apps/sequence/graph/graph_controller.cpp index 6e33b612f..f141eba34 100644 --- a/apps/sequence/graph/graph_controller.cpp +++ b/apps/sequence/graph/graph_controller.cpp @@ -11,7 +11,7 @@ static inline int minInt(int x, int y) { return (x < y ? x : y); } static inline int maxInt(int x, int y) { return (x > y ? x : y); } GraphController::GraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, SequenceStore * sequenceStore, CurveViewRange * graphRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) : - StorageFunctionGraphController(parentResponder, inputEventHandlerDelegate, header, graphRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion), + FunctionGraphController(parentResponder, inputEventHandlerDelegate, header, graphRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion), m_bannerView(), m_view(sequenceStore, graphRange, m_cursor, &m_bannerView, &m_cursorView), m_graphRange(graphRange), @@ -40,7 +40,7 @@ float GraphController::interestingXMin() const { } float GraphController::interestingXHalfRange() const { - float standardRange = Shared::StorageFunctionGraphController::interestingXHalfRange(); + float standardRange = Shared::FunctionGraphController::interestingXHalfRange(); int nmin = INT_MAX; int nmax = 0; int nbOfActiveModels = functionStore()->numberOfActiveFunctions(); @@ -57,7 +57,7 @@ float GraphController::interestingXHalfRange() const { bool GraphController::handleEnter() { Ion::Storage::Record record = functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor()); m_termSumController.setRecord(record); - return StorageFunctionGraphController::handleEnter(); + return FunctionGraphController::handleEnter(); } bool GraphController::moveCursorHorizontally(int direction) { @@ -84,7 +84,7 @@ bool GraphController::moveCursorHorizontally(int direction) { } double GraphController::defaultCursorAbscissa() { - return std::round(Shared::StorageFunctionGraphController::defaultCursorAbscissa()); + return std::round(Shared::FunctionGraphController::defaultCursorAbscissa()); } } diff --git a/apps/sequence/graph/graph_controller.h b/apps/sequence/graph/graph_controller.h index 1cdc56c46..0aac68efd 100644 --- a/apps/sequence/graph/graph_controller.h +++ b/apps/sequence/graph/graph_controller.h @@ -12,7 +12,7 @@ namespace Sequence { -class GraphController final : public Shared::StorageFunctionGraphController { +class GraphController final : public Shared::FunctionGraphController { public: GraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, SequenceStore * sequenceStore, CurveViewRange * graphRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header); I18n::Message emptyMessage() override; @@ -28,7 +28,7 @@ private: bool moveCursorHorizontally(int direction) override; double defaultCursorAbscissa() override; CurveViewRange * interactiveCurveViewRange() override { return m_graphRange; } - SequenceStore * functionStore() const override { return static_cast(Shared::StorageFunctionGraphController::functionStore()); } + SequenceStore * functionStore() const override { return static_cast(Shared::FunctionGraphController::functionStore()); } GraphView * functionGraphView() override { return &m_view; } View * cursorView() override { return &m_cursorView; diff --git a/apps/sequence/graph/graph_view.cpp b/apps/sequence/graph/graph_view.cpp index 9912b2ade..1577b2e1d 100644 --- a/apps/sequence/graph/graph_view.cpp +++ b/apps/sequence/graph/graph_view.cpp @@ -7,13 +7,13 @@ namespace Sequence { GraphView::GraphView(SequenceStore * sequenceStore, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) : - StorageFunctionGraphView(graphRange, cursor, bannerView, cursorView), + FunctionGraphView(graphRange, cursor, bannerView, cursorView), m_sequenceStore(sequenceStore) { } void GraphView::drawRect(KDContext * ctx, KDRect rect) const { - StorageFunctionGraphView::drawRect(ctx, rect); + FunctionGraphView::drawRect(ctx, rect); for (int i = 0; i < m_sequenceStore->numberOfActiveFunctions(); i++) { Ion::Storage::Record record = m_sequenceStore->activeRecordAtIndex(i); Sequence * s = m_sequenceStore->modelForRecord(record);; diff --git a/apps/sequence/graph/graph_view.h b/apps/sequence/graph/graph_view.h index 291ddf8fe..1f0fce5c3 100644 --- a/apps/sequence/graph/graph_view.h +++ b/apps/sequence/graph/graph_view.h @@ -6,7 +6,7 @@ namespace Sequence { -class GraphView : public Shared::StorageFunctionGraphView { +class GraphView : public Shared::FunctionGraphView { public: GraphView(SequenceStore * sequenceStore, Shared::InteractiveCurveViewRange * graphRange, Shared::CurveViewCursor * cursor, Shared::BannerView * bannerView, View * cursorView); diff --git a/apps/sequence/graph/term_sum_controller.cpp b/apps/sequence/graph/term_sum_controller.cpp index be27cea2f..8126f0577 100644 --- a/apps/sequence/graph/term_sum_controller.cpp +++ b/apps/sequence/graph/term_sum_controller.cpp @@ -48,7 +48,7 @@ double TermSumController::cursorNextStep(double x, int direction) { return std::round(m_cursor->x()+delta); } -Layout TermSumController::createFunctionLayout(Shared::ExpiringPointer function) { +Layout TermSumController::createFunctionLayout(Shared::ExpiringPointer function) { Sequence * sequence = static_cast(function.pointer()); return sequence->nameLayout(); } diff --git a/apps/sequence/graph/term_sum_controller.h b/apps/sequence/graph/term_sum_controller.h index 5d7e4b31b..9f00cacc8 100644 --- a/apps/sequence/graph/term_sum_controller.h +++ b/apps/sequence/graph/term_sum_controller.h @@ -17,7 +17,7 @@ private: bool moveCursorHorizontallyToPosition(double position) override; I18n::Message legendMessageAtStep(Step step) override; double cursorNextStep(double position, int direction) override; - Poincare::Layout createFunctionLayout(Shared::ExpiringPointer function) override; + Poincare::Layout createFunctionLayout(Shared::ExpiringPointer function) override; }; } diff --git a/apps/sequence/list/list_controller.cpp b/apps/sequence/list/list_controller.cpp index 61c52b8ff..08aab769f 100644 --- a/apps/sequence/list/list_controller.cpp +++ b/apps/sequence/list/list_controller.cpp @@ -10,7 +10,7 @@ static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { retur namespace Sequence { ListController::ListController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, ButtonRowController * header, ButtonRowController * footer) : - Shared::StorageFunctionListController(parentResponder, header, footer, I18n::Message::AddSequence), + Shared::FunctionListController(parentResponder, header, footer, I18n::Message::AddSequence), m_sequenceTitleCells{}, m_expressionCells{}, m_parameterController(inputEventHandlerDelegate, this), @@ -61,7 +61,7 @@ KDCoordinate ListController::expressionRowHeight(int j) { } void ListController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { - Shared::StorageFunctionListController::willDisplayCellAtLocation(cell, i, j); + Shared::FunctionListController::willDisplayCellAtLocation(cell, i, j); EvenOddCell * myCell = (EvenOddCell *)cell; myCell->setEven(modelIndexForRow(j)%2 == 0); } @@ -278,7 +278,7 @@ void ListController::editExpression(Ion::Events::Event event) { editExpression(sequenceDefinitionForRow(selectedRow()), event); } -void ListController::reinitSelectedExpression(ExpiringPointer model) { +void ListController::reinitSelectedExpression(ExpiringPointer model) { // Invalidate the sequences context cache static_cast(app())->localContext()->resetCache(); Sequence * sequence = static_cast(model.pointer()); @@ -306,7 +306,7 @@ void ListController::reinitSelectedExpression(ExpiringPointer(app())->localContext()->resetCache(); return true; diff --git a/apps/sequence/list/list_controller.h b/apps/sequence/list/list_controller.h index 0bd1deb71..0606a6e5e 100644 --- a/apps/sequence/list/list_controller.h +++ b/apps/sequence/list/list_controller.h @@ -15,7 +15,7 @@ namespace Sequence { -class ListController : public Shared::StorageFunctionListController, public Shared::InputEventHandlerDelegate, public Shared::TextFieldDelegate, public Shared::LayoutFieldDelegate { +class ListController : public Shared::FunctionListController, public Shared::InputEventHandlerDelegate, public Shared::TextFieldDelegate, public Shared::LayoutFieldDelegate { public: ListController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, ButtonRowController * header, ButtonRowController * footer); const char * title() override; @@ -41,10 +41,10 @@ private: bool isAddEmptyRow(int j) override; int sequenceDefinitionForRow(int j); void addEmptyModel() override; - void reinitSelectedExpression(Shared::ExpiringPointer model) override; + void reinitSelectedExpression(Shared::ExpiringPointer model) override; void editExpression(Ion::Events::Event event) override; bool removeModelRow(Ion::Storage::Record record) override; - SequenceStore * modelStore() override { return static_cast(Shared::StorageFunctionListController::modelStore()); } + SequenceStore * modelStore() override { return static_cast(Shared::FunctionListController::modelStore()); } constexpr static int k_maxNumberOfRows = 3*MaxNumberOfSequences; SequenceTitleCell m_sequenceTitleCells[k_maxNumberOfRows]; Shared::FunctionExpressionCell m_expressionCells[k_maxNumberOfRows]; diff --git a/apps/sequence/sequence.cpp b/apps/sequence/sequence.cpp index ba4ecb7cb..9ef1b7cb1 100644 --- a/apps/sequence/sequence.cpp +++ b/apps/sequence/sequence.cpp @@ -16,7 +16,7 @@ namespace Sequence { void Sequence::tidy() { m_definitionHandle.tidyName(); - StorageFunction::tidy(); // m_definitionName.tidy() + Function::tidy(); // m_definitionName.tidy() m_firstInitialConditionHandle.tidy(); m_firstInitialConditionHandle.tidyName(); m_secondInitialConditionHandle.tidy(); @@ -87,11 +87,11 @@ bool Sequence::isDefined() { SequenceRecordData * data = recordData(); switch (type()) { case Type::Explicit: - return StorageFunction::isDefined(); + return Function::isDefined(); case Type::SingleRecurrence: - return StorageFunction::isDefined() && data->firstInitialConditionSize() > 0; + return Function::isDefined() && data->firstInitialConditionSize() > 0; default: - return StorageFunction::isDefined() && data->firstInitialConditionSize() > 0 && data->secondInitialConditionSize() > 0; + return Function::isDefined() && data->firstInitialConditionSize() > 0 && data->secondInitialConditionSize() > 0; } } @@ -99,11 +99,11 @@ bool Sequence::isEmpty() { SequenceRecordData * data = recordData(); switch (type()) { case Type::Explicit: - return StorageFunction::isEmpty(); + return Function::isEmpty(); case Type::SingleRecurrence: - return StorageFunction::isEmpty() && data->firstInitialConditionSize() == 0; + return Function::isEmpty() && data->firstInitialConditionSize() == 0; default: - return StorageFunction::isEmpty() && data->firstInitialConditionSize() == 0 && data->secondInitialConditionSize() == 0; + return Function::isEmpty() && data->firstInitialConditionSize() == 0 && data->secondInitialConditionSize() == 0; } } diff --git a/apps/sequence/sequence.h b/apps/sequence/sequence.h index b6788ad6c..263c7aa41 100644 --- a/apps/sequence/sequence.h +++ b/apps/sequence/sequence.h @@ -1,7 +1,7 @@ #ifndef SEQUENCE_SEQUENCE_H #define SEQUENCE_SEQUENCE_H -#include "../shared/storage_function.h" +#include "../shared/function.h" #include "sequence_context.h" #include @@ -11,7 +11,7 @@ namespace Sequence { * or setSecondInitialConditionContent, the sequence context needs to * invalidate the cache because the sequences evaluations might have changed. */ -class Sequence : public Shared::StorageFunction { +class Sequence : public Shared::Function { friend class SequenceStore; public: enum class Type : uint8_t { @@ -20,7 +20,7 @@ public: DoubleRecurrence = 2 }; Sequence(Ion::Storage::Record record = Record()) : - StorageFunction(record), + Function(record), m_nameLayout() {} static char Symbol() { return 'n'; } void tidy() override; @@ -94,9 +94,9 @@ private: uint16_t m_secondInitialConditionSize; }; - class SequenceHandle : public Shared::ExpressionModelHandle { + class SequenceHandle : public Shared::ExpressionModel { public: - SequenceHandle() : Shared::ExpressionModelHandle(), m_name() {} + SequenceHandle() : Shared::ExpressionModel(), m_name() {} void tidyName() { m_name = Poincare::Layout(); } virtual Poincare::Layout name(Sequence * sequence); protected: @@ -135,7 +135,7 @@ private: template T templatedApproximateAtAbscissa(T x, SequenceContext * sqctx) const; size_t metaDataSize() const override { return sizeof(SequenceRecordData); } - const Shared::ExpressionModelHandle * handle() const override { return &m_definitionHandle; } + const Shared::ExpressionModel * handle() const override { return &m_definitionHandle; } SequenceRecordData * recordData() const; DefinitionHandle m_definitionHandle; FirstInitialConditionHandle m_firstInitialConditionHandle; diff --git a/apps/sequence/sequence_store.cpp b/apps/sequence/sequence_store.cpp index 6ede5a26a..3f96da4e8 100644 --- a/apps/sequence/sequence_store.cpp +++ b/apps/sequence/sequence_store.cpp @@ -42,7 +42,7 @@ void SequenceStore::setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record m_sequences[cacheIndex] = Sequence(record); } -Shared::SingleExpressionModelHandle * SequenceStore::memoizedModelAtIndex(int cacheIndex) const { +Shared::ExpressionModelHandle * SequenceStore::memoizedModelAtIndex(int cacheIndex) const { assert(cacheIndex >= 0 && cacheIndex < maxNumberOfMemoizedModels()); return &m_sequences[cacheIndex]; } diff --git a/apps/sequence/sequence_store.h b/apps/sequence/sequence_store.h index 3db947705..a4127e977 100644 --- a/apps/sequence/sequence_store.h +++ b/apps/sequence/sequence_store.h @@ -9,9 +9,9 @@ namespace Sequence { -class SequenceStore : public Shared::StorageFunctionStore { +class SequenceStore : public Shared::FunctionStore { public: - using Shared::StorageFunctionStore::StorageFunctionStore; + using Shared::FunctionStore::FunctionStore; char symbol() const override { return Sequence::Symbol(); } char unknownSymbol() const override { return Poincare::Symbol::SpecialSymbols::UnknownN; } /* Sequence Store hold all its Sequences in an array. The Sequence pointers @@ -34,7 +34,7 @@ private: /* We don't really use model memoization as the number of Sequence is limited * and we keep enough Sequences to store them all. */ void setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record record) const override; - Shared::SingleExpressionModelHandle * memoizedModelAtIndex(int cacheIndex) const override; + Shared::ExpressionModelHandle * memoizedModelAtIndex(int cacheIndex) const override; mutable Sequence m_sequences[MaxNumberOfSequences]; }; diff --git a/apps/shared/Makefile b/apps/shared/Makefile index ba497ab19..95dce6218 100644 --- a/apps/shared/Makefile +++ b/apps/shared/Makefile @@ -3,6 +3,7 @@ app_src += $(addprefix apps/shared/,\ buffer_function_title_cell.cpp \ buffer_text_view_with_text_field.cpp \ button_with_separator.cpp \ + cartesian_function.cpp\ cursor_view.cpp \ curve_view.cpp \ curve_view_cursor.cpp \ @@ -10,8 +11,11 @@ app_src += $(addprefix apps/shared/,\ double_pair_store.cpp \ editable_cell_table_view_controller.cpp \ expression_field_delegate_app.cpp \ + expression_model.cpp \ expression_model_handle.cpp \ float_parameter_controller.cpp \ + function.cpp \ + function_app.cpp \ function_expression_cell.cpp \ function_title_cell.cpp \ global_context.cpp \ @@ -39,12 +43,8 @@ app_src += $(addprefix apps/shared/,\ scrollable_exact_approximate_expressions_view.cpp \ separator_even_odd_buffer_text_cell.cpp \ simple_interactive_curve_view_controller.cpp \ - single_expression_model_handle.cpp\ - storage_cartesian_function.cpp \ storage_expression_model_list_controller.cpp \ storage_expression_model_store.cpp \ - storage_function.cpp \ - storage_function_app.cpp \ storage_function_banner_delegate.cpp \ storage_function_curve_parameter_controller.cpp \ storage_function_go_to_parameter_controller.cpp \ diff --git a/apps/shared/storage_cartesian_function.cpp b/apps/shared/cartesian_function.cpp similarity index 72% rename from apps/shared/storage_cartesian_function.cpp rename to apps/shared/cartesian_function.cpp index 4ce38c7fe..51eac961e 100644 --- a/apps/shared/storage_cartesian_function.cpp +++ b/apps/shared/cartesian_function.cpp @@ -1,4 +1,4 @@ -#include "storage_cartesian_function.h" +#include "cartesian_function.h" #include "storage_expression_model_store.h" #include "poincare_helpers.h" #include @@ -12,7 +12,7 @@ using namespace Poincare; namespace Shared { -void StorageCartesianFunction::DefaultName(char buffer[], size_t bufferSize) { +void CartesianFunction::DefaultName(char buffer[], size_t bufferSize) { constexpr int k_maxNumberOfDefaultLetterNames = 4; static constexpr const char k_defaultLetterNames[k_maxNumberOfDefaultLetterNames] = { 'f', 'g', 'h', 'p' @@ -43,7 +43,7 @@ void StorageCartesianFunction::DefaultName(char buffer[], size_t bufferSize) { assert(currentNumberLength >= 0 && currentNumberLength < availableBufferSize); } -StorageCartesianFunction StorageCartesianFunction::NewModel(Ion::Storage::Record::ErrorStatus * error, const char * baseName) { +CartesianFunction CartesianFunction::NewModel(Ion::Storage::Record::ErrorStatus * error, const char * baseName) { static int s_colorIndex = 0; // Create the record char nameBuffer[SymbolAbstract::k_maxNameSize]; @@ -57,15 +57,15 @@ StorageCartesianFunction StorageCartesianFunction::NewModel(Ion::Storage::Record // Return if error if (*error != Ion::Storage::Record::ErrorStatus::None) { - return StorageCartesianFunction(); + return CartesianFunction(); } - // Return the StorageCartesianFunction withthe new record - return StorageCartesianFunction(Ion::Storage::sharedStorage()->recordBaseNamedWithExtension(baseName, Ion::Storage::funcExtension)); + // Return the CartesianFunction withthe new record + return CartesianFunction(Ion::Storage::sharedStorage()->recordBaseNamedWithExtension(baseName, Ion::Storage::funcExtension)); } -int StorageCartesianFunction::derivativeNameWithArgument(char * buffer, size_t bufferSize, char arg) { - // Fill buffer with f(x). Keep one char foderivativeSizer derivative sign. +int CartesianFunction::derivativeNameWithArgument(char * buffer, size_t bufferSize, char arg) { + // Fill buffer with f(x). Keep size for derivative sign. int derivativeSize = UTF8Decoder::CharSizeOfCodePoint('\''); int numberOfChars = nameWithArgument(buffer, bufferSize - derivativeSize, arg); assert(numberOfChars + derivativeSize < bufferSize); @@ -78,15 +78,15 @@ int StorageCartesianFunction::derivativeNameWithArgument(char * buffer, size_t b return numberOfChars + derivativeSize; } -bool StorageCartesianFunction::displayDerivative() const { +bool CartesianFunction::displayDerivative() const { return recordData()->displayDerivative(); } -void StorageCartesianFunction::setDisplayDerivative(bool display) { +void CartesianFunction::setDisplayDerivative(bool display) { return recordData()->setDisplayDerivative(display); } -double StorageCartesianFunction::approximateDerivative(double x, Poincare::Context * context) const { +double CartesianFunction::approximateDerivative(double x, Poincare::Context * context) const { Poincare::Derivative derivative = Poincare::Derivative::Builder(expressionReduced(context).clone(), Symbol::Builder(Symbol::SpecialSymbols::UnknownX), Poincare::Float::Builder(x)); // derivative takes ownership of Poincare::Float::Builder(x) and the clone of expression /* TODO: when we approximate derivative, we might want to simplify the * derivative here. However, we might want to do it once for all x (to avoid @@ -94,7 +94,7 @@ double StorageCartesianFunction::approximateDerivative(double x, Poincare::Conte return PoincareHelpers::ApproximateToScalar(derivative, *context); } -double StorageCartesianFunction::sumBetweenBounds(double start, double end, Poincare::Context * context) const { +double CartesianFunction::sumBetweenBounds(double start, double end, Poincare::Context * context) const { // TODO: this does not work yet because integral does not understand UnknownX Poincare::Integral integral = Poincare::Integral::Builder(expressionReduced(context).clone(), Symbol::Builder(Symbol::SpecialSymbols::UnknownX), Poincare::Float::Builder(start), Poincare::Float::Builder(end)); // Integral takes ownership of args /* TODO: when we approximate integral, we might want to simplify the integral @@ -103,35 +103,35 @@ double StorageCartesianFunction::sumBetweenBounds(double start, double end, Poin return PoincareHelpers::ApproximateToScalar(integral, *context); } -Expression::Coordinate2D StorageCartesianFunction::nextMinimumFrom(double start, double step, double max, Context * context) const { +Expression::Coordinate2D CartesianFunction::nextMinimumFrom(double start, double step, double max, Context * context) const { const char unknownX[2] = {Poincare::Symbol::UnknownX, 0}; return PoincareHelpers::NextMinimum(expressionReduced(context), unknownX, start, step, max, *context); } -Expression::Coordinate2D StorageCartesianFunction::nextMaximumFrom(double start, double step, double max, Context * context) const { +Expression::Coordinate2D CartesianFunction::nextMaximumFrom(double start, double step, double max, Context * context) const { const char unknownX[2] = {Poincare::Symbol::UnknownX, 0}; return PoincareHelpers::NextMaximum(expressionReduced(context), unknownX, start, step, max, *context); } -double StorageCartesianFunction::nextRootFrom(double start, double step, double max, Context * context) const { +double CartesianFunction::nextRootFrom(double start, double step, double max, Context * context) const { const char unknownX[2] = {Poincare::Symbol::UnknownX, 0}; return PoincareHelpers::NextRoot(expressionReduced(context), unknownX, start, step, max, *context); } -Expression::Coordinate2D StorageCartesianFunction::nextIntersectionFrom(double start, double step, double max, Poincare::Context * context, Expression e) const { +Expression::Coordinate2D CartesianFunction::nextIntersectionFrom(double start, double step, double max, Poincare::Context * context, Expression e) const { const char unknownX[2] = {Poincare::Symbol::UnknownX, 0}; return PoincareHelpers::NextIntersection(expressionReduced(context), unknownX, start, step, max, *context, e); } -void * StorageCartesianFunction::Handle::expressionAddress(const Ion::Storage::Record * record) const { +void * CartesianFunction::Model::expressionAddress(const Ion::Storage::Record * record) const { return (char *)record->value().buffer+sizeof(CartesianFunctionRecordData); } -size_t StorageCartesianFunction::Handle::expressionSize(const Ion::Storage::Record * record) const { +size_t CartesianFunction::Model::expressionSize(const Ion::Storage::Record * record) const { return record->value().size-sizeof(CartesianFunctionRecordData); } -StorageCartesianFunction::CartesianFunctionRecordData * StorageCartesianFunction::recordData() const { +CartesianFunction::CartesianFunctionRecordData * CartesianFunction::recordData() const { assert(!isNull()); Ion::Storage::Record::Data d = value(); return reinterpret_cast(const_cast(d.buffer)); diff --git a/apps/shared/storage_cartesian_function.h b/apps/shared/cartesian_function.h similarity index 80% rename from apps/shared/storage_cartesian_function.h rename to apps/shared/cartesian_function.h index e7a4d5439..dae3a19a3 100644 --- a/apps/shared/storage_cartesian_function.h +++ b/apps/shared/cartesian_function.h @@ -1,19 +1,19 @@ -#ifndef SHARED_STORAGE_CARTESIAN_FUNCTION_H -#define SHARED_STORAGE_CARTESIAN_FUNCTION_H +#ifndef SHARED_CARTESIAN_FUNCTION_H +#define SHARED_CARTESIAN_FUNCTION_H #include "global_context.h" -#include "storage_function.h" +#include "function.h" #include namespace Shared { -class StorageCartesianFunction : public StorageFunction { +class CartesianFunction : public Function { public: static void DefaultName(char buffer[], size_t bufferSize); static char Symbol() { return 'x'; } - static StorageCartesianFunction NewModel(Ion::Storage::Record::ErrorStatus * error, const char * baseName = nullptr); - StorageCartesianFunction(Ion::Storage::Record record = Record()) : - StorageFunction(record) + static CartesianFunction NewModel(Ion::Storage::Record::ErrorStatus * error, const char * baseName = nullptr); + CartesianFunction(Ion::Storage::Record record = Record()) : + Function(record) {} Ion::Storage::Record::ErrorStatus setContent(const char * c) override { return editableHandle()->setContent(this, c, Symbol(), Poincare::Symbol::SpecialSymbols::UnknownX); } @@ -45,16 +45,16 @@ private: * the expression of the function, directly copied from the pool. */ //char m_expression[0]; }; - class Handle : public ExpressionModelHandle { + class Model : public ExpressionModel { public: void * expressionAddress(const Ion::Storage::Record * record) const override; private: size_t expressionSize(const Ion::Storage::Record * record) const override; }; size_t metaDataSize() const override { return sizeof(CartesianFunctionRecordData); } - const ExpressionModelHandle * handle() const override { return &m_handle; } + const ExpressionModel * handle() const override { return &m_model; } CartesianFunctionRecordData * recordData() const; - Handle m_handle; + Model m_model; }; } diff --git a/apps/shared/expression_model.cpp b/apps/shared/expression_model.cpp new file mode 100644 index 000000000..54f7b7f28 --- /dev/null +++ b/apps/shared/expression_model.cpp @@ -0,0 +1,131 @@ +#include "expression_model.h" +#include "global_context.h" +#include "poincare_helpers.h" +#include +#include +#include +#include + +using namespace Ion; +using namespace Poincare; + +namespace Shared { + +static inline int maxInt(int x, int y) { return x > y ? x : y; } + +ExpressionModel::ExpressionModel() : + m_expression(), + m_layout(), + m_circular(-1) +{ +} + +void ExpressionModel::text(const Storage::Record * record, char * buffer, size_t bufferSize) const { + Expression e = expressionClone(record); + if (e.isUninitialized() && bufferSize > 0) { + buffer[0] = 0; + } else { + e.serialize(buffer, bufferSize); + } +} + +bool ExpressionModel::isCircularlyDefined(const Storage::Record * record, Poincare::Context * context) const { + if (m_circular == -1) { + m_circular = Expression::ExpressionWithoutSymbols(expressionClone(record), *context).isUninitialized(); + } + return m_circular; +} + +Expression ExpressionModel::expressionReduced(const Storage::Record * record, Poincare::Context * context) const { + if (m_expression.isUninitialized()) { + assert(record->fullName() != nullptr); + m_expression = Expression::ExpressionFromAddress(expressionAddress(record), expressionSize(record)); + PoincareHelpers::Simplify(&m_expression, *context); + // simplify might return an uninitialized Expression if interrupted + if (m_expression.isUninitialized()) { + m_expression = Expression::ExpressionFromAddress(expressionAddress(record), expressionSize(record)); + } + } + return m_expression; +} + +Expression ExpressionModel::expressionClone(const Storage::Record * record) const { + assert(record->fullName() != nullptr); + /* A new Expression has to be created at each call (because it might be tempered with after calling) */ + return Expression::ExpressionFromAddress(expressionAddress(record), expressionSize(record)); +} + +Layout ExpressionModel::layout(const Storage::Record * record) const { + if (m_layout.isUninitialized()) { + m_layout = PoincareHelpers::CreateLayout(expressionClone(record)); + if (m_layout.isUninitialized()) { + m_layout = HorizontalLayout::Builder(); + } + } + return m_layout; +} + +Ion::Storage::Record::ErrorStatus ExpressionModel::setContent(Ion::Storage::Record * record, const char * c, char symbol, char unknownSymbol) { + Expression e = ExpressionModel::BuildExpressionFromText(c, symbol, unknownSymbol); + return setExpressionContent(record, e); +} + +Ion::Storage::Record::ErrorStatus ExpressionModel::setExpressionContent(Ion::Storage::Record * record, Expression & newExpression) { + assert(record->fullName() != nullptr); + // Prepare the new data to be stored + Ion::Storage::Record::Data newData = record->value(); + size_t previousExpressionSize = expressionSize(record); + size_t newExpressionSize = newExpression.isUninitialized() ? 0 : newExpression.size(); + size_t previousDataSize = newData.size; + size_t newDataSize = previousDataSize - previousExpressionSize + newExpressionSize; + void * expAddress = expressionAddress(record); + // Update size of record to maximal size between previous and new data + newData.size = maxInt(previousDataSize, newDataSize); + Ion::Storage::Record::ErrorStatus error = record->setValue(newData); + if (error != Ion::Storage::Record::ErrorStatus::None) { + assert(error == Ion::Storage::Record::ErrorStatus::NotEnoughSpaceAvailable); + return error; + } + // Prepare the new data content + /* WARNING: expressionAddress() cannot be used while the metadata is invalid + * (as it is sometimes computed from metadata). Thus, the expression address + * is given as a parameter to updateNewDataWithExpression. */ + updateNewDataWithExpression(record, newExpression, expAddress, newExpressionSize, previousExpressionSize); + // Set the data with the right size + newData.size = newDataSize; + error = record->setValue(newData); + // Any error would have occured at the first call to setValue + assert(error == Ion::Storage::Record::ErrorStatus::None); + + /* Here we delete only the elements relative to the expression model kept in + * this handle. */ + tidy(); + return error; +} + +void ExpressionModel::updateNewDataWithExpression(Ion::Storage::Record * record, Expression & expressionToStore, void * expressionAddress, size_t expressionToStoreSize, size_t previousExpressionSize) { + if (!expressionToStore.isUninitialized()) { + memmove(expressionAddress, expressionToStore.addressInPool(), expressionToStoreSize); + } +} + +void ExpressionModel::tidy() const { + m_layout = Layout(); + m_expression = Expression(); + m_circular = 0; +} + +Poincare::Expression ExpressionModel::BuildExpressionFromText(const char * c, char symbol, char unknownSymbol) { + Expression expressionToStore; + // if c = "", we want to reinit the Expression + if (c && *c != 0) { + // Compute the expression to store, without replacing symbols + expressionToStore = Expression::Parse(c); + if (!expressionToStore.isUninitialized() && symbol != 0) { + expressionToStore = expressionToStore.replaceUnknown(Symbol::Builder(symbol), Symbol::Builder(unknownSymbol)); + } + } + return expressionToStore; +} + +} diff --git a/apps/shared/expression_model.h b/apps/shared/expression_model.h new file mode 100644 index 000000000..265a7b721 --- /dev/null +++ b/apps/shared/expression_model.h @@ -0,0 +1,42 @@ +#ifndef SHARED_EXPRESSION_MODEL_H +#define SHARED_EXPRESSION_MODEL_H + +#include +#include +#include + +namespace Shared { + +class ExpressionModel { +public: + ExpressionModel(); + + // Getters + void text(const Ion::Storage::Record * record, char * buffer, size_t bufferSize) const; + Poincare::Expression expressionReduced(const Ion::Storage::Record * record, Poincare::Context * context) const; + Poincare::Expression expressionClone(const Ion::Storage::Record * record) const; + Poincare::Layout layout(const Ion::Storage::Record * record) const; + + // Setters + virtual Ion::Storage::Record::ErrorStatus setContent(Ion::Storage::Record * record, const char * c, char symbol = 0, char unknownSymbol = 0); + Ion::Storage::Record::ErrorStatus setExpressionContent(Ion::Storage::Record * record, Poincare::Expression & e); + + // Property + bool isCircularlyDefined(const Ion::Storage::Record * record, Poincare::Context * context) const; + virtual void * expressionAddress(const Ion::Storage::Record * record) const = 0; + + virtual void tidy() const; +protected: + // Setters helper + static Poincare::Expression BuildExpressionFromText(const char * c, char symbol = 0, char unknownSymbol = 0); + mutable Poincare::Expression m_expression; + mutable Poincare::Layout m_layout; +private: + virtual void updateNewDataWithExpression(Ion::Storage::Record * record, Poincare::Expression & expressionToStore, void * expressionAddress, size_t expressionToStoreSize, size_t previousExpressionSize); + virtual size_t expressionSize(const Ion::Storage::Record * record) const = 0; + mutable int m_circular; +}; + +} + +#endif diff --git a/apps/shared/expression_model_handle.cpp b/apps/shared/expression_model_handle.cpp index c1c5674f6..be8713249 100644 --- a/apps/shared/expression_model_handle.cpp +++ b/apps/shared/expression_model_handle.cpp @@ -13,119 +13,17 @@ namespace Shared { static inline int maxInt(int x, int y) { return x > y ? x : y; } -ExpressionModelHandle::ExpressionModelHandle() : - m_expression(), - m_layout(), - m_circular(-1) +ExpressionModelHandle::ExpressionModelHandle(Storage::Record record) : + Storage::Record(record) { } -void ExpressionModelHandle::text(const Storage::Record * record, char * buffer, size_t bufferSize) const { - Expression e = expressionClone(record); - if (e.isUninitialized() && bufferSize > 0) { - buffer[0] = 0; - } else { - e.serialize(buffer, bufferSize); - } +bool ExpressionModelHandle::isDefined() { + return !isEmpty(); } -bool ExpressionModelHandle::isCircularlyDefined(const Storage::Record * record, Poincare::Context * context) const { - if (m_circular == -1) { - m_circular = Expression::ExpressionWithoutSymbols(expressionClone(record), *context).isUninitialized(); - } - return m_circular; -} - -Expression ExpressionModelHandle::expressionReduced(const Storage::Record * record, Poincare::Context * context) const { - if (m_expression.isUninitialized()) { - assert(record->fullName() != nullptr); - m_expression = Expression::ExpressionFromAddress(expressionAddress(record), expressionSize(record)); - PoincareHelpers::Simplify(&m_expression, *context); - // simplify might return an uninitialized Expression if interrupted - if (m_expression.isUninitialized()) { - m_expression = Expression::ExpressionFromAddress(expressionAddress(record), expressionSize(record)); - } - } - return m_expression; -} - -Expression ExpressionModelHandle::expressionClone(const Storage::Record * record) const { - assert(record->fullName() != nullptr); - /* A new Expression has to be created at each call (because it might be tempered with after calling) */ - return Expression::ExpressionFromAddress(expressionAddress(record), expressionSize(record)); -} - -Layout ExpressionModelHandle::layout(const Storage::Record * record) const { - if (m_layout.isUninitialized()) { - m_layout = PoincareHelpers::CreateLayout(expressionClone(record)); - if (m_layout.isUninitialized()) { - m_layout = HorizontalLayout::Builder(); - } - } - return m_layout; -} - -Ion::Storage::Record::ErrorStatus ExpressionModelHandle::setContent(Ion::Storage::Record * record, const char * c, char symbol, char unknownSymbol) { - Expression e = ExpressionModelHandle::BuildExpressionFromText(c, symbol, unknownSymbol); - return setExpressionContent(record, e); -} - -Ion::Storage::Record::ErrorStatus ExpressionModelHandle::setExpressionContent(Ion::Storage::Record * record, Expression & newExpression) { - assert(record->fullName() != nullptr); - // Prepare the new data to be stored - Ion::Storage::Record::Data newData = record->value(); - size_t previousExpressionSize = expressionSize(record); - size_t newExpressionSize = newExpression.isUninitialized() ? 0 : newExpression.size(); - size_t previousDataSize = newData.size; - size_t newDataSize = previousDataSize - previousExpressionSize + newExpressionSize; - void * expAddress = expressionAddress(record); - // Update size of record to maximal size between previous and new data - newData.size = maxInt(previousDataSize, newDataSize); - Ion::Storage::Record::ErrorStatus error = record->setValue(newData); - if (error != Ion::Storage::Record::ErrorStatus::None) { - assert(error == Ion::Storage::Record::ErrorStatus::NotEnoughSpaceAvailable); - return error; - } - // Prepare the new data content - /* WARNING: expressionAddress() cannot be used while the metadata is invalid - * (as it is sometimes computed from metadata). Thus, the expression address - * is given as a parameter to updateNewDataWithExpression. */ - updateNewDataWithExpression(record, newExpression, expAddress, newExpressionSize, previousExpressionSize); - // Set the data with the right size - newData.size = newDataSize; - error = record->setValue(newData); - // Any error would have occured at the first call to setValue - assert(error == Ion::Storage::Record::ErrorStatus::None); - - /* Here we delete only the elements relative to the expression model kept in - * this handle. */ - tidy(); - return error; -} - -void ExpressionModelHandle::updateNewDataWithExpression(Ion::Storage::Record * record, Expression & expressionToStore, void * expressionAddress, size_t expressionToStoreSize, size_t previousExpressionSize) { - if (!expressionToStore.isUninitialized()) { - memmove(expressionAddress, expressionToStore.addressInPool(), expressionToStoreSize); - } -} - -void ExpressionModelHandle::tidy() const { - m_layout = Layout(); - m_expression = Expression(); - m_circular = 0; -} - -Poincare::Expression ExpressionModelHandle::BuildExpressionFromText(const char * c, char symbol, char unknownSymbol) { - Expression expressionToStore; - // if c = "", we want to reinit the Expression - if (c && *c != 0) { - // Compute the expression to store, without replacing symbols - expressionToStore = Expression::Parse(c); - if (!expressionToStore.isUninitialized() && symbol != 0) { - expressionToStore = expressionToStore.replaceUnknown(Symbol::Builder(symbol), Symbol::Builder(unknownSymbol)); - } - } - return expressionToStore; +bool ExpressionModelHandle::isEmpty() { + return value().size <= metaDataSize(); } } diff --git a/apps/shared/expression_model_handle.h b/apps/shared/expression_model_handle.h index dbfb98781..0dc368cfa 100644 --- a/apps/shared/expression_model_handle.h +++ b/apps/shared/expression_model_handle.h @@ -1,42 +1,41 @@ #ifndef SHARED_EXPRESSION_MODEL_HANDLE_H #define SHARED_EXPRESSION_MODEL_HANDLE_H -#include -#include -#include +#include "expression_model.h" namespace Shared { -// ExpressionModelHandle is a handle to Ion::Record +//ExpressionModelHandle is a handle for Ion::Record -class ExpressionModelHandle { +class ExpressionModelHandle : public Ion::Storage::Record { public: - ExpressionModelHandle(); - - // Getters - void text(const Ion::Storage::Record * record, char * buffer, size_t bufferSize) const; - Poincare::Expression expressionReduced(const Ion::Storage::Record * record, Poincare::Context * context) const; - Poincare::Expression expressionClone(const Ion::Storage::Record * record) const; - Poincare::Layout layout(const Ion::Storage::Record * record) const; - - // Setters - virtual Ion::Storage::Record::ErrorStatus setContent(Ion::Storage::Record * record, const char * c, char symbol = 0, char unknownSymbol = 0); - Ion::Storage::Record::ErrorStatus setExpressionContent(Ion::Storage::Record * record, Poincare::Expression & e); + ExpressionModelHandle(Ion::Storage::Record record = Ion::Storage::Record()); // Property - bool isCircularlyDefined(const Ion::Storage::Record * record, Poincare::Context * context) const; - virtual void * expressionAddress(const Ion::Storage::Record * record) const = 0; - - virtual void tidy() const; + void text(char * buffer, size_t bufferSize) const { return handle()->text(this, buffer, bufferSize); } + Poincare::Expression expressionReduced(Poincare::Context * context) const { return handle()->expressionReduced(this, context); } + Poincare::Expression expressionClone() const { return handle()->expressionClone(this); } + Poincare::Layout layout() { return handle()->layout(this); } + /* Here, isDefined is the exact contrary of isEmpty. However, for Sequence + * inheriting from ExpressionModelHandle, isEmpty and isDefined have not exactly + * opposite meaning. For instance, u(n+1)=u(n) & u(0) = ... is not empty and + * not defined. We thus have to keep both methods. */ + virtual bool isDefined(); + virtual bool isEmpty(); + virtual bool shouldBeClearedBeforeRemove() { return !isEmpty(); } + /* tidy is responsible to tidy the whole model whereas tidyExpressionModel + * tidies only the members associated with the ExpressionModel. In + * ExpressionModel, tidy and tidyExpressionModel trigger the same + * behaviour but it is not true for its child classes (for example, in + * Sequence). */ + virtual void tidy() { handle()->tidy(); } + virtual Ion::Storage::Record::ErrorStatus setContent(const char * c) { return editableHandle()->setContent(this, c); } + Ion::Storage::Record::ErrorStatus setExpressionContent(Poincare::Expression & e) { return editableHandle()->setExpressionContent(this, e); } protected: - // Setters helper - static Poincare::Expression BuildExpressionFromText(const char * c, char symbol = 0, char unknownSymbol = 0); - mutable Poincare::Expression m_expression; - mutable Poincare::Layout m_layout; -private: - virtual void updateNewDataWithExpression(Ion::Storage::Record * record, Poincare::Expression & expressionToStore, void * expressionAddress, size_t expressionToStoreSize, size_t previousExpressionSize); - virtual size_t expressionSize(const Ion::Storage::Record * record) const = 0; - mutable int m_circular; + bool isCircularlyDefined(Poincare::Context * context) const { return handle()->isCircularlyDefined(this, context); } + ExpressionModel * editableHandle() { return const_cast(handle()); } + virtual const ExpressionModel * handle() const = 0; + virtual size_t metaDataSize() const = 0; }; } diff --git a/apps/shared/storage_function.cpp b/apps/shared/function.cpp similarity index 73% rename from apps/shared/storage_function.cpp rename to apps/shared/function.cpp index 2af979fd6..f08f1b1d1 100644 --- a/apps/shared/storage_function.cpp +++ b/apps/shared/function.cpp @@ -1,4 +1,4 @@ -#include "storage_function.h" +#include "function.h" #include "poincare_helpers.h" #include #include "poincare/src/parsing/parser.h" @@ -12,9 +12,9 @@ using namespace Poincare; namespace Shared { -constexpr char StorageFunction::k_parenthesedArgument[]; +constexpr char Function::k_parenthesedArgument[]; -bool StorageFunction::BaseNameCompliant(const char * baseName, NameNotCompliantError * error) { +bool Function::BaseNameCompliant(const char * baseName, NameNotCompliantError * error) { assert(baseName[0] != 0); UTF8Decoder decoder(baseName); @@ -52,19 +52,19 @@ bool StorageFunction::BaseNameCompliant(const char * baseName, NameNotCompliantE return true; } -bool StorageFunction::isActive() const { +bool Function::isActive() const { return recordData()->isActive(); } -KDColor StorageFunction::color() const { +KDColor Function::color() const { return recordData()->color(); } -void StorageFunction::setActive(bool active) { +void Function::setActive(bool active) { recordData()->setActive(active); } -int StorageFunction::nameWithArgument(char * buffer, size_t bufferSize, char arg) { +int Function::nameWithArgument(char * buffer, size_t bufferSize, char arg) { const char * functionName = fullName(); size_t baseNameLength = SymbolAbstract::TruncateExtension(buffer, functionName, bufferSize - k_parenthesedArgumentLength); int result = baseNameLength + strlcpy(&buffer[baseNameLength], k_parenthesedArgument, bufferSize-baseNameLength); @@ -75,7 +75,7 @@ int StorageFunction::nameWithArgument(char * buffer, size_t bufferSize, char arg } template -T StorageFunction::templatedApproximateAtAbscissa(T x, Poincare::Context * context, char unknownSymbol) const { +T Function::templatedApproximateAtAbscissa(T x, Poincare::Context * context, char unknownSymbol) const { if (isCircularlyDefined(context)) { return NAN; } @@ -85,7 +85,7 @@ T StorageFunction::templatedApproximateAtAbscissa(T x, Poincare::Context * conte return PoincareHelpers::ApproximateWithValueForSymbol(expressionReduced(context), unknownX, x, *context); } -StorageFunction::FunctionRecordData * StorageFunction::recordData() const { +Function::FunctionRecordData * Function::recordData() const { assert(!isNull()); Ion::Storage::Record::Data d = value(); return reinterpret_cast(const_cast(d.buffer)); @@ -93,5 +93,5 @@ StorageFunction::FunctionRecordData * StorageFunction::recordData() const { } -template float Shared::StorageFunction::templatedApproximateAtAbscissa(float, Poincare::Context*, char) const; -template double Shared::StorageFunction::templatedApproximateAtAbscissa(double, Poincare::Context*, char) const; +template float Shared::Function::templatedApproximateAtAbscissa(float, Poincare::Context*, char) const; +template double Shared::Function::templatedApproximateAtAbscissa(double, Poincare::Context*, char) const; diff --git a/apps/shared/storage_function.h b/apps/shared/function.h similarity index 89% rename from apps/shared/storage_function.h rename to apps/shared/function.h index 047479735..9a93e6a50 100644 --- a/apps/shared/storage_function.h +++ b/apps/shared/function.h @@ -1,13 +1,13 @@ -#ifndef SHARED_STORAGE_FUNCTION_H -#define SHARED_STORAGE_FUNCTION_H +#ifndef SHARED_FUNCTION_H +#define SHARED_FUNCTION_H #include #include -#include "single_expression_model_handle.h" +#include "expression_model_handle.h" namespace Shared { -class StorageFunction : public SingleExpressionModelHandle { +class Function : public ExpressionModelHandle { public: enum class NameNotCompliantError { None = 0, @@ -21,7 +21,7 @@ public: static bool BaseNameCompliant(const char * baseName, NameNotCompliantError * error = nullptr); // Constructors - StorageFunction(Ion::Storage::Record record) : SingleExpressionModelHandle(record){} + Function(Ion::Storage::Record record) : ExpressionModelHandle(record){} // Properties bool isActive() const; diff --git a/apps/shared/storage_function_app.cpp b/apps/shared/function_app.cpp similarity index 73% rename from apps/shared/storage_function_app.cpp rename to apps/shared/function_app.cpp index c4dcc295e..58d3f9f3b 100644 --- a/apps/shared/storage_function_app.cpp +++ b/apps/shared/function_app.cpp @@ -1,11 +1,11 @@ -#include "storage_function_app.h" +#include "function_app.h" #include "../apps_container.h" using namespace Poincare; namespace Shared { -StorageFunctionApp::Snapshot::Snapshot() : +FunctionApp::Snapshot::Snapshot() : m_cursor(), m_interval(), m_indexFunctionSelectedByCursor(0), @@ -18,7 +18,7 @@ StorageFunctionApp::Snapshot::Snapshot() : m_interval.setStep(1); } -void StorageFunctionApp::Snapshot::reset() { +void FunctionApp::Snapshot::reset() { m_interval.setStart(0); m_interval.setEnd(10); m_interval.setStep(1); @@ -28,11 +28,11 @@ void StorageFunctionApp::Snapshot::reset() { setActiveTab(0); } -void StorageFunctionApp::Snapshot::storageDidChangeForRecord(const Ion::Storage::Record record) { +void FunctionApp::Snapshot::storageDidChangeForRecord(const Ion::Storage::Record record) { functionStore()->storageDidChangeForRecord(record); } -void StorageFunctionApp::willBecomeInactive() { +void FunctionApp::willBecomeInactive() { if (m_modalViewController.isDisplayingModal()) { m_modalViewController.dismissModalViewController(); } @@ -42,7 +42,7 @@ void StorageFunctionApp::willBecomeInactive() { ::App::willBecomeInactive(); } -bool StorageFunctionApp::isAcceptableExpression(const Poincare::Expression expression) { +bool FunctionApp::isAcceptableExpression(const Poincare::Expression expression) { if (!TextFieldDelegateApp::ExpressionCanBeSerialized(expression, false, Expression())) { return false; } diff --git a/apps/shared/storage_function_app.h b/apps/shared/function_app.h similarity index 77% rename from apps/shared/storage_function_app.h rename to apps/shared/function_app.h index 23e089e28..b9c784480 100644 --- a/apps/shared/storage_function_app.h +++ b/apps/shared/function_app.h @@ -10,7 +10,7 @@ class AppsContainer; namespace Shared { -class StorageFunctionApp : public ExpressionFieldDelegateApp { +class FunctionApp : public ExpressionFieldDelegateApp { public: class Snapshot : public ::App::Snapshot, public TabViewDataSource { public: @@ -19,7 +19,7 @@ public: uint32_t * modelVersion() { return &m_modelVersion; } uint32_t * rangeVersion() { return &m_rangeVersion; } Poincare::Preferences::AngleUnit * angleUnitVersion() { return &m_angleUnitVersion; } - virtual StorageFunctionStore * functionStore() = 0; + virtual FunctionStore * functionStore() = 0; Interval * interval() { return &m_interval; } int * indexFunctionSelectedByCursor() { return &m_indexFunctionSelectedByCursor; } void reset() override; @@ -33,13 +33,13 @@ public: uint32_t m_rangeVersion; Poincare::Preferences::AngleUnit m_angleUnitVersion; }; - virtual ~StorageFunctionApp() = default; - virtual StorageFunctionStore * functionStore() { return static_cast(snapshot())->functionStore(); } + virtual ~FunctionApp() = default; + virtual FunctionStore * functionStore() { return static_cast(snapshot())->functionStore(); } virtual InputViewController * inputViewController() = 0; void willBecomeInactive() override; protected: - StorageFunctionApp(Container * container, Snapshot * snapshot, ViewController * rootViewController) : + FunctionApp(Container * container, Snapshot * snapshot, ViewController * rootViewController) : ExpressionFieldDelegateApp(container, snapshot, rootViewController) {} // TextFieldDelegateApp diff --git a/apps/shared/global_context.cpp b/apps/shared/global_context.cpp index 9904d433d..fc26e28d5 100644 --- a/apps/shared/global_context.cpp +++ b/apps/shared/global_context.cpp @@ -1,5 +1,5 @@ #include "global_context.h" -#include "storage_cartesian_function.h" +#include "cartesian_function.h" #include #include #include @@ -45,7 +45,7 @@ Poincare::Expression GlobalContext::ExpressionFromFunctionRecord(Ion::Storage::R } /* An function record value has metadata before the expression. To get the * expression, use the function record handle. */ - StorageCartesianFunction f = StorageCartesianFunction(record); + CartesianFunction f = CartesianFunction(record); return f.expressionClone(); } @@ -116,13 +116,13 @@ Ion::Storage::Record::ErrorStatus GlobalContext::SetExpressionForFunctionRecord( if (!Ion::Storage::FullNameHasExtension(previousRecord.fullName(), Ion::Storage::funcExtension, strlen(Ion::Storage::funcExtension))) { // The previous record was not a function. Destroy it and create the new record. previousRecord.destroy(); - StorageCartesianFunction newModel = StorageCartesianFunction::NewModel(&error, baseName); + CartesianFunction newModel = CartesianFunction::NewModel(&error, baseName); if (error != Ion::Storage::Record::ErrorStatus::None) { return error; } recordToSet = newModel; } - error = StorageCartesianFunction(recordToSet).setExpressionContent(expressionToStore); + error = CartesianFunction(recordToSet).setExpressionContent(expressionToStore); return error; } diff --git a/apps/shared/single_expression_model_handle.cpp b/apps/shared/single_expression_model_handle.cpp deleted file mode 100644 index ef0037c73..000000000 --- a/apps/shared/single_expression_model_handle.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "single_expression_model_handle.h" -#include "global_context.h" -#include "poincare_helpers.h" -#include -#include -#include -#include - -using namespace Ion; -using namespace Poincare; - -namespace Shared { - -SingleExpressionModelHandle::SingleExpressionModelHandle(Storage::Record record) : - Storage::Record(record) -{ -} - -bool SingleExpressionModelHandle::isDefined() { - return !isEmpty(); -} - -bool SingleExpressionModelHandle::isEmpty() { - return value().size <= metaDataSize(); -} - -} diff --git a/apps/shared/single_expression_model_handle.h b/apps/shared/single_expression_model_handle.h deleted file mode 100644 index 3700e0fd9..000000000 --- a/apps/shared/single_expression_model_handle.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef SHARED_SINGLE_EXPRESSION_MODEL_HANDLE_H -#define SHARED_SINGLE_EXPRESSION_MODEL_HANDLE_H - -#include "expression_model_handle.h" - -namespace Shared { - - -class SingleExpressionModelHandle : public Ion::Storage::Record { -public: - SingleExpressionModelHandle(Ion::Storage::Record record = Ion::Storage::Record()); - - // Property - void text(char * buffer, size_t bufferSize) const { return handle()->text(this, buffer, bufferSize); } - Poincare::Expression expressionReduced(Poincare::Context * context) const { return handle()->expressionReduced(this, context); } - Poincare::Expression expressionClone() const { return handle()->expressionClone(this); } - Poincare::Layout layout() { return handle()->layout(this); } - /* TODO This comment will be true when Sequence inherits from this class - * Here, isDefined is the exact contrary of isEmpty. However, for Sequence - * inheriting from ExpressionModel, isEmpty and isDefined have not exactly - * opposite meaning. For instance, u(n+1)=u(n) & u(0) = ... is not empty and - * not defined. We thus have to keep both methods. */ - virtual bool isDefined(); - virtual bool isEmpty(); - virtual bool shouldBeClearedBeforeRemove() { return !isEmpty(); } - /* tidy is responsible to tidy the whole model whereas tidyExpressionModel - * tidies only the members associated with the ExpressionModel. In - * ExpressionModelHandle, tidy and tidyExpressionModel trigger the same - * behaviour but it is not true for its child classes (for example, in - * Sequence). */ - virtual void tidy() { handle()->tidy(); } - virtual Ion::Storage::Record::ErrorStatus setContent(const char * c) { return editableHandle()->setContent(this, c); } - Ion::Storage::Record::ErrorStatus setExpressionContent(Poincare::Expression & e) { return editableHandle()->setExpressionContent(this, e); } -protected: - bool isCircularlyDefined(Poincare::Context * context) const { return handle()->isCircularlyDefined(this, context); } - ExpressionModelHandle * editableHandle() { return const_cast(handle()); } - virtual const ExpressionModelHandle * handle() const = 0; - virtual size_t metaDataSize() const = 0; -}; - -} - -#endif diff --git a/apps/shared/storage_expression_model_list_controller.cpp b/apps/shared/storage_expression_model_list_controller.cpp index 1a823d9cb..021974647 100644 --- a/apps/shared/storage_expression_model_list_controller.cpp +++ b/apps/shared/storage_expression_model_list_controller.cpp @@ -145,7 +145,7 @@ KDCoordinate StorageExpressionModelListController::expressionRowHeight(int j) { if (isAddEmptyRow(j)) { return Metric::StoreRowHeight; } - ExpiringPointer m = modelStore()->modelForRecord(modelStore()->recordAtIndex(j)); + ExpiringPointer m = modelStore()->modelForRecord(modelStore()->recordAtIndex(j)); if (m->layout().isUninitialized()) { return Metric::StoreRowHeight; } @@ -156,7 +156,7 @@ KDCoordinate StorageExpressionModelListController::expressionRowHeight(int j) { void StorageExpressionModelListController::willDisplayExpressionCellAtIndex(HighlightCell * cell, int j) { EvenOddExpressionCell * myCell = (EvenOddExpressionCell *)cell; - ExpiringPointer m = modelStore()->modelForRecord(modelStore()->recordAtIndex(j)); + ExpiringPointer m = modelStore()->modelForRecord(modelStore()->recordAtIndex(j)); myCell->setLayout(m->layout()); } @@ -176,7 +176,7 @@ bool StorageExpressionModelListController::handleEventOnExpression(Ion::Events:: } if (event == Ion::Events::Backspace && !isAddEmptyRow(selectedRow())) { Ion::Storage::Record record = modelStore()->recordAtIndex(modelIndexForRow(selectedRow())); - ExpiringPointer model = modelStore()->modelForRecord(record); + ExpiringPointer model = modelStore()->modelForRecord(record); if (model->shouldBeClearedBeforeRemove()) { reinitSelectedExpression(model); } else { @@ -206,7 +206,7 @@ void StorageExpressionModelListController::addEmptyModel() { editExpression(Ion::Events::OK); } -void StorageExpressionModelListController::reinitSelectedExpression(ExpiringPointer model) { +void StorageExpressionModelListController::reinitSelectedExpression(ExpiringPointer model) { model->setContent(""); // Reset memoization of the selected cell which always corresponds to the k_memoizedCellsCount/2 memoized cell resetMemoizationForIndex(k_memoizedCellsCount/2); @@ -230,7 +230,7 @@ void StorageExpressionModelListController::editExpression(Ion::Events::Event eve char initialTextContent[initialTextContentMaxSize]; if (event == Ion::Events::OK || event == Ion::Events::EXE) { Ion::Storage::Record record = modelStore()->recordAtIndex(modelIndexForRow(selectedRow())); - ExpiringPointer model = modelStore()->modelForRecord(record); + ExpiringPointer model = modelStore()->modelForRecord(record); model->text(initialTextContent, initialTextContentMaxSize); initialText = initialTextContent; // Replace Poincare::Symbol::SpecialSymbols::UnknownX with 'x' @@ -252,7 +252,7 @@ bool StorageExpressionModelListController::editSelectedRecordWithText(const char // Reset memoization of the selected cell which always corresponds to the k_memoizedCellsCount/2 memoized cell resetMemoizationForIndex(k_memoizedCellsCount/2); Ion::Storage::Record record = modelStore()->recordAtIndex(modelIndexForRow(selectedRow())); - ExpiringPointer model = modelStore()->modelForRecord(record); + ExpiringPointer model = modelStore()->modelForRecord(record); return (model->setContent(text) == Ion::Storage::Record::ErrorStatus::None); } diff --git a/apps/shared/storage_expression_model_list_controller.h b/apps/shared/storage_expression_model_list_controller.h index 078aa9078..b901ead42 100644 --- a/apps/shared/storage_expression_model_list_controller.h +++ b/apps/shared/storage_expression_model_list_controller.h @@ -25,7 +25,7 @@ protected: bool handleEventOnExpression(Ion::Events::Event event); virtual void addEmptyModel(); virtual void didChangeModelsList() { resetMemoization(); } - virtual void reinitSelectedExpression(ExpiringPointer model); + virtual void reinitSelectedExpression(ExpiringPointer model); virtual void editExpression(Ion::Events::Event event); void replaceUnknownSymbolWithReadableSymbol(char * initialText); virtual bool editSelectedRecordWithText(const char * text); diff --git a/apps/shared/storage_expression_model_store.cpp b/apps/shared/storage_expression_model_store.cpp index 335d51a18..2a385730c 100644 --- a/apps/shared/storage_expression_model_store.cpp +++ b/apps/shared/storage_expression_model_store.cpp @@ -15,14 +15,14 @@ Ion::Storage::Record StorageExpressionModelStore::recordAtIndex(int i) const { return Ion::Storage::sharedStorage()->recordWithExtensionAtIndex(modelExtension(), i); } -SingleExpressionModelHandle * StorageExpressionModelStore::privateModelForRecord(Ion::Storage::Record record) const { +ExpressionModelHandle * StorageExpressionModelStore::privateModelForRecord(Ion::Storage::Record record) const { for (int i = 0; i < maxNumberOfMemoizedModels(); i++) { if (!memoizedModelAtIndex(i)->isNull() && *memoizedModelAtIndex(i) == record) { return memoizedModelAtIndex(i); } } setMemoizedModelAtIndex(m_oldestMemoizedIndex, record); - SingleExpressionModelHandle * result = memoizedModelAtIndex(m_oldestMemoizedIndex); + ExpressionModelHandle * result = memoizedModelAtIndex(m_oldestMemoizedIndex); m_oldestMemoizedIndex = (m_oldestMemoizedIndex+1) % maxNumberOfMemoizedModels(); return result; } @@ -44,7 +44,7 @@ void StorageExpressionModelStore::tidy() { int StorageExpressionModelStore::numberOfModelsSatisfyingTest(ModelTest test) const { int result = 0; int i = 0; - SingleExpressionModelHandle * m = privateModelForRecord(recordAtIndex(i++)); + ExpressionModelHandle * m = privateModelForRecord(recordAtIndex(i++)); while (!m->isNull()) { if (test(m)) { result++; @@ -59,7 +59,7 @@ Ion::Storage::Record StorageExpressionModelStore::recordStatifyingTestAtIndex(in int index = 0; int currentModelIndex = 0; Ion::Storage::Record r = recordAtIndex(currentModelIndex++); - SingleExpressionModelHandle * m = privateModelForRecord(r); + ExpressionModelHandle * m = privateModelForRecord(r); while (!m->isNull()) { assert(currentModelIndex <= numberOfModels()); if (test(m)) { diff --git a/apps/shared/storage_expression_model_store.h b/apps/shared/storage_expression_model_store.h index f5393e292..9d5e40ce4 100644 --- a/apps/shared/storage_expression_model_store.h +++ b/apps/shared/storage_expression_model_store.h @@ -1,7 +1,7 @@ #ifndef SHARED_STORAGE_EXPRESSION_MODEL_STORE_H #define SHARED_STORAGE_EXPRESSION_MODEL_STORE_H -#include "single_expression_model_handle.h" +#include "expression_model_handle.h" #include "expiring_pointer.h" #include #include @@ -21,10 +21,10 @@ public: // By default, the number of models is not bounded virtual int maxNumberOfModels() const { return -1; } int numberOfModels() const; - int numberOfDefinedModels() const { return numberOfModelsSatisfyingTest([](SingleExpressionModelHandle * m) { return m->isDefined(); }); } + int numberOfDefinedModels() const { return numberOfModelsSatisfyingTest([](ExpressionModelHandle * m) { return m->isDefined(); }); } Ion::Storage::Record recordAtIndex(int i) const; - Ion::Storage::Record definedRecordAtIndex(int i) const { return recordStatifyingTestAtIndex(i, [](SingleExpressionModelHandle * m) { return m->isDefined(); }); } - ExpiringPointer modelForRecord(Ion::Storage::Record record) const { return ExpiringPointer(privateModelForRecord(record)); } + Ion::Storage::Record definedRecordAtIndex(int i) const { return recordStatifyingTestAtIndex(i, [](ExpressionModelHandle * m) { return m->isDefined(); }); } + ExpiringPointer modelForRecord(Ion::Storage::Record record) const { return ExpiringPointer(privateModelForRecord(record)); } // Add and Remove virtual Ion::Storage::Record::ErrorStatus addEmptyModel() = 0; @@ -37,14 +37,14 @@ public: protected: constexpr static int k_maxNumberOfMemoizedModels = 10; int maxNumberOfMemoizedModels() const { return maxNumberOfModels() < 0 ? k_maxNumberOfMemoizedModels : maxNumberOfModels(); } - typedef bool (*ModelTest)(SingleExpressionModelHandle * model); + typedef bool (*ModelTest)(ExpressionModelHandle * model); int numberOfModelsSatisfyingTest(ModelTest test) const; Ion::Storage::Record recordStatifyingTestAtIndex(int i, ModelTest test) const; - SingleExpressionModelHandle * privateModelForRecord(Ion::Storage::Record record) const; + ExpressionModelHandle * privateModelForRecord(Ion::Storage::Record record) const; private: void resetMemoizedModelsExceptRecord(const Ion::Storage::Record record = Ion::Storage::Record()) const; virtual void setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record) const = 0; - virtual SingleExpressionModelHandle * memoizedModelAtIndex(int cacheIndex) const = 0; + virtual ExpressionModelHandle * memoizedModelAtIndex(int cacheIndex) const = 0; virtual const char * modelExtension() const = 0; /* Memoization of k_maxNumberOfMemoizedModels. When the required model is not * present, we override the m_oldestMemoizedIndex model. This actually diff --git a/apps/shared/storage_function_banner_delegate.cpp b/apps/shared/storage_function_banner_delegate.cpp index a59d2bd07..381e07d49 100644 --- a/apps/shared/storage_function_banner_delegate.cpp +++ b/apps/shared/storage_function_banner_delegate.cpp @@ -6,8 +6,8 @@ using namespace Poincare; namespace Shared { -void StorageFunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor * cursor, Ion::Storage::Record record, StorageFunctionStore * functionStore, char symbol) { - ExpiringPointer function = functionStore->modelForRecord(record); +void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor * cursor, Ion::Storage::Record record, FunctionStore * functionStore, char symbol) { + ExpiringPointer function = functionStore->modelForRecord(record); constexpr int bufferSize = k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); char buffer[bufferSize]; const char * space = " "; diff --git a/apps/shared/storage_function_banner_delegate.h b/apps/shared/storage_function_banner_delegate.h index 6d3ccd4e7..b0edcbf7c 100644 --- a/apps/shared/storage_function_banner_delegate.h +++ b/apps/shared/storage_function_banner_delegate.h @@ -7,11 +7,11 @@ namespace Shared { -class StorageFunctionBannerDelegate { +class FunctionBannerDelegate { public: constexpr static int k_maxNumberOfCharacters = 50; protected: - void reloadBannerViewForCursorOnFunction(CurveViewCursor * cursor, Ion::Storage::Record record, StorageFunctionStore * functionStore, char symbol); + void reloadBannerViewForCursorOnFunction(CurveViewCursor * cursor, Ion::Storage::Record record, FunctionStore * functionStore, char symbol); virtual BannerView * bannerView() = 0; }; diff --git a/apps/shared/storage_function_curve_parameter_controller.cpp b/apps/shared/storage_function_curve_parameter_controller.cpp index 90d26e570..14a71658a 100644 --- a/apps/shared/storage_function_curve_parameter_controller.cpp +++ b/apps/shared/storage_function_curve_parameter_controller.cpp @@ -3,7 +3,7 @@ namespace Shared { -StorageFunctionCurveParameterController::StorageFunctionCurveParameterController(InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor) : +FunctionCurveParameterController::FunctionCurveParameterController(InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor) : ViewController(nullptr), m_goToCell(I18n::Message::Goto), m_selectableTableView(this, this, this), @@ -11,18 +11,18 @@ StorageFunctionCurveParameterController::StorageFunctionCurveParameterController { } -View * StorageFunctionCurveParameterController::view() { +View * FunctionCurveParameterController::view() { return &m_selectableTableView; } -void StorageFunctionCurveParameterController::didBecomeFirstResponder() { +void FunctionCurveParameterController::didBecomeFirstResponder() { if (selectedRow() < 0) { selectCellAtLocation(0, 0); } app()->setFirstResponder(&m_selectableTableView); } -bool StorageFunctionCurveParameterController::handleGotoSelection() { +bool FunctionCurveParameterController::handleGotoSelection() { if (m_record.isNull()) { return false; } @@ -32,11 +32,11 @@ bool StorageFunctionCurveParameterController::handleGotoSelection() { return true; } -KDCoordinate StorageFunctionCurveParameterController::cellHeight() { +KDCoordinate FunctionCurveParameterController::cellHeight() { return Metric::ParameterCellHeight; } -void StorageFunctionCurveParameterController::setRecord(Ion::Storage::Record record) { +void FunctionCurveParameterController::setRecord(Ion::Storage::Record record) { m_record = record; } diff --git a/apps/shared/storage_function_curve_parameter_controller.h b/apps/shared/storage_function_curve_parameter_controller.h index e88f9a4ec..02c6236fa 100644 --- a/apps/shared/storage_function_curve_parameter_controller.h +++ b/apps/shared/storage_function_curve_parameter_controller.h @@ -8,9 +8,9 @@ namespace Shared { -class StorageFunctionCurveParameterController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource { +class FunctionCurveParameterController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource { public: - StorageFunctionCurveParameterController(InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor); + FunctionCurveParameterController(InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor); View * view() override; void didBecomeFirstResponder() override; KDCoordinate cellHeight() override; @@ -21,7 +21,7 @@ protected: SelectableTableView m_selectableTableView; Ion::Storage::Record m_record; private: - virtual StorageFunctionGoToParameterController * goToParameterController() = 0; + virtual FunctionGoToParameterController * goToParameterController() = 0; }; } diff --git a/apps/shared/storage_function_go_to_parameter_controller.cpp b/apps/shared/storage_function_go_to_parameter_controller.cpp index 622b3ccff..178d0e312 100644 --- a/apps/shared/storage_function_go_to_parameter_controller.cpp +++ b/apps/shared/storage_function_go_to_parameter_controller.cpp @@ -1,29 +1,29 @@ #include "storage_function_go_to_parameter_controller.h" -#include "storage_function_app.h" +#include "function_app.h" #include #include namespace Shared { -StorageFunctionGoToParameterController::StorageFunctionGoToParameterController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, I18n::Message symbol) : +FunctionGoToParameterController::FunctionGoToParameterController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, I18n::Message symbol) : GoToParameterController(parentResponder, inputEventHandlerDelegate, graphRange, cursor, symbol), m_record() { } -const char * StorageFunctionGoToParameterController::title() { +const char * FunctionGoToParameterController::title() { return I18n::translate(I18n::Message::Goto); } -double StorageFunctionGoToParameterController::parameterAtIndex(int index) { +double FunctionGoToParameterController::parameterAtIndex(int index) { assert(index == 0); return m_cursor->x(); } -bool StorageFunctionGoToParameterController::setParameterAtIndex(int parameterIndex, double f) { +bool FunctionGoToParameterController::setParameterAtIndex(int parameterIndex, double f) { assert(parameterIndex == 0); - StorageFunctionApp * myApp = (StorageFunctionApp *)app(); - ExpiringPointer function = myApp->functionStore()->modelForRecord(m_record); + FunctionApp * myApp = (FunctionApp *)app(); + ExpiringPointer function = myApp->functionStore()->modelForRecord(m_record); float y = function->evaluateAtAbscissa(f, myApp->localContext()); if (std::fabs(f) > k_maxDisplayableFloat || std::fabs(y) > k_maxDisplayableFloat) { app()->displayWarning(I18n::Message::ForbiddenValue); @@ -39,7 +39,7 @@ bool StorageFunctionGoToParameterController::setParameterAtIndex(int parameterIn return true; } -void StorageFunctionGoToParameterController::setRecord(Ion::Storage::Record record) { +void FunctionGoToParameterController::setRecord(Ion::Storage::Record record) { m_record = record; } diff --git a/apps/shared/storage_function_go_to_parameter_controller.h b/apps/shared/storage_function_go_to_parameter_controller.h index d5c0b898e..c06157225 100644 --- a/apps/shared/storage_function_go_to_parameter_controller.h +++ b/apps/shared/storage_function_go_to_parameter_controller.h @@ -2,13 +2,13 @@ #define SHARED_STORAGE_FUNCTION_GO_TO_PARAMETER_CONTROLLER_H #include "go_to_parameter_controller.h" -#include "storage_function.h" +#include "function.h" namespace Shared { -class StorageFunctionGoToParameterController : public GoToParameterController { +class FunctionGoToParameterController : public GoToParameterController { public: - StorageFunctionGoToParameterController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, I18n::Message symbol); + FunctionGoToParameterController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, I18n::Message symbol); const char * title() override; void setRecord(Ion::Storage::Record record); protected: diff --git a/apps/shared/storage_function_graph_controller.cpp b/apps/shared/storage_function_graph_controller.cpp index bc34ce043..9263144f9 100644 --- a/apps/shared/storage_function_graph_controller.cpp +++ b/apps/shared/storage_function_graph_controller.cpp @@ -1,5 +1,5 @@ #include "storage_function_graph_controller.h" -#include "storage_function_app.h" +#include "function_app.h" #include #include #include @@ -8,7 +8,7 @@ using namespace Poincare; namespace Shared { -StorageFunctionGraphController::StorageFunctionGraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Preferences::AngleUnit * angleUnitVersion) : +FunctionGraphController::FunctionGraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Preferences::AngleUnit * angleUnitVersion) : InteractiveCurveViewController(parentResponder, inputEventHandlerDelegate, header, interactiveRange, curveView, cursor, modelVersion, rangeVersion), m_initialisationParameterController(this, interactiveRange), m_angleUnitVersion(angleUnitVersion), @@ -16,24 +16,24 @@ StorageFunctionGraphController::StorageFunctionGraphController(Responder * paren { } -bool StorageFunctionGraphController::isEmpty() const { +bool FunctionGraphController::isEmpty() const { if (functionStore()->numberOfActiveFunctions() == 0) { return true; } return false; } -ViewController * StorageFunctionGraphController::initialisationParameterController() { +ViewController * FunctionGraphController::initialisationParameterController() { return &m_initialisationParameterController; } -void StorageFunctionGraphController::viewWillAppear() { +void FunctionGraphController::viewWillAppear() { functionGraphView()->setCursorView(cursorView()); functionGraphView()->setBannerView(bannerView()); functionGraphView()->setAreaHighlight(NAN,NAN); if (functionGraphView()->context() == nullptr) { - StorageFunctionApp * myApp = static_cast(app()); + FunctionApp * myApp = static_cast(app()); functionGraphView()->setContext(myApp->localContext()); } Preferences::AngleUnit newAngleUnitVersion = Preferences::sharedPreferences()->angleUnit(); @@ -44,7 +44,7 @@ void StorageFunctionGraphController::viewWillAppear() { InteractiveCurveViewController::viewWillAppear(); } -bool StorageFunctionGraphController::handleEnter() { +bool FunctionGraphController::handleEnter() { Ion::Storage::Record record = functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor()); curveParameterController()->setRecord(record); StackViewController * stack = stackController(); @@ -52,15 +52,15 @@ bool StorageFunctionGraphController::handleEnter() { return true; } -void StorageFunctionGraphController::selectFunctionWithCursor(int functionIndex) { +void FunctionGraphController::selectFunctionWithCursor(int functionIndex) { *m_indexFunctionSelectedByCursor = functionIndex; } -float StorageFunctionGraphController::cursorBottomMarginRatio() { +float FunctionGraphController::cursorBottomMarginRatio() { return (cursorView()->minimalSizeForOptimalDisplay().height()/2+estimatedBannerHeight())/k_viewHeight; } -void StorageFunctionGraphController::reloadBannerView() { +void FunctionGraphController::reloadBannerView() { if (functionStore()->numberOfActiveFunctions() == 0) { return; } @@ -68,16 +68,16 @@ void StorageFunctionGraphController::reloadBannerView() { reloadBannerViewForCursorOnFunction(m_cursor, record, functionStore(), functionStore()->symbol()); } -float StorageFunctionGraphController::displayBottomMarginRatio() { +float FunctionGraphController::displayBottomMarginRatio() { return (cursorView()->minimalSizeForOptimalDisplay().height() + 2 + estimatedBannerHeight()) / k_viewHeight; } -float StorageFunctionGraphController::estimatedBannerHeight() const { +float FunctionGraphController::estimatedBannerHeight() const { return BannerView::HeightGivenNumberOfLines(estimatedBannerNumberOfLines()); } -InteractiveCurveViewRangeDelegate::Range StorageFunctionGraphController::computeYRange(InteractiveCurveViewRange * interactiveCurveViewRange) { - StorageFunctionApp * myApp = static_cast(app()); +InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange(InteractiveCurveViewRange * interactiveCurveViewRange) { + FunctionApp * myApp = static_cast(app()); float min = FLT_MAX; float max = -FLT_MAX; float xMin = interactiveCurveViewRange->xMin(); @@ -89,7 +89,7 @@ InteractiveCurveViewRangeDelegate::Range StorageFunctionGraphController::compute return range; } for (int i=0; inumberOfActiveFunctions(); i++) { - ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i)); + ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i)); float y = 0.0f; float res = curveView()->resolution(); /* Scan x-range from the middle to the extrema in order to get balanced @@ -109,28 +109,28 @@ InteractiveCurveViewRangeDelegate::Range StorageFunctionGraphController::compute return range; } -void StorageFunctionGraphController::initRangeParameters() { +void FunctionGraphController::initRangeParameters() { interactiveCurveViewRange()->setDefault(); initCursorParameters(); selectFunctionWithCursor(0); } -double StorageFunctionGraphController::defaultCursorAbscissa() { +double FunctionGraphController::defaultCursorAbscissa() { return (interactiveCurveViewRange()->xMin()+interactiveCurveViewRange()->xMax())/2.0f; } -StorageFunctionStore * StorageFunctionGraphController::functionStore() const { - StorageFunctionApp * myApp = static_cast(app()); +FunctionStore * FunctionGraphController::functionStore() const { + FunctionApp * myApp = static_cast(app()); return myApp->functionStore(); } -void StorageFunctionGraphController::initCursorParameters() { +void FunctionGraphController::initCursorParameters() { double x = defaultCursorAbscissa(); - StorageFunctionApp * myApp = static_cast(app()); + FunctionApp * myApp = static_cast(app()); int functionIndex = 0; double y = 0; do { - ExpiringPointer firstFunction = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(functionIndex++)); + ExpiringPointer firstFunction = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(functionIndex++)); y = firstFunction->evaluateAtAbscissa(x, myApp->localContext()); } while ((std::isnan(y) || std::isinf(y)) && functionIndex < functionStore()->numberOfActiveFunctions()); m_cursor->moveTo(x, y); @@ -141,9 +141,9 @@ void StorageFunctionGraphController::initCursorParameters() { } } -bool StorageFunctionGraphController::moveCursorVertically(int direction) { +bool FunctionGraphController::moveCursorVertically(int direction) { int currentActiveFunctionIndex = indexFunctionSelectedByCursor(); - Poincare::Context * context = static_cast(app())->localContext(); + Poincare::Context * context = static_cast(app())->localContext(); int nextActiveFunctionIndex = InteractiveCurveViewController::closestCurveIndexVertically(direction > 0, currentActiveFunctionIndex, context); if (nextActiveFunctionIndex < 0) { @@ -155,31 +155,31 @@ bool StorageFunctionGraphController::moveCursorVertically(int direction) { return true; } -CurveView * StorageFunctionGraphController::curveView() { +CurveView * FunctionGraphController::curveView() { return functionGraphView(); } -uint32_t StorageFunctionGraphController::modelVersion() { +uint32_t FunctionGraphController::modelVersion() { return functionStore()->storeChecksum(); } -uint32_t StorageFunctionGraphController::rangeVersion() { +uint32_t FunctionGraphController::rangeVersion() { return interactiveCurveViewRange()->rangeChecksum(); } -bool StorageFunctionGraphController::isCursorVisible() { +bool FunctionGraphController::isCursorVisible() { return interactiveCurveViewRange()->isCursorVisible(cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio); } -bool StorageFunctionGraphController::closestCurveIndexIsSuitable(int newIndex, int currentIndex) const { +bool FunctionGraphController::closestCurveIndexIsSuitable(int newIndex, int currentIndex) const { return newIndex != currentIndex; } -double StorageFunctionGraphController::yValue(int curveIndex, double x, Poincare::Context * context) const { +double FunctionGraphController::yValue(int curveIndex, double x, Poincare::Context * context) const { return functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(curveIndex))->evaluateAtAbscissa(x, context); } -int StorageFunctionGraphController::numberOfCurves() const { +int FunctionGraphController::numberOfCurves() const { return functionStore()->numberOfActiveFunctions(); } diff --git a/apps/shared/storage_function_graph_controller.h b/apps/shared/storage_function_graph_controller.h index 6266f55f1..e6b8faa92 100644 --- a/apps/shared/storage_function_graph_controller.h +++ b/apps/shared/storage_function_graph_controller.h @@ -11,9 +11,9 @@ namespace Shared { -class StorageFunctionGraphController : public InteractiveCurveViewController, public StorageFunctionBannerDelegate { +class FunctionGraphController : public InteractiveCurveViewController, public FunctionBannerDelegate { public: - StorageFunctionGraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion); + FunctionGraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion); bool isEmpty() const override; ViewController * initialisationParameterController() override; void viewWillAppear() override; @@ -26,14 +26,14 @@ protected: int indexFunctionSelectedByCursor() const { return *m_indexFunctionSelectedByCursor; } virtual void selectFunctionWithCursor(int functionIndex); virtual double defaultCursorAbscissa(); - virtual StorageFunctionStore * functionStore() const; + virtual FunctionStore * functionStore() const; private: constexpr static float k_viewHeight = 174.0f; // TODO Taken from Regresssion/graph_controller. Maybe we should compute and/or put in common ? - virtual StorageFunctionGraphView * functionGraphView() = 0; + virtual FunctionGraphView * functionGraphView() = 0; virtual View * cursorView() = 0; - virtual StorageFunctionCurveParameterController * curveParameterController() = 0; + virtual FunctionCurveParameterController * curveParameterController() = 0; // InteractiveCurveViewController /* When y auto is ticked, we use a display margin to be ensure that the user diff --git a/apps/shared/storage_function_graph_view.cpp b/apps/shared/storage_function_graph_view.cpp index 91e0fe8cd..045809587 100644 --- a/apps/shared/storage_function_graph_view.cpp +++ b/apps/shared/storage_function_graph_view.cpp @@ -6,7 +6,7 @@ using namespace Poincare; namespace Shared { -StorageFunctionGraphView::StorageFunctionGraphView(InteractiveCurveViewRange * graphRange, +FunctionGraphView::FunctionGraphView(InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) : CurveView(graphRange, cursor, bannerView, cursorView), m_selectedRecord(), @@ -19,29 +19,29 @@ StorageFunctionGraphView::StorageFunctionGraphView(InteractiveCurveViewRange * g { } -void StorageFunctionGraphView::drawRect(KDContext * ctx, KDRect rect) const { +void FunctionGraphView::drawRect(KDContext * ctx, KDRect rect) const { ctx->fillRect(rect, KDColorWhite); drawGrid(ctx, rect); drawAxes(ctx, rect); simpleDrawBothAxesLabels(ctx, rect); } -void StorageFunctionGraphView::setContext(Context * context) { +void FunctionGraphView::setContext(Context * context) { m_context = context; } -Context * StorageFunctionGraphView::context() const { +Context * FunctionGraphView::context() const { return m_context; } -void StorageFunctionGraphView::selectRecord(Ion::Storage::Record record) { +void FunctionGraphView::selectRecord(Ion::Storage::Record record) { if (m_selectedRecord != record) { m_selectedRecord = record; reloadBetweenBounds(m_highlightedStart, m_highlightedEnd); } } -void StorageFunctionGraphView::setAreaHighlight(float start, float end) { +void FunctionGraphView::setAreaHighlight(float start, float end) { if (m_highlightedStart != start || m_highlightedEnd != end) { float dirtyStart = start > m_highlightedStart ? m_highlightedStart : start; float dirtyEnd = start > m_highlightedStart ? start : m_highlightedStart; @@ -60,18 +60,18 @@ void StorageFunctionGraphView::setAreaHighlight(float start, float end) { } } -void StorageFunctionGraphView::setAreaHighlightColor(bool highlightColor) { +void FunctionGraphView::setAreaHighlightColor(bool highlightColor) { if (m_shouldColorHighlighted != highlightColor) { reloadBetweenBounds(m_highlightedStart, m_highlightedEnd); m_shouldColorHighlighted = highlightColor; } } -char * StorageFunctionGraphView::label(Axis axis, int index) const { +char * FunctionGraphView::label(Axis axis, int index) const { return (axis == Axis::Horizontal ? (char *)m_xLabels[index] : (char *)m_yLabels[index]); } -void StorageFunctionGraphView::reloadBetweenBounds(float start, float end) { +void FunctionGraphView::reloadBetweenBounds(float start, float end) { if (start == end) { return; } diff --git a/apps/shared/storage_function_graph_view.h b/apps/shared/storage_function_graph_view.h index 97b5f6990..fb2986443 100644 --- a/apps/shared/storage_function_graph_view.h +++ b/apps/shared/storage_function_graph_view.h @@ -3,15 +3,15 @@ #include #include "curve_view.h" -#include "storage_function.h" +#include "function.h" #include "../constant.h" #include "interactive_curve_view_range.h" namespace Shared { -class StorageFunctionGraphView : public CurveView { +class FunctionGraphView : public CurveView { public: - StorageFunctionGraphView(InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, + FunctionGraphView(InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, BannerView * bannerView, View * cursorView); void drawRect(KDContext * ctx, KDRect rect) const override; void setContext(Poincare::Context * context); diff --git a/apps/shared/storage_function_list_controller.cpp b/apps/shared/storage_function_list_controller.cpp index e2f379e4e..b0825f2c9 100644 --- a/apps/shared/storage_function_list_controller.cpp +++ b/apps/shared/storage_function_list_controller.cpp @@ -1,5 +1,5 @@ #include "storage_function_list_controller.h" -#include "storage_function_app.h" +#include "function_app.h" #include "function_expression_cell.h" namespace Shared { @@ -7,19 +7,19 @@ namespace Shared { static inline int maxInt(int x, int y) { return x > y ? x : y; } static inline int minInt(int x, int y) { return x < y ? x : y; } -StorageFunctionListController::StorageFunctionListController(Responder * parentResponder, ButtonRowController * header, ButtonRowController * footer, I18n::Message text) : +FunctionListController::FunctionListController(Responder * parentResponder, ButtonRowController * header, ButtonRowController * footer, I18n::Message text) : StorageExpressionModelListController(parentResponder, text), ButtonRowDelegate(header, footer), m_selectableTableView(this, this, this, this), m_emptyCell(), m_plotButton(this, I18n::Message::Plot, Invocation([](void * context, void * sender) { - StorageFunctionListController * list = (StorageFunctionListController *)context; + FunctionListController * list = (FunctionListController *)context; TabViewController * tabController = list->tabController(); tabController->setActiveTab(1); return true; }, this), KDFont::SmallFont, Palette::PurpleBright), m_valuesButton(this, I18n::Message::DisplayValues, Invocation([](void * context, void * sender) { - StorageFunctionListController * list = (StorageFunctionListController *)context; + FunctionListController * list = (FunctionListController *)context; TabViewController * tabController = list->tabController(); tabController->setActiveTab(2); return true; @@ -38,11 +38,11 @@ StorageFunctionListController::StorageFunctionListController(Responder * parentR /* TableViewDataSource */ -void StorageFunctionListController::viewWillAppear() { +void FunctionListController::viewWillAppear() { computeTitlesColumnWidth(); } -KDCoordinate StorageFunctionListController::columnWidth(int i) { +KDCoordinate FunctionListController::columnWidth(int i) { switch (i) { case 0: return m_titlesColumnWidth; @@ -54,7 +54,7 @@ KDCoordinate StorageFunctionListController::columnWidth(int i) { } } -KDCoordinate StorageFunctionListController::cumulatedWidthFromIndex(int i) { +KDCoordinate FunctionListController::cumulatedWidthFromIndex(int i) { switch (i) { case 0: return 0; @@ -68,7 +68,7 @@ KDCoordinate StorageFunctionListController::cumulatedWidthFromIndex(int i) { } } -int StorageFunctionListController::indexFromCumulatedWidth(KDCoordinate offsetX) { +int FunctionListController::indexFromCumulatedWidth(KDCoordinate offsetX) { if (offsetX <= m_titlesColumnWidth) { return 0; } else { @@ -80,14 +80,14 @@ int StorageFunctionListController::indexFromCumulatedWidth(KDCoordinate offsetX) } } -int StorageFunctionListController::typeAtLocation(int i, int j) { +int FunctionListController::typeAtLocation(int i, int j) { if (isAddEmptyRow(j)){ return i + 2; } return i; } -HighlightCell * StorageFunctionListController::reusableCell(int index, int type) { +HighlightCell * FunctionListController::reusableCell(int index, int type) { assert(index >= 0); assert(index < maxNumberOfDisplayableRows()); switch (type) { @@ -105,14 +105,14 @@ HighlightCell * StorageFunctionListController::reusableCell(int index, int type) } } -int StorageFunctionListController::reusableCellCount(int type) { +int FunctionListController::reusableCellCount(int type) { if (type > 1) { return 1; } return maxNumberOfDisplayableRows(); } -void StorageFunctionListController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { +void FunctionListController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { if (!isAddEmptyRow(j)) { if (i == 0) { willDisplayTitleCellAtIndex(cell, j); @@ -128,14 +128,14 @@ void StorageFunctionListController::willDisplayCellAtLocation(HighlightCell * ce /* ButtonRowDelegate */ -int StorageFunctionListController::numberOfButtons(ButtonRowController::Position position) const { +int FunctionListController::numberOfButtons(ButtonRowController::Position position) const { if (position == ButtonRowController::Position::Bottom) { return 2; } return 0; } -Button * StorageFunctionListController::buttonAtIndex(int index, ButtonRowController::Position position) const { +Button * FunctionListController::buttonAtIndex(int index, ButtonRowController::Position position) const { if (position == ButtonRowController::Position::Top) { return nullptr; } @@ -145,7 +145,7 @@ Button * StorageFunctionListController::buttonAtIndex(int index, ButtonRowContro /* Responder */ -void StorageFunctionListController::didBecomeFirstResponder() { +void FunctionListController::didBecomeFirstResponder() { if (selectedRow() == -1) { selectCellAtLocation(1, 0); } else { @@ -158,7 +158,7 @@ void StorageFunctionListController::didBecomeFirstResponder() { app()->setFirstResponder(selectableTableView()); } -bool StorageFunctionListController::handleEvent(Ion::Events::Event event) { +bool FunctionListController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::Up) { if (selectedRow() == -1) { footer()->setSelectedButton(-1); @@ -202,11 +202,11 @@ bool StorageFunctionListController::handleEvent(Ion::Events::Event event) { return false; } -void StorageFunctionListController::didEnterResponderChain(Responder * previousFirstResponder) { +void FunctionListController::didEnterResponderChain(Responder * previousFirstResponder) { selectableTableView()->reloadData(); } -void StorageFunctionListController::willExitResponderChain(Responder * nextFirstResponder) { +void FunctionListController::willExitResponderChain(Responder * nextFirstResponder) { if (nextFirstResponder == tabController()) { selectableTableView()->deselectTable(); footer()->setSelectedButton(-1); @@ -215,7 +215,7 @@ void StorageFunctionListController::willExitResponderChain(Responder * nextFirst /* SelectableTableViewDelegate */ -void StorageFunctionListController::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) { +void FunctionListController::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) { // Update memoization of cell heights StorageExpressionModelListController::tableViewDidChangeSelection(t, previousSelectedCellX, previousSelectedCellY); // Do not select the cell left of the "addEmptyFunction" cell @@ -226,40 +226,40 @@ void StorageFunctionListController::tableViewDidChangeSelection(SelectableTableV /* ExpressionModelListController */ -StackViewController * StorageFunctionListController::stackController() const { +StackViewController * FunctionListController::stackController() const { return static_cast(parentResponder()->parentResponder()->parentResponder()); } -void StorageFunctionListController::configureFunction(Ion::Storage::Record record) { +void FunctionListController::configureFunction(Ion::Storage::Record record) { StackViewController * stack = stackController(); parameterController()->setRecord(record); stack->push(parameterController()); } -void StorageFunctionListController::computeTitlesColumnWidth(bool forceMax) { +void FunctionListController::computeTitlesColumnWidth(bool forceMax) { if (forceMax) { - m_titlesColumnWidth = nameWidth(StorageFunction::k_maxNameWithArgumentSize - 1)+k_functionTitleSumOfMargins; + m_titlesColumnWidth = nameWidth(Function::k_maxNameWithArgumentSize - 1)+k_functionTitleSumOfMargins; return; } KDCoordinate maxTitleWidth = maxFunctionNameWidth()+k_functionTitleSumOfMargins; m_titlesColumnWidth = maxInt(maxTitleWidth, k_minTitleColumnWidth); } -TabViewController * StorageFunctionListController::tabController() const { +TabViewController * FunctionListController::tabController() const { return static_cast(parentResponder()->parentResponder()->parentResponder()->parentResponder()); } -StorageFunctionStore * StorageFunctionListController::modelStore() { - StorageFunctionApp * myApp = static_cast(app()); +FunctionStore * FunctionListController::modelStore() { + FunctionApp * myApp = static_cast(app()); return myApp->functionStore(); } -InputViewController * StorageFunctionListController::inputController() { - StorageFunctionApp * myApp = static_cast(app()); +InputViewController * FunctionListController::inputController() { + FunctionApp * myApp = static_cast(app()); return myApp->inputViewController(); } -KDCoordinate StorageFunctionListController::maxFunctionNameWidth() { +KDCoordinate FunctionListController::maxFunctionNameWidth() { int maxNameLength = 0; int numberOfModels = modelStore()->numberOfModels(); for (int i = 0; i < numberOfModels; i++) { @@ -269,15 +269,15 @@ KDCoordinate StorageFunctionListController::maxFunctionNameWidth() { assert(dotPosition != nullptr); maxNameLength = maxInt(maxNameLength, dotPosition-functionName); } - return nameWidth(maxNameLength + StorageFunction::k_parenthesedArgumentLength); + return nameWidth(maxNameLength + Function::k_parenthesedArgumentLength); } -void StorageFunctionListController::didChangeModelsList() { +void FunctionListController::didChangeModelsList() { StorageExpressionModelListController::didChangeModelsList(); computeTitlesColumnWidth(); } -KDCoordinate StorageFunctionListController::baseline(int j) { +KDCoordinate FunctionListController::baseline(int j) { if (j < 0) { return -1; } @@ -293,13 +293,13 @@ KDCoordinate StorageFunctionListController::baseline(int j) { return privateBaseline(j); } -void StorageFunctionListController::resetMemoizationForIndex(int index) { +void FunctionListController::resetMemoizationForIndex(int index) { assert(index >= 0 && index < k_memoizedCellsCount); m_memoizedCellBaseline[index] = -1; StorageExpressionModelListController::resetMemoizationForIndex(index); } -void StorageFunctionListController::shiftMemoization(bool newCellIsUnder) { +void FunctionListController::shiftMemoization(bool newCellIsUnder) { if (newCellIsUnder) { for (int i = 0; i < k_memoizedCellsCount - 1; i++) { m_memoizedCellBaseline[i] = m_memoizedCellBaseline[i+1]; @@ -312,19 +312,19 @@ void StorageFunctionListController::shiftMemoization(bool newCellIsUnder) { StorageExpressionModelListController::shiftMemoization(newCellIsUnder); } -KDCoordinate StorageFunctionListController::nameWidth(int nameLength) const { +KDCoordinate FunctionListController::nameWidth(int nameLength) const { assert(nameLength >= 0); - return nameLength * const_cast(this)->titleCells(0)->font()->glyphSize().width(); + return nameLength * const_cast(this)->titleCells(0)->font()->glyphSize().width(); } -KDCoordinate StorageFunctionListController::privateBaseline(int j) const { - assert(j >= 0 && j < const_cast(this)->numberOfExpressionRows()); +KDCoordinate FunctionListController::privateBaseline(int j) const { + assert(j >= 0 && j < const_cast(this)->numberOfExpressionRows()); FunctionExpressionCell * cell = static_cast((const_cast(&m_selectableTableView))->cellAtLocation(1, j)); Poincare::Layout layout = cell->layout(); if (layout.isUninitialized()) { return -1; // Baseline < 0 triggers default behaviour (centered alignment) } - return 0.5*(const_cast(this)->rowHeight(j)-layout.layoutSize().height())+layout.baseline(); + return 0.5*(const_cast(this)->rowHeight(j)-layout.layoutSize().height())+layout.baseline(); } } diff --git a/apps/shared/storage_function_list_controller.h b/apps/shared/storage_function_list_controller.h index 3f57a1d96..9e77869e7 100644 --- a/apps/shared/storage_function_list_controller.h +++ b/apps/shared/storage_function_list_controller.h @@ -10,9 +10,9 @@ namespace Shared { -class StorageFunctionListController : public StorageExpressionModelListController, public ButtonRowDelegate, public TableViewDataSource { +class FunctionListController : public StorageExpressionModelListController, public ButtonRowDelegate, public TableViewDataSource { public: - StorageFunctionListController(Responder * parentResponder, ButtonRowController * header, ButtonRowController * footer, I18n::Message text); + FunctionListController(Responder * parentResponder, ButtonRowController * header, ButtonRowController * footer, I18n::Message text); /* ViewController */ void viewWillAppear() override; @@ -53,7 +53,7 @@ protected: StackViewController * stackController() const; void configureFunction(Ion::Storage::Record record); void computeTitlesColumnWidth(bool forceMax = false); - StorageFunctionStore * modelStore() override; + FunctionStore * modelStore() override; KDCoordinate baseline(int j); void resetMemoizationForIndex(int index) override; void shiftMemoization(bool newCellIsUnder) override; diff --git a/apps/shared/storage_function_store.cpp b/apps/shared/storage_function_store.cpp index 37c18a45e..143767c2e 100644 --- a/apps/shared/storage_function_store.cpp +++ b/apps/shared/storage_function_store.cpp @@ -1,10 +1,10 @@ #include "storage_function_store.h" -#include "storage_cartesian_function.h" +#include "cartesian_function.h" #include namespace Shared { -uint32_t StorageFunctionStore::storeChecksum() { +uint32_t FunctionStore::storeChecksum() { return Ion::Storage::sharedStorage()->checksum(); } diff --git a/apps/shared/storage_function_store.h b/apps/shared/storage_function_store.h index 7195a48a8..f5f15ff05 100644 --- a/apps/shared/storage_function_store.h +++ b/apps/shared/storage_function_store.h @@ -1,7 +1,7 @@ #ifndef SHARED_STORAGE_FUNCTION_STORE_H #define SHARED_STORAGE_FUNCTION_STORE_H -#include "storage_function.h" +#include "function.h" #include "storage_expression_model_store.h" #include @@ -9,15 +9,15 @@ namespace Shared { /* FunctionStore storse functions and gives them a color. */ -class StorageFunctionStore : public StorageExpressionModelStore { +class FunctionStore : public StorageExpressionModelStore { public: - StorageFunctionStore() : StorageExpressionModelStore() {} + FunctionStore() : StorageExpressionModelStore() {} uint32_t storeChecksum(); // An active function must be defined to be counted - int numberOfActiveFunctions() const { return numberOfModelsSatisfyingTest([](SingleExpressionModelHandle * m) { return m->isDefined() && static_cast(m)->isActive(); }); } - Ion::Storage::Record activeRecordAtIndex(int i) const { return recordStatifyingTestAtIndex(i, [](SingleExpressionModelHandle * m) { return m->isDefined() && static_cast(m)->isActive(); }); } + int numberOfActiveFunctions() const { return numberOfModelsSatisfyingTest([](ExpressionModelHandle * m) { return m->isDefined() && static_cast(m)->isActive(); }); } + Ion::Storage::Record activeRecordAtIndex(int i) const { return recordStatifyingTestAtIndex(i, [](ExpressionModelHandle * m) { return m->isDefined() && static_cast(m)->isActive(); }); } - ExpiringPointer modelForRecord(Ion::Storage::Record record) const { return ExpiringPointer(static_cast(privateModelForRecord(record))); } + ExpiringPointer modelForRecord(Ion::Storage::Record record) const { return ExpiringPointer(static_cast(privateModelForRecord(record))); } }; diff --git a/apps/shared/storage_list_parameter_controller.cpp b/apps/shared/storage_list_parameter_controller.cpp index b518db47e..f2b3eeda7 100644 --- a/apps/shared/storage_list_parameter_controller.cpp +++ b/apps/shared/storage_list_parameter_controller.cpp @@ -1,5 +1,5 @@ #include "storage_list_parameter_controller.h" -#include "storage_function_app.h" +#include "function_app.h" #include namespace Shared { @@ -94,12 +94,12 @@ bool StorageListParameterController::handleEnterOnRow(int rowIndex) { } } -ExpiringPointer StorageListParameterController::function() { +ExpiringPointer StorageListParameterController::function() { return functionStore()->modelForRecord(m_record); } -StorageFunctionStore * StorageListParameterController::functionStore() { - StorageFunctionApp * a = static_cast(app()); +FunctionStore * StorageListParameterController::functionStore() { + FunctionApp * a = static_cast(app()); return a->functionStore(); } diff --git a/apps/shared/storage_list_parameter_controller.h b/apps/shared/storage_list_parameter_controller.h index 88e61fb73..f039db41b 100644 --- a/apps/shared/storage_list_parameter_controller.h +++ b/apps/shared/storage_list_parameter_controller.h @@ -31,8 +31,8 @@ protected: return 2; #endif } - StorageFunctionStore * functionStore(); - ExpiringPointer function(); + FunctionStore * functionStore(); + ExpiringPointer function(); SelectableTableView m_selectableTableView; Ion::Storage::Record m_record; private: diff --git a/apps/shared/storage_sum_graph_controller.cpp b/apps/shared/storage_sum_graph_controller.cpp index 0d05cb93d..e0b92e3e9 100644 --- a/apps/shared/storage_sum_graph_controller.cpp +++ b/apps/shared/storage_sum_graph_controller.cpp @@ -1,5 +1,5 @@ #include "storage_sum_graph_controller.h" -#include "storage_function_app.h" +#include "function_app.h" #include "../apps_container.h" #include #include @@ -13,7 +13,7 @@ using namespace Poincare; namespace Shared { -StorageSumGraphController::StorageSumGraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, StorageFunctionGraphView * graphView, InteractiveCurveViewRange * range, CurveViewCursor * cursor, CodePoint sumSymbol) : +StorageSumGraphController::StorageSumGraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, FunctionGraphView * graphView, InteractiveCurveViewRange * range, CurveViewCursor * cursor, CodePoint sumSymbol) : SimpleInteractiveCurveViewController(parentResponder, range, graphView, cursor), m_step(Step::FirstParameter), m_startSum(NAN), @@ -101,9 +101,9 @@ bool StorageSumGraphController::handleEvent(Ion::Events::Event event) { } bool StorageSumGraphController::moveCursorHorizontallyToPosition(double x) { - StorageFunctionApp * myApp = static_cast(app()); + FunctionApp * myApp = static_cast(app()); assert(!m_record.isNull()); - ExpiringPointer function = myApp->functionStore()->modelForRecord(m_record); + ExpiringPointer function = myApp->functionStore()->modelForRecord(m_record); double y = function->evaluateAtAbscissa(x, myApp->localContext()); m_cursor->moveTo(x, y); if (m_step == Step::FirstParameter) { @@ -189,9 +189,9 @@ bool StorageSumGraphController::handleEnter() { return true; } m_step = (Step)((int)m_step+1); - StorageFunctionApp * myApp = static_cast(app()); + FunctionApp * myApp = static_cast(app()); assert(!m_record.isNull()); - ExpiringPointer function = myApp->functionStore()->modelForRecord(m_record); + ExpiringPointer function = myApp->functionStore()->modelForRecord(m_record); double sum = function->sumBetweenBounds(m_startSum, m_endSum, myApp->localContext()); m_legendView.setSumSymbol(m_step, m_startSum, m_endSum, sum, createFunctionLayout(function)); m_legendView.setLegendMessage(I18n::Message::Default, m_step); diff --git a/apps/shared/storage_sum_graph_controller.h b/apps/shared/storage_sum_graph_controller.h index 7b9aceecc..f8224b127 100644 --- a/apps/shared/storage_sum_graph_controller.h +++ b/apps/shared/storage_sum_graph_controller.h @@ -7,7 +7,7 @@ #include "vertical_cursor_view.h" #include "curve_view_cursor.h" #include "simple_interactive_curve_view_controller.h" -#include "storage_function.h" +#include "function.h" #include "text_field_delegate.h" #include "expiring_pointer.h" @@ -15,7 +15,7 @@ namespace Shared { class StorageSumGraphController : public SimpleInteractiveCurveViewController, public TextFieldDelegate { public: - StorageSumGraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, StorageFunctionGraphView * curveView, InteractiveCurveViewRange * range, CurveViewCursor * cursor, CodePoint sumSymbol); + StorageSumGraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, FunctionGraphView * curveView, InteractiveCurveViewRange * range, CurveViewCursor * cursor, CodePoint sumSymbol); void viewWillAppear() override; void didEnterResponderChain(Responder * previousFirstResponder) override; bool handleEvent(Ion::Events::Event event) override; @@ -40,7 +40,7 @@ private: constexpr static float k_cursorBottomMarginRatio = 0.28f; // (cursorHeight/2+bannerHeigh)/graphViewHeight virtual I18n::Message legendMessageAtStep(Step step) = 0; virtual double cursorNextStep(double position, int direction) = 0; - virtual Poincare::Layout createFunctionLayout(ExpiringPointer function) = 0; + virtual Poincare::Layout createFunctionLayout(ExpiringPointer function) = 0; Shared::InteractiveCurveViewRange * interactiveCurveViewRange() override { return m_graphRange; } Shared::CurveView * curveView() override { return m_graphView; } TextFieldDelegateApp * textFieldDelegateApp() override { @@ -78,7 +78,7 @@ private: char m_draftText[TextField::maxBufferSize()]; CodePoint m_sumSymbol; }; - StorageFunctionGraphView * m_graphView; + FunctionGraphView * m_graphView; LegendView m_legendView; VerticalCursorView m_cursorView; }; diff --git a/apps/shared/storage_values_controller.cpp b/apps/shared/storage_values_controller.cpp index d8946031d..7ab7f2839 100644 --- a/apps/shared/storage_values_controller.cpp +++ b/apps/shared/storage_values_controller.cpp @@ -1,5 +1,5 @@ #include "storage_values_controller.h" -#include "storage_function_app.h" +#include "function_app.h" #include "../constant.h" #include "../apps_container.h" #include "poincare_helpers.h" @@ -309,7 +309,7 @@ int StorageValuesController::maxNumberOfElements() const { } double StorageValuesController::evaluationOfAbscissaAtColumn(double abscissa, int columnIndex) { - ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(columnIndex)); + ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(columnIndex)); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); return function->evaluateAtAbscissa(abscissa, myApp->localContext()); } @@ -318,8 +318,8 @@ void StorageValuesController::updateNumberOfColumns() { m_numberOfColumns = 1+functionStore()->numberOfActiveFunctions(); } -StorageFunctionStore * StorageValuesController::functionStore() const { - StorageFunctionApp * myApp = static_cast(app()); +FunctionStore * StorageValuesController::functionStore() const { + FunctionApp * myApp = static_cast(app()); return myApp->functionStore(); } diff --git a/apps/shared/storage_values_controller.h b/apps/shared/storage_values_controller.h index 0e5219a86..7c2c6b1a4 100644 --- a/apps/shared/storage_values_controller.h +++ b/apps/shared/storage_values_controller.h @@ -46,7 +46,7 @@ protected: StackViewController * stackController() const; bool setDataAtLocation(double floatBody, int columnIndex, int rowIndex) override; virtual void updateNumberOfColumns(); - virtual StorageFunctionStore * functionStore() const; + virtual FunctionStore * functionStore() const; virtual Ion::Storage::Record recordAtColumn(int i); Interval * m_interval; int m_numberOfColumns; diff --git a/apps/shared/storage_values_function_parameter_controller.cpp b/apps/shared/storage_values_function_parameter_controller.cpp index c457e23e9..3047e49b4 100644 --- a/apps/shared/storage_values_function_parameter_controller.cpp +++ b/apps/shared/storage_values_function_parameter_controller.cpp @@ -1,5 +1,5 @@ #include "storage_values_function_parameter_controller.h" -#include "storage_function_app.h" +#include "function_app.h" #include namespace Shared { @@ -9,8 +9,8 @@ const char * StorageValuesFunctionParameterController::title() { } void StorageValuesFunctionParameterController::viewWillAppear() { - StorageFunctionApp * myApp = static_cast(app()); - myApp->functionStore()->modelForRecord(m_record)->nameWithArgument(m_pageTitle, StorageFunction::k_maxNameWithArgumentSize, m_symbol); + FunctionApp * myApp = static_cast(app()); + myApp->functionStore()->modelForRecord(m_record)->nameWithArgument(m_pageTitle, Function::k_maxNameWithArgumentSize, m_symbol); } void StorageValuesFunctionParameterController::didBecomeFirstResponder() { diff --git a/apps/shared/storage_values_function_parameter_controller.h b/apps/shared/storage_values_function_parameter_controller.h index 6d2a4b376..d9a1dcd3f 100644 --- a/apps/shared/storage_values_function_parameter_controller.h +++ b/apps/shared/storage_values_function_parameter_controller.h @@ -2,7 +2,7 @@ #define SHARED_STORAGE_VALUES_FUNCTION_PARAM_CONTROLLER_H #include -#include "storage_function.h" +#include "function.h" #include namespace Shared { @@ -34,7 +34,7 @@ protected: SelectableTableView m_selectableTableView; Ion::Storage::Record m_record; private: - char m_pageTitle[StorageFunction::k_maxNameWithArgumentSize]; + char m_pageTitle[Function::k_maxNameWithArgumentSize]; char m_symbol; }; diff --git a/apps/solver/equation.cpp b/apps/solver/equation.cpp index 52041e04e..20ed34a41 100644 --- a/apps/solver/equation.cpp +++ b/apps/solver/equation.cpp @@ -13,7 +13,7 @@ using namespace Shared; namespace Solver { Equation::Equation(Ion::Storage::Record record) : - SingleExpressionModelHandle(record) + ExpressionModelHandle(record) { } @@ -45,7 +45,7 @@ Expression Equation::Handle::standardForm(const Storage::Record * record, Contex } void Equation::Handle::tidy() const { - ExpressionModelHandle::tidy(); + ExpressionModel::tidy(); // Free the pool of the m_standardForm m_standardForm = Expression(); } diff --git a/apps/solver/equation.h b/apps/solver/equation.h index 65bda4052..d112d2a3d 100644 --- a/apps/solver/equation.h +++ b/apps/solver/equation.h @@ -1,11 +1,11 @@ #ifndef SOLVER_EQUATION_h #define SOLVER_EQUATION_h -#include "../shared/single_expression_model_handle.h" +#include "../shared/expression_model_handle.h" namespace Solver { -class Equation : public Shared::SingleExpressionModelHandle { +class Equation : public Shared::ExpressionModelHandle { public: Equation(Ion::Storage::Record record = Record()); bool shouldBeClearedBeforeRemove() override { @@ -15,7 +15,7 @@ public: bool containsIComplex(Poincare::Context * context) const; private: - class Handle : public Shared::ExpressionModelHandle { + class Handle : public Shared::ExpressionModel { public: Poincare::Expression standardForm(const Ion::Storage::Record * record, Poincare::Context * context) const; void tidy() const override; @@ -25,7 +25,7 @@ private: mutable Poincare::Expression m_standardForm; }; size_t metaDataSize() const override { return 0; } - const Shared::ExpressionModelHandle * handle() const override { return &m_handle; } + const Shared::ExpressionModel * handle() const override { return &m_handle; } Handle m_handle; }; diff --git a/apps/solver/equation_store.cpp b/apps/solver/equation_store.cpp index be1491cf5..ab65d8497 100644 --- a/apps/solver/equation_store.cpp +++ b/apps/solver/equation_store.cpp @@ -49,7 +49,7 @@ void EquationStore::setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record m_equations[cacheIndex] = Equation(record); } -SingleExpressionModelHandle * EquationStore::memoizedModelAtIndex(int cacheIndex) const { +ExpressionModelHandle * EquationStore::memoizedModelAtIndex(int cacheIndex) const { assert(cacheIndex >= 0 && cacheIndex < maxNumberOfMemoizedModels()); return &m_equations[cacheIndex]; } diff --git a/apps/solver/equation_store.h b/apps/solver/equation_store.h index 835da0ec2..a667fc5a8 100644 --- a/apps/solver/equation_store.h +++ b/apps/solver/equation_store.h @@ -82,7 +82,7 @@ private: /* We don't really use model memoization as the number of Equation is limited * and we keep enough Equations to store them all. */ void setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record record) const override; - Shared::SingleExpressionModelHandle * memoizedModelAtIndex(int cacheIndex) const override; + Shared::ExpressionModelHandle * memoizedModelAtIndex(int cacheIndex) const override; Error resolveLinearSystem(Poincare::Expression solutions[k_maxNumberOfExactSolutions], Poincare::Expression solutionApproximations[k_maxNumberOfExactSolutions], Poincare::Expression coefficients[k_maxNumberOfEquations][Poincare::Expression::k_maxNumberOfVariables], Poincare::Expression constants[k_maxNumberOfEquations], Poincare::Context * context); Error oneDimensialPolynomialSolve(Poincare::Expression solutions[k_maxNumberOfExactSolutions], Poincare::Expression solutionApproximations[k_maxNumberOfExactSolutions], Poincare::Expression polynomialCoefficients[Poincare::Expression::k_maxNumberOfPolynomialCoefficients], int degree, Poincare::Context * context); diff --git a/apps/variable_box_controller.cpp b/apps/variable_box_controller.cpp index 086947b52..5f05e6a8e 100644 --- a/apps/variable_box_controller.cpp +++ b/apps/variable_box_controller.cpp @@ -1,8 +1,8 @@ #include "variable_box_controller.h" #include "shared/global_context.h" #include "shared/poincare_helpers.h" -#include "shared/storage_function.h" -#include "shared/storage_cartesian_function.h" +#include "shared/function.h" +#include "shared/cartesian_function.h" #include "graph/storage_cartesian_function_store.h" #include "constant.h" #include @@ -103,18 +103,18 @@ void VariableBoxController::willDisplayCellForIndex(HighlightCell * cell, int in } ExpressionTableCellWithExpression * myCell = (ExpressionTableCellWithExpression *)cell; Storage::Record record = recordAtIndex(index); - assert(Shared::StorageFunction::k_maxNameWithArgumentSize > SymbolAbstract::k_maxNameSize); - char symbolName[Shared::StorageFunction::k_maxNameWithArgumentSize]; + assert(Shared::Function::k_maxNameWithArgumentSize > SymbolAbstract::k_maxNameSize); + char symbolName[Shared::Function::k_maxNameWithArgumentSize]; size_t symbolLength = 0; if (m_currentPage == Page::Expression) { symbolLength = SymbolAbstract::TruncateExtension(symbolName, record.fullName(), SymbolAbstract::k_maxNameSize); } else { assert(m_currentPage == Page::Function); - StorageCartesianFunction f(record); + CartesianFunction f(record); symbolLength = f.nameWithArgument( symbolName, - Shared::StorageFunction::k_maxNameWithArgumentSize, - Shared::StorageCartesianFunction::Symbol()); + Shared::Function::k_maxNameWithArgumentSize, + Shared::CartesianFunction::Symbol()); } Layout symbolLayout = LayoutHelper::String(symbolName, symbolLength); myCell->setLayout(symbolLayout); @@ -191,9 +191,9 @@ bool VariableBoxController::selectLeaf(int selectedRow) { // Get the name text to insert Storage::Record record = recordAtIndex(selectedRow); - assert(Shared::StorageFunction::k_maxNameWithArgumentSize > 0); - assert(Shared::StorageFunction::k_maxNameWithArgumentSize > SymbolAbstract::k_maxNameSize); - constexpr size_t nameToHandleMaxSize = Shared::StorageFunction::k_maxNameWithArgumentSize; + assert(Shared::Function::k_maxNameWithArgumentSize > 0); + assert(Shared::Function::k_maxNameWithArgumentSize > SymbolAbstract::k_maxNameSize); + constexpr size_t nameToHandleMaxSize = Shared::Function::k_maxNameWithArgumentSize; char nameToHandle[nameToHandleMaxSize]; size_t nameLength = SymbolAbstract::TruncateExtension(nameToHandle, record.fullName(), nameToHandleMaxSize);