Refacto: less indent levels

This commit is contained in:
Cyril Garsaud 2019-03-08 12:21:49 +01:00
commit 2cfb2f2973
2 changed files with 384 additions and 375 deletions

View file

@ -483,8 +483,11 @@ namespace CalculationManager
void CalculatorManager::MemorizeNumber()
{
m_savedCommands.push_back(MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizeNumber));
if (!(m_currentCalculatorEngine->FInErrorState()))
{
if (m_currentCalculatorEngine->FInErrorState()) {
return;
}
m_currentCalculatorEngine->ProcessCommand(IDC_STORE);
auto memoryObjectPtr = m_currentCalculatorEngine->PersistedMemObject();
@ -499,7 +502,6 @@ namespace CalculationManager
}
this->SetMemorizedNumbersString();
}
}
/// <summary>
/// Recall the memorized number.
@ -509,12 +511,14 @@ namespace CalculationManager
void CalculatorManager::MemorizedNumberLoad(_In_ unsigned int indexOfMemory)
{
SaveMemoryCommand(MemoryCommand::MemorizedNumberLoad, indexOfMemory);
if (!(m_currentCalculatorEngine->FInErrorState()))
{
if (m_currentCalculatorEngine->FInErrorState()) {
return;
}
this->MemorizedNumberSelect(indexOfMemory);
m_currentCalculatorEngine->ProcessCommand(IDC_RECALL);
}
}
/// <summary>
/// Do the addition to the selected memory
@ -525,8 +529,11 @@ namespace CalculationManager
void CalculatorManager::MemorizedNumberAdd(_In_ unsigned int indexOfMemory)
{
SaveMemoryCommand(MemoryCommand::MemorizedNumberAdd, indexOfMemory);
if (!(m_currentCalculatorEngine->FInErrorState()))
{
if (m_currentCalculatorEngine->FInErrorState()) {
return;
}
if (m_memorizedNumbers.empty())
{
this->MemorizeNumber();
@ -543,7 +550,6 @@ namespace CalculationManager
m_displayCallback->MemoryItemChanged(indexOfMemory);
}
}
void CalculatorManager::MemorizedNumberClear(_In_ unsigned int indexOfMemory)
{
@ -563,8 +569,11 @@ namespace CalculationManager
void CalculatorManager::MemorizedNumberSubtract(_In_ unsigned int indexOfMemory)
{
SaveMemoryCommand(MemoryCommand::MemorizedNumberSubtract, indexOfMemory);
if (!(m_currentCalculatorEngine->FInErrorState()))
{
if (m_currentCalculatorEngine->FInErrorState()) {
return;
}
// To add negative of the number on display to the memory -x = x - 2x
if (m_memorizedNumbers.empty())
{
@ -584,7 +593,6 @@ namespace CalculationManager
m_displayCallback->MemoryItemChanged(indexOfMemory);
}
}
/// <summary>
/// Clear all the memorized values
@ -606,12 +614,13 @@ namespace CalculationManager
/// <param name="indexOfMemory">Index of the target memory</param>
void CalculatorManager::MemorizedNumberSelect(_In_ unsigned int indexOfMemory)
{
if (!(m_currentCalculatorEngine->FInErrorState()))
{
if (m_currentCalculatorEngine->FInErrorState()) {
return;
}
auto memoryObject = m_memorizedNumbers.at(indexOfMemory);
m_currentCalculatorEngine->PersistedMemObject(memoryObject);
}
}
/// <summary>
/// Helper function that needs to be executed when memory is modified
@ -620,15 +629,16 @@ namespace CalculationManager
/// <param name="indexOfMemory">Index of the target memory</param>
void CalculatorManager::MemorizedNumberChanged(_In_ unsigned int indexOfMemory)
{
if (!(m_currentCalculatorEngine->FInErrorState()))
{
if (m_currentCalculatorEngine->FInErrorState()) {
return;
}
auto memoryObject = m_currentCalculatorEngine->PersistedMemObject();
if (memoryObject != nullptr)
{
m_memorizedNumbers.at(indexOfMemory) = *memoryObject;
}
}
}
void CalculatorManager::SaveMemoryCommand(_In_ MemoryCommand command, _In_ unsigned int indexOfMemory)
{

View file

@ -109,22 +109,8 @@ CategorySelectionInitializer UnitConverter::SetCurrentCategory(const Category& i
vector<Unit>& unitVector = m_categoryToUnits[m_currentCategory];
for (unsigned int i = 0; i < unitVector.size(); i++)
{
if (unitVector[i].id == m_fromType.id)
{
unitVector[i].isConversionSource = true;
}
else
{
unitVector[i].isConversionSource = false;
}
if (unitVector[i].id == m_toType.id)
{
unitVector[i].isConversionTarget = true;
}
else
{
unitVector[i].isConversionTarget = false;
}
unitVector[i].isConversionSource = (unitVector[i].id == m_fromType.id);
unitVector[i].isConversionTarget = (unitVector[i].id == m_toType.id);
}
m_currentCategory = input;
if (!m_currentCategory.supportsNegative && m_currentDisplay.front() == L'-')
@ -156,8 +142,11 @@ Category UnitConverter::GetCurrentCategory()
/// <param name="toType">Unit struct we are converting to</param>
void UnitConverter::SetCurrentUnitTypes(const Unit& fromType, const Unit& toType)
{
if (CheckLoad())
if (!CheckLoad())
{
return;
}
m_fromType = fromType;
m_toType = toType;
Calculate();
@ -165,7 +154,6 @@ void UnitConverter::SetCurrentUnitTypes(const Unit& fromType, const Unit& toType
UpdateCurrencySymbols();
UpdateViewModel();
}
}
/// <summary>
/// Switches the active field, indicating that we are now entering data into
@ -181,8 +169,11 @@ void UnitConverter::SetCurrentUnitTypes(const Unit& fromType, const Unit& toType
/// </param>
void UnitConverter::SwitchActive(const wstring& newValue)
{
if (CheckLoad())
if (!CheckLoad())
{
return;
}
swap(m_fromType, m_toType);
swap(m_currentHasDecimal, m_returnHasDecimal);
m_returnDisplay = m_currentDisplay;
@ -198,7 +189,6 @@ void UnitConverter::SwitchActive(const wstring& newValue)
m_vmCurrencyCallback->CurrencyRatiosCallback(currencyRatios.first, currencyRatios.second);
}
}
}
wstring UnitConverter::CategoryToString(const Category& c, const wchar_t * delimiter)
{
@ -291,8 +281,11 @@ wstring UnitConverter::ConversionDataToString(ConversionData d, const wchar_t *
/// </summary>
wstring UnitConverter::Serialize()
{
if (CheckLoad())
if (!CheckLoad())
{
return wstring();
}
wstringstream out(wstringstream::out);
const wchar_t * delimiter = L";";
@ -336,11 +329,6 @@ wstring UnitConverter::Serialize()
wstring test = out.str();
return test;
}
else
{
return wstring();
}
}
/// <summary>
/// De-Serializes the data in the converter from a string
@ -349,8 +337,12 @@ wstring UnitConverter::Serialize()
void UnitConverter::DeSerialize(const wstring& serializedData)
{
Reset();
if (!serializedData.empty())
{
return;
}
vector<wstring> outerTokens = StringToVector(serializedData, L"|");
assert(outerTokens.size() == EXPECTEDSERIALIZEDTOKENCOUNT);
m_fromType = StringToUnit(outerTokens[0]);
@ -398,7 +390,6 @@ void UnitConverter::DeSerialize(const wstring& serializedData)
}
UpdateViewModel();
}
}
/// <summary>
/// De-Serializes the data in the converter from a string
@ -406,8 +397,11 @@ void UnitConverter::DeSerialize(const wstring& serializedData)
/// <param name="userPreferences">wstring holding the serialized data. If it does not have expected number of parameters, we will ignore it</param>
void UnitConverter::RestoreUserPreferences(const wstring& userPreferences)
{
if (!userPreferences.empty())
if (userPreferences.empty())
{
return;
}
vector<wstring> outerTokens = StringToVector(userPreferences, L"|");
if (outerTokens.size() == 3)
{
@ -416,7 +410,6 @@ void UnitConverter::RestoreUserPreferences(const wstring& userPreferences)
m_currentCategory = StringToCategory(outerTokens[2]);
}
}
}
/// <summary>
/// Serializes the Category and Associated Units in the converter and returns it as a string
@ -505,6 +498,9 @@ void UnitConverter::SendCommand(Command command)
{
if (CheckLoad())
{
return;
}
//TODO: Localization of characters
bool clearFront = false;
if (m_currentDisplay == L"0")
@ -641,7 +637,6 @@ void UnitConverter::SendCommand(Command command)
UpdateViewModel();
}
}
/// <summary>
/// Sets the callback interface to send display update calls to
@ -844,8 +839,11 @@ void UnitConverter::Reset()
ClearValues();
m_switchedActive = false;
if (!m_categories.empty())
if (m_categories.empty())
{
return;
}
m_currentCategory = m_categories[0];
m_categoryToUnits.clear();
@ -885,7 +883,6 @@ void UnitConverter::Reset()
InitializeSelectedUnits();
Calculate();
}
}
/// <summary>
/// Sets the active data loader based on the input category.
@ -1029,8 +1026,11 @@ void UnitConverter::Calculate()
/// <param name="input">wstring to trim</param>
void UnitConverter::TrimString(wstring& returnString)
{
if (returnString.find(L'.') != m_returnDisplay.npos)
if (returnString.find(L'.') == m_returnDisplay.npos)
{
return;
}
wstring::iterator iter;
for (iter = returnString.end() - 1; ;iter--)
{
@ -1045,7 +1045,6 @@ void UnitConverter::TrimString(wstring& returnString)
returnString.erase(returnString.end()-1, returnString.end());
}
}
}
/// <summary>
/// Rounds the given double to the given number of significant digits