mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-21 05:43:10 -07:00
stash changes
This commit is contained in:
parent
ff9d026ea7
commit
5bb3c54840
3 changed files with 104 additions and 22 deletions
|
@ -3,26 +3,102 @@
|
|||
|
||||
#include "pch.h"
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "Snapshots.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
ref struct UnaryCommand sealed : public CalculatorApp::ViewModel::ICalcManagerIExprCommand
|
||||
{
|
||||
property Windows::Foundation::Collections::IVector<int> ^ Commands;
|
||||
};
|
||||
|
||||
ref struct BinaryCommand sealed : public CalculatorApp::ViewModel::ICalcManagerIExprCommand
|
||||
{
|
||||
property int Command;
|
||||
};
|
||||
|
||||
ref struct OperandCommand sealed : public CalculatorApp::ViewModel::ICalcManagerIExprCommand
|
||||
{
|
||||
property bool IsNegative;
|
||||
property bool IsDecimalPresent;
|
||||
property bool IsSciFmt;
|
||||
property Windows::Foundation::Collections::IVector<int> ^ Commands;
|
||||
};
|
||||
|
||||
ref struct Parentheses sealed : public CalculatorApp::ViewModel::ICalcManagerIExprCommand
|
||||
{
|
||||
property int Command;
|
||||
};
|
||||
|
||||
CalculatorApp::ViewModel::ICalcManagerIExprCommand ^ CreateExprCommand(const IExpressionCommand* exprCmd) {
|
||||
switch (exprCmd->GetCommandType())
|
||||
{
|
||||
case CalculationManager::CommandType::UnaryCommand:
|
||||
{
|
||||
auto cmd = static_cast<const IUnaryCommand*>(exprCmd);
|
||||
auto result = ref new UnaryCommand();
|
||||
result->Commands = ref new Platform::Collections::Vector<int>();
|
||||
for (auto& subcmd : *cmd->GetCommands())
|
||||
{
|
||||
result->Commands->Append(subcmd);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
case CalculationManager::CommandType::BinaryCommand:
|
||||
{
|
||||
auto cmd = static_cast<const IBinaryCommand*>(exprCmd);
|
||||
auto result = ref new BinaryCommand();
|
||||
result->Command = cmd->GetCommand();
|
||||
return result;
|
||||
}
|
||||
case CalculationManager::CommandType::OperandCommand:
|
||||
{
|
||||
auto cmd = static_cast<const IOpndCommand*>(exprCmd);
|
||||
auto result = ref new OperandCommand();
|
||||
result->IsNegative = cmd->IsNegative();
|
||||
result->IsDecimalPresent = cmd->IsDecimalPresent();
|
||||
result->IsSciFmt = cmd->IsSciFmt();
|
||||
result->Commands = ref new Platform::Collections::Vector<int>();
|
||||
for (auto& subcmd : *cmd->GetCommands())
|
||||
{
|
||||
result->Commands->Append(subcmd);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
case CalculationManager::CommandType::Parentheses:
|
||||
{
|
||||
auto cmd = static_cast<const IParenthesisCommand*>(exprCmd);
|
||||
auto result = ref new Parentheses();
|
||||
result->Command = cmd->GetCommand();
|
||||
return result;
|
||||
}
|
||||
default:
|
||||
throw std::logic_error{ "unhandled command type." };
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace CalculatorApp::ViewModel
|
||||
{
|
||||
CalcEngineHistoryToken::CalcEngineHistoryToken(Platform::String ^ opCodeName, int cmdIndex)
|
||||
CalcManagerHistoryToken::CalcManagerHistoryToken(Platform::String ^ opCodeName, int cmdIndex)
|
||||
{
|
||||
assert(opCodeName != nullptr && "opCodeName is mandatory.");
|
||||
OpCodeName = opCodeName;
|
||||
CommandIndex = cmdIndex;
|
||||
}
|
||||
|
||||
CalcEnginHistoryItem::CalcEnginHistoryItem(const CalculationManager::HISTORYITEM& item)
|
||||
CalcManagerHistoryItem::CalcManagerHistoryItem(const CalculationManager::HISTORYITEM& item)
|
||||
{
|
||||
Tokens = ref new Platform::Collections::Vector<CalcEngineHistoryToken ^>();
|
||||
Tokens = ref new Platform::Collections::Vector<CalcManagerHistoryToken ^>();
|
||||
Commands = ref new Platform::Collections::Vector<ICalcManagerIExprCommand ^>();
|
||||
if (item.historyItemVector.spTokens != nullptr)
|
||||
{
|
||||
for (auto& [opCode, cmdIdx] : *item.historyItemVector.spTokens)
|
||||
{
|
||||
Tokens->Append(ref new CalcEngineHistoryToken(ref new Platform::String(opCode.c_str()), cmdIdx));
|
||||
Tokens->Append(ref new CalcManagerHistoryToken(ref new Platform::String(opCode.c_str()), cmdIdx));
|
||||
// Commands->Append();
|
||||
}
|
||||
}
|
||||
Expression = ref new Platform::String(item.historyItemVector.expression.c_str());
|
||||
|
@ -36,7 +112,7 @@ namespace CalculatorApp::ViewModel
|
|||
{
|
||||
for (auto& item : items)
|
||||
{
|
||||
HistoryItems->Append(ref new CalcEnginHistoryItem(*item));
|
||||
HistoryItems->Append(ref new CalcManagerHistoryItem(*item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,10 +126,10 @@ namespace CalculatorApp::ViewModel
|
|||
|
||||
ExpressionDisplaySnapshot::ExpressionDisplaySnapshot(const std::vector<CalcHistoryToken>& tokens)
|
||||
{
|
||||
Tokens = ref new Platform::Collections::Vector<CalcEngineHistoryToken ^>();
|
||||
Tokens = ref new Platform::Collections::Vector<CalcManagerHistoryToken ^>();
|
||||
for (auto& [opCode, cmdIdx] : tokens)
|
||||
{
|
||||
Tokens->Append(ref new CalcEngineHistoryToken(ref new Platform::String(opCode.c_str()), cmdIdx));
|
||||
Tokens->Append(ref new CalcManagerHistoryToken(ref new Platform::String(opCode.c_str()), cmdIdx));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,31 +7,36 @@
|
|||
namespace CalculatorApp::ViewModel
|
||||
{
|
||||
public
|
||||
ref struct CalcEngineHistoryToken sealed
|
||||
interface struct ICalcManagerIExprCommand
|
||||
{
|
||||
};
|
||||
|
||||
public
|
||||
ref struct CalcManagerHistoryToken sealed
|
||||
{
|
||||
property Platform::String ^ OpCodeName; // mandatory
|
||||
property int CommandIndex;
|
||||
|
||||
internal :;
|
||||
explicit CalcEngineHistoryToken(Platform::String ^ opCodeName, int cmdIndex);
|
||||
explicit CalcManagerHistoryToken(Platform::String ^ opCodeName, int cmdIndex);
|
||||
};
|
||||
|
||||
public
|
||||
ref struct CalcEnginHistoryItem sealed
|
||||
ref struct CalcManagerHistoryItem sealed
|
||||
{
|
||||
property Windows::Foundation::Collections::IVector<CalcEngineHistoryToken ^> ^ Tokens; // mandatory
|
||||
// TODO: commands
|
||||
property Windows::Foundation::Collections::IVector<CalcManagerHistoryToken ^> ^ Tokens; // mandatory
|
||||
property Windows::Foundation::Collections::IVector<ICalcManagerIExprCommand ^> ^ Commands; // mandatory
|
||||
property Platform::String ^ Expression; // mandatory
|
||||
property Platform::String ^ Result; // mandatory
|
||||
|
||||
internal :;
|
||||
explicit CalcEnginHistoryItem(const CalculationManager::HISTORYITEM& item);
|
||||
explicit CalcManagerHistoryItem(const CalculationManager::HISTORYITEM& item);
|
||||
};
|
||||
|
||||
public
|
||||
ref struct CalcManagerSnapshot sealed
|
||||
{
|
||||
property Windows::Foundation::Collections::IVector<CalcEnginHistoryItem ^> ^ HistoryItems; // optional
|
||||
property Windows::Foundation::Collections::IVector<CalcManagerHistoryItem ^> ^ HistoryItems; // optional
|
||||
|
||||
internal :;
|
||||
explicit CalcManagerSnapshot(const CalculationManager::CalculatorManager& calcMgr);
|
||||
|
@ -50,7 +55,7 @@ public
|
|||
public
|
||||
ref struct ExpressionDisplaySnapshot sealed
|
||||
{
|
||||
property Windows::Foundation::Collections::IVector<CalcEngineHistoryToken ^> ^ Tokens;
|
||||
property Windows::Foundation::Collections::IVector<CalcManagerHistoryToken ^> ^ Tokens;
|
||||
// TODO: commands
|
||||
|
||||
internal :;
|
||||
|
@ -64,6 +69,6 @@ public
|
|||
property CalcManagerSnapshot ^ CalcManager; // mandatory
|
||||
property PrimaryDisplaySnapshot ^ PrimaryDisplay; // mandatory
|
||||
property ExpressionDisplaySnapshot ^ ExpressionDisplay; // optional
|
||||
// TODO: commands
|
||||
property Windows::Foundation::Collections::IVector<ICalcManagerIExprCommand ^> ^ Commands; // mandatory
|
||||
};
|
||||
}
|
||||
} // namespace CalculatorApp::ViewModel
|
||||
|
|
|
@ -1789,6 +1789,7 @@ void StandardCalculatorViewModel::SetBitshiftRadioButtonCheckedAnnouncement(Plat
|
|||
|
||||
StandardCalculatorSnapshot ^ StandardCalculatorViewModel::GetSnapshot() const
|
||||
{
|
||||
CUnaryCommand;
|
||||
auto result = ref new StandardCalculatorSnapshot();
|
||||
result->CalcManager = ref new CalcManagerSnapshot(m_standardCalculatorManager);
|
||||
result->PrimaryDisplay = ref new PrimaryDisplaySnapshot(m_DisplayValue, m_IsInError);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue