calculator/src/CalcManager/ExpressionCommand.h
Scott Freeman 6366e0c535 Replacing CalculatorVector usage with std::vector (#756)
* Replacing CalculatorVector usage with std::vector

Assumptions made here are that memory allocations
are not recoverable.  If it can be proved that an index
will be in range, then the indexing operation is used.
If not (without manual checks) the std::vector::at function
is used to throw an exception in case of a programmer bug.

* Changes based on PR feedback

Using auto& in CalculatorCollector::UpdateHistoryExpression
so the token.first value is properly updated.

Using range for loop to GenerateExpressions.

Setting isEditable directly to the result of boolean expression.

Using token.second directly instead of creating a
separate tokenCommandIndex variable.

* Fixing issue with generating expressions strings.

A space should not be added before the first item.
2019-10-30 10:55:13 -07:00

87 lines
2.8 KiB
C++

// 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 override;
CalculationManager::CommandType GetCommandType() const override;
void Accept(_In_ ISerializeCommandVisitor& commandVisitor) override;
private:
int m_command;
};
class CUnaryCommand final : public IUnaryCommand
{
public:
CUnaryCommand(int command);
CUnaryCommand(int command1, int command2);
const std::shared_ptr<std::vector<int>>& GetCommands() const override;
CalculationManager::CommandType GetCommandType() const override;
void SetCommand(int command) override;
void SetCommands(int command1, int command2) override;
void Accept(_In_ ISerializeCommandVisitor& commandVisitor) override;
private:
std::shared_ptr<std::vector<int>> m_command;
};
class CBinaryCommand final : public IBinaryCommand
{
public:
CBinaryCommand(int command);
void SetCommand(int command) override;
int GetCommand() const override;
CalculationManager::CommandType GetCommandType() const override;
void Accept(_In_ ISerializeCommandVisitor& commandVisitor) override;
private:
int m_command;
};
class COpndCommand final : public IOpndCommand
{
public:
COpndCommand(std::shared_ptr<std::vector<int>> const& commands, bool fNegative, bool fDecimal, bool fSciFmt);
void Initialize(CalcEngine::Rational const& rat);
const std::shared_ptr<std::vector<int>>& GetCommands() const override;
void SetCommands(std::shared_ptr<std::vector<int>> const& commands) override;
void AppendCommand(int command) override;
void ToggleSign() override;
void RemoveFromEnd() override;
bool IsNegative() const override;
bool IsSciFmt() const override;
bool IsDecimalPresent() const override;
const std::wstring& GetToken(wchar_t decimalSymbol) override;
CalculationManager::CommandType GetCommandType() const override;
void Accept(_In_ ISerializeCommandVisitor& commandVisitor) override;
std::wstring GetString(uint32_t radix, int32_t precision);
private:
std::shared_ptr<std::vector<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& paraCmd) = 0;
};