Improving code style : verbosity, indentation levels (#200)
Fixing some nested if() statements and reducing indentation levels. Making some sections less verbose, e.g: if (a == 1) { b = true; } else { b = false; } ↓ b = (a == 1)
This commit is contained in:
parent
cd7c266a6b
commit
b8b0fdf86b
@ -416,8 +416,11 @@ int CHistoryCollector::AddCommand(_In_ const std::shared_ptr<IExpressionCommand>
|
|||||||
// To Update the operands in the Expression according to the current Radix
|
// To Update the operands in the Expression according to the current Radix
|
||||||
void CHistoryCollector::UpdateHistoryExpression(uint32_t radix, int32_t precision)
|
void CHistoryCollector::UpdateHistoryExpression(uint32_t radix, int32_t precision)
|
||||||
{
|
{
|
||||||
if (m_spTokens != nullptr)
|
if (m_spTokens == nullptr)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
IFT(m_spTokens->GetSize(&size));
|
IFT(m_spTokens->GetSize(&size));
|
||||||
|
|
||||||
@ -443,7 +446,6 @@ void CHistoryCollector::UpdateHistoryExpression(uint32_t radix, int32_t precisio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetExpressionDisplay();
|
SetExpressionDisplay();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHistoryCollector::SetDecimalSymbol(wchar_t decimalSymbol)
|
void CHistoryCollector::SetDecimalSymbol(wchar_t decimalSymbol)
|
||||||
|
@ -490,8 +490,12 @@ namespace CalculationManager
|
|||||||
void CalculatorManager::MemorizeNumber()
|
void CalculatorManager::MemorizeNumber()
|
||||||
{
|
{
|
||||||
m_savedCommands.push_back(MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::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);
|
m_currentCalculatorEngine->ProcessCommand(IDC_STORE);
|
||||||
|
|
||||||
auto memoryObjectPtr = m_currentCalculatorEngine->PersistedMemObject();
|
auto memoryObjectPtr = m_currentCalculatorEngine->PersistedMemObject();
|
||||||
@ -506,7 +510,6 @@ namespace CalculationManager
|
|||||||
}
|
}
|
||||||
this->SetMemorizedNumbersString();
|
this->SetMemorizedNumbersString();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Recall the memorized number.
|
/// Recall the memorized number.
|
||||||
@ -516,12 +519,15 @@ namespace CalculationManager
|
|||||||
void CalculatorManager::MemorizedNumberLoad(_In_ unsigned int indexOfMemory)
|
void CalculatorManager::MemorizedNumberLoad(_In_ unsigned int indexOfMemory)
|
||||||
{
|
{
|
||||||
SaveMemoryCommand(MemoryCommand::MemorizedNumberLoad, indexOfMemory);
|
SaveMemoryCommand(MemoryCommand::MemorizedNumberLoad, indexOfMemory);
|
||||||
if (!(m_currentCalculatorEngine->FInErrorState()))
|
|
||||||
|
if (m_currentCalculatorEngine->FInErrorState())
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this->MemorizedNumberSelect(indexOfMemory);
|
this->MemorizedNumberSelect(indexOfMemory);
|
||||||
m_currentCalculatorEngine->ProcessCommand(IDC_RECALL);
|
m_currentCalculatorEngine->ProcessCommand(IDC_RECALL);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Do the addition to the selected memory
|
/// Do the addition to the selected memory
|
||||||
@ -532,8 +538,12 @@ namespace CalculationManager
|
|||||||
void CalculatorManager::MemorizedNumberAdd(_In_ unsigned int indexOfMemory)
|
void CalculatorManager::MemorizedNumberAdd(_In_ unsigned int indexOfMemory)
|
||||||
{
|
{
|
||||||
SaveMemoryCommand(MemoryCommand::MemorizedNumberAdd, indexOfMemory);
|
SaveMemoryCommand(MemoryCommand::MemorizedNumberAdd, indexOfMemory);
|
||||||
if (!(m_currentCalculatorEngine->FInErrorState()))
|
|
||||||
|
if (m_currentCalculatorEngine->FInErrorState())
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_memorizedNumbers.empty())
|
if (m_memorizedNumbers.empty())
|
||||||
{
|
{
|
||||||
this->MemorizeNumber();
|
this->MemorizeNumber();
|
||||||
@ -550,7 +560,6 @@ namespace CalculationManager
|
|||||||
|
|
||||||
m_displayCallback->MemoryItemChanged(indexOfMemory);
|
m_displayCallback->MemoryItemChanged(indexOfMemory);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CalculatorManager::MemorizedNumberClear(_In_ unsigned int indexOfMemory)
|
void CalculatorManager::MemorizedNumberClear(_In_ unsigned int indexOfMemory)
|
||||||
{
|
{
|
||||||
@ -570,8 +579,12 @@ namespace CalculationManager
|
|||||||
void CalculatorManager::MemorizedNumberSubtract(_In_ unsigned int indexOfMemory)
|
void CalculatorManager::MemorizedNumberSubtract(_In_ unsigned int indexOfMemory)
|
||||||
{
|
{
|
||||||
SaveMemoryCommand(MemoryCommand::MemorizedNumberSubtract, 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
|
// To add negative of the number on display to the memory -x = x - 2x
|
||||||
if (m_memorizedNumbers.empty())
|
if (m_memorizedNumbers.empty())
|
||||||
{
|
{
|
||||||
@ -591,7 +604,6 @@ namespace CalculationManager
|
|||||||
|
|
||||||
m_displayCallback->MemoryItemChanged(indexOfMemory);
|
m_displayCallback->MemoryItemChanged(indexOfMemory);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clear all the memorized values
|
/// Clear all the memorized values
|
||||||
@ -613,12 +625,14 @@ namespace CalculationManager
|
|||||||
/// <param name="indexOfMemory">Index of the target memory</param>
|
/// <param name="indexOfMemory">Index of the target memory</param>
|
||||||
void CalculatorManager::MemorizedNumberSelect(_In_ unsigned int indexOfMemory)
|
void CalculatorManager::MemorizedNumberSelect(_In_ unsigned int indexOfMemory)
|
||||||
{
|
{
|
||||||
if (!(m_currentCalculatorEngine->FInErrorState()))
|
if (m_currentCalculatorEngine->FInErrorState())
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto memoryObject = m_memorizedNumbers.at(indexOfMemory);
|
auto memoryObject = m_memorizedNumbers.at(indexOfMemory);
|
||||||
m_currentCalculatorEngine->PersistedMemObject(memoryObject);
|
m_currentCalculatorEngine->PersistedMemObject(memoryObject);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper function that needs to be executed when memory is modified
|
/// Helper function that needs to be executed when memory is modified
|
||||||
@ -627,15 +641,17 @@ namespace CalculationManager
|
|||||||
/// <param name="indexOfMemory">Index of the target memory</param>
|
/// <param name="indexOfMemory">Index of the target memory</param>
|
||||||
void CalculatorManager::MemorizedNumberChanged(_In_ unsigned int indexOfMemory)
|
void CalculatorManager::MemorizedNumberChanged(_In_ unsigned int indexOfMemory)
|
||||||
{
|
{
|
||||||
if (!(m_currentCalculatorEngine->FInErrorState()))
|
if (m_currentCalculatorEngine->FInErrorState())
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto memoryObject = m_currentCalculatorEngine->PersistedMemObject();
|
auto memoryObject = m_currentCalculatorEngine->PersistedMemObject();
|
||||||
if (memoryObject != nullptr)
|
if (memoryObject != nullptr)
|
||||||
{
|
{
|
||||||
m_memorizedNumbers.at(indexOfMemory) = *memoryObject;
|
m_memorizedNumbers.at(indexOfMemory) = *memoryObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CalculatorManager::SaveMemoryCommand(_In_ MemoryCommand command, _In_ unsigned int indexOfMemory)
|
void CalculatorManager::SaveMemoryCommand(_In_ MemoryCommand command, _In_ unsigned int indexOfMemory)
|
||||||
{
|
{
|
||||||
|
@ -109,22 +109,8 @@ CategorySelectionInitializer UnitConverter::SetCurrentCategory(const Category& i
|
|||||||
vector<Unit>& unitVector = m_categoryToUnits[m_currentCategory];
|
vector<Unit>& unitVector = m_categoryToUnits[m_currentCategory];
|
||||||
for (unsigned int i = 0; i < unitVector.size(); i++)
|
for (unsigned int i = 0; i < unitVector.size(); i++)
|
||||||
{
|
{
|
||||||
if (unitVector[i].id == m_fromType.id)
|
unitVector[i].isConversionSource = (unitVector[i].id == m_fromType.id);
|
||||||
{
|
unitVector[i].isConversionTarget = (unitVector[i].id == m_toType.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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
m_currentCategory = input;
|
m_currentCategory = input;
|
||||||
if (!m_currentCategory.supportsNegative && m_currentDisplay.front() == L'-')
|
if (!m_currentCategory.supportsNegative && m_currentDisplay.front() == L'-')
|
||||||
@ -156,15 +142,17 @@ Category UnitConverter::GetCurrentCategory()
|
|||||||
/// <param name="toType">Unit struct we are converting to</param>
|
/// <param name="toType">Unit struct we are converting to</param>
|
||||||
void UnitConverter::SetCurrentUnitTypes(const Unit& fromType, const Unit& toType)
|
void UnitConverter::SetCurrentUnitTypes(const Unit& fromType, const Unit& toType)
|
||||||
{
|
{
|
||||||
if (CheckLoad())
|
if (!CheckLoad())
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_fromType = fromType;
|
m_fromType = fromType;
|
||||||
m_toType = toType;
|
m_toType = toType;
|
||||||
Calculate();
|
Calculate();
|
||||||
|
|
||||||
UpdateCurrencySymbols();
|
UpdateCurrencySymbols();
|
||||||
UpdateViewModel();
|
UpdateViewModel();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -181,8 +169,11 @@ void UnitConverter::SetCurrentUnitTypes(const Unit& fromType, const Unit& toType
|
|||||||
/// </param>
|
/// </param>
|
||||||
void UnitConverter::SwitchActive(const wstring& newValue)
|
void UnitConverter::SwitchActive(const wstring& newValue)
|
||||||
{
|
{
|
||||||
if (CheckLoad())
|
if (!CheckLoad())
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
swap(m_fromType, m_toType);
|
swap(m_fromType, m_toType);
|
||||||
swap(m_currentHasDecimal, m_returnHasDecimal);
|
swap(m_currentHasDecimal, m_returnHasDecimal);
|
||||||
m_returnDisplay = m_currentDisplay;
|
m_returnDisplay = m_currentDisplay;
|
||||||
@ -197,7 +188,6 @@ void UnitConverter::SwitchActive(const wstring& newValue)
|
|||||||
|
|
||||||
m_vmCurrencyCallback->CurrencyRatiosCallback(currencyRatios.first, currencyRatios.second);
|
m_vmCurrencyCallback->CurrencyRatiosCallback(currencyRatios.first, currencyRatios.second);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wstring UnitConverter::CategoryToString(const Category& c, const wchar_t * delimiter)
|
wstring UnitConverter::CategoryToString(const Category& c, const wchar_t * delimiter)
|
||||||
@ -291,8 +281,11 @@ wstring UnitConverter::ConversionDataToString(ConversionData d, const wchar_t *
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
wstring UnitConverter::Serialize()
|
wstring UnitConverter::Serialize()
|
||||||
{
|
{
|
||||||
if (CheckLoad())
|
if (!CheckLoad())
|
||||||
{
|
{
|
||||||
|
return wstring();
|
||||||
|
}
|
||||||
|
|
||||||
wstringstream out(wstringstream::out);
|
wstringstream out(wstringstream::out);
|
||||||
const wchar_t * delimiter = L";";
|
const wchar_t * delimiter = L";";
|
||||||
|
|
||||||
@ -335,11 +328,6 @@ wstring UnitConverter::Serialize()
|
|||||||
out << unitToUnitToDoubleString.str() << "|";
|
out << unitToUnitToDoubleString.str() << "|";
|
||||||
wstring test = out.str();
|
wstring test = out.str();
|
||||||
return test;
|
return test;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return wstring();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -349,8 +337,12 @@ wstring UnitConverter::Serialize()
|
|||||||
void UnitConverter::DeSerialize(const wstring& serializedData)
|
void UnitConverter::DeSerialize(const wstring& serializedData)
|
||||||
{
|
{
|
||||||
Reset();
|
Reset();
|
||||||
if (!serializedData.empty())
|
|
||||||
|
if (serializedData.empty())
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
vector<wstring> outerTokens = StringToVector(serializedData, L"|");
|
vector<wstring> outerTokens = StringToVector(serializedData, L"|");
|
||||||
assert(outerTokens.size() == EXPECTEDSERIALIZEDTOKENCOUNT);
|
assert(outerTokens.size() == EXPECTEDSERIALIZEDTOKENCOUNT);
|
||||||
m_fromType = StringToUnit(outerTokens[0]);
|
m_fromType = StringToUnit(outerTokens[0]);
|
||||||
@ -397,7 +389,6 @@ void UnitConverter::DeSerialize(const wstring& serializedData)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateViewModel();
|
UpdateViewModel();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -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>
|
/// <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)
|
void UnitConverter::RestoreUserPreferences(const wstring& userPreferences)
|
||||||
{
|
{
|
||||||
if (!userPreferences.empty())
|
if (userPreferences.empty())
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
vector<wstring> outerTokens = StringToVector(userPreferences, L"|");
|
vector<wstring> outerTokens = StringToVector(userPreferences, L"|");
|
||||||
if (outerTokens.size() == 3)
|
if (outerTokens.size() == 3)
|
||||||
{
|
{
|
||||||
@ -415,7 +409,6 @@ void UnitConverter::RestoreUserPreferences(const wstring& userPreferences)
|
|||||||
m_toType = StringToUnit(outerTokens[1]);
|
m_toType = StringToUnit(outerTokens[1]);
|
||||||
m_currentCategory = StringToCategory(outerTokens[2]);
|
m_currentCategory = StringToCategory(outerTokens[2]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -503,8 +496,11 @@ wstring UnitConverter::Unquote(const wstring& s)
|
|||||||
/// <param name="command">Command enum representing the command that was entered</param>
|
/// <param name="command">Command enum representing the command that was entered</param>
|
||||||
void UnitConverter::SendCommand(Command command)
|
void UnitConverter::SendCommand(Command command)
|
||||||
{
|
{
|
||||||
if (CheckLoad())
|
if (!CheckLoad())
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Localization of characters
|
// TODO: Localization of characters
|
||||||
bool clearFront = false;
|
bool clearFront = false;
|
||||||
if (m_currentDisplay == L"0")
|
if (m_currentDisplay == L"0")
|
||||||
@ -640,7 +636,6 @@ void UnitConverter::SendCommand(Command command)
|
|||||||
Calculate();
|
Calculate();
|
||||||
|
|
||||||
UpdateViewModel();
|
UpdateViewModel();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -844,8 +839,11 @@ void UnitConverter::Reset()
|
|||||||
ClearValues();
|
ClearValues();
|
||||||
m_switchedActive = false;
|
m_switchedActive = false;
|
||||||
|
|
||||||
if (!m_categories.empty())
|
if (m_categories.empty())
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_currentCategory = m_categories[0];
|
m_currentCategory = m_categories[0];
|
||||||
|
|
||||||
m_categoryToUnits.clear();
|
m_categoryToUnits.clear();
|
||||||
@ -884,7 +882,6 @@ void UnitConverter::Reset()
|
|||||||
|
|
||||||
InitializeSelectedUnits();
|
InitializeSelectedUnits();
|
||||||
Calculate();
|
Calculate();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -1029,8 +1026,11 @@ void UnitConverter::Calculate()
|
|||||||
/// <param name="input">wstring to trim</param>
|
/// <param name="input">wstring to trim</param>
|
||||||
void UnitConverter::TrimString(wstring& returnString)
|
void UnitConverter::TrimString(wstring& returnString)
|
||||||
{
|
{
|
||||||
if (returnString.find(L'.') != m_returnDisplay.npos)
|
if (returnString.find(L'.') == m_returnDisplay.npos)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wstring::iterator iter;
|
wstring::iterator iter;
|
||||||
for (iter = returnString.end() - 1; ;iter--)
|
for (iter = returnString.end() - 1; ;iter--)
|
||||||
{
|
{
|
||||||
@ -1044,7 +1044,6 @@ void UnitConverter::TrimString(wstring& returnString)
|
|||||||
{
|
{
|
||||||
returnString.erase(returnString.end()-1, returnString.end());
|
returnString.erase(returnString.end()-1, returnString.end());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user