Some more refactoring

This commit is contained in:
Cyril Garsaud 2019-03-08 13:03:43 +01:00
commit 874e049532
3 changed files with 44 additions and 36 deletions

View file

@ -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 *) // 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) ^) // 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) void CHistoryCollector::ChangeLastBinOp(int nOpCode, bool fPrecInvToHigher)
{ {
@ -196,7 +196,7 @@ bool CHistoryCollector::FOpndAddedToHistory()
// AddUnaryOpToHistory // 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) // 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) 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 // 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 // history of equations
void CHistoryCollector::CompleteHistoryLine(wstring_view numStr) void CHistoryCollector::CompleteHistoryLine(wstring_view numStr)
{ {
@ -406,37 +406,39 @@ int CHistoryCollector::AddCommand(_In_ const std::shared_ptr<IExpressionCommand>
return nCommands - 1; 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) void CHistoryCollector::UpdateHistoryExpression(uint32_t radix, int32_t precision)
{ {
if (m_spTokens != nullptr) if (m_spTokens == nullptr)
{ {
unsigned int size; return;
IFT(m_spTokens->GetSize(&size)); }
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<std::wstring, int> token;
IFT(m_spTokens->GetAt(i, &token));
int commandPosition = token.second;
if (commandPosition != -1)
{ {
std::pair<std::wstring, int> token; std::shared_ptr<IExpressionCommand> expCommand;
IFT(m_spTokens->GetAt(i, &token)); IFT(m_spCommands->GetAt(commandPosition, &expCommand));
int commandPosition = token.second; if (expCommand != nullptr && CalculationManager::CommandType::OperandCommand == expCommand->GetCommandType())
if (commandPosition != -1)
{ {
std::shared_ptr<IExpressionCommand> expCommand; std::shared_ptr<COpndCommand> opndCommand = std::static_pointer_cast<COpndCommand>(expCommand);
IFT(m_spCommands->GetAt(commandPosition, &expCommand)); if (opndCommand != nullptr)
if (expCommand != nullptr && CalculationManager::CommandType::OperandCommand == expCommand->GetCommandType())
{ {
std::shared_ptr<COpndCommand> opndCommand = std::static_pointer_cast<COpndCommand>(expCommand); token.first = opndCommand->GetString(radix, precision, m_decimalSymbol);
if (opndCommand != nullptr) 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) void CHistoryCollector::SetDecimalSymbol(wchar_t decimalSymbol)

View file

@ -293,7 +293,7 @@ namespace CalculationManager
} }
/// <summary> /// <summary>
/// Convert Command to unsigned char. /// Convert Command to unsigned char.
/// Since some Commands are higher than 255, they are saved after subtracting 255 /// 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. /// The smallest Command is CommandSIGN = 80, thus, subtracted value does not overlap with other values.
/// </summary> /// </summary>
@ -484,7 +484,8 @@ namespace CalculationManager
{ {
m_savedCommands.push_back(MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizeNumber)); m_savedCommands.push_back(MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizeNumber));
if (m_currentCalculatorEngine->FInErrorState()) { if (m_currentCalculatorEngine->FInErrorState())
{
return; return;
} }
@ -512,7 +513,8 @@ namespace CalculationManager
{ {
SaveMemoryCommand(MemoryCommand::MemorizedNumberLoad, indexOfMemory); SaveMemoryCommand(MemoryCommand::MemorizedNumberLoad, indexOfMemory);
if (m_currentCalculatorEngine->FInErrorState()) { if (m_currentCalculatorEngine->FInErrorState())
{
return; return;
} }
@ -530,7 +532,8 @@ namespace CalculationManager
{ {
SaveMemoryCommand(MemoryCommand::MemorizedNumberAdd, indexOfMemory); SaveMemoryCommand(MemoryCommand::MemorizedNumberAdd, indexOfMemory);
if (m_currentCalculatorEngine->FInErrorState()) { if (m_currentCalculatorEngine->FInErrorState())
{
return; return;
} }
@ -570,7 +573,8 @@ namespace CalculationManager
{ {
SaveMemoryCommand(MemoryCommand::MemorizedNumberSubtract, indexOfMemory); SaveMemoryCommand(MemoryCommand::MemorizedNumberSubtract, indexOfMemory);
if (m_currentCalculatorEngine->FInErrorState()) { if (m_currentCalculatorEngine->FInErrorState())
{
return; return;
} }
@ -614,7 +618,8 @@ namespace CalculationManager
/// <param name="indexOfMemory">Index of the target memory</param> /// <param name="indexOfMemory">Index of the target memory</param>
void CalculatorManager::MemorizedNumberSelect(_In_ unsigned int indexOfMemory) void CalculatorManager::MemorizedNumberSelect(_In_ unsigned int indexOfMemory)
{ {
if (m_currentCalculatorEngine->FInErrorState()) { if (m_currentCalculatorEngine->FInErrorState())
{
return; return;
} }
@ -629,7 +634,8 @@ namespace CalculationManager
/// <param name="indexOfMemory">Index of the target memory</param> /// <param name="indexOfMemory">Index of the target memory</param>
void CalculatorManager::MemorizedNumberChanged(_In_ unsigned int indexOfMemory) void CalculatorManager::MemorizedNumberChanged(_In_ unsigned int indexOfMemory)
{ {
if (m_currentCalculatorEngine->FInErrorState()) { if (m_currentCalculatorEngine->FInErrorState())
{
return; return;
} }
@ -764,7 +770,7 @@ namespace CalculationManager
} }
void CalculatorManager::UpdateMaxIntDigits() void CalculatorManager::UpdateMaxIntDigits()
{ {
m_currentCalculatorEngine->UpdateMaxIntDigits(); m_currentCalculatorEngine->UpdateMaxIntDigits();
} }
@ -788,7 +794,7 @@ namespace CalculationManager
/// How Rational is serialized : /// How Rational is serialized :
/// Serialized Rational.P(Number) + Serialized Rational.Q(Number) /// Serialized Rational.P(Number) + Serialized Rational.Q(Number)
/// How Number is saved : /// How Number is saved :
/// [0] = Rational.P.Sign /// [0] = Rational.P.Sign
/// [1] = Rational.P.Mantissa.size /// [1] = Rational.P.Mantissa.size
/// [2] = Rational.P.Exp /// [2] = Rational.P.Exp
/// [3] = Rational.P.Mantissa[0] /// [3] = Rational.P.Mantissa[0]
@ -826,7 +832,7 @@ namespace CalculationManager
/// <summary> /// <summary>
/// Serialize Number to vector of long /// Serialize Number to vector of long
/// How Number is saved : /// How Number is saved :
/// [0] = Number.Sign /// [0] = Number.Sign
/// [1] = Number.Mantissa.size /// [1] = Number.Mantissa.size
/// [2] = Number.Exp /// [2] = Number.Exp
/// [3] = Number.Mantissa[0] /// [3] = Number.Mantissa[0]
@ -853,7 +859,7 @@ namespace CalculationManager
/// <summary> /// <summary>
/// DeserializeNumber vector and construct a Number /// DeserializeNumber vector and construct a Number
/// How Number is saved : /// How Number is saved :
/// [0] = Number.Sign /// [0] = Number.Sign
/// [1] = Number.Mantissa.size /// [1] = Number.Mantissa.size
/// [2] = Number.Exp /// [2] = Number.Exp
/// [3] = Number.Mantissa[0] /// [3] = Number.Mantissa[0]

View file

@ -90,7 +90,7 @@ vector<Category> UnitConverter::GetCategories()
} }
/// <summary> /// <summary>
/// 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. /// and returns a list of unit types that exist under the given category.
/// </summary> /// </summary>
/// <param name="input">Category struct which we are setting</param> /// <param name="input">Category struct which we are setting</param>
@ -338,7 +338,7 @@ void UnitConverter::DeSerialize(const wstring& serializedData)
{ {
Reset(); Reset();
if (!serializedData.empty()) if (serializedData.empty())
{ {
return; return;
} }