From 874e049532470551b1002caf1ae7fc2c4eefb546 Mon Sep 17 00:00:00 2001 From: Cyril Garsaud Date: Fri, 8 Mar 2019 13:03:43 +0100 Subject: [PATCH] Some more refactoring --- src/CalcManager/CEngine/History.cpp | 48 ++++++++++++++------------- src/CalcManager/CalculatorManager.cpp | 28 ++++++++++------ src/CalcManager/UnitConverter.cpp | 4 +-- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/src/CalcManager/CEngine/History.cpp b/src/CalcManager/CEngine/History.cpp index fe14425d..1f536fbd 100644 --- a/src/CalcManager/CEngine/History.cpp +++ b/src/CalcManager/CEngine/History.cpp @@ -129,7 +129,7 @@ void CHistoryCollector::AddBinOpToHistory(int nOpCode, bool fNoRepetition) } // This is expected to be called when a binary op in the last say 1+2+ is changing to another one say 1+2* (+ changed to *) -// It needs to know by this change a Precedence inversion happened. i.e. previous op was lower or equal to its previous op, but the new +// It needs to know by this change a Precedence inversion happened. i.e. previous op was lower or equal to its previous op, but the new // one isn't. (Eg. 1*2* to 1*2^). It can add explicit brackets to ensure the precedence is inverted. (Eg. (1*2) ^) void CHistoryCollector::ChangeLastBinOp(int nOpCode, bool fPrecInvToHigher) { @@ -196,7 +196,7 @@ bool CHistoryCollector::FOpndAddedToHistory() // AddUnaryOpToHistory // -// This is does the postfix to prefix translation of the input and adds the text to the history. Eg. doing 2 + 4 (sqrt), +// This is does the postfix to prefix translation of the input and adds the text to the history. Eg. doing 2 + 4 (sqrt), // this routine will ensure the last sqrt call unary operator, actually goes back in history and wraps 4 in sqrt(4) // void CHistoryCollector::AddUnaryOpToHistory(int nOpCode, bool fInv, ANGLE_TYPE angletype) @@ -290,7 +290,7 @@ void CHistoryCollector::AddUnaryOpToHistory(int nOpCode, bool fInv, ANGLE_TYPE a } // Called after = with the result of the equation -// Responsible for clearing the top line of current running history display, as well as adding yet another element to +// Responsible for clearing the top line of current running history display, as well as adding yet another element to // history of equations void CHistoryCollector::CompleteHistoryLine(wstring_view numStr) { @@ -406,37 +406,39 @@ int CHistoryCollector::AddCommand(_In_ const std::shared_ptr return nCommands - 1; } -//To Update the operands in the Expression according to the current Radix +//To Update the operands in the Expression according to the current Radix void CHistoryCollector::UpdateHistoryExpression(uint32_t radix, int32_t precision) { - if (m_spTokens != nullptr) + if (m_spTokens == nullptr) { - unsigned int size; - IFT(m_spTokens->GetSize(&size)); + return; + } - for (unsigned int i = 0; i < size; ++i) + unsigned int size; + IFT(m_spTokens->GetSize(&size)); + + for (unsigned int i = 0; i < size; ++i) + { + std::pair token; + IFT(m_spTokens->GetAt(i, &token)); + int commandPosition = token.second; + if (commandPosition != -1) { - std::pair token; - IFT(m_spTokens->GetAt(i, &token)); - int commandPosition = token.second; - if (commandPosition != -1) + std::shared_ptr expCommand; + IFT(m_spCommands->GetAt(commandPosition, &expCommand)); + if (expCommand != nullptr && CalculationManager::CommandType::OperandCommand == expCommand->GetCommandType()) { - std::shared_ptr expCommand; - IFT(m_spCommands->GetAt(commandPosition, &expCommand)); - if (expCommand != nullptr && CalculationManager::CommandType::OperandCommand == expCommand->GetCommandType()) + std::shared_ptr opndCommand = std::static_pointer_cast(expCommand); + if (opndCommand != nullptr) { - std::shared_ptr opndCommand = std::static_pointer_cast(expCommand); - if (opndCommand != nullptr) - { - token.first = opndCommand->GetString(radix, precision, m_decimalSymbol); - IFT(m_spTokens->SetAt(i, token)); - opndCommand->SetCommands(GetOperandCommandsFromString(token.first)); - } + token.first = opndCommand->GetString(radix, precision, m_decimalSymbol); + IFT(m_spTokens->SetAt(i, token)); + opndCommand->SetCommands(GetOperandCommandsFromString(token.first)); } } } - SetExpressionDisplay(); } + SetExpressionDisplay(); } void CHistoryCollector::SetDecimalSymbol(wchar_t decimalSymbol) diff --git a/src/CalcManager/CalculatorManager.cpp b/src/CalcManager/CalculatorManager.cpp index ed21478f..375279e9 100644 --- a/src/CalcManager/CalculatorManager.cpp +++ b/src/CalcManager/CalculatorManager.cpp @@ -293,7 +293,7 @@ namespace CalculationManager } /// - /// Convert Command to unsigned char. + /// Convert Command to unsigned char. /// Since some Commands are higher than 255, they are saved after subtracting 255 /// The smallest Command is CommandSIGN = 80, thus, subtracted value does not overlap with other values. /// @@ -484,7 +484,8 @@ namespace CalculationManager { m_savedCommands.push_back(MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizeNumber)); - if (m_currentCalculatorEngine->FInErrorState()) { + if (m_currentCalculatorEngine->FInErrorState()) + { return; } @@ -512,7 +513,8 @@ namespace CalculationManager { SaveMemoryCommand(MemoryCommand::MemorizedNumberLoad, indexOfMemory); - if (m_currentCalculatorEngine->FInErrorState()) { + if (m_currentCalculatorEngine->FInErrorState()) + { return; } @@ -530,7 +532,8 @@ namespace CalculationManager { SaveMemoryCommand(MemoryCommand::MemorizedNumberAdd, indexOfMemory); - if (m_currentCalculatorEngine->FInErrorState()) { + if (m_currentCalculatorEngine->FInErrorState()) + { return; } @@ -570,7 +573,8 @@ namespace CalculationManager { SaveMemoryCommand(MemoryCommand::MemorizedNumberSubtract, indexOfMemory); - if (m_currentCalculatorEngine->FInErrorState()) { + if (m_currentCalculatorEngine->FInErrorState()) + { return; } @@ -614,7 +618,8 @@ namespace CalculationManager /// Index of the target memory void CalculatorManager::MemorizedNumberSelect(_In_ unsigned int indexOfMemory) { - if (m_currentCalculatorEngine->FInErrorState()) { + if (m_currentCalculatorEngine->FInErrorState()) + { return; } @@ -629,7 +634,8 @@ namespace CalculationManager /// Index of the target memory void CalculatorManager::MemorizedNumberChanged(_In_ unsigned int indexOfMemory) { - if (m_currentCalculatorEngine->FInErrorState()) { + if (m_currentCalculatorEngine->FInErrorState()) + { return; } @@ -764,7 +770,7 @@ namespace CalculationManager } void CalculatorManager::UpdateMaxIntDigits() - { + { m_currentCalculatorEngine->UpdateMaxIntDigits(); } @@ -788,7 +794,7 @@ namespace CalculationManager /// How Rational is serialized : /// Serialized Rational.P(Number) + Serialized Rational.Q(Number) /// How Number is saved : - /// [0] = Rational.P.Sign + /// [0] = Rational.P.Sign /// [1] = Rational.P.Mantissa.size /// [2] = Rational.P.Exp /// [3] = Rational.P.Mantissa[0] @@ -826,7 +832,7 @@ namespace CalculationManager /// /// Serialize Number to vector of long /// How Number is saved : - /// [0] = Number.Sign + /// [0] = Number.Sign /// [1] = Number.Mantissa.size /// [2] = Number.Exp /// [3] = Number.Mantissa[0] @@ -853,7 +859,7 @@ namespace CalculationManager /// /// DeserializeNumber vector and construct a Number /// How Number is saved : - /// [0] = Number.Sign + /// [0] = Number.Sign /// [1] = Number.Mantissa.size /// [2] = Number.Exp /// [3] = Number.Mantissa[0] diff --git a/src/CalcManager/UnitConverter.cpp b/src/CalcManager/UnitConverter.cpp index 9a82db6c..013a7fc5 100644 --- a/src/CalcManager/UnitConverter.cpp +++ b/src/CalcManager/UnitConverter.cpp @@ -90,7 +90,7 @@ vector UnitConverter::GetCategories() } /// -/// Sets the current category in use by this converter, +/// Sets the current category in use by this converter, /// and returns a list of unit types that exist under the given category. /// /// Category struct which we are setting @@ -338,7 +338,7 @@ void UnitConverter::DeSerialize(const wstring& serializedData) { Reset(); - if (!serializedData.empty()) + if (serializedData.empty()) { return; }