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 "pch.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "Snapshots.h"
|
#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
|
namespace CalculatorApp::ViewModel
|
||||||
{
|
{
|
||||||
CalcEngineHistoryToken::CalcEngineHistoryToken(Platform::String ^ opCodeName, int cmdIndex)
|
CalcManagerHistoryToken::CalcManagerHistoryToken(Platform::String ^ opCodeName, int cmdIndex)
|
||||||
{
|
{
|
||||||
assert(opCodeName != nullptr && "opCodeName is mandatory.");
|
assert(opCodeName != nullptr && "opCodeName is mandatory.");
|
||||||
OpCodeName = opCodeName;
|
OpCodeName = opCodeName;
|
||||||
CommandIndex = cmdIndex;
|
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)
|
if (item.historyItemVector.spTokens != nullptr)
|
||||||
{
|
{
|
||||||
for (auto& [opCode, cmdIdx] : *item.historyItemVector.spTokens)
|
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());
|
Expression = ref new Platform::String(item.historyItemVector.expression.c_str());
|
||||||
|
@ -36,7 +112,7 @@ namespace CalculatorApp::ViewModel
|
||||||
{
|
{
|
||||||
for (auto& item : items)
|
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)
|
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)
|
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
|
namespace CalculatorApp::ViewModel
|
||||||
{
|
{
|
||||||
public
|
public
|
||||||
ref struct CalcEngineHistoryToken sealed
|
interface struct ICalcManagerIExprCommand
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
public
|
||||||
|
ref struct CalcManagerHistoryToken sealed
|
||||||
{
|
{
|
||||||
property Platform::String ^ OpCodeName; // mandatory
|
property Platform::String ^ OpCodeName; // mandatory
|
||||||
property int CommandIndex;
|
property int CommandIndex;
|
||||||
|
|
||||||
internal :;
|
internal :;
|
||||||
explicit CalcEngineHistoryToken(Platform::String ^ opCodeName, int cmdIndex);
|
explicit CalcManagerHistoryToken(Platform::String ^ opCodeName, int cmdIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
public
|
public
|
||||||
ref struct CalcEnginHistoryItem sealed
|
ref struct CalcManagerHistoryItem sealed
|
||||||
{
|
{
|
||||||
property Windows::Foundation::Collections::IVector<CalcEngineHistoryToken ^> ^ Tokens; // mandatory
|
property Windows::Foundation::Collections::IVector<CalcManagerHistoryToken ^> ^ Tokens; // mandatory
|
||||||
// TODO: commands
|
property Windows::Foundation::Collections::IVector<ICalcManagerIExprCommand ^> ^ Commands; // mandatory
|
||||||
property Platform::String ^ Expression; // mandatory
|
property Platform::String ^ Expression; // mandatory
|
||||||
property Platform::String ^ Result; // mandatory
|
property Platform::String ^ Result; // mandatory
|
||||||
|
|
||||||
internal :;
|
internal :;
|
||||||
explicit CalcEnginHistoryItem(const CalculationManager::HISTORYITEM& item);
|
explicit CalcManagerHistoryItem(const CalculationManager::HISTORYITEM& item);
|
||||||
};
|
};
|
||||||
|
|
||||||
public
|
public
|
||||||
ref struct CalcManagerSnapshot sealed
|
ref struct CalcManagerSnapshot sealed
|
||||||
{
|
{
|
||||||
property Windows::Foundation::Collections::IVector<CalcEnginHistoryItem ^> ^ HistoryItems; // optional
|
property Windows::Foundation::Collections::IVector<CalcManagerHistoryItem ^> ^ HistoryItems; // optional
|
||||||
|
|
||||||
internal :;
|
internal :;
|
||||||
explicit CalcManagerSnapshot(const CalculationManager::CalculatorManager& calcMgr);
|
explicit CalcManagerSnapshot(const CalculationManager::CalculatorManager& calcMgr);
|
||||||
|
@ -50,7 +55,7 @@ public
|
||||||
public
|
public
|
||||||
ref struct ExpressionDisplaySnapshot sealed
|
ref struct ExpressionDisplaySnapshot sealed
|
||||||
{
|
{
|
||||||
property Windows::Foundation::Collections::IVector<CalcEngineHistoryToken ^> ^ Tokens;
|
property Windows::Foundation::Collections::IVector<CalcManagerHistoryToken ^> ^ Tokens;
|
||||||
// TODO: commands
|
// TODO: commands
|
||||||
|
|
||||||
internal :;
|
internal :;
|
||||||
|
@ -61,9 +66,9 @@ public
|
||||||
public
|
public
|
||||||
ref struct StandardCalculatorSnapshot sealed
|
ref struct StandardCalculatorSnapshot sealed
|
||||||
{
|
{
|
||||||
property CalcManagerSnapshot ^ CalcManager; // mandatory
|
property CalcManagerSnapshot ^ CalcManager; // mandatory
|
||||||
property PrimaryDisplaySnapshot ^ PrimaryDisplay; // mandatory
|
property PrimaryDisplaySnapshot ^ PrimaryDisplay; // mandatory
|
||||||
property ExpressionDisplaySnapshot ^ ExpressionDisplay; // optional
|
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
|
StandardCalculatorSnapshot ^ StandardCalculatorViewModel::GetSnapshot() const
|
||||||
{
|
{
|
||||||
|
CUnaryCommand;
|
||||||
auto result = ref new StandardCalculatorSnapshot();
|
auto result = ref new StandardCalculatorSnapshot();
|
||||||
result->CalcManager = ref new CalcManagerSnapshot(m_standardCalculatorManager);
|
result->CalcManager = ref new CalcManagerSnapshot(m_standardCalculatorManager);
|
||||||
result->PrimaryDisplay = ref new PrimaryDisplaySnapshot(m_DisplayValue, m_IsInError);
|
result->PrimaryDisplay = ref new PrimaryDisplaySnapshot(m_DisplayValue, m_IsInError);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue