2019-01-29 11:34:36 +08:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
2019-01-29 08:24:37 +08:00
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "ExpressionCommandInterface.h"
|
2019-01-29 11:14:15 +08:00
|
|
|
#include "Header Files/CalcEngine.h"
|
|
|
|
#include "Header Files/Rational.h"
|
2019-01-29 08:24:37 +08:00
|
|
|
|
|
|
|
class CParentheses : public IParenthesisCommand
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CParentheses(_In_ int command);
|
|
|
|
int GetCommand() const;
|
|
|
|
CalculationManager::CommandType GetCommandType() const;
|
|
|
|
void Accept(_In_ ISerializeCommandVisitor &commandVisitor);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_command;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CUnaryCommand : public IUnaryCommand
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CUnaryCommand(int command);
|
|
|
|
CUnaryCommand(int command1, int command2);
|
|
|
|
const std::shared_ptr<CalculatorVector<int>> & GetCommands() const;
|
|
|
|
CalculationManager::CommandType GetCommandType() const;
|
|
|
|
void SetCommand(int command);
|
|
|
|
void SetCommands(int command1, int command2);
|
|
|
|
void Accept(_In_ ISerializeCommandVisitor &commandVisitor);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<CalculatorVector<int>> m_command;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CBinaryCommand : public IBinaryCommand
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CBinaryCommand(int command);
|
|
|
|
void SetCommand(int command);
|
|
|
|
int GetCommand() const;
|
|
|
|
CalculationManager::CommandType GetCommandType() const;
|
|
|
|
void Accept(_In_ ISerializeCommandVisitor &commandVisitor);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_command;
|
|
|
|
};
|
|
|
|
|
|
|
|
class COpndCommand : public IOpndCommand
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
COpndCommand(_In_ std::shared_ptr<CalculatorVector<int>> const &commands,
|
2019-01-29 11:14:15 +08:00
|
|
|
bool fNegative,
|
|
|
|
bool fDecimal,
|
|
|
|
bool fSciFmt);
|
2019-01-29 08:24:37 +08:00
|
|
|
~COpndCommand();
|
2019-01-29 11:34:36 +08:00
|
|
|
void Initialize(CalcEngine::Rational const& rat);
|
2019-01-29 08:24:37 +08:00
|
|
|
|
|
|
|
const std::shared_ptr<CalculatorVector<int>> & GetCommands() const;
|
|
|
|
void SetCommands(std::shared_ptr<CalculatorVector<int>> const& commands);
|
|
|
|
void AppendCommand(int command);
|
|
|
|
void ToggleSign();
|
|
|
|
void RemoveFromEnd();
|
|
|
|
bool IsNegative() const;
|
|
|
|
bool IsSciFmt() const;
|
|
|
|
bool IsDecimalPresent() const;
|
|
|
|
const std::wstring & GetToken(wchar_t decimalSymbol);
|
|
|
|
CalculationManager::CommandType GetCommandType() const;
|
|
|
|
void Accept(_In_ ISerializeCommandVisitor &commandVisitor);
|
|
|
|
std::wstring GetString(uint32_t radix, int32_t precision, wchar_t decimalSymbol);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<CalculatorVector<int>> m_commands;
|
|
|
|
bool m_fNegative;
|
|
|
|
bool m_fSciFmt;
|
|
|
|
bool m_fDecimal;
|
2019-01-29 11:34:36 +08:00
|
|
|
bool m_fInitialized;
|
2019-01-29 08:24:37 +08:00
|
|
|
std::wstring m_token;
|
2019-01-29 11:14:15 +08:00
|
|
|
CalcEngine::Rational m_value;
|
2019-01-29 08:24:37 +08:00
|
|
|
void ClearAllAndAppendCommand(CalculationManager::Command command);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ISerializeCommandVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void Visit(_In_ COpndCommand &opndCmd) = 0;
|
|
|
|
virtual void Visit(_In_ CUnaryCommand &unaryCmd) = 0;
|
|
|
|
virtual void Visit(_In_ CBinaryCommand &binaryCmd) = 0;
|
|
|
|
virtual void Visit(_In_ CParentheses ¶Cmd) = 0;
|
|
|
|
};
|