From 21907fb89a8fe69d7d789c4705757b8d4692d7d0 Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Mon, 3 Jun 2019 15:40:54 +0200 Subject: [PATCH] [apps] Get rid of App casts --- apps/calculation/app.h | 4 ++++ apps/calculation/edit_expression_controller.cpp | 14 ++++++-------- apps/calculation/history_controller.cpp | 3 +-- apps/calculation/history_view_cell.cpp | 10 ++++------ apps/code/app.h | 4 ++++ apps/code/console_controller.cpp | 4 ++-- apps/code/editor_controller.cpp | 6 +++--- apps/code/menu_controller.cpp | 2 +- apps/code/variable_box_controller.cpp | 2 +- apps/graph/app.h | 4 ++++ .../graph/calculation_graph_controller.cpp | 6 ++---- apps/graph/graph/graph_controller.cpp | 11 ++++------- apps/graph/graph/graph_controller.h | 2 +- apps/graph/graph/tangent_graph_controller.cpp | 17 +++++++---------- apps/graph/list/list_controller.cpp | 4 ++++ apps/graph/list/list_controller.h | 4 +--- .../values/derivative_parameter_controller.cpp | 3 +-- .../values/function_parameter_controller.cpp | 3 +-- apps/graph/values/values_controller.cpp | 6 +++--- apps/probability/app.h | 2 +- apps/regression/app.h | 4 ++++ apps/regression/graph_options_controller.cpp | 2 +- apps/regression/store_parameter_controller.cpp | 2 +- apps/sequence/app.h | 4 ++++ apps/sequence/graph/graph_controller.cpp | 6 +++--- apps/sequence/graph/graph_controller.h | 2 +- apps/sequence/list/list_controller.cpp | 15 +++++++-------- .../sequence/list/list_parameter_controller.cpp | 6 +++--- .../sequence/list/type_parameter_controller.cpp | 5 ++--- apps/settings/app.h | 2 +- apps/solver/app.h | 4 ++++ apps/solver/interval_controller.cpp | 5 ++--- apps/solver/list_controller.cpp | 14 ++++++-------- apps/solver/solutions_controller.cpp | 3 +-- escher/include/escher/container.h | 2 +- 35 files changed, 96 insertions(+), 91 deletions(-) diff --git a/apps/calculation/app.h b/apps/calculation/app.h index 62410ffee..0040fcd51 100644 --- a/apps/calculation/app.h +++ b/apps/calculation/app.h @@ -39,6 +39,10 @@ private: EditExpressionController m_editExpressionController; }; +inline App * app() { + return static_cast(::app()); +} + } #endif diff --git a/apps/calculation/edit_expression_controller.cpp b/apps/calculation/edit_expression_controller.cpp index 3b30b042f..857a7f755 100644 --- a/apps/calculation/edit_expression_controller.cpp +++ b/apps/calculation/edit_expression_controller.cpp @@ -109,11 +109,11 @@ void EditExpressionController::layoutFieldDidChangeSize(::LayoutField * layoutFi } TextFieldDelegateApp * EditExpressionController::textFieldDelegateApp() { - return (App *)app(); + return app(); } ExpressionFieldDelegateApp * EditExpressionController::expressionFieldDelegateApp() { - return (App *)app(); + return app(); } void EditExpressionController::reloadView() { @@ -126,14 +126,13 @@ void EditExpressionController::reloadView() { bool EditExpressionController::inputViewDidReceiveEvent(Ion::Events::Event event, bool shouldDuplicateLastCalculation) { if (shouldDuplicateLastCalculation && m_cacheBuffer[0] != 0) { - App * calculationApp = (App *)app(); /* The input text store in m_cacheBuffer might have beed correct the first * time but then be too long when replacing ans in another context */ - if (!calculationApp->isAcceptableText(m_cacheBuffer)) { - calculationApp->displayWarning(I18n::Message::SyntaxError); + if (!app()->isAcceptableText(m_cacheBuffer)) { + app()->displayWarning(I18n::Message::SyntaxError); return true; } - m_calculationStore->push(m_cacheBuffer, calculationApp->localContext()); + m_calculationStore->push(m_cacheBuffer, app()->localContext()); m_historyController->reload(); ((ContentView *)view())->mainView()->scrollToCell(0, m_historyController->numberOfRows()-1); return true; @@ -151,14 +150,13 @@ bool EditExpressionController::inputViewDidReceiveEvent(Ion::Events::Event event bool EditExpressionController::inputViewDidFinishEditing(const char * text, Layout layoutR) { - App * calculationApp = (App *)app(); if (layoutR.isUninitialized()) { assert(text); strlcpy(m_cacheBuffer, text, k_cacheBufferSize); } else { layoutR.serializeParsedExpression(m_cacheBuffer, k_cacheBufferSize); } - m_calculationStore->push(m_cacheBuffer, calculationApp->localContext()); + m_calculationStore->push(m_cacheBuffer, app()->localContext()); m_historyController->reload(); ((ContentView *)view())->mainView()->scrollToCell(0, m_historyController->numberOfRows()-1); ((ContentView *)view())->expressionField()->setEditing(true, true); diff --git a/apps/calculation/history_controller.cpp b/apps/calculation/history_controller.cpp index 71d193f39..8a60a1827 100644 --- a/apps/calculation/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -151,8 +151,7 @@ KDCoordinate HistoryController::rowHeight(int j) { return 0; } Calculation * calculation = m_calculationStore->calculationAtIndex(j); - App * calculationApp = (App *)app(); - return calculation->height(calculationApp->localContext(), j == selectedRow() && selectedSubviewType() == SubviewType::Output) + 4 * Metric::CommonSmallMargin; + return calculation->height(app()->localContext(), j == selectedRow() && selectedSubviewType() == SubviewType::Output) + 4 * Metric::CommonSmallMargin; } int HistoryController::typeAtLocation(int i, int j) { diff --git a/apps/calculation/history_view_cell.cpp b/apps/calculation/history_view_cell.cpp index f886a2674..3156a46a7 100644 --- a/apps/calculation/history_view_cell.cpp +++ b/apps/calculation/history_view_cell.cpp @@ -75,8 +75,7 @@ void HistoryViewCell::reloadScroll() { } void HistoryViewCell::reloadOutputSelection() { - App * calculationApp = (App *)app(); - Calculation::DisplayOutput display = m_calculation.displayOutput(calculationApp->localContext()); + Calculation::DisplayOutput display = m_calculation.displayOutput(app()->localContext()); /* Select the right output according to the calculation display output. This * will reload the scroll to display the selected output. */ if (display == Calculation::DisplayOutput::ExactAndApproximate) { @@ -140,8 +139,7 @@ void HistoryViewCell::setCalculation(Calculation * calculation, bool expanded) { // Memoization m_calculation = *calculation; m_calculationExpanded = expanded; - App * calculationApp = (App *)app(); - Calculation::DisplayOutput display = calculation->displayOutput(calculationApp->localContext()); + Calculation::DisplayOutput display = calculation->displayOutput(app()->localContext()); m_inputView.setLayout(calculation->createInputLayout()); /* Both output expressions have to be updated at the same time. Otherwise, * when updating one layout, if the second one still points to a deleted @@ -151,13 +149,13 @@ void HistoryViewCell::setCalculation(Calculation * calculation, bool expanded) { if (display == Calculation::DisplayOutput::ExactOnly) { rightOutputLayout = calculation->createExactOutputLayout(); } else { - rightOutputLayout = calculation->createApproximateOutputLayout(calculationApp->localContext()); + rightOutputLayout = calculation->createApproximateOutputLayout(app()->localContext()); if (display == Calculation::DisplayOutput::ExactAndApproximate || (display == Calculation::DisplayOutput::ExactAndApproximateToggle && expanded)) { leftOutputLayout = calculation->createExactOutputLayout(); } } m_scrollableOutputView.setLayouts(rightOutputLayout, leftOutputLayout); - I18n::Message equalMessage = calculation->exactAndApproximateDisplayedOutputsAreEqual(calculationApp->localContext()) == Calculation::EqualSign::Equal ? I18n::Message::Equal : I18n::Message::AlmostEqual; + I18n::Message equalMessage = calculation->exactAndApproximateDisplayedOutputsAreEqual(app()->localContext()) == Calculation::EqualSign::Equal ? I18n::Message::Equal : I18n::Message::AlmostEqual; m_scrollableOutputView.setEqualMessage(equalMessage); /* The displayed input and outputs have changed. We need to re-layout the cell diff --git a/apps/code/app.h b/apps/code/app.h index 2c215d26a..841c54542 100644 --- a/apps/code/app.h +++ b/apps/code/app.h @@ -84,6 +84,10 @@ private: VariableBoxController m_variableBoxController; }; +inline App * app() { + return static_cast(::app()); +} + } #endif diff --git a/apps/code/console_controller.cpp b/apps/code/console_controller.cpp index cd4c0ceb9..9c2042020 100644 --- a/apps/code/console_controller.cpp +++ b/apps/code/console_controller.cpp @@ -57,7 +57,7 @@ bool ConsoleController::loadPythonEnvironment() { /* We load functions and variables names in the variable box before running * any other python code to avoid failling to load functions and variables * due to memory exhaustion. */ - static_cast(app())->variableBoxController()->loadFunctionsAndVariables(); + app()->variableBoxController()->loadFunctionsAndVariables(); return true; } @@ -290,7 +290,7 @@ bool ConsoleController::textFieldDidReceiveEvent(TextField * textField, Ion::Eve return true; } } - return static_cast(app())->textInputDidReceiveEvent(textField, event); + return app()->textInputDidReceiveEvent(textField, event); } bool ConsoleController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { diff --git a/apps/code/editor_controller.cpp b/apps/code/editor_controller.cpp index 034d960d0..6f9e4df2a 100644 --- a/apps/code/editor_controller.cpp +++ b/apps/code/editor_controller.cpp @@ -58,7 +58,7 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events: saveScript(); return false; } - if (static_cast(app())->textInputDidReceiveEvent(textArea, event)) { + if (app()->textInputDidReceiveEvent(textArea, event)) { return true; } if (event == Ion::Events::EXE) { @@ -109,13 +109,13 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events: } VariableBoxController * EditorController::variableBoxForInputEventHandler(InputEventHandler * textInput) { - VariableBoxController * varBox = static_cast(app())->variableBoxController(); + VariableBoxController * varBox = app()->variableBoxController(); varBox->loadFunctionsAndVariables(); return varBox; } InputEventHandlerDelegateApp * EditorController::inputEventHandlerDelegateApp() { - return static_cast(app()); + return app(); } StackViewController * EditorController::stackController() { diff --git a/apps/code/menu_controller.cpp b/apps/code/menu_controller.cpp index c9378bcbe..dabd1e7a8 100644 --- a/apps/code/menu_controller.cpp +++ b/apps/code/menu_controller.cpp @@ -36,7 +36,7 @@ MenuController::MenuController(Responder * parentResponder, App * pythonDelegate } ConsoleController * MenuController::consoleController() { - return static_cast(app())->consoleController(); + return app()->consoleController(); } StackViewController * MenuController::stackViewController() { diff --git a/apps/code/variable_box_controller.cpp b/apps/code/variable_box_controller.cpp index 13f086a57..b8345ec01 100644 --- a/apps/code/variable_box_controller.cpp +++ b/apps/code/variable_box_controller.cpp @@ -33,7 +33,7 @@ void VariableBoxController::didEnterResponderChain(Responder * previousFirstResp * environment where Python has already been inited. This way, we do not * deinit Python when leaving the VariableBoxController, so we do not lose the * environment that was loaded when entering the VariableBoxController. */ - assert(static_cast(app())->pythonIsInited()); + assert(app()->pythonIsInited()); } static bool shouldAddObject(const char * name, int maxLength) { diff --git a/apps/graph/app.h b/apps/graph/app.h index 1a7fdbf6a..362dfe858 100644 --- a/apps/graph/app.h +++ b/apps/graph/app.h @@ -52,6 +52,10 @@ private: InputViewController m_inputViewController; }; +inline App * app() { + return static_cast(::app()); +} + } #endif diff --git a/apps/graph/graph/calculation_graph_controller.cpp b/apps/graph/graph/calculation_graph_controller.cpp index e72b21167..bb9513eec 100644 --- a/apps/graph/graph/calculation_graph_controller.cpp +++ b/apps/graph/graph/calculation_graph_controller.cpp @@ -45,16 +45,14 @@ void CalculationGraphController::reloadBannerView() { } Expression::Coordinate2D CalculationGraphController::computeNewPointOfInteresetFromAbscissa(double start, int direction) { - App * myApp = static_cast(app()); double step = m_graphRange->xGridUnit()/10.0; step = direction < 0 ? -step : step; double max = direction > 0 ? m_graphRange->xMax() : m_graphRange->xMin(); - return computeNewPointOfInterest(start, step, max, myApp->localContext()); + return computeNewPointOfInterest(start, step, max, app()->localContext()); } CartesianFunctionStore * CalculationGraphController::functionStore() const { - App * a = static_cast(app()); - return a->functionStore(); + return app()->functionStore(); } bool CalculationGraphController::handleLeftRightEvent(Ion::Events::Event event) { diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 23e5e2e23..b07587948 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -7,7 +7,7 @@ namespace Graph { static inline float maxFloat(float x, float y) { return x > y ? x : y; } -GraphController::GraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) : +GraphController::GraphController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) : FunctionGraphController(parentResponder, inputEventHandlerDelegate, header, curveViewRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion), m_bannerView(this, inputEventHandlerDelegate, this), m_view(functionStore, curveViewRange, m_cursor, &m_bannerView, &m_cursorView), @@ -43,10 +43,9 @@ void GraphController::setDisplayDerivativeInBanner(bool displayDerivative) { 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)); - float fRange = f->expressionReduced(myApp->localContext()).characteristicXRange(*(myApp->localContext()), Poincare::Preferences::sharedPreferences()->angleUnit()); + float fRange = f->expressionReduced(app()->localContext()).characteristicXRange(*(app()->localContext()), Poincare::Preferences::sharedPreferences()->angleUnit()); if (!std::isnan(fRange)) { characteristicRange = maxFloat(fRange, characteristicRange); } @@ -74,14 +73,12 @@ void GraphController::reloadBannerView() { return; } Ion::Storage::Record record = functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor()); - App * myApp = static_cast(app()); - reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, record, myApp); + reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, record, app()); } bool GraphController::moveCursorHorizontally(int direction) { Ion::Storage::Record record = functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor()); - App * myApp = static_cast(app()); - return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, record, myApp); + return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, record, app()); } InteractiveCurveViewRange * GraphController::interactiveCurveViewRange() { diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index b81df43d4..2b7719e27 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -15,7 +15,7 @@ namespace Graph { class GraphController : public Shared::FunctionGraphController, public GraphControllerHelper { public: - GraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header); + GraphController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, CartesianFunctionStore * 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; void viewWillAppear() override; bool displayDerivativeInBanner() const; diff --git a/apps/graph/graph/tangent_graph_controller.cpp b/apps/graph/graph/tangent_graph_controller.cpp index 5f11be357..805c57240 100644 --- a/apps/graph/graph/tangent_graph_controller.cpp +++ b/apps/graph/graph/tangent_graph_controller.cpp @@ -43,8 +43,7 @@ bool TangentGraphController::textFieldDidFinishEditing(TextField * textField, co if (textFieldDelegateApp()->hasUndefinedValue(text, floatBody)) { return false; } - App * myApp = static_cast(app()); - ExpiringPointer function = myApp->functionStore()->modelForRecord(m_record); + ExpiringPointer function = app()->functionStore()->modelForRecord(m_record); double y = function->evaluateAtAbscissa(floatBody, textFieldDelegateApp()->localContext()); m_cursor->moveTo(floatBody, y); interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio); @@ -62,29 +61,27 @@ void TangentGraphController::reloadBannerView() { if (m_record.isNull()) { return; } - App * myApp = static_cast(app()); - FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_record, myApp->functionStore(), CartesianFunction::Symbol()); - GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, m_record, myApp); + FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_record, app()->functionStore(), CartesianFunction::Symbol()); + GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, m_record, app()); 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); - double y = function->approximateDerivative(m_cursor->x(), myApp->localContext()); + ExpiringPointer function = app()->functionStore()->modelForRecord(m_record); + double y = function->approximateDerivative(m_cursor->x(), app()->localContext()); PoincareHelpers::ConvertFloatToText(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); m_bannerView->aView()->setText(buffer); legend = "b="; legendLength = strlcpy(buffer, legend, bufferSize); - y = -y*m_cursor->x()+function->evaluateAtAbscissa(m_cursor->x(), myApp->localContext()); + y = -y*m_cursor->x()+function->evaluateAtAbscissa(m_cursor->x(), app()->localContext()); PoincareHelpers::ConvertFloatToText(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); m_bannerView->bView()->setText(buffer); m_bannerView->reload(); } bool TangentGraphController::moveCursorHorizontally(int direction) { - App * myApp = static_cast(app()); - return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, m_record, myApp); + return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, m_record, app()); } bool TangentGraphController::handleEnter() { diff --git a/apps/graph/list/list_controller.cpp b/apps/graph/list/list_controller.cpp index 5d7a26a02..751634b06 100644 --- a/apps/graph/list/list_controller.cpp +++ b/apps/graph/list/list_controller.cpp @@ -189,4 +189,8 @@ void ListController::setFunctionNameInTextField(ExpiringPointer functi textField->setText(bufferName); } +Shared::TextFieldDelegateApp * ListController::textFieldDelegateApp() { + return app(); +} + } diff --git a/apps/graph/list/list_controller.h b/apps/graph/list/list_controller.h index 2841df254..a4e439b4b 100644 --- a/apps/graph/list/list_controller.h +++ b/apps/graph/list/list_controller.h @@ -29,9 +29,7 @@ private: HighlightCell * expressionCells(int index) override; void willDisplayTitleCellAtIndex(HighlightCell * cell, int j) override; void willDisplayExpressionCellAtIndex(HighlightCell * cell, int j) override; - Shared::TextFieldDelegateApp * textFieldDelegateApp() override { - return static_cast(app()); - } + Shared::TextFieldDelegateApp * textFieldDelegateApp() override; void setFunctionNameInTextField(Shared::ExpiringPointer function, TextField * textField); TextFieldFunctionTitleCell m_functionTitleCells[k_maxNumberOfDisplayableRows]; Shared::FunctionExpressionCell m_expressionCells[k_maxNumberOfDisplayableRows]; diff --git a/apps/graph/values/derivative_parameter_controller.cpp b/apps/graph/values/derivative_parameter_controller.cpp index c7d44b95e..4a411bf58 100644 --- a/apps/graph/values/derivative_parameter_controller.cpp +++ b/apps/graph/values/derivative_parameter_controller.cpp @@ -82,8 +82,7 @@ KDCoordinate DerivativeParameterController::cellHeight() { } CartesianFunctionStore * DerivativeParameterController::functionStore() { - App * a = static_cast(app()); - return a->functionStore(); + return app()->functionStore(); } } diff --git a/apps/graph/values/function_parameter_controller.cpp b/apps/graph/values/function_parameter_controller.cpp index 2ceca2e65..a95d14373 100644 --- a/apps/graph/values/function_parameter_controller.cpp +++ b/apps/graph/values/function_parameter_controller.cpp @@ -70,8 +70,7 @@ void FunctionParameterController::willDisplayCellForIndex(HighlightCell * cell, } ExpiringPointer FunctionParameterController::function() { - App * a = static_cast(app()); - return a->functionStore()->modelForRecord(m_record); + return app()->functionStore()->modelForRecord(m_record); } } diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index 85310c9ca..46e0e5123 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -1,6 +1,7 @@ #include "values_controller.h" #include #include "../../constant.h" +#include "../app.h" using namespace Shared; using namespace Poincare; @@ -142,15 +143,14 @@ FunctionParameterController * ValuesController::functionParameterController() { } double ValuesController::evaluationOfAbscissaAtColumn(double abscissa, int columnIndex) { - TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); 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)); if (isDerivative) { - return function->approximateDerivative(abscissa, myApp->localContext()); + return function->approximateDerivative(abscissa, app()->localContext()); } - return function->evaluateAtAbscissa(abscissa, myApp->localContext()); + return function->evaluateAtAbscissa(abscissa, app()->localContext()); } void ValuesController::updateNumberOfColumns() { diff --git a/apps/probability/app.h b/apps/probability/app.h index 4cabd396a..a8cdd606d 100644 --- a/apps/probability/app.h +++ b/apps/probability/app.h @@ -63,7 +63,7 @@ private: StackViewController m_stackViewController; }; -App * app() { +inline App * app() { return static_cast(::app()); } diff --git a/apps/regression/app.h b/apps/regression/app.h index f19a4d113..06f443195 100644 --- a/apps/regression/app.h +++ b/apps/regression/app.h @@ -57,6 +57,10 @@ private: RegressionController m_regressionController; }; +inline App * app() { + return static_cast(::app()); +} + } #endif diff --git a/apps/regression/graph_options_controller.cpp b/apps/regression/graph_options_controller.cpp index eec852d66..642f43ef9 100644 --- a/apps/regression/graph_options_controller.cpp +++ b/apps/regression/graph_options_controller.cpp @@ -42,7 +42,7 @@ void GraphOptionsController::viewWillAppear() { bool GraphOptionsController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) { if (selectedRow() == numberOfRows() -1) { - RegressionController * regressionController = static_cast(app())->regressionController(); + RegressionController * regressionController = app()->regressionController(); regressionController->setSeries(m_graphController->selectedSeriesIndex()); StackViewController * stack = static_cast(parentResponder()); stack->push(regressionController); diff --git a/apps/regression/store_parameter_controller.cpp b/apps/regression/store_parameter_controller.cpp index 285ddd7df..a82408cd5 100644 --- a/apps/regression/store_parameter_controller.cpp +++ b/apps/regression/store_parameter_controller.cpp @@ -20,7 +20,7 @@ void StoreParameterController::viewWillAppear() { bool StoreParameterController::handleEvent(Ion::Events::Event event) { if ((event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) && selectedRow() == numberOfRows() - 1) { - RegressionController * regressionController = static_cast(app())->regressionController(); + RegressionController * regressionController = app()->regressionController(); regressionController->setSeries(m_series); StackViewController * stack = static_cast(parentResponder()); stack->push(regressionController); diff --git a/apps/sequence/app.h b/apps/sequence/app.h index 02c215f77..1201105fe 100644 --- a/apps/sequence/app.h +++ b/apps/sequence/app.h @@ -58,6 +58,10 @@ private: InputViewController m_inputViewController; }; +inline App * app() { + return static_cast(::app()); +} + } #endif diff --git a/apps/sequence/graph/graph_controller.cpp b/apps/sequence/graph/graph_controller.cpp index 4e10f4df0..97351f460 100644 --- a/apps/sequence/graph/graph_controller.cpp +++ b/apps/sequence/graph/graph_controller.cpp @@ -1,6 +1,7 @@ #include "graph_controller.h" #include #include +#include "../app.h" using namespace Shared; using namespace Poincare; @@ -10,7 +11,7 @@ namespace Sequence { 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) : +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) : FunctionGraphController(parentResponder, inputEventHandlerDelegate, header, graphRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion), m_bannerView(this, inputEventHandlerDelegate, this), m_view(sequenceStore, graphRange, m_cursor, &m_bannerView, &m_cursorView), @@ -95,8 +96,7 @@ bool GraphController::moveCursorHorizontally(int direction) { return false; } Sequence * s = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor())); - TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); - double y = s->evaluateAtAbscissa(x, myApp->localContext()); + double y = s->evaluateAtAbscissa(x, app()->localContext()); m_cursor->moveTo(x, y); return true; } diff --git a/apps/sequence/graph/graph_controller.h b/apps/sequence/graph/graph_controller.h index d9230c1d8..5d538ec78 100644 --- a/apps/sequence/graph/graph_controller.h +++ b/apps/sequence/graph/graph_controller.h @@ -14,7 +14,7 @@ namespace Sequence { 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); + 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; void viewWillAppear() override; TermSumController * termSumController() { return &m_termSumController; } diff --git a/apps/sequence/list/list_controller.cpp b/apps/sequence/list/list_controller.cpp index 3a38c38a7..a066517f3 100644 --- a/apps/sequence/list/list_controller.cpp +++ b/apps/sequence/list/list_controller.cpp @@ -107,10 +107,9 @@ void ListController::editExpression(int sequenceDefinition, Ion::Events::Event e // Replace UCodePointUnknownN with 'n' replaceUnknownSymbolWithReadableSymbol(initialText); } - App * myApp = (App *)app(); - InputViewController * inputController = myApp->inputViewController(); + InputViewController * inputController = app()->inputViewController(); // Invalidate the sequences context cache - static_cast(app())->localContext()->resetCache(); + app()->localContext()->resetCache(); switch (sequenceDefinition) { case 0: inputController->edit(this, event, this, initialText, @@ -160,15 +159,15 @@ bool ListController::editInitialConditionOfSelectedRecordWithText(const char * t } TextFieldDelegateApp * ListController::textFieldDelegateApp() { - return (App *)app(); + return app(); } ExpressionFieldDelegateApp * ListController::expressionFieldDelegateApp() { - return (App *)app(); + return app(); } InputEventHandlerDelegateApp * ListController::inputEventHandlerDelegateApp() { - return (App *)app(); + return app(); } ListParameterController * ListController::parameterController() { @@ -280,7 +279,7 @@ void ListController::editExpression(Ion::Events::Event event) { void ListController::reinitSelectedExpression(ExpiringPointer model) { // Invalidate the sequences context cache - static_cast(app())->localContext()->resetCache(); + app()->localContext()->resetCache(); Sequence * sequence = static_cast(model.pointer()); switch (sequenceDefinitionForRow(selectedRow())) { case 1: @@ -308,7 +307,7 @@ void ListController::reinitSelectedExpression(ExpiringPointer(app())->localContext()->resetCache(); + app()->localContext()->resetCache(); return true; } diff --git a/apps/sequence/list/list_parameter_controller.cpp b/apps/sequence/list/list_parameter_controller.cpp index fac6aba66..28d6472c0 100644 --- a/apps/sequence/list/list_parameter_controller.cpp +++ b/apps/sequence/list/list_parameter_controller.cpp @@ -56,7 +56,7 @@ bool ListParameterController::handleEvent(Ion::Events::Event event) { #else if (selectedRowIndex == 2+hasAdditionalRow) { #endif - static_cast(app())->localContext()->resetCache(); + app()->localContext()->resetCache(); return handleEnterOnRow(selectedRowIndex-hasAdditionalRow-1); } } @@ -82,7 +82,7 @@ bool ListParameterController::textFieldDidFinishEditing(TextField * textField, c } sequence()->setInitialRank(index); // Invalidate sequence context cache when changing sequence type - static_cast(app())->localContext()->resetCache(); + app()->localContext()->resetCache(); m_selectableTableView.reloadCellAtLocation(0, selectedRow()); m_selectableTableView.handleEvent(event); return true; @@ -149,7 +149,7 @@ void ListParameterController::willDisplayCellForIndex(HighlightCell * cell, int } TextFieldDelegateApp * ListParameterController::textFieldDelegateApp() { - return (TextFieldDelegateApp *)app(); + return app(); } int ListParameterController::totalNumberOfCells() const { diff --git a/apps/sequence/list/type_parameter_controller.cpp b/apps/sequence/list/type_parameter_controller.cpp index aa2e9b4e7..de2c8d35a 100644 --- a/apps/sequence/list/type_parameter_controller.cpp +++ b/apps/sequence/list/type_parameter_controller.cpp @@ -60,7 +60,7 @@ bool TypeParameterController::handleEvent(Ion::Events::Event event) { m_listController->selectPreviousNewSequenceCell(); sequence()->setType(sequenceType); // Invalidate sequence context cache when changing sequence type - static_cast(app())->localContext()->resetCache(); + app()->localContext()->resetCache(); // Reset the first index if the new type is "Explicit" if (sequenceType == Sequence::Type::Explicit) { sequence()->setInitialRank(0); @@ -135,8 +135,7 @@ void TypeParameterController::setRecord(Ion::Storage::Record record) { } SequenceStore * TypeParameterController::sequenceStore() { - App * a = static_cast(app()); - return a->functionStore(); + return app()->functionStore(); } StackViewController * TypeParameterController::stackController() const { diff --git a/apps/settings/app.h b/apps/settings/app.h index c534be1f8..3189364d4 100644 --- a/apps/settings/app.h +++ b/apps/settings/app.h @@ -25,7 +25,7 @@ private: StackViewController m_stackViewController; }; -App * app() { +inline App * app() { return static_cast(::app()); } diff --git a/apps/solver/app.h b/apps/solver/app.h index d9c8cae6a..cf62f7b5b 100644 --- a/apps/solver/app.h +++ b/apps/solver/app.h @@ -45,6 +45,10 @@ private: InputViewController m_inputViewController; }; +inline App * app() { + return static_cast(::app()); +} + } #endif diff --git a/apps/solver/interval_controller.cpp b/apps/solver/interval_controller.cpp index 19d061602..19b1c5aed 100644 --- a/apps/solver/interval_controller.cpp +++ b/apps/solver/interval_controller.cpp @@ -103,9 +103,8 @@ bool IntervalController::textFieldDidFinishEditing(TextField * textField, const void IntervalController::buttonAction() { StackViewController * stack = stackController(); - App * solverApp = static_cast(app()); - m_equationStore->approximateSolve(solverApp->localContext()); - stack->push(solverApp->solutionsControllerStack(), KDColorWhite, Palette::SubTab, Palette::SubTab); + m_equationStore->approximateSolve(app()->localContext()); + stack->push(app()->solutionsControllerStack(), KDColorWhite, Palette::SubTab, Palette::SubTab); } } diff --git a/apps/solver/list_controller.cpp b/apps/solver/list_controller.cpp index bd8cb69a0..6b8429713 100644 --- a/apps/solver/list_controller.cpp +++ b/apps/solver/list_controller.cpp @@ -175,7 +175,7 @@ void ListController::resolveEquations() { app()->displayWarning(I18n::Message::EnterEquation); return; } - EquationStore::Error e = m_equationStore->exactSolve(static_cast(app())->localContext()); + EquationStore::Error e = m_equationStore->exactSolve(app()->localContext()); switch (e) { case EquationStore::Error::EquationUndefined: app()->displayWarning(I18n::Message::UndefinedEquation); @@ -192,16 +192,14 @@ void ListController::resolveEquations() { case EquationStore::Error::RequireApproximateSolution: { StackViewController * stack = stackController(); - App * solverApp = static_cast(app()); - stack->push(solverApp->intervalController(), KDColorWhite, Palette::PurpleBright, Palette::PurpleBright); + stack->push(app()->intervalController(), KDColorWhite, Palette::PurpleBright, Palette::PurpleBright); return; } default: { assert(e == EquationStore::Error::NoError); StackViewController * stack = stackController(); - App * solverApp = static_cast(app()); - stack->push(solverApp->solutionsControllerStack(), KDColorWhite, Palette::PurpleBright, Palette::PurpleBright); + stack->push(app()->solutionsControllerStack(), KDColorWhite, Palette::PurpleBright, Palette::PurpleBright); } } } @@ -231,11 +229,11 @@ SelectableTableView * ListController::selectableTableView() { } Shared::TextFieldDelegateApp * ListController::textFieldDelegateApp() { - return static_cast(app()); + return app(); } Shared::ExpressionFieldDelegateApp * ListController::expressionFieldDelegateApp() { - return static_cast(app()); + return app(); } StackViewController * ListController::stackController() const { @@ -243,7 +241,7 @@ StackViewController * ListController::stackController() const { } InputViewController * ListController::inputController() { - return static_cast(app())->inputViewController(); + return app()->inputViewController(); } } diff --git a/apps/solver/solutions_controller.cpp b/apps/solver/solutions_controller.cpp index dcb422691..2da207c87 100644 --- a/apps/solver/solutions_controller.cpp +++ b/apps/solver/solutions_controller.cpp @@ -105,11 +105,10 @@ View * SolutionsController::view() { void SolutionsController::viewWillAppear() { ViewController::viewWillAppear(); - App * solverApp = static_cast(app()); bool requireWarning = false; if (m_equationStore->type() == EquationStore::Type::Monovariable) { m_contentView.setWarningMessages(I18n::Message::OnlyFirstSolutionsDisplayed0, I18n::Message::OnlyFirstSolutionsDisplayed1); - requireWarning = m_equationStore->haveMoreApproximationSolutions(solverApp->localContext()); + requireWarning = m_equationStore->haveMoreApproximationSolutions(app()->localContext()); } else if (m_equationStore->type() == EquationStore::Type::PolynomialMonovariable && m_equationStore->numberOfSolutions() == 1) { assert(Preferences::sharedPreferences()->complexFormat() == Preferences::ComplexFormat::Real); m_contentView.setWarningMessages(I18n::Message::PolynomeHasNoRealSolution0, I18n::Message::PolynomeHasNoRealSolution1); diff --git a/escher/include/escher/container.h b/escher/include/escher/container.h index 52f20a53b..9d70aa331 100644 --- a/escher/include/escher/container.h +++ b/escher/include/escher/container.h @@ -47,7 +47,7 @@ private: static Container * s_sharedContainer; }; -App * app() { +inline App * app() { return Container::sharedContainer()->activeApp(); }