Return to initialization pattern in ExpressionCommand
This commit is contained in:
parent
4883fab7f7
commit
db4a6eb9ea
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
#include "pch.h"
|
#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>>();
|
std::shared_ptr<CalculatorVector<int>> commands = std::make_shared<CalculatorVector<int>>();
|
||||||
// Check for negate
|
// 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);
|
int iCommandEnd = AddCommand(operandCommand);
|
||||||
m_lastOpStartIndex = IchAddSzToEquationSz(numStr, iCommandEnd);
|
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.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
@ -96,13 +96,18 @@ void CBinaryCommand::Accept(_In_ ISerializeCommandVisitor &commandVisitor)
|
|||||||
}
|
}
|
||||||
|
|
||||||
COpndCommand::COpndCommand(_In_ shared_ptr<CalculatorVector<int>> const &commands,
|
COpndCommand::COpndCommand(_In_ shared_ptr<CalculatorVector<int>> const &commands,
|
||||||
Rational const& rat,
|
|
||||||
bool fNegative,
|
bool fNegative,
|
||||||
bool fDecimal,
|
bool fDecimal,
|
||||||
bool fSciFmt) :
|
bool fSciFmt) :
|
||||||
m_commands(commands), m_value{ rat }, m_fNegative(fNegative), m_fDecimal(fDecimal), m_fSciFmt(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
|
const shared_ptr<CalculatorVector<int>> & COpndCommand::GetCommands() const
|
||||||
{
|
{
|
||||||
return m_commands;
|
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)
|
wstring COpndCommand::GetString(uint32_t radix, int32_t precision, wchar_t decimalSymbol)
|
||||||
{
|
{
|
||||||
|
wstring result{};
|
||||||
|
|
||||||
|
if (m_fInitialized)
|
||||||
|
{
|
||||||
PRAT valRat = m_value.ToPRAT();
|
PRAT valRat = m_value.ToPRAT();
|
||||||
auto result = NumObjToString(valRat, radix, eNUMOBJ_FMT::FMT_FLOAT, precision);
|
result = NumObjToString(valRat, radix, eNUMOBJ_FMT::FMT_FLOAT, precision);
|
||||||
destroyrat(valRat);
|
destroyrat(valRat);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
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.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@ -50,11 +50,11 @@ class COpndCommand : public IOpndCommand
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
COpndCommand(_In_ std::shared_ptr<CalculatorVector<int>> const &commands,
|
COpndCommand(_In_ std::shared_ptr<CalculatorVector<int>> const &commands,
|
||||||
CalcEngine::Rational const& rat,
|
|
||||||
bool fNegative,
|
bool fNegative,
|
||||||
bool fDecimal,
|
bool fDecimal,
|
||||||
bool fSciFmt);
|
bool fSciFmt);
|
||||||
~COpndCommand();
|
~COpndCommand();
|
||||||
|
void Initialize(CalcEngine::Rational const& rat);
|
||||||
|
|
||||||
const std::shared_ptr<CalculatorVector<int>> & GetCommands() const;
|
const std::shared_ptr<CalculatorVector<int>> & GetCommands() const;
|
||||||
void SetCommands(std::shared_ptr<CalculatorVector<int>> const& commands);
|
void SetCommands(std::shared_ptr<CalculatorVector<int>> const& commands);
|
||||||
@ -74,6 +74,7 @@ private:
|
|||||||
bool m_fNegative;
|
bool m_fNegative;
|
||||||
bool m_fSciFmt;
|
bool m_fSciFmt;
|
||||||
bool m_fDecimal;
|
bool m_fDecimal;
|
||||||
|
bool m_fInitialized;
|
||||||
std::wstring m_token;
|
std::wstring m_token;
|
||||||
CalcEngine::Rational m_value;
|
CalcEngine::Rational m_value;
|
||||||
void ClearAllAndAppendCommand(CalculationManager::Command command);
|
void ClearAllAndAppendCommand(CalculationManager::Command command);
|
||||||
|
@ -17,7 +17,7 @@ class CHistoryCollector {
|
|||||||
public:
|
public:
|
||||||
CHistoryCollector(ICalcDisplay *pCalcDisplay, std::shared_ptr<IHistoryDisplay> pHistoryDisplay, wchar_t decimalSymbol); // Can throw errors
|
CHistoryCollector(ICalcDisplay *pCalcDisplay, std::shared_ptr<IHistoryDisplay> pHistoryDisplay, wchar_t decimalSymbol); // Can throw errors
|
||||||
~CHistoryCollector();
|
~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 RemoveLastOpndFromHistory();
|
||||||
void AddBinOpToHistory(int nOpCode, bool fNoRepetition = true);
|
void AddBinOpToHistory(int nOpCode, bool fNoRepetition = true);
|
||||||
void ChangeLastBinOp(int nOpCode, bool fPrecInvToHigher);
|
void ChangeLastBinOp(int nOpCode, bool fPrecInvToHigher);
|
||||||
|
Loading…
Reference in New Issue
Block a user