forked from microsoft/calculator
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExpressionCommand.h
More file actions
90 lines (79 loc) · 2.67 KB
/
ExpressionCommand.h
File metadata and controls
90 lines (79 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#include "ExpressionCommandInterface.h"
#include "Header Files/CalcEngine.h"
#include "Header Files/Rational.h"
class CParentheses final : 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 final : 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 final : 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 final : public IOpndCommand
{
public:
COpndCommand(
std::shared_ptr<CalculatorVector<int>> const &commands,
bool fNegative,
bool fDecimal,
bool fSciFmt);
void Initialize(CalcEngine::Rational const& rat);
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;
bool m_fInitialized;
std::wstring m_token;
CalcEngine::Rational m_value;
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;
};