From b665e841adbd6ed3b528ce3a0ece628eab680837 Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Tue, 16 Jul 2019 15:33:03 +0200 Subject: [PATCH] [apps] Remove arg parameter in Shared::Function::nameWithArgument and Shared::CartesianFunction::derivativeNameWithArgument --- apps/graph/graph/graph_controller_helper.cpp | 2 +- apps/graph/graph/integral_graph_controller.cpp | 2 +- apps/graph/graph/intersection_graph_controller.cpp | 4 ++-- apps/graph/list/list_controller.cpp | 2 +- apps/graph/values/derivative_parameter_controller.cpp | 2 +- apps/graph/values/values_controller.cpp | 4 ++-- apps/shared/cartesian_function.cpp | 4 ++-- apps/shared/cartesian_function.h | 2 +- apps/shared/function.cpp | 9 +++++---- apps/shared/function.h | 2 +- apps/shared/function_banner_delegate.cpp | 5 ++--- apps/shared/values_function_parameter_controller.cpp | 3 +-- apps/variable_box_controller.cpp | 4 ++-- 13 files changed, 22 insertions(+), 23 deletions(-) diff --git a/apps/graph/graph/graph_controller_helper.cpp b/apps/graph/graph/graph_controller_helper.cpp index 2ef5fd11b..e0ffeb964 100644 --- a/apps/graph/graph/graph_controller_helper.cpp +++ b/apps/graph/graph/graph_controller_helper.cpp @@ -23,7 +23,7 @@ void GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(Shar constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Preferences::LargeNumberOfSignificantDigits); char buffer[bufferSize]; const char * space = " "; - int numberOfChar = function->derivativeNameWithArgument(buffer, bufferSize, CartesianFunction::Symbol()); + int numberOfChar = function->derivativeNameWithArgument(buffer, bufferSize); const char * legend = "="; assert(numberOfChar <= bufferSize); numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar); diff --git a/apps/graph/graph/integral_graph_controller.cpp b/apps/graph/graph/integral_graph_controller.cpp index feef0091a..3c781c31d 100644 --- a/apps/graph/graph/integral_graph_controller.cpp +++ b/apps/graph/graph/integral_graph_controller.cpp @@ -40,7 +40,7 @@ Layout IntegralGraphController::createFunctionLayout(ExpiringPointernameWithArgument(buffer, bufferSize-strlen(dx), CartesianFunction::Symbol()); + int numberOfChars = function->nameWithArgument(buffer, bufferSize-strlen(dx)); assert(numberOfChars <= bufferSize); strlcpy(buffer+numberOfChars, dx, bufferSize-numberOfChars); return LayoutHelper::String(buffer, strlen(buffer), KDFont::SmallFont); diff --git a/apps/graph/graph/intersection_graph_controller.cpp b/apps/graph/graph/intersection_graph_controller.cpp index 169f1fcdb..87f363fb7 100644 --- a/apps/graph/graph/intersection_graph_controller.cpp +++ b/apps/graph/graph/intersection_graph_controller.cpp @@ -25,12 +25,12 @@ void IntersectionGraphController::reloadBannerView() { const char * legend = "="; // 'f(x)=g(x)=', keep 2 chars for '=' ExpiringPointer f = functionStore()->modelForRecord(m_record); - int numberOfChar = f->nameWithArgument(buffer, bufferSize-2, CartesianFunction::Symbol()); + int numberOfChar = f->nameWithArgument(buffer, bufferSize-2); assert(numberOfChar <= bufferSize); 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, CartesianFunction::Symbol()); + numberOfChar += g->nameWithArgument(buffer+numberOfChar, bufferSize-numberOfChar-1); assert(numberOfChar <= bufferSize); numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar); numberOfChar += PoincareHelpers::ConvertFloatToText(m_cursor->y(), buffer+numberOfChar, bufferSize-numberOfChar, Poincare::Preferences::MediumNumberOfSignificantDigits); diff --git a/apps/graph/list/list_controller.cpp b/apps/graph/list/list_controller.cpp index ecd0babf5..ac8ccc2ec 100644 --- a/apps/graph/list/list_controller.cpp +++ b/apps/graph/list/list_controller.cpp @@ -187,7 +187,7 @@ void ListController::willDisplayExpressionCellAtIndex(HighlightCell * cell, int void ListController::setFunctionNameInTextField(ExpiringPointer function, TextField * textField) { assert(textField != nullptr); char bufferName[BufferTextView::k_maxNumberOfChar]; - function->nameWithArgument(bufferName, BufferTextView::k_maxNumberOfChar, modelStore()->symbol()); + function->nameWithArgument(bufferName, BufferTextView::k_maxNumberOfChar); textField->setText(bufferName); } diff --git a/apps/graph/values/derivative_parameter_controller.cpp b/apps/graph/values/derivative_parameter_controller.cpp index e2725fcac..22f53e803 100644 --- a/apps/graph/values/derivative_parameter_controller.cpp +++ b/apps/graph/values/derivative_parameter_controller.cpp @@ -18,7 +18,7 @@ DerivativeParameterController::DerivativeParameterController(ValuesController * } void DerivativeParameterController::viewWillAppear() { - functionStore()->modelForRecord(m_record)->derivativeNameWithArgument(m_pageTitle, k_maxNumberOfCharsInTitle, Shared::CartesianFunction::Symbol()); + functionStore()->modelForRecord(m_record)->derivativeNameWithArgument(m_pageTitle, k_maxNumberOfCharsInTitle); } const char * DerivativeParameterController::title() { diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index 6c2d00b09..e191d8441 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -49,9 +49,9 @@ void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, in * after the isDerivativeColumn call, else it will expire. */ Shared::ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(i)); if (isDerivative) { - function->derivativeNameWithArgument(bufferName, bufferNameSize, CartesianFunction::Symbol()); + function->derivativeNameWithArgument(bufferName, bufferNameSize); } else { - function->nameWithArgument(bufferName, bufferNameSize, CartesianFunction::Symbol()); + function->nameWithArgument(bufferName, bufferNameSize); } myFunctionCell->setText(bufferName); myFunctionCell->setColor(function->color()); diff --git a/apps/shared/cartesian_function.cpp b/apps/shared/cartesian_function.cpp index d0913cd1f..a87bf018c 100644 --- a/apps/shared/cartesian_function.cpp +++ b/apps/shared/cartesian_function.cpp @@ -65,10 +65,10 @@ CartesianFunction CartesianFunction::NewModel(Ion::Storage::Record::ErrorStatus return CartesianFunction(Ion::Storage::sharedStorage()->recordBaseNamedWithExtension(baseName, Ion::Storage::funcExtension)); } -int CartesianFunction::derivativeNameWithArgument(char * buffer, size_t bufferSize, CodePoint arg) { +int CartesianFunction::derivativeNameWithArgument(char * buffer, size_t bufferSize) { // Fill buffer with f(x). Keep size for derivative sign. int derivativeSize = UTF8Decoder::CharSizeOfCodePoint('\''); - int numberOfChars = nameWithArgument(buffer, bufferSize - derivativeSize, arg); + int numberOfChars = nameWithArgument(buffer, bufferSize - derivativeSize); assert(numberOfChars + derivativeSize < (int)bufferSize); char * firstParenthesis = const_cast(UTF8Helper::CodePointSearch(buffer, '(')); if (!UTF8Helper::CodePointIs(firstParenthesis, '(')) { diff --git a/apps/shared/cartesian_function.h b/apps/shared/cartesian_function.h index 845f6dc87..999098895 100644 --- a/apps/shared/cartesian_function.h +++ b/apps/shared/cartesian_function.h @@ -21,7 +21,7 @@ public: // Derivative bool displayDerivative() const; void setDisplayDerivative(bool display); - int derivativeNameWithArgument(char * buffer, size_t bufferSize, CodePoint arg); + int derivativeNameWithArgument(char * buffer, size_t bufferSize); double approximateDerivative(double x, Poincare::Context * context) const; // Integral double sumBetweenBounds(double start, double end, Poincare::Context * context) const override; diff --git a/apps/shared/function.cpp b/apps/shared/function.cpp index 21a76d388..14ca2f663 100644 --- a/apps/shared/function.cpp +++ b/apps/shared/function.cpp @@ -64,14 +64,15 @@ void Function::setActive(bool active) { recordData()->setActive(active); } -int Function::nameWithArgument(char * buffer, size_t bufferSize, CodePoint arg) { - assert(UTF8Decoder::CharSizeOfCodePoint(arg) == 1); +int Function::nameWithArgument(char * buffer, size_t bufferSize) { const char * functionName = fullName(); size_t baseNameLength = SymbolAbstract::TruncateExtension(buffer, functionName, bufferSize - k_parenthesedArgumentLength); assert(baseNameLength <= bufferSize); size_t result = baseNameLength + strlcpy(&buffer[baseNameLength], k_parenthesedArgument, bufferSize-baseNameLength); - if (baseNameLength + 1 < bufferSize) { - UTF8Decoder::CodePointToChars(arg, buffer+baseNameLength+1, bufferSize - (baseNameLength+1)); + int bufferRemainingSize = bufferSize - (baseNameLength+1); + if (bufferRemainingSize > 0) { + assert(UTF8Decoder::CharSizeOfCodePoint(symbol()) == 1); + UTF8Decoder::CodePointToChars(symbol(), buffer+baseNameLength+1, bufferRemainingSize); } return result; } diff --git a/apps/shared/function.h b/apps/shared/function.h index 19c16b218..c4f9085f1 100644 --- a/apps/shared/function.h +++ b/apps/shared/function.h @@ -33,7 +33,7 @@ public: void setActive(bool active); // Name - int nameWithArgument(char * buffer, size_t bufferSize, CodePoint arg); + int nameWithArgument(char * buffer, size_t bufferSize); // Evaluation virtual float evaluateAtAbscissa(float x, Poincare::Context * context) const { diff --git a/apps/shared/function_banner_delegate.cpp b/apps/shared/function_banner_delegate.cpp index e511a0b1a..fcb96eb2b 100644 --- a/apps/shared/function_banner_delegate.cpp +++ b/apps/shared/function_banner_delegate.cpp @@ -7,13 +7,12 @@ using namespace Poincare; namespace Shared { void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor * cursor, Ion::Storage::Record record, FunctionStore * functionStore) { - CodePoint symbol = functionStore->symbol(); ExpiringPointer function = functionStore->modelForRecord(record); constexpr int bufferSize = k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Preferences::LargeNumberOfSignificantDigits); char buffer[bufferSize]; const char * space = " "; int numberOfChar = 0; - buffer[numberOfChar++] = symbol; + buffer[numberOfChar++] = function->symbol(); assert(numberOfChar <= bufferSize); strlcpy(buffer + numberOfChar, "=", bufferSize - numberOfChar); bannerView()->abscissaSymbol()->setText(buffer); @@ -25,7 +24,7 @@ void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor strlcpy(buffer+numberOfChar, space, bufferSize - numberOfChar); bannerView()->abscissaValue()->setText(buffer); - numberOfChar = function->nameWithArgument(buffer, bufferSize, symbol); + numberOfChar = function->nameWithArgument(buffer, bufferSize); assert(numberOfChar <= bufferSize); numberOfChar += strlcpy(buffer+numberOfChar, "=", bufferSize-numberOfChar); numberOfChar += PoincareHelpers::ConvertFloatToText(cursor->y(), buffer+numberOfChar, bufferSize-numberOfChar, precision); diff --git a/apps/shared/values_function_parameter_controller.cpp b/apps/shared/values_function_parameter_controller.cpp index 09f1a4f9a..76571d1bc 100644 --- a/apps/shared/values_function_parameter_controller.cpp +++ b/apps/shared/values_function_parameter_controller.cpp @@ -9,8 +9,7 @@ const char * ValuesFunctionParameterController::title() { } void ValuesFunctionParameterController::viewWillAppear() { - CodePoint symbol = FunctionApp::app()->functionStore()->symbol(); - FunctionApp::app()->functionStore()->modelForRecord(m_record)->nameWithArgument(m_pageTitle, Function::k_maxNameWithArgumentSize, symbol); + FunctionApp::app()->functionStore()->modelForRecord(m_record)->nameWithArgument(m_pageTitle, Function::k_maxNameWithArgumentSize); } void ValuesFunctionParameterController::didBecomeFirstResponder() { diff --git a/apps/variable_box_controller.cpp b/apps/variable_box_controller.cpp index eeb49a238..be69339fa 100644 --- a/apps/variable_box_controller.cpp +++ b/apps/variable_box_controller.cpp @@ -113,8 +113,8 @@ void VariableBoxController::willDisplayCellForIndex(HighlightCell * cell, int in CartesianFunction f(record); symbolLength = f.nameWithArgument( symbolName, - Shared::Function::k_maxNameWithArgumentSize, - Shared::CartesianFunction::Symbol()); + Shared::Function::k_maxNameWithArgumentSize + ); } Layout symbolLayout = LayoutHelper::String(symbolName, symbolLength); myCell->setLayout(symbolLayout);