Replacing CalculatorVector usage with std::vector (#756)
* Replacing CalculatorVector usage with std::vector Assumptions made here are that memory allocations are not recoverable. If it can be proved that an index will be in range, then the indexing operation is used. If not (without manual checks) the std::vector::at function is used to throw an exception in case of a programmer bug. * Changes based on PR feedback Using auto& in CalculatorCollector::UpdateHistoryExpression so the token.first value is properly updated. Using range for loop to GenerateExpressions. Setting isEditable directly to the result of boolean expression. Using token.second directly instead of creating a separate tokenCommandIndex variable. * Fixing issue with generating expressions strings. A space should not be added before the first item.
This commit is contained in:
parent
25cdca991c
commit
6366e0c535
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "Header Files/CalcEngine.h"
|
#include "Header Files/CalcEngine.h"
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
#include "CalculatorVector.h"
|
|
||||||
#include "ExpressionCommand.h"
|
#include "ExpressionCommand.h"
|
||||||
|
|
||||||
constexpr int ASCII_0 = 48;
|
constexpr int ASCII_0 = 48;
|
||||||
@ -13,14 +12,19 @@ using namespace CalcEngine;
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
void IFT(ResultCode hr)
|
template <typename T>
|
||||||
|
static void Truncate(vector<T>& v, unsigned int index)
|
||||||
{
|
{
|
||||||
if (FAILED(hr))
|
if (index >= v.size())
|
||||||
{
|
{
|
||||||
throw hr;
|
throw E_BOUNDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto startIter = v.begin() + index;
|
||||||
|
v.erase(startIter, v.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHistoryCollector::ReinitHistory()
|
void CHistoryCollector::ReinitHistory()
|
||||||
{
|
{
|
||||||
m_lastOpStartIndex = -1;
|
m_lastOpStartIndex = -1;
|
||||||
@ -29,11 +33,11 @@ void CHistoryCollector::ReinitHistory()
|
|||||||
m_bLastOpndBrace = false;
|
m_bLastOpndBrace = false;
|
||||||
if (m_spTokens != nullptr)
|
if (m_spTokens != nullptr)
|
||||||
{
|
{
|
||||||
m_spTokens->Clear();
|
m_spTokens->clear();
|
||||||
}
|
}
|
||||||
if (m_spCommands != nullptr)
|
if (m_spCommands != nullptr)
|
||||||
{
|
{
|
||||||
m_spCommands->Clear();
|
m_spCommands->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,13 +59,13 @@ CHistoryCollector::~CHistoryCollector()
|
|||||||
|
|
||||||
if (m_spTokens != nullptr)
|
if (m_spTokens != nullptr)
|
||||||
{
|
{
|
||||||
m_spTokens->Clear();
|
m_spTokens->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHistoryCollector::AddOpndToHistory(wstring_view numStr, Rational const& 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<std::vector<int>> commands = std::make_shared<vector<int>>();
|
||||||
// Check for negate
|
// Check for negate
|
||||||
bool fNegative = (numStr[0] == L'-');
|
bool fNegative = (numStr[0] == L'-');
|
||||||
bool fSciFmt = false;
|
bool fSciFmt = false;
|
||||||
@ -71,7 +75,7 @@ void CHistoryCollector::AddOpndToHistory(wstring_view numStr, Rational const& ra
|
|||||||
{
|
{
|
||||||
if (numStr[i] == m_decimalSymbol)
|
if (numStr[i] == m_decimalSymbol)
|
||||||
{
|
{
|
||||||
IFT(commands->Append(IDC_PNT));
|
commands->push_back(IDC_PNT);
|
||||||
if (!fSciFmt)
|
if (!fSciFmt)
|
||||||
{
|
{
|
||||||
fDecimal = true;
|
fDecimal = true;
|
||||||
@ -79,12 +83,12 @@ void CHistoryCollector::AddOpndToHistory(wstring_view numStr, Rational const& ra
|
|||||||
}
|
}
|
||||||
else if (numStr[i] == L'e')
|
else if (numStr[i] == L'e')
|
||||||
{
|
{
|
||||||
IFT(commands->Append(IDC_EXP));
|
commands->push_back(IDC_EXP);
|
||||||
fSciFmt = true;
|
fSciFmt = true;
|
||||||
}
|
}
|
||||||
else if (numStr[i] == L'-')
|
else if (numStr[i] == L'-')
|
||||||
{
|
{
|
||||||
IFT(commands->Append(IDC_SIGN));
|
commands->push_back(IDC_SIGN);
|
||||||
}
|
}
|
||||||
else if (numStr[i] == L'+')
|
else if (numStr[i] == L'+')
|
||||||
{
|
{
|
||||||
@ -95,7 +99,7 @@ void CHistoryCollector::AddOpndToHistory(wstring_view numStr, Rational const& ra
|
|||||||
{
|
{
|
||||||
int num = static_cast<int>(numStr[i]) - ASCII_0;
|
int num = static_cast<int>(numStr[i]) - ASCII_0;
|
||||||
num += IDC_0;
|
num += IDC_0;
|
||||||
IFT(commands->Append(num));
|
commands->push_back(num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,7 +358,7 @@ void CHistoryCollector::ClearHistoryLine(wstring_view errStr)
|
|||||||
if (nullptr != m_pCalcDisplay)
|
if (nullptr != m_pCalcDisplay)
|
||||||
{
|
{
|
||||||
m_pCalcDisplay->SetExpressionDisplay(
|
m_pCalcDisplay->SetExpressionDisplay(
|
||||||
std::make_shared<CalculatorVector<std::pair<std::wstring, int>>>(), std::make_shared<CalculatorVector<std::shared_ptr<IExpressionCommand>>>());
|
std::make_shared<std::vector<std::pair<std::wstring, int>>>(), std::make_shared<std::vector<std::shared_ptr<IExpressionCommand>>>());
|
||||||
}
|
}
|
||||||
m_iCurLineHistStart = -1; // It will get recomputed at the first Opnd
|
m_iCurLineHistStart = -1; // It will get recomputed at the first Opnd
|
||||||
ReinitHistory();
|
ReinitHistory();
|
||||||
@ -367,26 +371,17 @@ int CHistoryCollector::IchAddSzToEquationSz(wstring_view str, int icommandIndex)
|
|||||||
{
|
{
|
||||||
if (m_spTokens == nullptr)
|
if (m_spTokens == nullptr)
|
||||||
{
|
{
|
||||||
m_spTokens = std::make_shared<CalculatorVector<std::pair<std::wstring, int>>>();
|
m_spTokens = std::make_shared<std::vector<std::pair<std::wstring, int>>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FAILED(m_spTokens->Append(std::make_pair(wstring(str), icommandIndex))))
|
m_spTokens->push_back(std::pair(wstring(str), icommandIndex));
|
||||||
{
|
return static_cast<int>(m_spTokens->size() - 1);
|
||||||
throw(CALC_E_OUTOFMEMORY);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int nTokens;
|
|
||||||
m_spTokens->GetSize(&nTokens);
|
|
||||||
return nTokens - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inserts a given string into the global m_pszEquation at the given index ich taking care of reallocations etc.
|
// Inserts a given string into the global m_pszEquation at the given index ich taking care of reallocations etc.
|
||||||
void CHistoryCollector::InsertSzInEquationSz(wstring_view str, int icommandIndex, int ich)
|
void CHistoryCollector::InsertSzInEquationSz(wstring_view str, int icommandIndex, int ich)
|
||||||
{
|
{
|
||||||
if (FAILED(m_spTokens->InsertAt(ich, std::make_pair(wstring(str), icommandIndex))))
|
m_spTokens->emplace(m_spTokens->begin() + ich, wstring(str), icommandIndex);
|
||||||
{
|
|
||||||
throw(CALC_E_OUTOFMEMORY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chops off the current equation string from the given index
|
// Chops off the current equation string from the given index
|
||||||
@ -394,25 +389,23 @@ void CHistoryCollector::TruncateEquationSzFromIch(int ich)
|
|||||||
{
|
{
|
||||||
// Truncate commands
|
// Truncate commands
|
||||||
int minIdx = -1;
|
int minIdx = -1;
|
||||||
unsigned int nTokens = 0;
|
unsigned int nTokens = static_cast<unsigned int>(m_spTokens->size());
|
||||||
std::pair<std::wstring, int> currentPair;
|
|
||||||
m_spTokens->GetSize(&nTokens);
|
|
||||||
|
|
||||||
for (unsigned int i = ich; i < nTokens; i++)
|
for (unsigned int i = ich; i < nTokens; i++)
|
||||||
{
|
{
|
||||||
IFT(m_spTokens->GetAt(i, ¤tPair));
|
const auto& currentPair = (*m_spTokens)[i];
|
||||||
int curTokenId = currentPair.second;
|
int curTokenId = currentPair.second;
|
||||||
if (curTokenId != -1)
|
if (curTokenId != -1)
|
||||||
{
|
{
|
||||||
if ((minIdx != -1) || (curTokenId < minIdx))
|
if ((minIdx != -1) || (curTokenId < minIdx))
|
||||||
{
|
{
|
||||||
minIdx = curTokenId;
|
minIdx = curTokenId;
|
||||||
IFT(m_spCommands->Truncate(minIdx));
|
Truncate(*m_spCommands, minIdx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IFT(m_spTokens->Truncate(ich));
|
Truncate(*m_spTokens, ich);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds the m_pszEquation into the running history text
|
// Adds the m_pszEquation into the running history text
|
||||||
@ -428,17 +421,11 @@ int CHistoryCollector::AddCommand(_In_ const std::shared_ptr<IExpressionCommand>
|
|||||||
{
|
{
|
||||||
if (m_spCommands == nullptr)
|
if (m_spCommands == nullptr)
|
||||||
{
|
{
|
||||||
m_spCommands = std::make_shared<CalculatorVector<std::shared_ptr<IExpressionCommand>>>();
|
m_spCommands = std::make_shared<std::vector<std::shared_ptr<IExpressionCommand>>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FAILED(m_spCommands->Append(spCommand)))
|
m_spCommands->push_back(spCommand);
|
||||||
{
|
return static_cast<int>(m_spCommands->size() - 1);
|
||||||
throw(CALC_E_OUTOFMEMORY);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int nCommands = 0;
|
|
||||||
m_spCommands->GetSize(&nCommands);
|
|
||||||
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
|
||||||
@ -449,30 +436,25 @@ void CHistoryCollector::UpdateHistoryExpression(uint32_t radix, int32_t precisio
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int size;
|
for (auto& token : *m_spTokens)
|
||||||
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;
|
int commandPosition = token.second;
|
||||||
if (commandPosition != -1)
|
if (commandPosition != -1)
|
||||||
{
|
{
|
||||||
std::shared_ptr<IExpressionCommand> expCommand;
|
const std::shared_ptr<IExpressionCommand>& expCommand = m_spCommands->at(commandPosition);
|
||||||
IFT(m_spCommands->GetAt(commandPosition, &expCommand));
|
|
||||||
if (expCommand != nullptr && CalculationManager::CommandType::OperandCommand == expCommand->GetCommandType())
|
if (expCommand != nullptr && CalculationManager::CommandType::OperandCommand == expCommand->GetCommandType())
|
||||||
{
|
{
|
||||||
std::shared_ptr<COpndCommand> opndCommand = std::static_pointer_cast<COpndCommand>(expCommand);
|
const std::shared_ptr<COpndCommand>& opndCommand = std::static_pointer_cast<COpndCommand>(expCommand);
|
||||||
if (opndCommand != nullptr)
|
if (opndCommand != nullptr)
|
||||||
{
|
{
|
||||||
token.first = opndCommand->GetString(radix, precision);
|
token.first = opndCommand->GetString(radix, precision);
|
||||||
IFT(m_spTokens->SetAt(i, token));
|
|
||||||
opndCommand->SetCommands(GetOperandCommandsFromString(token.first));
|
opndCommand->SetCommands(GetOperandCommandsFromString(token.first));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetExpressionDisplay();
|
SetExpressionDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,9 +464,9 @@ void CHistoryCollector::SetDecimalSymbol(wchar_t decimalSymbol)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the commands corresponding to the passed string Number
|
// Update the commands corresponding to the passed string Number
|
||||||
std::shared_ptr<CalculatorVector<int>> CHistoryCollector::GetOperandCommandsFromString(wstring_view numStr)
|
std::shared_ptr<std::vector<int>> CHistoryCollector::GetOperandCommandsFromString(wstring_view numStr)
|
||||||
{
|
{
|
||||||
std::shared_ptr<CalculatorVector<int>> commands = std::make_shared<CalculatorVector<int>>();
|
std::shared_ptr<std::vector<int>> commands = std::make_shared<std::vector<int>>();
|
||||||
// Check for negate
|
// Check for negate
|
||||||
bool fNegative = (numStr[0] == L'-');
|
bool fNegative = (numStr[0] == L'-');
|
||||||
|
|
||||||
@ -492,15 +474,15 @@ std::shared_ptr<CalculatorVector<int>> CHistoryCollector::GetOperandCommandsFrom
|
|||||||
{
|
{
|
||||||
if (numStr[i] == m_decimalSymbol)
|
if (numStr[i] == m_decimalSymbol)
|
||||||
{
|
{
|
||||||
IFT(commands->Append(IDC_PNT));
|
commands->push_back(IDC_PNT);
|
||||||
}
|
}
|
||||||
else if (numStr[i] == L'e')
|
else if (numStr[i] == L'e')
|
||||||
{
|
{
|
||||||
IFT(commands->Append(IDC_EXP));
|
commands->push_back(IDC_EXP);
|
||||||
}
|
}
|
||||||
else if (numStr[i] == L'-')
|
else if (numStr[i] == L'-')
|
||||||
{
|
{
|
||||||
IFT(commands->Append(IDC_SIGN));
|
commands->push_back(IDC_SIGN);
|
||||||
}
|
}
|
||||||
else if (numStr[i] == L'+')
|
else if (numStr[i] == L'+')
|
||||||
{
|
{
|
||||||
@ -511,14 +493,14 @@ std::shared_ptr<CalculatorVector<int>> CHistoryCollector::GetOperandCommandsFrom
|
|||||||
{
|
{
|
||||||
int num = static_cast<int>(numStr[i]) - ASCII_0;
|
int num = static_cast<int>(numStr[i]) - ASCII_0;
|
||||||
num += IDC_0;
|
num += IDC_0;
|
||||||
IFT(commands->Append(num));
|
commands->push_back(num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the number is negative, append a sign command at the end.
|
// If the number is negative, append a sign command at the end.
|
||||||
if (fNegative)
|
if (fNegative)
|
||||||
{
|
{
|
||||||
IFT(commands->Append(IDC_SIGN));
|
commands->push_back(IDC_SIGN);
|
||||||
}
|
}
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ void CCalcEngine::ClearDisplay()
|
|||||||
if (nullptr != m_pCalcDisplay)
|
if (nullptr != m_pCalcDisplay)
|
||||||
{
|
{
|
||||||
m_pCalcDisplay->SetExpressionDisplay(
|
m_pCalcDisplay->SetExpressionDisplay(
|
||||||
make_shared<CalculatorVector<pair<wstring, int>>>(), make_shared<CalculatorVector<shared_ptr<IExpressionCommand>>>());
|
make_shared<vector<pair<wstring, int>>>(), make_shared<vector<shared_ptr<IExpressionCommand>>>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +289,6 @@
|
|||||||
<ClInclude Include="CalculatorHistory.h" />
|
<ClInclude Include="CalculatorHistory.h" />
|
||||||
<ClInclude Include="CalculatorManager.h" />
|
<ClInclude Include="CalculatorManager.h" />
|
||||||
<ClInclude Include="CalculatorResource.h" />
|
<ClInclude Include="CalculatorResource.h" />
|
||||||
<ClInclude Include="CalculatorVector.h" />
|
|
||||||
<ClInclude Include="Command.h" />
|
<ClInclude Include="Command.h" />
|
||||||
<ClInclude Include="ExpressionCommand.h" />
|
<ClInclude Include="ExpressionCommand.h" />
|
||||||
<ClInclude Include="ExpressionCommandInterface.h" />
|
<ClInclude Include="ExpressionCommandInterface.h" />
|
||||||
|
@ -120,7 +120,6 @@
|
|||||||
<ClInclude Include="Ratpack\ratpak.h">
|
<ClInclude Include="Ratpack\ratpak.h">
|
||||||
<Filter>RatPack</Filter>
|
<Filter>RatPack</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="CalculatorVector.h" />
|
|
||||||
<ClInclude Include="Header Files\CalcEngine.h">
|
<ClInclude Include="Header Files\CalcEngine.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -7,25 +7,48 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace CalculationManager;
|
using namespace CalculationManager;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
static wstring GetGeneratedExpression(const vector<pair<wstring, int>>& tokens)
|
||||||
|
{
|
||||||
|
wstring expression;
|
||||||
|
bool isFirst = true;
|
||||||
|
|
||||||
|
for (auto const& token : tokens)
|
||||||
|
{
|
||||||
|
if (isFirst)
|
||||||
|
{
|
||||||
|
isFirst = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
expression += L' ';
|
||||||
|
}
|
||||||
|
expression.append(token.first);
|
||||||
|
}
|
||||||
|
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CalculatorHistory::CalculatorHistory(size_t maxSize)
|
CalculatorHistory::CalculatorHistory(size_t maxSize)
|
||||||
: m_maxHistorySize(maxSize)
|
: m_maxHistorySize(maxSize)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CalculatorHistory::AddToHistory(
|
unsigned int CalculatorHistory::AddToHistory(
|
||||||
_In_ shared_ptr<CalculatorVector<pair<wstring, int>>> const& tokens,
|
_In_ shared_ptr<vector<pair<wstring, int>>> const& tokens,
|
||||||
_In_ shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>> const& commands,
|
_In_ shared_ptr<vector<shared_ptr<IExpressionCommand>>> const& commands,
|
||||||
_In_ wstring_view result)
|
_In_ wstring_view result)
|
||||||
{
|
{
|
||||||
unsigned int addedIndex;
|
unsigned int addedIndex;
|
||||||
wstring generatedExpression;
|
|
||||||
shared_ptr<HISTORYITEM> spHistoryItem = make_shared<HISTORYITEM>();
|
shared_ptr<HISTORYITEM> spHistoryItem = make_shared<HISTORYITEM>();
|
||||||
|
|
||||||
spHistoryItem->historyItemVector.spTokens = tokens;
|
spHistoryItem->historyItemVector.spTokens = tokens;
|
||||||
spHistoryItem->historyItemVector.spCommands = commands;
|
spHistoryItem->historyItemVector.spCommands = commands;
|
||||||
|
|
||||||
// to be changed when pszexp is back
|
// to be changed when pszexp is back
|
||||||
tokens->GetString(&generatedExpression);
|
wstring generatedExpression = GetGeneratedExpression(*tokens);
|
||||||
// Prefixing and suffixing the special Unicode markers to ensure that the expression
|
// Prefixing and suffixing the special Unicode markers to ensure that the expression
|
||||||
// in the history doesn't get broken for RTL languages
|
// in the history doesn't get broken for RTL languages
|
||||||
spHistoryItem->historyItemVector.expression = L'\u202d' + generatedExpression + L'\u202c';
|
spHistoryItem->historyItemVector.expression = L'\u202d' + generatedExpression + L'\u202c';
|
||||||
|
@ -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
|
||||||
@ -15,8 +15,8 @@ namespace CalculationManager
|
|||||||
|
|
||||||
struct HISTORYITEMVECTOR
|
struct HISTORYITEMVECTOR
|
||||||
{
|
{
|
||||||
std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> spTokens;
|
std::shared_ptr<std::vector<std::pair<std::wstring, int>>> spTokens;
|
||||||
std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> spCommands;
|
std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> spCommands;
|
||||||
std::wstring expression;
|
std::wstring expression;
|
||||||
std::wstring result;
|
std::wstring result;
|
||||||
};
|
};
|
||||||
@ -31,8 +31,8 @@ namespace CalculationManager
|
|||||||
public:
|
public:
|
||||||
CalculatorHistory(const size_t maxSize);
|
CalculatorHistory(const size_t maxSize);
|
||||||
unsigned int AddToHistory(
|
unsigned int AddToHistory(
|
||||||
_In_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& spTokens,
|
_In_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& spTokens,
|
||||||
_In_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& spCommands,
|
_In_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& spCommands,
|
||||||
std::wstring_view result);
|
std::wstring_view result);
|
||||||
std::vector<std::shared_ptr<HISTORYITEM>> const& GetHistory();
|
std::vector<std::shared_ptr<HISTORYITEM>> const& GetHistory();
|
||||||
std::shared_ptr<HISTORYITEM> const& GetHistoryItem(unsigned int uIdx);
|
std::shared_ptr<HISTORYITEM> const& GetHistoryItem(unsigned int uIdx);
|
||||||
|
@ -86,8 +86,8 @@ namespace CalculationManager
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="expressionString">wstring representing expression to be displayed</param>
|
/// <param name="expressionString">wstring representing expression to be displayed</param>
|
||||||
void CalculatorManager::SetExpressionDisplay(
|
void CalculatorManager::SetExpressionDisplay(
|
||||||
_Inout_ shared_ptr<CalculatorVector<pair<wstring, int>>> const& tokens,
|
_Inout_ shared_ptr<vector<pair<wstring, int>>> const& tokens,
|
||||||
_Inout_ shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>> const& commands)
|
_Inout_ shared_ptr<vector<shared_ptr<IExpressionCommand>>> const& commands)
|
||||||
{
|
{
|
||||||
if (!m_inHistoryItemLoadMode)
|
if (!m_inHistoryItemLoadMode)
|
||||||
{
|
{
|
||||||
|
@ -91,8 +91,8 @@ namespace CalculationManager
|
|||||||
void SetPrimaryDisplay(_In_ const std::wstring& displayString, _In_ bool isError) override;
|
void SetPrimaryDisplay(_In_ const std::wstring& displayString, _In_ bool isError) override;
|
||||||
void SetIsInError(bool isError) override;
|
void SetIsInError(bool isError) override;
|
||||||
void SetExpressionDisplay(
|
void SetExpressionDisplay(
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens,
|
_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens,
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& commands) override;
|
_Inout_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& commands) override;
|
||||||
void SetMemorizedNumbers(_In_ const std::vector<std::wstring>& memorizedNumbers) override;
|
void SetMemorizedNumbers(_In_ const std::vector<std::wstring>& memorizedNumbers) override;
|
||||||
void OnHistoryItemAdded(_In_ unsigned int addedItemIndex) override;
|
void OnHistoryItemAdded(_In_ unsigned int addedItemIndex) override;
|
||||||
void SetParenthesisNumber(_In_ unsigned int parenthesisCount) override;
|
void SetParenthesisNumber(_In_ unsigned int parenthesisCount) override;
|
||||||
|
@ -1,143 +0,0 @@
|
|||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
// Licensed under the MIT License.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include "winerror_cross_platform.h"
|
|
||||||
#include "Ratpack/CalcErr.h"
|
|
||||||
#include <stdexcept> // for std::out_of_range
|
|
||||||
#include "sal_cross_platform.h" // for SAL
|
|
||||||
|
|
||||||
template <typename TType>
|
|
||||||
class CalculatorVector
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ResultCode GetAt(_In_opt_ unsigned int index, _Out_ TType* item)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
*item = m_vector.at(index);
|
|
||||||
}
|
|
||||||
catch (const std::out_of_range& /*ex*/)
|
|
||||||
{
|
|
||||||
return E_BOUNDS;
|
|
||||||
}
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultCode GetSize(_Out_ unsigned int* size)
|
|
||||||
{
|
|
||||||
*size = static_cast<unsigned>(m_vector.size());
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultCode SetAt(_In_ unsigned int index, _In_opt_ TType item)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
m_vector[index] = item;
|
|
||||||
}
|
|
||||||
catch (const std::out_of_range& /*ex*/)
|
|
||||||
{
|
|
||||||
return E_BOUNDS;
|
|
||||||
}
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultCode RemoveAt(_In_ unsigned int index)
|
|
||||||
{
|
|
||||||
if (index < m_vector.size())
|
|
||||||
{
|
|
||||||
m_vector.erase(m_vector.begin() + index);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return E_BOUNDS;
|
|
||||||
}
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultCode InsertAt(_In_ unsigned int index, _In_ TType item)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
auto iter = m_vector.begin() + index;
|
|
||||||
m_vector.insert(iter, item);
|
|
||||||
}
|
|
||||||
catch (const std::bad_alloc& /*ex*/)
|
|
||||||
{
|
|
||||||
return E_OUTOFMEMORY;
|
|
||||||
}
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultCode Truncate(_In_ unsigned int index)
|
|
||||||
{
|
|
||||||
if (index < m_vector.size())
|
|
||||||
{
|
|
||||||
auto startIter = m_vector.begin() + index;
|
|
||||||
m_vector.erase(startIter, m_vector.end());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return E_BOUNDS;
|
|
||||||
}
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultCode Append(_In_opt_ TType item)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
m_vector.push_back(item);
|
|
||||||
}
|
|
||||||
catch (const std::bad_alloc& /*ex*/)
|
|
||||||
{
|
|
||||||
return E_OUTOFMEMORY;
|
|
||||||
}
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultCode RemoveAtEnd()
|
|
||||||
{
|
|
||||||
m_vector.erase(--(m_vector.end()));
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultCode Clear()
|
|
||||||
{
|
|
||||||
m_vector.clear();
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultCode GetString(_Out_ std::wstring* expression)
|
|
||||||
{
|
|
||||||
unsigned int nTokens = 0;
|
|
||||||
ResultCode hr = this->GetSize(&nTokens);
|
|
||||||
if (SUCCEEDED(hr))
|
|
||||||
{
|
|
||||||
|
|
||||||
std::pair<std::wstring, int> currentPair;
|
|
||||||
for (unsigned int i = 0; i < nTokens; i++)
|
|
||||||
{
|
|
||||||
hr = this->GetAt(i, ¤tPair);
|
|
||||||
if (SUCCEEDED(hr))
|
|
||||||
{
|
|
||||||
expression->append(currentPair.first);
|
|
||||||
|
|
||||||
if (i != (nTokens - 1))
|
|
||||||
{
|
|
||||||
expression->append(L" ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<TType> m_vector;
|
|
||||||
};
|
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Header Files/CCommand.h"
|
#include "Header Files/CCommand.h"
|
||||||
#include "CalculatorVector.h"
|
|
||||||
#include "ExpressionCommand.h"
|
#include "ExpressionCommand.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -35,18 +34,18 @@ void CParentheses::Accept(_In_ ISerializeCommandVisitor& commandVisitor)
|
|||||||
|
|
||||||
CUnaryCommand::CUnaryCommand(int command)
|
CUnaryCommand::CUnaryCommand(int command)
|
||||||
{
|
{
|
||||||
m_command = make_shared<CalculatorVector<int>>();
|
m_command = make_shared<vector<int>>();
|
||||||
m_command->Append(command);
|
m_command->push_back(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
CUnaryCommand::CUnaryCommand(int command1, int command2)
|
CUnaryCommand::CUnaryCommand(int command1, int command2)
|
||||||
{
|
{
|
||||||
m_command = make_shared<CalculatorVector<int>>();
|
m_command = make_shared<vector<int>>();
|
||||||
m_command->Append(command1);
|
m_command->push_back(command1);
|
||||||
m_command->Append(command2);
|
m_command->push_back(command2);
|
||||||
}
|
}
|
||||||
|
|
||||||
const shared_ptr<CalculatorVector<int>>& CUnaryCommand::GetCommands() const
|
const shared_ptr<vector<int>>& CUnaryCommand::GetCommands() const
|
||||||
{
|
{
|
||||||
return m_command;
|
return m_command;
|
||||||
}
|
}
|
||||||
@ -58,15 +57,15 @@ CalculationManager::CommandType CUnaryCommand::GetCommandType() const
|
|||||||
|
|
||||||
void CUnaryCommand::SetCommand(int command)
|
void CUnaryCommand::SetCommand(int command)
|
||||||
{
|
{
|
||||||
m_command->Clear();
|
m_command->clear();
|
||||||
m_command->Append(command);
|
m_command->push_back(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnaryCommand::SetCommands(int command1, int command2)
|
void CUnaryCommand::SetCommands(int command1, int command2)
|
||||||
{
|
{
|
||||||
m_command->Clear();
|
m_command->clear();
|
||||||
m_command->Append(command1);
|
m_command->push_back(command1);
|
||||||
m_command->Append(command2);
|
m_command->push_back(command2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnaryCommand::Accept(_In_ ISerializeCommandVisitor& commandVisitor)
|
void CUnaryCommand::Accept(_In_ ISerializeCommandVisitor& commandVisitor)
|
||||||
@ -99,7 +98,7 @@ void CBinaryCommand::Accept(_In_ ISerializeCommandVisitor& commandVisitor)
|
|||||||
commandVisitor.Visit(*this);
|
commandVisitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
COpndCommand::COpndCommand(shared_ptr<CalculatorVector<int>> const& commands, bool fNegative, bool fDecimal, bool fSciFmt)
|
COpndCommand::COpndCommand(shared_ptr<vector<int>> const& commands, bool fNegative, bool fDecimal, bool fSciFmt)
|
||||||
: m_commands(commands)
|
: m_commands(commands)
|
||||||
, m_fNegative(fNegative)
|
, m_fNegative(fNegative)
|
||||||
, m_fSciFmt(fSciFmt)
|
, m_fSciFmt(fSciFmt)
|
||||||
@ -115,27 +114,25 @@ void COpndCommand::Initialize(Rational const& rat)
|
|||||||
m_fInitialized = true;
|
m_fInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const shared_ptr<CalculatorVector<int>>& COpndCommand::GetCommands() const
|
const shared_ptr<vector<int>>& COpndCommand::GetCommands() const
|
||||||
{
|
{
|
||||||
return m_commands;
|
return m_commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
void COpndCommand::SetCommands(shared_ptr<CalculatorVector<int>> const& commands)
|
void COpndCommand::SetCommands(shared_ptr<vector<int>> const& commands)
|
||||||
{
|
{
|
||||||
m_commands = commands;
|
m_commands = commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
void COpndCommand::AppendCommand(int command)
|
void COpndCommand::AppendCommand(int command)
|
||||||
{
|
{
|
||||||
unsigned int nCommands;
|
|
||||||
m_commands->GetSize(&nCommands);
|
|
||||||
if (m_fSciFmt)
|
if (m_fSciFmt)
|
||||||
{
|
{
|
||||||
ClearAllAndAppendCommand(static_cast<CalculationManager::Command>(command));
|
ClearAllAndAppendCommand(static_cast<CalculationManager::Command>(command));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_commands->Append(command);
|
m_commands->push_back(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == IDC_PNT)
|
if (command == IDC_PNT)
|
||||||
@ -146,14 +143,8 @@ void COpndCommand::AppendCommand(int command)
|
|||||||
|
|
||||||
void COpndCommand::ToggleSign()
|
void COpndCommand::ToggleSign()
|
||||||
{
|
{
|
||||||
unsigned int commandCount;
|
for (int nOpCode : *m_commands)
|
||||||
m_commands->GetSize(&commandCount);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < commandCount; i++)
|
|
||||||
{
|
{
|
||||||
int nOpCode;
|
|
||||||
m_commands->GetAt(i, &nOpCode);
|
|
||||||
|
|
||||||
if (nOpCode != IDC_0)
|
if (nOpCode != IDC_0)
|
||||||
{
|
{
|
||||||
m_fNegative = !m_fNegative;
|
m_fNegative = !m_fNegative;
|
||||||
@ -170,8 +161,7 @@ void COpndCommand::RemoveFromEnd()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned int nCommands;
|
const size_t nCommands = m_commands->size();
|
||||||
m_commands->GetSize(&nCommands);
|
|
||||||
|
|
||||||
if (nCommands == 1)
|
if (nCommands == 1)
|
||||||
{
|
{
|
||||||
@ -179,13 +169,14 @@ void COpndCommand::RemoveFromEnd()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int nOpCode;
|
int nOpCode = m_commands->at(nCommands - 1);
|
||||||
m_commands->GetAt(nCommands - 1, &nOpCode);
|
|
||||||
if (nOpCode == IDC_PNT)
|
if (nOpCode == IDC_PNT)
|
||||||
{
|
{
|
||||||
m_fDecimal = false;
|
m_fDecimal = false;
|
||||||
}
|
}
|
||||||
m_commands->RemoveAt(nCommands - 1);
|
|
||||||
|
m_commands->pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,8 +203,8 @@ CalculationManager::CommandType COpndCommand::GetCommandType() const
|
|||||||
|
|
||||||
void COpndCommand::ClearAllAndAppendCommand(CalculationManager::Command command)
|
void COpndCommand::ClearAllAndAppendCommand(CalculationManager::Command command)
|
||||||
{
|
{
|
||||||
m_commands->Clear();
|
m_commands->clear();
|
||||||
m_commands->Append(static_cast<int>(command));
|
m_commands->push_back(static_cast<int>(command));
|
||||||
m_fSciFmt = false;
|
m_fSciFmt = false;
|
||||||
m_fNegative = false;
|
m_fNegative = false;
|
||||||
m_fDecimal = false;
|
m_fDecimal = false;
|
||||||
@ -223,14 +214,13 @@ const wstring& COpndCommand::GetToken(wchar_t decimalSymbol)
|
|||||||
{
|
{
|
||||||
static const wchar_t chZero = L'0';
|
static const wchar_t chZero = L'0';
|
||||||
|
|
||||||
unsigned int nCommands;
|
const size_t nCommands = m_commands->size();
|
||||||
m_commands->GetSize(&nCommands);
|
|
||||||
m_token.clear();
|
m_token.clear();
|
||||||
int nOpCode;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < nCommands; i++)
|
for (size_t i = 0; i < nCommands; i++)
|
||||||
{
|
{
|
||||||
m_commands->GetAt(i, &nOpCode);
|
int nOpCode = (*m_commands)[i];
|
||||||
|
|
||||||
if (nOpCode == IDC_PNT)
|
if (nOpCode == IDC_PNT)
|
||||||
{
|
{
|
||||||
m_token.append(wstring{ decimalSymbol });
|
m_token.append(wstring{ decimalSymbol });
|
||||||
@ -238,8 +228,7 @@ const wstring& COpndCommand::GetToken(wchar_t decimalSymbol)
|
|||||||
else if (nOpCode == IDC_EXP)
|
else if (nOpCode == IDC_EXP)
|
||||||
{
|
{
|
||||||
m_token.append(&chExp);
|
m_token.append(&chExp);
|
||||||
int nextOpCode;
|
int nextOpCode = m_commands->at(i + 1);
|
||||||
m_commands->GetAt(i + 1, &nextOpCode);
|
|
||||||
if (nextOpCode != IDC_SIGN)
|
if (nextOpCode != IDC_SIGN)
|
||||||
{
|
{
|
||||||
m_token.append(&chPlus);
|
m_token.append(&chPlus);
|
||||||
@ -257,7 +246,7 @@ const wstring& COpndCommand::GetToken(wchar_t decimalSymbol)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove zeros
|
// Remove zeros
|
||||||
for (unsigned int i = 0; i < m_token.size(); i++)
|
for (size_t i = 0; i < m_token.size(); i++)
|
||||||
{
|
{
|
||||||
if (m_token.at(i) != chZero)
|
if (m_token.at(i) != chZero)
|
||||||
{
|
{
|
||||||
|
@ -23,14 +23,14 @@ class CUnaryCommand final : public IUnaryCommand
|
|||||||
public:
|
public:
|
||||||
CUnaryCommand(int command);
|
CUnaryCommand(int command);
|
||||||
CUnaryCommand(int command1, int command2);
|
CUnaryCommand(int command1, int command2);
|
||||||
const std::shared_ptr<CalculatorVector<int>>& GetCommands() const override;
|
const std::shared_ptr<std::vector<int>>& GetCommands() const override;
|
||||||
CalculationManager::CommandType GetCommandType() const override;
|
CalculationManager::CommandType GetCommandType() const override;
|
||||||
void SetCommand(int command) override;
|
void SetCommand(int command) override;
|
||||||
void SetCommands(int command1, int command2) override;
|
void SetCommands(int command1, int command2) override;
|
||||||
void Accept(_In_ ISerializeCommandVisitor& commandVisitor) override;
|
void Accept(_In_ ISerializeCommandVisitor& commandVisitor) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<CalculatorVector<int>> m_command;
|
std::shared_ptr<std::vector<int>> m_command;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CBinaryCommand final : public IBinaryCommand
|
class CBinaryCommand final : public IBinaryCommand
|
||||||
@ -49,11 +49,11 @@ private:
|
|||||||
class COpndCommand final : public IOpndCommand
|
class COpndCommand final : public IOpndCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
COpndCommand(std::shared_ptr<CalculatorVector<int>> const& commands, bool fNegative, bool fDecimal, bool fSciFmt);
|
COpndCommand(std::shared_ptr<std::vector<int>> const& commands, bool fNegative, bool fDecimal, bool fSciFmt);
|
||||||
void Initialize(CalcEngine::Rational const& rat);
|
void Initialize(CalcEngine::Rational const& rat);
|
||||||
|
|
||||||
const std::shared_ptr<CalculatorVector<int>>& GetCommands() const override;
|
const std::shared_ptr<std::vector<int>>& GetCommands() const override;
|
||||||
void SetCommands(std::shared_ptr<CalculatorVector<int>> const& commands) override;
|
void SetCommands(std::shared_ptr<std::vector<int>> const& commands) override;
|
||||||
void AppendCommand(int command) override;
|
void AppendCommand(int command) override;
|
||||||
void ToggleSign() override;
|
void ToggleSign() override;
|
||||||
void RemoveFromEnd() override;
|
void RemoveFromEnd() override;
|
||||||
@ -66,7 +66,7 @@ public:
|
|||||||
std::wstring GetString(uint32_t radix, int32_t precision);
|
std::wstring GetString(uint32_t radix, int32_t precision);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<CalculatorVector<int>> m_commands;
|
std::shared_ptr<std::vector<int>> m_commands;
|
||||||
bool m_fNegative;
|
bool m_fNegative;
|
||||||
bool m_fSciFmt;
|
bool m_fSciFmt;
|
||||||
bool m_fDecimal;
|
bool m_fDecimal;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory> // for std::shared_ptr
|
#include <memory> // for std::shared_ptr
|
||||||
#include "CalculatorVector.h"
|
#include <vector>
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
|
|
||||||
class ISerializeCommandVisitor;
|
class ISerializeCommandVisitor;
|
||||||
@ -25,7 +25,7 @@ public:
|
|||||||
class IUnaryCommand : public IOperatorCommand
|
class IUnaryCommand : public IOperatorCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::shared_ptr<CalculatorVector<int>>& GetCommands() const = 0;
|
virtual const std::shared_ptr<std::vector<int>>& GetCommands() const = 0;
|
||||||
virtual void SetCommands(int command1, int command2) = 0;
|
virtual void SetCommands(int command1, int command2) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ public:
|
|||||||
class IOpndCommand : public IExpressionCommand
|
class IOpndCommand : public IExpressionCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::shared_ptr<CalculatorVector<int>>& GetCommands() const = 0;
|
virtual const std::shared_ptr<std::vector<int>>& GetCommands() const = 0;
|
||||||
virtual void AppendCommand(int command) = 0;
|
virtual void AppendCommand(int command) = 0;
|
||||||
virtual void ToggleSign() = 0;
|
virtual void ToggleSign() = 0;
|
||||||
virtual void RemoveFromEnd() = 0;
|
virtual void RemoveFromEnd() = 0;
|
||||||
@ -47,7 +47,7 @@ public:
|
|||||||
virtual bool IsSciFmt() const = 0;
|
virtual bool IsSciFmt() const = 0;
|
||||||
virtual bool IsDecimalPresent() const = 0;
|
virtual bool IsDecimalPresent() const = 0;
|
||||||
virtual const std::wstring& GetToken(wchar_t decimalSymbol) = 0;
|
virtual const std::wstring& GetToken(wchar_t decimalSymbol) = 0;
|
||||||
virtual void SetCommands(std::shared_ptr<CalculatorVector<int>> const& commands) = 0;
|
virtual void SetCommands(std::shared_ptr<std::vector<int>> const& commands) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IParenthesisCommand : public IExpressionCommand
|
class IParenthesisCommand : public IExpressionCommand
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#include "CCommand.h"
|
#include "CCommand.h"
|
||||||
#include "EngineStrings.h"
|
#include "EngineStrings.h"
|
||||||
#include "../Command.h"
|
#include "../Command.h"
|
||||||
#include "../CalculatorVector.h"
|
|
||||||
#include "../ExpressionCommand.h"
|
#include "../ExpressionCommand.h"
|
||||||
#include "RadixType.h"
|
#include "RadixType.h"
|
||||||
#include "History.h" // for History Collector
|
#include "History.h" // for History Collector
|
||||||
|
@ -51,8 +51,8 @@ private:
|
|||||||
int m_curOperandIndex; // Stack index for the above stack
|
int m_curOperandIndex; // Stack index for the above stack
|
||||||
bool m_bLastOpndBrace; // iff the last opnd in history is already braced so we can avoid putting another one for unary operator
|
bool m_bLastOpndBrace; // iff the last opnd in history is already braced so we can avoid putting another one for unary operator
|
||||||
wchar_t m_decimalSymbol;
|
wchar_t m_decimalSymbol;
|
||||||
std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> m_spTokens;
|
std::shared_ptr<std::vector<std::pair<std::wstring, int>>> m_spTokens;
|
||||||
std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> m_spCommands;
|
std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> m_spCommands;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ReinitHistory();
|
void ReinitHistory();
|
||||||
@ -60,5 +60,5 @@ private:
|
|||||||
void TruncateEquationSzFromIch(int ich);
|
void TruncateEquationSzFromIch(int ich);
|
||||||
void SetExpressionDisplay();
|
void SetExpressionDisplay();
|
||||||
void InsertSzInEquationSz(std::wstring_view str, int icommandIndex, int ich);
|
void InsertSzInEquationSz(std::wstring_view str, int icommandIndex, int ich);
|
||||||
std::shared_ptr<CalculatorVector<int>> GetOperandCommandsFromString(std::wstring_view numStr);
|
std::shared_ptr<std::vector<int>> GetOperandCommandsFromString(std::wstring_view numStr);
|
||||||
};
|
};
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../CalculatorVector.h"
|
|
||||||
#include "../ExpressionCommandInterface.h"
|
#include "../ExpressionCommandInterface.h"
|
||||||
|
|
||||||
// Callback interface to be implemented by the clients of CCalcEngine
|
// Callback interface to be implemented by the clients of CCalcEngine
|
||||||
@ -13,8 +12,8 @@ public:
|
|||||||
virtual void SetPrimaryDisplay(const std::wstring& pszText, bool isError) = 0;
|
virtual void SetPrimaryDisplay(const std::wstring& pszText, bool isError) = 0;
|
||||||
virtual void SetIsInError(bool isInError) = 0;
|
virtual void SetIsInError(bool isInError) = 0;
|
||||||
virtual void SetExpressionDisplay(
|
virtual void SetExpressionDisplay(
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens,
|
_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens,
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& commands) = 0;
|
_Inout_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& commands) = 0;
|
||||||
virtual void SetParenthesisNumber(_In_ unsigned int count) = 0;
|
virtual void SetParenthesisNumber(_In_ unsigned int count) = 0;
|
||||||
virtual void OnNoRightParenAdded() = 0;
|
virtual void OnNoRightParenAdded() = 0;
|
||||||
virtual void MaxDigitsReached() = 0; // not an error but still need to inform UI layer.
|
virtual void MaxDigitsReached() = 0; // not an error but still need to inform UI layer.
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
// 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
|
||||||
|
|
||||||
|
#include "../ExpressionCommandInterface.h"
|
||||||
|
|
||||||
// Callback interface to be implemented by the clients of CCalcEngine if they require equation history
|
// Callback interface to be implemented by the clients of CCalcEngine if they require equation history
|
||||||
class IHistoryDisplay
|
class IHistoryDisplay
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IHistoryDisplay(){};
|
virtual ~IHistoryDisplay(){};
|
||||||
virtual unsigned int AddToHistory(
|
virtual unsigned int AddToHistory(
|
||||||
_In_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens,
|
_In_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens,
|
||||||
_In_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& commands,
|
_In_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& commands,
|
||||||
_In_ std::wstring_view result) = 0;
|
_In_ std::wstring_view result) = 0;
|
||||||
};
|
};
|
||||||
|
@ -70,8 +70,8 @@ void CalculatorDisplay::SetIsInError(bool isError)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CalculatorDisplay::SetExpressionDisplay(
|
void CalculatorDisplay::SetExpressionDisplay(
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens,
|
_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens,
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& commands)
|
_Inout_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& commands)
|
||||||
{
|
{
|
||||||
if (m_callbackReference != nullptr)
|
if (m_callbackReference != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -19,8 +19,8 @@ namespace CalculatorApp
|
|||||||
void SetPrimaryDisplay(_In_ const std::wstring& displayString, _In_ bool isError) override;
|
void SetPrimaryDisplay(_In_ const std::wstring& displayString, _In_ bool isError) override;
|
||||||
void SetIsInError(bool isError) override;
|
void SetIsInError(bool isError) override;
|
||||||
void SetExpressionDisplay(
|
void SetExpressionDisplay(
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens,
|
_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens,
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& commands) override;
|
_Inout_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& commands) override;
|
||||||
void SetMemorizedNumbers(_In_ const std::vector<std::wstring>& memorizedNumbers) override;
|
void SetMemorizedNumbers(_In_ const std::vector<std::wstring>& memorizedNumbers) override;
|
||||||
void OnHistoryItemAdded(_In_ unsigned int addedItemIndex) override;
|
void OnHistoryItemAdded(_In_ unsigned int addedItemIndex) override;
|
||||||
void SetParenthesisNumber(_In_ unsigned int parenthesisCount) override;
|
void SetParenthesisNumber(_In_ unsigned int parenthesisCount) override;
|
||||||
|
@ -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"
|
||||||
@ -47,13 +47,13 @@ COpndCommand CommandDeserializer::DeserializeOperand()
|
|||||||
bool fDecimal = m_dataReader->ReadBoolean();
|
bool fDecimal = m_dataReader->ReadBoolean();
|
||||||
bool fSciFmt = m_dataReader->ReadBoolean();
|
bool fSciFmt = m_dataReader->ReadBoolean();
|
||||||
|
|
||||||
std::shared_ptr<CalculatorVector<int>> cmdVector = std::make_shared<CalculatorVector<int>>();
|
std::shared_ptr<std::vector<int>> cmdVector = std::make_shared<std::vector<int>>();
|
||||||
auto cmdVectorSize = m_dataReader->ReadUInt32();
|
auto cmdVectorSize = m_dataReader->ReadUInt32();
|
||||||
|
|
||||||
for (unsigned int j = 0; j < cmdVectorSize; ++j)
|
for (unsigned int j = 0; j < cmdVectorSize; ++j)
|
||||||
{
|
{
|
||||||
int eachOpndcmd = m_dataReader->ReadInt32();
|
int eachOpndcmd = m_dataReader->ReadInt32();
|
||||||
cmdVector->Append(eachOpndcmd);
|
cmdVector->push_back(eachOpndcmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return COpndCommand(cmdVector, fNegative, fDecimal, fSciFmt);
|
return COpndCommand(cmdVector, fNegative, fDecimal, fSciFmt);
|
||||||
@ -68,7 +68,6 @@ CParentheses CommandDeserializer::DeserializeParentheses()
|
|||||||
CUnaryCommand CommandDeserializer::DeserializeUnary()
|
CUnaryCommand CommandDeserializer::DeserializeUnary()
|
||||||
{
|
{
|
||||||
auto cmdSize = m_dataReader->ReadUInt32();
|
auto cmdSize = m_dataReader->ReadUInt32();
|
||||||
std::shared_ptr<CalculatorVector<int>> cmdVector = std::make_shared<CalculatorVector<int>>();
|
|
||||||
|
|
||||||
if (cmdSize == 1)
|
if (cmdSize == 1)
|
||||||
{
|
{
|
||||||
|
@ -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"
|
||||||
@ -18,28 +18,22 @@ void SerializeCommandVisitor::Visit(_In_ COpndCommand& opndCmd)
|
|||||||
m_dataWriter->WriteBoolean(opndCmd.IsDecimalPresent());
|
m_dataWriter->WriteBoolean(opndCmd.IsDecimalPresent());
|
||||||
m_dataWriter->WriteBoolean(opndCmd.IsSciFmt());
|
m_dataWriter->WriteBoolean(opndCmd.IsSciFmt());
|
||||||
|
|
||||||
auto opndCmds = opndCmd.GetCommands();
|
const auto& opndCmds = opndCmd.GetCommands();
|
||||||
unsigned int opndCmdSize;
|
unsigned int opndCmdSize = static_cast<unsigned int>(opndCmds->size());
|
||||||
opndCmds->GetSize(&opndCmdSize);
|
|
||||||
m_dataWriter->WriteUInt32(opndCmdSize);
|
m_dataWriter->WriteUInt32(opndCmdSize);
|
||||||
for (unsigned int j = 0; j < opndCmdSize; ++j)
|
for (int eachOpndcmd : *opndCmds)
|
||||||
{
|
{
|
||||||
int eachOpndcmd;
|
|
||||||
opndCmds->GetAt(j, &eachOpndcmd);
|
|
||||||
m_dataWriter->WriteInt32(eachOpndcmd);
|
m_dataWriter->WriteInt32(eachOpndcmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializeCommandVisitor::Visit(_In_ CUnaryCommand& unaryCmd)
|
void SerializeCommandVisitor::Visit(_In_ CUnaryCommand& unaryCmd)
|
||||||
{
|
{
|
||||||
auto cmds = unaryCmd.GetCommands();
|
const auto& cmds = unaryCmd.GetCommands();
|
||||||
unsigned int cmdSize;
|
unsigned int cmdSize = static_cast<unsigned int>(cmds->size());
|
||||||
cmds->GetSize(&cmdSize);
|
|
||||||
m_dataWriter->WriteUInt32(cmdSize);
|
m_dataWriter->WriteUInt32(cmdSize);
|
||||||
for (unsigned int j = 0; j < cmdSize; ++j)
|
for (int eachOpndcmd : *cmds)
|
||||||
{
|
{
|
||||||
int eachOpndcmd;
|
|
||||||
cmds->GetAt(j, &eachOpndcmd);
|
|
||||||
m_dataWriter->WriteInt32(eachOpndcmd);
|
m_dataWriter->WriteInt32(eachOpndcmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,36 +92,25 @@ wstring Utils::RemoveUnwantedCharsFromWstring(wstring input, wchar_t* unwantedCh
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Utils::SerializeCommandsAndTokens(
|
void Utils::SerializeCommandsAndTokens(
|
||||||
_In_ shared_ptr<CalculatorVector<pair<wstring, int>>> const& tokens,
|
_In_ shared_ptr<vector<pair<wstring, int>>> const& tokens,
|
||||||
_In_ shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>> const& commands,
|
_In_ shared_ptr<vector<shared_ptr<IExpressionCommand>>> const& commands,
|
||||||
DataWriter ^ writer)
|
DataWriter ^ writer)
|
||||||
{
|
{
|
||||||
unsigned int commandsSize;
|
|
||||||
IFTPlatformException(commands->GetSize(&commandsSize));
|
|
||||||
|
|
||||||
// Save the size of the commands vector
|
// Save the size of the commands vector
|
||||||
writer->WriteUInt32(commandsSize);
|
writer->WriteUInt32(static_cast<unsigned int>(commands->size()));
|
||||||
|
|
||||||
SerializeCommandVisitor cmdVisitor(writer);
|
SerializeCommandVisitor cmdVisitor(writer);
|
||||||
for (unsigned int i = 0; i < commandsSize; ++i)
|
for (const auto& exprCmd : *commands)
|
||||||
{
|
{
|
||||||
shared_ptr<IExpressionCommand> exprCmd;
|
|
||||||
IFTPlatformException(commands->GetAt(i, &exprCmd));
|
|
||||||
|
|
||||||
CalculationManager::CommandType commandType = exprCmd->GetCommandType();
|
CalculationManager::CommandType commandType = exprCmd->GetCommandType();
|
||||||
writer->WriteInt32(static_cast<int>(commandType));
|
writer->WriteInt32(static_cast<int>(commandType));
|
||||||
exprCmd->Accept(cmdVisitor);
|
exprCmd->Accept(cmdVisitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int tokensSize;
|
writer->WriteUInt32(static_cast<unsigned int>(tokens->size()));
|
||||||
IFTPlatformException(tokens->GetSize(&tokensSize));
|
|
||||||
writer->WriteUInt32(tokensSize);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < tokensSize; ++i)
|
for (const auto& eachToken : *tokens)
|
||||||
{
|
{
|
||||||
pair<wstring, int> eachToken;
|
|
||||||
IFTPlatformException(tokens->GetAt(i, &eachToken));
|
|
||||||
|
|
||||||
auto stringData = ref new Platform::String(eachToken.first.c_str());
|
auto stringData = ref new Platform::String(eachToken.first.c_str());
|
||||||
auto intData = eachToken.second;
|
auto intData = eachToken.second;
|
||||||
writer->WriteUInt32(writer->MeasureString(stringData));
|
writer->WriteUInt32(writer->MeasureString(stringData));
|
||||||
@ -130,9 +119,9 @@ void Utils::SerializeCommandsAndTokens(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>> Utils::DeserializeCommands(DataReader ^ reader)
|
const shared_ptr<vector<shared_ptr<IExpressionCommand>>> Utils::DeserializeCommands(DataReader ^ reader)
|
||||||
{
|
{
|
||||||
shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>> commandVector = make_shared<CalculatorVector<shared_ptr<IExpressionCommand>>>();
|
auto commandVector = make_shared<vector<shared_ptr<IExpressionCommand>>>();
|
||||||
auto commandVectorSize = reader->ReadUInt32();
|
auto commandVectorSize = reader->ReadUInt32();
|
||||||
|
|
||||||
CommandDeserializer cmdDeserializer(reader);
|
CommandDeserializer cmdDeserializer(reader);
|
||||||
@ -141,26 +130,23 @@ const shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>> Utils::Deseri
|
|||||||
auto commandTypeInt = reader->ReadInt32();
|
auto commandTypeInt = reader->ReadInt32();
|
||||||
CalculationManager::CommandType commandType = static_cast<CalculationManager::CommandType>(commandTypeInt);
|
CalculationManager::CommandType commandType = static_cast<CalculationManager::CommandType>(commandTypeInt);
|
||||||
shared_ptr<IExpressionCommand> exprCmd = cmdDeserializer.Deserialize(commandType);
|
shared_ptr<IExpressionCommand> exprCmd = cmdDeserializer.Deserialize(commandType);
|
||||||
commandVector->Append(exprCmd);
|
commandVector->push_back(exprCmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return commandVector;
|
return commandVector;
|
||||||
}
|
}
|
||||||
|
|
||||||
const shared_ptr<CalculatorVector<pair<wstring, int>>> Utils::DeserializeTokens(DataReader ^ reader)
|
const shared_ptr<vector<pair<wstring, int>>> Utils::DeserializeTokens(DataReader ^ reader)
|
||||||
{
|
{
|
||||||
shared_ptr<CalculatorVector<pair<wstring, int>>> tokenVector = make_shared<CalculatorVector<pair<wstring, int>>>();
|
auto tokenVector = make_shared<vector<pair<wstring, int>>>();
|
||||||
auto tokensSize = reader->ReadUInt32();
|
auto tokensSize = reader->ReadUInt32();
|
||||||
|
|
||||||
for (unsigned int i = 0; i < tokensSize; ++i)
|
for (unsigned int i = 0; i < tokensSize; ++i)
|
||||||
{
|
{
|
||||||
pair<wstring, int> eachToken;
|
|
||||||
auto stringDataLen = reader->ReadUInt32();
|
auto stringDataLen = reader->ReadUInt32();
|
||||||
auto stringData = reader->ReadString(stringDataLen);
|
auto stringData = reader->ReadString(stringDataLen);
|
||||||
auto intData = reader->ReadInt32();
|
auto intData = reader->ReadInt32();
|
||||||
eachToken.first = stringData->Data();
|
tokenVector->emplace_back(stringData->Data(), intData);
|
||||||
eachToken.second = intData;
|
|
||||||
tokenVector->Append(eachToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tokenVector;
|
return tokenVector;
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CalcManager/CalculatorVector.h"
|
|
||||||
#include "CalcManager/ExpressionCommandInterface.h"
|
#include "CalcManager/ExpressionCommandInterface.h"
|
||||||
#include "DelegateCommand.h"
|
#include "DelegateCommand.h"
|
||||||
|
|
||||||
@ -385,12 +384,12 @@ namespace Utils
|
|||||||
int GetWindowId();
|
int GetWindowId();
|
||||||
void RunOnUIThreadNonblocking(std::function<void()>&& function, _In_ Windows::UI::Core::CoreDispatcher ^ currentDispatcher);
|
void RunOnUIThreadNonblocking(std::function<void()>&& function, _In_ Windows::UI::Core::CoreDispatcher ^ currentDispatcher);
|
||||||
void SerializeCommandsAndTokens(
|
void SerializeCommandsAndTokens(
|
||||||
_In_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens,
|
_In_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens,
|
||||||
_In_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& commands,
|
_In_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& commands,
|
||||||
Windows::Storage::Streams::DataWriter ^ writer);
|
Windows::Storage::Streams::DataWriter ^ writer);
|
||||||
|
|
||||||
const std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> DeserializeCommands(Windows::Storage::Streams::DataReader ^ reader);
|
const std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> DeserializeCommands(Windows::Storage::Streams::DataReader ^ reader);
|
||||||
const std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> DeserializeTokens(Windows::Storage::Streams::DataReader ^ reader);
|
const std::shared_ptr<std::vector<std::pair<std::wstring, int>>> DeserializeTokens(Windows::Storage::Streams::DataReader ^ reader);
|
||||||
|
|
||||||
Windows::Foundation::DateTime GetUniversalSystemTime();
|
Windows::Foundation::DateTime GetUniversalSystemTime();
|
||||||
bool IsDateTimeOlderThan(Windows::Foundation::DateTime dateTime, const long long duration);
|
bool IsDateTimeOlderThan(Windows::Foundation::DateTime dateTime, const long long duration);
|
||||||
|
@ -13,8 +13,8 @@ using namespace Platform;
|
|||||||
HistoryItemViewModel::HistoryItemViewModel(
|
HistoryItemViewModel::HistoryItemViewModel(
|
||||||
String ^ expression,
|
String ^ expression,
|
||||||
String ^ result,
|
String ^ result,
|
||||||
_In_ const shared_ptr<CalculatorVector<pair<wstring, int>>>& spTokens,
|
_In_ const shared_ptr<vector<pair<wstring, int>>>& spTokens,
|
||||||
_In_ const shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>>& spCommands)
|
_In_ const shared_ptr<vector<shared_ptr<IExpressionCommand>>>& spCommands)
|
||||||
: m_expression(expression)
|
: m_expression(expression)
|
||||||
, m_result(result)
|
, m_result(result)
|
||||||
, m_spTokens(spTokens)
|
, m_spTokens(spTokens)
|
||||||
@ -27,37 +27,17 @@ HistoryItemViewModel::HistoryItemViewModel(
|
|||||||
|
|
||||||
String
|
String
|
||||||
^ HistoryItemViewModel::GetAccessibleExpressionFromTokens(
|
^ HistoryItemViewModel::GetAccessibleExpressionFromTokens(
|
||||||
_In_ shared_ptr<CalculatorVector<pair<wstring, int>>> const& spTokens,
|
_In_ shared_ptr<vector<pair<wstring, int>>> const& spTokens,
|
||||||
_In_ String ^ fallbackExpression)
|
_In_ String ^ fallbackExpression)
|
||||||
{
|
{
|
||||||
// updating accessibility names for expression and result
|
// updating accessibility names for expression and result
|
||||||
wstringstream accExpression{};
|
wstringstream accExpression{};
|
||||||
accExpression << L"";
|
accExpression << L"";
|
||||||
|
|
||||||
unsigned int nTokens;
|
for (const auto& tokenItem : *spTokens)
|
||||||
HRESULT hr = spTokens->GetSize(&nTokens);
|
|
||||||
if (SUCCEEDED(hr))
|
|
||||||
{
|
{
|
||||||
pair<wstring, int> tokenItem;
|
accExpression << LocalizationService::GetNarratorReadableToken(StringReference(tokenItem.first.c_str()))->Data();
|
||||||
for (unsigned int i = 0; i < nTokens; i++)
|
|
||||||
{
|
|
||||||
hr = spTokens->GetAt(i, &tokenItem);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wstring token = tokenItem.first;
|
|
||||||
accExpression << LocalizationService::GetNarratorReadableToken(StringReference(token.c_str()))->Data();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
return LocalizationService::GetNarratorReadableString(fallbackExpression);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return ref new String(accExpression.str().c_str());
|
return ref new String(accExpression.str().c_str());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CalcManager/CalculatorVector.h"
|
|
||||||
#include "CalcManager/ExpressionCommandInterface.h"
|
#include "CalcManager/ExpressionCommandInterface.h"
|
||||||
|
|
||||||
namespace CalculatorApp
|
namespace CalculatorApp
|
||||||
@ -17,15 +16,15 @@ namespace CalculatorApp
|
|||||||
HistoryItemViewModel(
|
HistoryItemViewModel(
|
||||||
Platform::String ^ expression,
|
Platform::String ^ expression,
|
||||||
Platform::String ^ result,
|
Platform::String ^ result,
|
||||||
_In_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& spTokens,
|
_In_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& spTokens,
|
||||||
_In_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& spCommands);
|
_In_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& spCommands);
|
||||||
|
|
||||||
std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& GetTokens()
|
std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& GetTokens()
|
||||||
{
|
{
|
||||||
return m_spTokens;
|
return m_spTokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& GetCommands()
|
std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& GetCommands()
|
||||||
{
|
{
|
||||||
return m_spCommands;
|
return m_spCommands;
|
||||||
}
|
}
|
||||||
@ -62,7 +61,7 @@ namespace CalculatorApp
|
|||||||
|
|
||||||
private : static Platform::String
|
private : static Platform::String
|
||||||
^ GetAccessibleExpressionFromTokens(
|
^ GetAccessibleExpressionFromTokens(
|
||||||
_In_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& spTokens,
|
_In_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& spTokens,
|
||||||
_In_ Platform::String ^ fallbackExpression);
|
_In_ Platform::String ^ fallbackExpression);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -70,8 +69,8 @@ namespace CalculatorApp
|
|||||||
Platform::String ^ m_accExpression;
|
Platform::String ^ m_accExpression;
|
||||||
Platform::String ^ m_accResult;
|
Platform::String ^ m_accResult;
|
||||||
Platform::String ^ m_result;
|
Platform::String ^ m_result;
|
||||||
std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> m_spTokens;
|
std::shared_ptr<std::vector<std::pair<std::wstring, int>>> m_spTokens;
|
||||||
std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> m_spCommands;
|
std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> m_spCommands;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,8 +289,8 @@ void StandardCalculatorViewModel::DisableButtons(CommandType selectedExpressionC
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StandardCalculatorViewModel::SetExpressionDisplay(
|
void StandardCalculatorViewModel::SetExpressionDisplay(
|
||||||
_Inout_ shared_ptr<CalculatorVector<pair<wstring, int>>> const& tokens,
|
_Inout_ shared_ptr<std::vector<pair<wstring, int>>> const& tokens,
|
||||||
_Inout_ shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>> const& commands)
|
_Inout_ shared_ptr<std::vector<shared_ptr<IExpressionCommand>>> const& commands)
|
||||||
{
|
{
|
||||||
m_tokens = tokens;
|
m_tokens = tokens;
|
||||||
m_commands = commands;
|
m_commands = commands;
|
||||||
@ -305,11 +305,11 @@ void StandardCalculatorViewModel::SetExpressionDisplay(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StandardCalculatorViewModel::SetHistoryExpressionDisplay(
|
void StandardCalculatorViewModel::SetHistoryExpressionDisplay(
|
||||||
_Inout_ shared_ptr<CalculatorVector<pair<wstring, int>>> const& tokens,
|
_Inout_ shared_ptr<vector<pair<wstring, int>>> const& tokens,
|
||||||
_Inout_ shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>> const& commands)
|
_Inout_ shared_ptr<vector<shared_ptr<IExpressionCommand>>> const& commands)
|
||||||
{
|
{
|
||||||
m_tokens = make_shared<CalculatorVector<pair<wstring, int>>>(*tokens);
|
m_tokens = make_shared<vector<pair<wstring, int>>>(*tokens);
|
||||||
m_commands = make_shared<CalculatorVector<shared_ptr<IExpressionCommand>>>(*commands);
|
m_commands = make_shared<vector<shared_ptr<IExpressionCommand>>>(*commands);
|
||||||
IsEditingEnabled = false;
|
IsEditingEnabled = false;
|
||||||
|
|
||||||
// Setting the History Item Load Mode so that UI does not get updated with recalculation of every token
|
// Setting the History Item Load Mode so that UI does not get updated with recalculation of every token
|
||||||
@ -319,12 +319,11 @@ void StandardCalculatorViewModel::SetHistoryExpressionDisplay(
|
|||||||
m_isLastOperationHistoryLoad = true;
|
m_isLastOperationHistoryLoad = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandardCalculatorViewModel::SetTokens(_Inout_ shared_ptr<CalculatorVector<pair<wstring, int>>> const& tokens)
|
void StandardCalculatorViewModel::SetTokens(_Inout_ shared_ptr<vector<pair<wstring, int>>> const& tokens)
|
||||||
{
|
{
|
||||||
AreTokensUpdated = false;
|
AreTokensUpdated = false;
|
||||||
|
|
||||||
unsigned int nTokens = 0;
|
const size_t nTokens = tokens->size();
|
||||||
tokens->GetSize(&nTokens);
|
|
||||||
|
|
||||||
if (nTokens == 0)
|
if (nTokens == 0)
|
||||||
{
|
{
|
||||||
@ -332,16 +331,15 @@ void StandardCalculatorViewModel::SetTokens(_Inout_ shared_ptr<CalculatorVector<
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<wstring, int> currentToken;
|
|
||||||
const auto& localizer = LocalizationSettings::GetInstance();
|
const auto& localizer = LocalizationSettings::GetInstance();
|
||||||
|
|
||||||
const wstring separator = L" ";
|
const wstring separator = L" ";
|
||||||
for (unsigned int i = 0; i < nTokens; ++i)
|
for (unsigned int i = 0; i < nTokens; ++i)
|
||||||
{
|
{
|
||||||
if (SUCCEEDED(tokens->GetAt(i, ¤tToken)))
|
auto currentToken = (*tokens)[i];
|
||||||
{
|
|
||||||
Common::TokenType type;
|
Common::TokenType type;
|
||||||
bool isEditable = (currentToken.second == -1) ? false : true;
|
bool isEditable = currentToken.second != -1;
|
||||||
localizer.LocalizeDisplayValue(&(currentToken.first));
|
localizer.LocalizeDisplayValue(&(currentToken.first));
|
||||||
|
|
||||||
if (!isEditable)
|
if (!isEditable)
|
||||||
@ -350,8 +348,7 @@ void StandardCalculatorViewModel::SetTokens(_Inout_ shared_ptr<CalculatorVector<
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shared_ptr<IExpressionCommand> command;
|
const shared_ptr<IExpressionCommand>& command = m_commands->at(currentToken.second);
|
||||||
IFTPlatformException(m_commands->GetAt(static_cast<unsigned int>(currentToken.second), &command));
|
|
||||||
type = command->GetCommandType() == CommandType::OperandCommand ? TokenType::Operand : TokenType::Operator;
|
type = command->GetCommandType() == CommandType::OperandCommand ? TokenType::Operand : TokenType::Operator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,7 +374,6 @@ void StandardCalculatorViewModel::SetTokens(_Inout_ shared_ptr<CalculatorVector<
|
|||||||
m_ExpressionTokens->Append(expressionToken);
|
m_ExpressionTokens->Append(expressionToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
while (m_ExpressionTokens->Size != nTokens)
|
while (m_ExpressionTokens->Size != nTokens)
|
||||||
{
|
{
|
||||||
@ -1277,16 +1273,12 @@ ANGLE_TYPE GetAngleTypeFromCommand(Command command)
|
|||||||
|
|
||||||
void StandardCalculatorViewModel::SaveEditedCommand(_In_ unsigned int tokenPosition, _In_ Command command)
|
void StandardCalculatorViewModel::SaveEditedCommand(_In_ unsigned int tokenPosition, _In_ Command command)
|
||||||
{
|
{
|
||||||
pair<wstring, int> token;
|
|
||||||
bool handleOperand = false;
|
bool handleOperand = false;
|
||||||
int nOpCode = static_cast<int>(command);
|
int nOpCode = static_cast<int>(command);
|
||||||
wstring updatedToken = L"";
|
wstring updatedToken = L"";
|
||||||
|
|
||||||
shared_ptr<IExpressionCommand> tokenCommand;
|
const pair<wstring, int>& token = m_tokens->at(tokenPosition);
|
||||||
IFTPlatformException(m_tokens->GetAt(tokenPosition, &token));
|
const shared_ptr<IExpressionCommand>& tokenCommand = m_commands->at(token.second);
|
||||||
|
|
||||||
unsigned int tokenCommandIndex = token.second;
|
|
||||||
IFTPlatformException(m_commands->GetAt(tokenCommandIndex, &tokenCommand));
|
|
||||||
|
|
||||||
if (IsUnaryOp(nOpCode) && command != Command::CommandSIGN)
|
if (IsUnaryOp(nOpCode) && command != Command::CommandSIGN)
|
||||||
{
|
{
|
||||||
@ -1352,7 +1344,7 @@ void StandardCalculatorViewModel::SaveEditedCommand(_In_ unsigned int tokenPosit
|
|||||||
if (tokenCommand->GetCommandType() == CommandType::UnaryCommand)
|
if (tokenCommand->GetCommandType() == CommandType::UnaryCommand)
|
||||||
{
|
{
|
||||||
shared_ptr<IExpressionCommand> spSignCommand = make_shared<CUnaryCommand>(nOpCode);
|
shared_ptr<IExpressionCommand> spSignCommand = make_shared<CUnaryCommand>(nOpCode);
|
||||||
IFTPlatformException(m_commands->InsertAt(tokenCommandIndex + 1, spSignCommand));
|
m_commands->insert(m_commands->begin() + token.second + 1, spSignCommand);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1365,12 +1357,8 @@ void StandardCalculatorViewModel::SaveEditedCommand(_In_ unsigned int tokenPosit
|
|||||||
|
|
||||||
if (!handleOperand)
|
if (!handleOperand)
|
||||||
{
|
{
|
||||||
IFTPlatformException(m_commands->SetAt(tokenCommandIndex, tokenCommand));
|
(*m_commands)[token.second] = tokenCommand;
|
||||||
|
(*m_tokens)[tokenPosition].first = updatedToken;
|
||||||
pair<wstring, int> selectedToken;
|
|
||||||
IFTPlatformException(m_tokens->GetAt(tokenPosition, &selectedToken));
|
|
||||||
selectedToken.first = updatedToken;
|
|
||||||
IFTPlatformException(m_tokens->SetAt(tokenPosition, selectedToken));
|
|
||||||
|
|
||||||
DisplayExpressionToken ^ displayExpressionToken = ExpressionTokens->GetAt(tokenPosition);
|
DisplayExpressionToken ^ displayExpressionToken = ExpressionTokens->GetAt(tokenPosition);
|
||||||
displayExpressionToken->Token = ref new Platform::String(updatedToken.c_str());
|
displayExpressionToken->Token = ref new Platform::String(updatedToken.c_str());
|
||||||
@ -1388,30 +1376,21 @@ void StandardCalculatorViewModel::Recalculate(bool fromHistory)
|
|||||||
{
|
{
|
||||||
// Recalculate
|
// Recalculate
|
||||||
Command currentDegreeMode = m_standardCalculatorManager.GetCurrentDegreeMode();
|
Command currentDegreeMode = m_standardCalculatorManager.GetCurrentDegreeMode();
|
||||||
shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>> savedCommands = make_shared<CalculatorVector<shared_ptr<IExpressionCommand>>>();
|
shared_ptr<vector<shared_ptr<IExpressionCommand>>> savedCommands = make_shared<vector<shared_ptr<IExpressionCommand>>>();
|
||||||
|
|
||||||
vector<int> currentCommands;
|
vector<int> currentCommands;
|
||||||
unsigned int commandListCount;
|
|
||||||
m_commands->GetSize(&commandListCount);
|
|
||||||
for (unsigned int i = 0; i < commandListCount; i++)
|
|
||||||
{
|
|
||||||
shared_ptr<IExpressionCommand> command;
|
|
||||||
IFTPlatformException(m_commands->GetAt(i, &command));
|
|
||||||
|
|
||||||
savedCommands->Append(command);
|
for (const auto& command : *m_commands)
|
||||||
|
{
|
||||||
|
savedCommands->push_back(command);
|
||||||
CommandType commandType = command->GetCommandType();
|
CommandType commandType = command->GetCommandType();
|
||||||
|
|
||||||
if (commandType == CommandType::UnaryCommand)
|
if (commandType == CommandType::UnaryCommand)
|
||||||
{
|
{
|
||||||
shared_ptr<IUnaryCommand> spCommand = dynamic_pointer_cast<IUnaryCommand>(command);
|
shared_ptr<IUnaryCommand> spCommand = dynamic_pointer_cast<IUnaryCommand>(command);
|
||||||
shared_ptr<CalculatorVector<int>> unaryCommands = spCommand->GetCommands();
|
const shared_ptr<vector<int>>& unaryCommands = spCommand->GetCommands();
|
||||||
unsigned int unaryCommandCount;
|
|
||||||
unaryCommands->GetSize(&unaryCommandCount);
|
|
||||||
|
|
||||||
int nUCode;
|
for (int nUCode : *unaryCommands)
|
||||||
for (unsigned int j = 0; j < unaryCommandCount; ++j)
|
|
||||||
{
|
{
|
||||||
IFTPlatformException(unaryCommands->GetAt(j, &nUCode));
|
|
||||||
currentCommands.push_back(nUCode);
|
currentCommands.push_back(nUCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1431,15 +1410,11 @@ void StandardCalculatorViewModel::Recalculate(bool fromHistory)
|
|||||||
if (commandType == CommandType::OperandCommand)
|
if (commandType == CommandType::OperandCommand)
|
||||||
{
|
{
|
||||||
shared_ptr<IOpndCommand> spCommand = dynamic_pointer_cast<IOpndCommand>(command);
|
shared_ptr<IOpndCommand> spCommand = dynamic_pointer_cast<IOpndCommand>(command);
|
||||||
shared_ptr<CalculatorVector<int>> opndCommands = spCommand->GetCommands();
|
const shared_ptr<vector<int>>& opndCommands = spCommand->GetCommands();
|
||||||
unsigned int opndCommandCount;
|
|
||||||
opndCommands->GetSize(&opndCommandCount);
|
|
||||||
bool fNeedIDCSign = spCommand->IsNegative();
|
bool fNeedIDCSign = spCommand->IsNegative();
|
||||||
|
|
||||||
int nOCode;
|
for (int nOCode : *opndCommands)
|
||||||
for (unsigned int j = 0; j < opndCommandCount; ++j)
|
|
||||||
{
|
{
|
||||||
IFTPlatformException(opndCommands->GetAt(j, &nOCode));
|
|
||||||
currentCommands.push_back(nOCode);
|
currentCommands.push_back(nOCode);
|
||||||
|
|
||||||
if (fNeedIDCSign && nOCode != IDC_0)
|
if (fNeedIDCSign && nOCode != IDC_0)
|
||||||
@ -1450,16 +1425,12 @@ void StandardCalculatorViewModel::Recalculate(bool fromHistory)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shared_ptr<CalculatorVector<pair<wstring, int>>> savedTokens = make_shared<CalculatorVector<pair<wstring, int>>>();
|
|
||||||
|
|
||||||
unsigned int tokenCount;
|
shared_ptr<vector<pair<wstring, int>>> savedTokens = make_shared<vector<pair<wstring, int>>>();
|
||||||
IFTPlatformException(m_tokens->GetSize(&tokenCount));
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < tokenCount; ++i)
|
for (const auto& currentToken : *m_tokens)
|
||||||
{
|
{
|
||||||
pair<wstring, int> currentToken;
|
savedTokens->push_back(currentToken);
|
||||||
IFTPlatformException(m_tokens->GetAt(i, ¤tToken));
|
|
||||||
savedTokens->Append(currentToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_standardCalculatorManager.Reset(false);
|
m_standardCalculatorManager.Reset(false);
|
||||||
@ -1497,12 +1468,9 @@ void StandardCalculatorViewModel::Recalculate(bool fromHistory)
|
|||||||
|
|
||||||
CommandType StandardCalculatorViewModel::GetSelectedTokenType(_In_ unsigned int tokenPosition)
|
CommandType StandardCalculatorViewModel::GetSelectedTokenType(_In_ unsigned int tokenPosition)
|
||||||
{
|
{
|
||||||
pair<wstring, int> token;
|
const pair<wstring, int>& token = m_tokens->at(tokenPosition);
|
||||||
shared_ptr<IExpressionCommand> tokenCommand;
|
|
||||||
IFTPlatformException(m_tokens->GetAt(tokenPosition, &token));
|
|
||||||
|
|
||||||
unsigned int tokenCommandIndex = token.second;
|
unsigned int tokenCommandIndex = token.second;
|
||||||
IFTPlatformException(m_commands->GetAt(tokenCommandIndex, &tokenCommand));
|
const shared_ptr<IExpressionCommand>& tokenCommand = m_commands->at(tokenCommandIndex);
|
||||||
|
|
||||||
return tokenCommand->GetCommandType();
|
return tokenCommand->GetCommandType();
|
||||||
}
|
}
|
||||||
@ -1715,20 +1683,18 @@ NumbersAndOperatorsEnum StandardCalculatorViewModel::ConvertIntegerToNumbersAndO
|
|||||||
|
|
||||||
void StandardCalculatorViewModel::UpdateOperand(int pos, String ^ text)
|
void StandardCalculatorViewModel::UpdateOperand(int pos, String ^ text)
|
||||||
{
|
{
|
||||||
pair<wstring, int> p;
|
pair<wstring, int> p = m_tokens->at(pos);
|
||||||
m_tokens->GetAt(pos, &p);
|
|
||||||
|
|
||||||
String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(text->Data());
|
String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(text->Data());
|
||||||
p.first = englishString->Data();
|
p.first = englishString->Data();
|
||||||
|
|
||||||
int commandPos = p.second;
|
int commandPos = p.second;
|
||||||
shared_ptr<IExpressionCommand> exprCmd;
|
const shared_ptr<IExpressionCommand>& exprCmd = m_commands->at(commandPos);
|
||||||
m_commands->GetAt(commandPos, &exprCmd);
|
|
||||||
auto operandCommand = std::dynamic_pointer_cast<IOpndCommand>(exprCmd);
|
auto operandCommand = std::dynamic_pointer_cast<IOpndCommand>(exprCmd);
|
||||||
|
|
||||||
if (operandCommand != nullptr)
|
if (operandCommand != nullptr)
|
||||||
{
|
{
|
||||||
shared_ptr<CalculatorVector<int>> commands = make_shared<CalculatorVector<int>>();
|
shared_ptr<vector<int>> commands = make_shared<vector<int>>();
|
||||||
size_t length = p.first.length();
|
size_t length = p.first.length();
|
||||||
if (length > 0)
|
if (length > 0)
|
||||||
{
|
{
|
||||||
@ -1766,12 +1732,12 @@ void StandardCalculatorViewModel::UpdateOperand(int pos, String ^ text)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commands->Append(num);
|
commands->push_back(num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
commands->Append(0);
|
commands->push_back(0);
|
||||||
}
|
}
|
||||||
operandCommand->SetCommands(commands);
|
operandCommand->SetCommands(commands);
|
||||||
}
|
}
|
||||||
@ -1780,7 +1746,7 @@ void StandardCalculatorViewModel::UpdateOperand(int pos, String ^ text)
|
|||||||
void StandardCalculatorViewModel::UpdatecommandsInRecordingMode()
|
void StandardCalculatorViewModel::UpdatecommandsInRecordingMode()
|
||||||
{
|
{
|
||||||
vector<unsigned char> savedCommands = m_standardCalculatorManager.GetSavedCommands();
|
vector<unsigned char> savedCommands = m_standardCalculatorManager.GetSavedCommands();
|
||||||
shared_ptr<CalculatorVector<int>> commands = make_shared<CalculatorVector<int>>();
|
shared_ptr<vector<int>> commands = make_shared<vector<int>>();
|
||||||
bool isDecimal = false;
|
bool isDecimal = false;
|
||||||
bool isNegative = false;
|
bool isNegative = false;
|
||||||
bool isExpMode = false;
|
bool isExpMode = false;
|
||||||
@ -1827,18 +1793,16 @@ void StandardCalculatorViewModel::UpdatecommandsInRecordingMode()
|
|||||||
isExpMode = false;
|
isExpMode = false;
|
||||||
ePlusMode = false;
|
ePlusMode = false;
|
||||||
eMinusMode = false;
|
eMinusMode = false;
|
||||||
commands->Clear();
|
commands->clear();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
commands->Append(num);
|
commands->push_back(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int size = 0;
|
if (!commands->empty())
|
||||||
commands->GetSize(&size);
|
|
||||||
if (size > 0)
|
|
||||||
{
|
{
|
||||||
shared_ptr<IOpndCommand> sp = make_shared<COpndCommand>(commands, isNegative, isDecimal, isExpMode);
|
shared_ptr<IOpndCommand> sp = make_shared<COpndCommand>(commands, isNegative, isDecimal, isExpMode);
|
||||||
m_commands->Append(sp);
|
m_commands->push_back(sp);
|
||||||
}
|
}
|
||||||
Recalculate();
|
Recalculate();
|
||||||
}
|
}
|
||||||
|
@ -342,13 +342,13 @@ namespace CalculatorApp
|
|||||||
void OnInputChanged();
|
void OnInputChanged();
|
||||||
void SetPrimaryDisplay(_In_ std::wstring const& displayString, _In_ bool isError);
|
void SetPrimaryDisplay(_In_ std::wstring const& displayString, _In_ bool isError);
|
||||||
void DisplayPasteError();
|
void DisplayPasteError();
|
||||||
void SetTokens(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens);
|
void SetTokens(_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens);
|
||||||
void SetExpressionDisplay(
|
void SetExpressionDisplay(
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens,
|
_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens,
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& commands);
|
_Inout_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& commands);
|
||||||
void SetHistoryExpressionDisplay(
|
void SetHistoryExpressionDisplay(
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens,
|
_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens,
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& commands);
|
_Inout_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& commands);
|
||||||
void SetParenthesisCount(_In_ unsigned int parenthesisCount);
|
void SetParenthesisCount(_In_ unsigned int parenthesisCount);
|
||||||
void SetOpenParenthesisCountNarratorAnnouncement();
|
void SetOpenParenthesisCountNarratorAnnouncement();
|
||||||
void OnNoRightParenAdded();
|
void OnNoRightParenAdded();
|
||||||
@ -444,8 +444,8 @@ namespace CalculatorApp
|
|||||||
std::wstring AddPadding(std::wstring);
|
std::wstring AddPadding(std::wstring);
|
||||||
size_t LengthWithoutPadding(std::wstring);
|
size_t LengthWithoutPadding(std::wstring);
|
||||||
|
|
||||||
std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> m_tokens;
|
std::shared_ptr<std::vector<std::pair<std::wstring, int>>> m_tokens;
|
||||||
std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> m_commands;
|
std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> m_commands;
|
||||||
|
|
||||||
// Token types
|
// Token types
|
||||||
bool IsUnaryOp(int nOpCode);
|
bool IsUnaryOp(int nOpCode);
|
||||||
|
@ -476,9 +476,7 @@ void Calculator::OnHideHistoryClicked()
|
|||||||
|
|
||||||
void Calculator::OnHistoryItemClicked(_In_ HistoryItemViewModel ^ e)
|
void Calculator::OnHistoryItemClicked(_In_ HistoryItemViewModel ^ e)
|
||||||
{
|
{
|
||||||
unsigned int tokenSize;
|
|
||||||
assert(e->GetTokens() != nullptr);
|
assert(e->GetTokens() != nullptr);
|
||||||
e->GetTokens()->GetSize(&tokenSize);
|
|
||||||
Model->SetHistoryExpressionDisplay(e->GetTokens(), e->GetCommands());
|
Model->SetHistoryExpressionDisplay(e->GetTokens(), e->GetCommands());
|
||||||
Model->SetExpressionDisplay(e->GetTokens(), e->GetCommands());
|
Model->SetExpressionDisplay(e->GetTokens(), e->GetCommands());
|
||||||
Model->SetPrimaryDisplay(e->Result->Data(), false);
|
Model->SetPrimaryDisplay(e->Result->Data(), false);
|
||||||
|
@ -43,16 +43,13 @@ namespace CalculatorManagerTest
|
|||||||
m_isError = isError;
|
m_isError = isError;
|
||||||
}
|
}
|
||||||
void SetExpressionDisplay(
|
void SetExpressionDisplay(
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens,
|
_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens,
|
||||||
_Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& /*commands*/) override
|
_Inout_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& /*commands*/) override
|
||||||
{
|
{
|
||||||
m_expression.clear();
|
m_expression.clear();
|
||||||
unsigned int nTokens = 0;
|
|
||||||
std::pair<std::wstring, int> currentPair;
|
for (const auto& currentPair : *tokens)
|
||||||
tokens->GetSize(&nTokens);
|
|
||||||
for (unsigned int i = 0; i < nTokens; ++i)
|
|
||||||
{
|
{
|
||||||
tokens->GetAt(i, ¤tPair);
|
|
||||||
m_expression += currentPair.first;
|
m_expression += currentPair.first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,6 @@ namespace CalculatorApp::Common::Automation
|
|||||||
namespace CustomPeers = CalculatorApp::Common::Automation;
|
namespace CustomPeers = CalculatorApp::Common::Automation;
|
||||||
|
|
||||||
// CalcManager Headers
|
// CalcManager Headers
|
||||||
#include "CalcManager/CalculatorVector.h"
|
|
||||||
#include "CalcManager/ExpressionCommand.h"
|
#include "CalcManager/ExpressionCommand.h"
|
||||||
#include "CalcManager/CalculatorResource.h"
|
#include "CalcManager/CalculatorResource.h"
|
||||||
#include "CalcManager/CalculatorManager.h"
|
#include "CalcManager/CalculatorManager.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user