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
|
||||
void CHistoryCollector::UpdateHistoryExpression(uint32_t radix, int32_t precision)
|
||||
{
|
||||
if (m_spTokens != nullptr)
|
||||
if (m_spTokens == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int size;
|
||||
IFT(m_spTokens->GetSize(&size));
|
||||
|
||||
@ -444,7 +447,6 @@ void CHistoryCollector::UpdateHistoryExpression(uint32_t radix, int32_t precisio
|
||||
}
|
||||
SetExpressionDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
void CHistoryCollector::SetDecimalSymbol(wchar_t decimalSymbol)
|
||||
{
|
||||
|
@ -490,8 +490,12 @@ 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();
|
||||
@ -506,7 +510,6 @@ namespace CalculationManager
|
||||
}
|
||||
this->SetMemorizedNumbersString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recall the memorized number.
|
||||
@ -516,12 +519,15 @@ 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
|
||||
@ -532,8 +538,12 @@ 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();
|
||||
@ -550,7 +560,6 @@ namespace CalculationManager
|
||||
|
||||
m_displayCallback->MemoryItemChanged(indexOfMemory);
|
||||
}
|
||||
}
|
||||
|
||||
void CalculatorManager::MemorizedNumberClear(_In_ unsigned int indexOfMemory)
|
||||
{
|
||||
@ -570,8 +579,12 @@ 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())
|
||||
{
|
||||
@ -591,7 +604,6 @@ namespace CalculationManager
|
||||
|
||||
m_displayCallback->MemoryItemChanged(indexOfMemory);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear all the memorized values
|
||||
@ -613,12 +625,14 @@ 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
|
||||
@ -627,15 +641,17 @@ 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)
|
||||
{
|
||||
|
@ -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())
|
||||
|
||||
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
|
||||
@ -503,8 +496,11 @@ wstring UnitConverter::Unquote(const wstring& s)
|
||||
/// <param name="command">Command enum representing the command that was entered</param>
|
||||
void UnitConverter::SendCommand(Command command)
|
||||
{
|
||||
if (CheckLoad())
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user