mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-21 22:03:11 -07:00
Some more refactoring
This commit is contained in:
parent
2cfb2f2973
commit
874e049532
3 changed files with 44 additions and 36 deletions
|
@ -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<IExpressionCommand>
|
|||
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<std::wstring, int> token;
|
||||
IFT(m_spTokens->GetAt(i, &token));
|
||||
int commandPosition = token.second;
|
||||
if (commandPosition != -1)
|
||||
{
|
||||
std::pair<std::wstring, int> token;
|
||||
IFT(m_spTokens->GetAt(i, &token));
|
||||
int commandPosition = token.second;
|
||||
if (commandPosition != -1)
|
||||
std::shared_ptr<IExpressionCommand> expCommand;
|
||||
IFT(m_spCommands->GetAt(commandPosition, &expCommand));
|
||||
if (expCommand != nullptr && CalculationManager::CommandType::OperandCommand == expCommand->GetCommandType())
|
||||
{
|
||||
std::shared_ptr<IExpressionCommand> expCommand;
|
||||
IFT(m_spCommands->GetAt(commandPosition, &expCommand));
|
||||
if (expCommand != nullptr && CalculationManager::CommandType::OperandCommand == expCommand->GetCommandType())
|
||||
std::shared_ptr<COpndCommand> opndCommand = std::static_pointer_cast<COpndCommand>(expCommand);
|
||||
if (opndCommand != nullptr)
|
||||
{
|
||||
std::shared_ptr<COpndCommand> opndCommand = std::static_pointer_cast<COpndCommand>(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)
|
||||
|
|
|
@ -293,7 +293,7 @@ namespace CalculationManager
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
|
@ -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
|
|||
/// <param name="indexOfMemory">Index of the target memory</param>
|
||||
void CalculatorManager::MemorizedNumberSelect(_In_ unsigned int indexOfMemory)
|
||||
{
|
||||
if (m_currentCalculatorEngine->FInErrorState()) {
|
||||
if (m_currentCalculatorEngine->FInErrorState())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -629,7 +634,8 @@ namespace CalculationManager
|
|||
/// <param name="indexOfMemory">Index of the target memory</param>
|
||||
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
|
|||
/// <summary>
|
||||
/// 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
|
|||
/// <summary>
|
||||
/// 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]
|
||||
|
|
|
@ -90,7 +90,7 @@ vector<Category> UnitConverter::GetCategories()
|
|||
}
|
||||
|
||||
/// <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.
|
||||
/// </summary>
|
||||
/// <param name="input">Category struct which we are setting</param>
|
||||
|
@ -338,7 +338,7 @@ void UnitConverter::DeSerialize(const wstring& serializedData)
|
|||
{
|
||||
Reset();
|
||||
|
||||
if (!serializedData.empty())
|
||||
if (serializedData.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue