* 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.
52 lines
1.5 KiB
C++
52 lines
1.5 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#pragma once
|
|
#include "ExpressionCommandInterface.h"
|
|
#include "Header Files/IHistoryDisplay.h"
|
|
|
|
namespace CalculationManager
|
|
{
|
|
enum CALCULATOR_MODE
|
|
{
|
|
CM_STD = 0,
|
|
CM_SCI,
|
|
};
|
|
|
|
struct HISTORYITEMVECTOR
|
|
{
|
|
std::shared_ptr<std::vector<std::pair<std::wstring, int>>> spTokens;
|
|
std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> spCommands;
|
|
std::wstring expression;
|
|
std::wstring result;
|
|
};
|
|
|
|
struct HISTORYITEM
|
|
{
|
|
HISTORYITEMVECTOR historyItemVector;
|
|
};
|
|
|
|
class CalculatorHistory : public IHistoryDisplay
|
|
{
|
|
public:
|
|
CalculatorHistory(const size_t maxSize);
|
|
unsigned int AddToHistory(
|
|
_In_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& spTokens,
|
|
_In_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& spCommands,
|
|
std::wstring_view result);
|
|
std::vector<std::shared_ptr<HISTORYITEM>> const& GetHistory();
|
|
std::shared_ptr<HISTORYITEM> const& GetHistoryItem(unsigned int uIdx);
|
|
void ClearHistory();
|
|
unsigned int AddItem(_In_ std::shared_ptr<HISTORYITEM> const& spHistoryItem);
|
|
bool RemoveItem(unsigned int uIdx);
|
|
size_t MaxHistorySize() const
|
|
{
|
|
return m_maxHistorySize;
|
|
}
|
|
|
|
private:
|
|
std::vector<std::shared_ptr<HISTORYITEM>> m_historyItems;
|
|
const size_t m_maxHistorySize;
|
|
};
|
|
}
|