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.
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
#include "CCommand.h"
|
||||
#include "EngineStrings.h"
|
||||
#include "../Command.h"
|
||||
#include "../CalculatorVector.h"
|
||||
#include "../ExpressionCommand.h"
|
||||
#include "RadixType.h"
|
||||
#include "History.h" // for History Collector
|
||||
|
@@ -51,8 +51,8 @@ private:
|
||||
int m_curOperandIndex; // Stack index for the above stack
|
||||
bool m_bLastOpndBrace; // iff the last opnd in history is already braced so we can avoid putting another one for unary operator
|
||||
wchar_t m_decimalSymbol;
|
||||
std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> m_spTokens;
|
||||
std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> m_spCommands;
|
||||
std::shared_ptr<std::vector<std::pair<std::wstring, int>>> m_spTokens;
|
||||
std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> m_spCommands;
|
||||
|
||||
private:
|
||||
void ReinitHistory();
|
||||
@@ -60,5 +60,5 @@ private:
|
||||
void TruncateEquationSzFromIch(int ich);
|
||||
void SetExpressionDisplay();
|
||||
void InsertSzInEquationSz(std::wstring_view str, int icommandIndex, int ich);
|
||||
std::shared_ptr<CalculatorVector<int>> GetOperandCommandsFromString(std::wstring_view numStr);
|
||||
std::shared_ptr<std::vector<int>> GetOperandCommandsFromString(std::wstring_view numStr);
|
||||
};
|
||||
|
@@ -3,7 +3,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../CalculatorVector.h"
|
||||
#include "../ExpressionCommandInterface.h"
|
||||
|
||||
// Callback interface to be implemented by the clients of CCalcEngine
|
||||
@@ -13,8 +12,8 @@ public:
|
||||
virtual void SetPrimaryDisplay(const std::wstring& pszText, bool isError) = 0;
|
||||
virtual void SetIsInError(bool isInError) = 0;
|
||||
virtual void SetExpressionDisplay(
|
||||
_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens,
|
||||
_Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& commands) = 0;
|
||||
_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens,
|
||||
_Inout_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& commands) = 0;
|
||||
virtual void SetParenthesisNumber(_In_ unsigned int count) = 0;
|
||||
virtual void OnNoRightParenAdded() = 0;
|
||||
virtual void MaxDigitsReached() = 0; // not an error but still need to inform UI layer.
|
||||
|
@@ -1,15 +1,17 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../ExpressionCommandInterface.h"
|
||||
|
||||
// Callback interface to be implemented by the clients of CCalcEngine if they require equation history
|
||||
class IHistoryDisplay
|
||||
{
|
||||
public:
|
||||
virtual ~IHistoryDisplay(){};
|
||||
virtual unsigned int AddToHistory(
|
||||
_In_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens,
|
||||
_In_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& commands,
|
||||
_In_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens,
|
||||
_In_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& commands,
|
||||
_In_ std::wstring_view result) = 0;
|
||||
};
|
||||
|
Reference in New Issue
Block a user