Return to initialization pattern in ExpressionCommand
This commit is contained in:
Родитель
4883fab7f7
Коммит
db4a6eb9ea
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
|
@ -52,7 +52,7 @@ CHistoryCollector::~CHistoryCollector()
|
|||
}
|
||||
}
|
||||
|
||||
void CHistoryCollector::AddOpndToHistory(wstring_view numStr, Rational rat, bool fRepetition)
|
||||
void CHistoryCollector::AddOpndToHistory(wstring_view numStr, Rational const& rat, bool fRepetition)
|
||||
{
|
||||
std::shared_ptr<CalculatorVector<int>> commands = std::make_shared<CalculatorVector<int>>();
|
||||
// Check for negate
|
||||
|
@ -92,7 +92,8 @@ void CHistoryCollector::AddOpndToHistory(wstring_view numStr, Rational rat, bool
|
|||
}
|
||||
}
|
||||
|
||||
auto operandCommand = std::make_shared<COpndCommand>(commands, rat, fNegative, fDecimal, fSciFmt);
|
||||
auto operandCommand = std::make_shared<COpndCommand>(commands, fNegative, fDecimal, fSciFmt);
|
||||
operandCommand->Initialize(rat);
|
||||
int iCommandEnd = AddCommand(operandCommand);
|
||||
m_lastOpStartIndex = IchAddSzToEquationSz(numStr, iCommandEnd);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
|
@ -96,13 +96,18 @@ void CBinaryCommand::Accept(_In_ ISerializeCommandVisitor &commandVisitor)
|
|||
}
|
||||
|
||||
COpndCommand::COpndCommand(_In_ shared_ptr<CalculatorVector<int>> const &commands,
|
||||
Rational const& rat,
|
||||
bool fNegative,
|
||||
bool fDecimal,
|
||||
bool fSciFmt) :
|
||||
m_commands(commands), m_value{ rat }, m_fNegative(fNegative), m_fDecimal(fDecimal), m_fSciFmt(fSciFmt)
|
||||
bool fNegative,
|
||||
bool fDecimal,
|
||||
bool fSciFmt) :
|
||||
m_commands(commands), m_fNegative(fNegative), m_fDecimal(fDecimal), m_fSciFmt(fSciFmt), m_fInitialized(false), m_value{}
|
||||
{}
|
||||
|
||||
void COpndCommand::Initialize(Rational const& rat)
|
||||
{
|
||||
m_value = rat;
|
||||
m_fInitialized = true;
|
||||
}
|
||||
|
||||
const shared_ptr<CalculatorVector<int>> & COpndCommand::GetCommands() const
|
||||
{
|
||||
return m_commands;
|
||||
|
@ -282,9 +287,14 @@ const wstring & COpndCommand::GetToken(wchar_t decimalSymbol)
|
|||
|
||||
wstring COpndCommand::GetString(uint32_t radix, int32_t precision, wchar_t decimalSymbol)
|
||||
{
|
||||
PRAT valRat = m_value.ToPRAT();
|
||||
auto result = NumObjToString(valRat, radix, eNUMOBJ_FMT::FMT_FLOAT, precision);
|
||||
destroyrat(valRat);
|
||||
wstring result{};
|
||||
|
||||
if (m_fInitialized)
|
||||
{
|
||||
PRAT valRat = m_value.ToPRAT();
|
||||
result = NumObjToString(valRat, radix, eNUMOBJ_FMT::FMT_FLOAT, precision);
|
||||
destroyrat(valRat);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
@ -50,11 +50,11 @@ class COpndCommand : public IOpndCommand
|
|||
{
|
||||
public:
|
||||
COpndCommand(_In_ std::shared_ptr<CalculatorVector<int>> const &commands,
|
||||
CalcEngine::Rational const& rat,
|
||||
bool fNegative,
|
||||
bool fDecimal,
|
||||
bool fSciFmt);
|
||||
~COpndCommand();
|
||||
void Initialize(CalcEngine::Rational const& rat);
|
||||
|
||||
const std::shared_ptr<CalculatorVector<int>> & GetCommands() const;
|
||||
void SetCommands(std::shared_ptr<CalculatorVector<int>> const& commands);
|
||||
|
@ -74,6 +74,7 @@ private:
|
|||
bool m_fNegative;
|
||||
bool m_fSciFmt;
|
||||
bool m_fDecimal;
|
||||
bool m_fInitialized;
|
||||
std::wstring m_token;
|
||||
CalcEngine::Rational m_value;
|
||||
void ClearAllAndAppendCommand(CalculationManager::Command command);
|
||||
|
|
|
@ -17,7 +17,7 @@ class CHistoryCollector {
|
|||
public:
|
||||
CHistoryCollector(ICalcDisplay *pCalcDisplay, std::shared_ptr<IHistoryDisplay> pHistoryDisplay, wchar_t decimalSymbol); // Can throw errors
|
||||
~CHistoryCollector();
|
||||
void AddOpndToHistory(std::wstring_view numStr, CalcEngine::Rational rat, bool fRepetition = false);
|
||||
void AddOpndToHistory(std::wstring_view numStr, CalcEngine::Rational const& rat, bool fRepetition = false);
|
||||
void RemoveLastOpndFromHistory();
|
||||
void AddBinOpToHistory(int nOpCode, bool fNoRepetition = true);
|
||||
void ChangeLastBinOp(int nOpCode, bool fPrecInvToHigher);
|
||||
|
|
Загрузка…
Ссылка в новой задаче