From c3d3581240ce07d46da008010adb965576dbef56 Mon Sep 17 00:00:00 2001 From: Nicholas Baron <35079404+Nicholas-Baron@users.noreply.github.com> Date: Thu, 11 Jul 2019 10:46:13 -0700 Subject: [PATCH] Applying NR 1 to CalculatorVector.h (#491) Applied [NR 1](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rnr-top) from the ISO C++ Guidelines to CalculatorVector.h ### Description of the changes: - Move towards understandable and maintainable code --- src/CalcManager/CalculatorVector.h | 36 +++++++++++++----------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/CalcManager/CalculatorVector.h b/src/CalcManager/CalculatorVector.h index bd82abb..4a139c8 100644 --- a/src/CalcManager/CalculatorVector.h +++ b/src/CalcManager/CalculatorVector.h @@ -16,16 +16,15 @@ class CalculatorVector public: ResultCode GetAt(_In_opt_ unsigned int index, _Out_ TType* item) { - ResultCode hr = S_OK; try { *item = m_vector.at(index); } catch (const std::out_of_range& /*ex*/) { - hr = E_BOUNDS; + return E_BOUNDS; } - return hr; + return S_OK; } ResultCode GetSize(_Out_ unsigned int* size) @@ -36,35 +35,32 @@ public: ResultCode SetAt(_In_ unsigned int index, _In_opt_ TType item) { - ResultCode hr = S_OK; try { m_vector[index] = item; } catch (const std::out_of_range& /*ex*/) { - hr = E_BOUNDS; + return E_BOUNDS; } - return hr; + return S_OK; } ResultCode RemoveAt(_In_ unsigned int index) { - ResultCode hr = S_OK; if (index < m_vector.size()) { m_vector.erase(m_vector.begin() + index); } else { - hr = E_BOUNDS; + return E_BOUNDS; } - return hr; + return S_OK; } ResultCode InsertAt(_In_ unsigned int index, _In_ TType item) { - ResultCode hr = S_OK; try { auto iter = m_vector.begin() + index; @@ -72,14 +68,13 @@ public: } catch (const std::bad_alloc& /*ex*/) { - hr = E_OUTOFMEMORY; + return E_OUTOFMEMORY; } - return hr; + return S_OK; } ResultCode Truncate(_In_ unsigned int index) { - ResultCode hr = S_OK; if (index < m_vector.size()) { auto startIter = m_vector.begin() + index; @@ -87,23 +82,22 @@ public: } else { - hr = E_BOUNDS; + return E_BOUNDS; } - return hr; + return S_OK; } ResultCode Append(_In_opt_ TType item) { - ResultCode hr = S_OK; try { m_vector.push_back(item); } catch (const std::bad_alloc& /*ex*/) { - hr = E_OUTOFMEMORY; + return E_OUTOFMEMORY; } - return hr; + return S_OK; } ResultCode RemoveAtEnd() @@ -120,12 +114,12 @@ public: ResultCode GetString(_Out_ std::wstring* expression) { - ResultCode hr = S_OK; unsigned int nTokens = 0; - std::pair currentPair; - hr = this->GetSize(&nTokens); + ResultCode hr = this->GetSize(&nTokens); if (SUCCEEDED(hr)) { + + std::pair currentPair; for (unsigned int i = 0; i < nTokens; i++) { hr = this->GetAt(i, ¤tPair);