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:
Scott Freeman
2019-10-30 13:55:13 -04:00
committed by Rudy Huyn
parent 25cdca991c
commit 6366e0c535
29 changed files with 244 additions and 480 deletions

View File

@@ -13,8 +13,8 @@ using namespace Platform;
HistoryItemViewModel::HistoryItemViewModel(
String ^ expression,
String ^ result,
_In_ const shared_ptr<CalculatorVector<pair<wstring, int>>>& spTokens,
_In_ const shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>>& spCommands)
_In_ const shared_ptr<vector<pair<wstring, int>>>& spTokens,
_In_ const shared_ptr<vector<shared_ptr<IExpressionCommand>>>& spCommands)
: m_expression(expression)
, m_result(result)
, m_spTokens(spTokens)
@@ -27,37 +27,17 @@ HistoryItemViewModel::HistoryItemViewModel(
String
^ HistoryItemViewModel::GetAccessibleExpressionFromTokens(
_In_ shared_ptr<CalculatorVector<pair<wstring, int>>> const& spTokens,
_In_ shared_ptr<vector<pair<wstring, int>>> const& spTokens,
_In_ String ^ fallbackExpression)
{
// updating accessibility names for expression and result
wstringstream accExpression{};
accExpression << L"";
unsigned int nTokens;
HRESULT hr = spTokens->GetSize(&nTokens);
if (SUCCEEDED(hr))
for (const auto& tokenItem : *spTokens)
{
pair<wstring, int> tokenItem;
for (unsigned int i = 0; i < nTokens; i++)
{
hr = spTokens->GetAt(i, &tokenItem);
if (FAILED(hr))
{
break;
}
wstring token = tokenItem.first;
accExpression << LocalizationService::GetNarratorReadableToken(StringReference(token.c_str()))->Data();
}
accExpression << LocalizationService::GetNarratorReadableToken(StringReference(tokenItem.first.c_str()))->Data();
}
if (FAILED(hr))
{
return LocalizationService::GetNarratorReadableString(fallbackExpression);
}
else
{
return ref new String(accExpression.str().c_str());
}
return ref new String(accExpression.str().c_str());
}