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
|
|
|
|
2019-03-08 11:46:53 +08:00
|
|
|
class CParentheses final : public IParenthesisCommand
|
2019-01-29 08:24:37 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CParentheses(_In_ int command);
|
2019-03-09 03:18:01 +08:00
|
|
|
int GetCommand() const override;
|
|
|
|
CalculationManager::CommandType GetCommandType() const override;
|
2019-05-03 02:59:19 +08:00
|
|
|
void Accept(_In_ ISerializeCommandVisitor& commandVisitor) override;
|
2019-01-29 08:24:37 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
int m_command;
|
|
|
|
};
|
|
|
|
|
2019-03-08 11:46:53 +08:00
|
|
|
class CUnaryCommand final : public IUnaryCommand
|
2019-01-29 08:24:37 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CUnaryCommand(int command);
|
|
|
|
CUnaryCommand(int command1, int command2);
|
2019-10-31 01:55:13 +08:00
|
|
|
const std::shared_ptr<std::vector<int>>& GetCommands() const override;
|
2019-03-09 03:18:01 +08:00
|
|
|
CalculationManager::CommandType GetCommandType() const override;
|
|
|
|
void SetCommand(int command) override;
|
|
|
|
void SetCommands(int command1, int command2) override;
|
2019-05-03 02:59:19 +08:00
|
|
|
void Accept(_In_ ISerializeCommandVisitor& commandVisitor) override;
|
2019-01-29 08:24:37 +08:00
|
|
|
|
|
|
|
private:
|
2019-10-31 01:55:13 +08:00
|
|
|
std::shared_ptr<std::vector<int>> m_command;
|
2019-01-29 08:24:37 +08:00
|
|
|
};
|
|
|
|
|
2019-03-08 11:46:53 +08:00
|
|
|
class CBinaryCommand final : public IBinaryCommand
|
2019-01-29 08:24:37 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CBinaryCommand(int command);
|
2019-03-09 03:18:01 +08:00
|
|
|
void SetCommand(int command) override;
|
|
|
|
int GetCommand() const override;
|
|
|
|
CalculationManager::CommandType GetCommandType() const override;
|
2019-05-03 02:59:19 +08:00
|
|
|
void Accept(_In_ ISerializeCommandVisitor& commandVisitor) override;
|
2019-01-29 08:24:37 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
int m_command;
|
|
|
|
};
|
|
|
|
|
2019-03-08 11:46:53 +08:00
|
|
|
class COpndCommand final : public IOpndCommand
|
2019-01-29 08:24:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2019-10-31 01:55:13 +08:00
|
|
|
COpndCommand(std::shared_ptr<std::vector<int>> const& commands, bool fNegative, bool fDecimal, bool fSciFmt);
|
2019-01-29 11:34:36 +08:00
|
|
|
void Initialize(CalcEngine::Rational const& rat);
|
2019-01-29 08:24:37 +08:00
|
|
|
|
2019-10-31 01:55:13 +08:00
|
|
|
const std::shared_ptr<std::vector<int>>& GetCommands() const override;
|
|
|
|
void SetCommands(std::shared_ptr<std::vector<int>> const& commands) override;
|
2019-03-09 03:18:01 +08:00
|
|
|
void AppendCommand(int command) override;
|
|
|
|
void ToggleSign() override;
|
|
|
|
void RemoveFromEnd() override;
|
|
|
|
bool IsNegative() const override;
|
|
|
|
bool IsSciFmt() const override;
|
|
|
|
bool IsDecimalPresent() const override;
|
2019-05-03 02:59:19 +08:00
|
|
|
const std::wstring& GetToken(wchar_t decimalSymbol) override;
|
2019-03-09 03:18:01 +08:00
|
|
|
CalculationManager::CommandType GetCommandType() const override;
|
2019-05-03 02:59:19 +08:00
|
|
|
void Accept(_In_ ISerializeCommandVisitor& commandVisitor) override;
|
2019-03-09 15:15:28 +08:00
|
|
|
std::wstring GetString(uint32_t radix, int32_t precision);
|
2019-01-29 08:24:37 +08:00
|
|
|
|
|
|
|
private:
|
2019-10-31 01:55:13 +08:00
|
|
|
std::shared_ptr<std::vector<int>> m_commands;
|
2019-01-29 08:24:37 +08:00
|
|
|
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:
|
2019-05-03 02:59:19 +08:00
|
|
|
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& paraCmd) = 0;
|
2019-01-29 08:24:37 +08:00
|
|
|
};
|