mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-13 18:16:49 -07:00
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
3 changed files with 406 additions and 389 deletions
|
@ -490,22 +490,25 @@ namespace CalculationManager
|
|||
void CalculatorManager::MemorizeNumber()
|
||||
{
|
||||
m_savedCommands.push_back(MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizeNumber));
|
||||
if (!(m_currentCalculatorEngine->FInErrorState()))
|
||||
|
||||
if (m_currentCalculatorEngine->FInErrorState())
|
||||
{
|
||||
m_currentCalculatorEngine->ProcessCommand(IDC_STORE);
|
||||
|
||||
auto memoryObjectPtr = m_currentCalculatorEngine->PersistedMemObject();
|
||||
if (memoryObjectPtr != nullptr)
|
||||
{
|
||||
m_memorizedNumbers.insert(m_memorizedNumbers.begin(), *memoryObjectPtr);
|
||||
}
|
||||
|
||||
if (m_memorizedNumbers.size() > m_maximumMemorySize)
|
||||
{
|
||||
m_memorizedNumbers.resize(m_maximumMemorySize);
|
||||
}
|
||||
this->SetMemorizedNumbersString();
|
||||
return;
|
||||
}
|
||||
|
||||
m_currentCalculatorEngine->ProcessCommand(IDC_STORE);
|
||||
|
||||
auto memoryObjectPtr = m_currentCalculatorEngine->PersistedMemObject();
|
||||
if (memoryObjectPtr != nullptr)
|
||||
{
|
||||
m_memorizedNumbers.insert(m_memorizedNumbers.begin(), *memoryObjectPtr);
|
||||
}
|
||||
|
||||
if (m_memorizedNumbers.size() > m_maximumMemorySize)
|
||||
{
|
||||
m_memorizedNumbers.resize(m_maximumMemorySize);
|
||||
}
|
||||
this->SetMemorizedNumbersString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -516,11 +519,14 @@ namespace CalculationManager
|
|||
void CalculatorManager::MemorizedNumberLoad(_In_ unsigned int indexOfMemory)
|
||||
{
|
||||
SaveMemoryCommand(MemoryCommand::MemorizedNumberLoad, indexOfMemory);
|
||||
if (!(m_currentCalculatorEngine->FInErrorState()))
|
||||
|
||||
if (m_currentCalculatorEngine->FInErrorState())
|
||||
{
|
||||
this->MemorizedNumberSelect(indexOfMemory);
|
||||
m_currentCalculatorEngine->ProcessCommand(IDC_RECALL);
|
||||
return;
|
||||
}
|
||||
|
||||
this->MemorizedNumberSelect(indexOfMemory);
|
||||
m_currentCalculatorEngine->ProcessCommand(IDC_RECALL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -532,24 +538,27 @@ namespace CalculationManager
|
|||
void CalculatorManager::MemorizedNumberAdd(_In_ unsigned int indexOfMemory)
|
||||
{
|
||||
SaveMemoryCommand(MemoryCommand::MemorizedNumberAdd, indexOfMemory);
|
||||
if (!(m_currentCalculatorEngine->FInErrorState()))
|
||||
|
||||
if (m_currentCalculatorEngine->FInErrorState())
|
||||
{
|
||||
if (m_memorizedNumbers.empty())
|
||||
{
|
||||
this->MemorizeNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->MemorizedNumberSelect(indexOfMemory);
|
||||
m_currentCalculatorEngine->ProcessCommand(IDC_MPLUS);
|
||||
|
||||
this->MemorizedNumberChanged(indexOfMemory);
|
||||
|
||||
this->SetMemorizedNumbersString();
|
||||
}
|
||||
|
||||
m_displayCallback->MemoryItemChanged(indexOfMemory);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_memorizedNumbers.empty())
|
||||
{
|
||||
this->MemorizeNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->MemorizedNumberSelect(indexOfMemory);
|
||||
m_currentCalculatorEngine->ProcessCommand(IDC_MPLUS);
|
||||
|
||||
this->MemorizedNumberChanged(indexOfMemory);
|
||||
|
||||
this->SetMemorizedNumbersString();
|
||||
}
|
||||
|
||||
m_displayCallback->MemoryItemChanged(indexOfMemory);
|
||||
}
|
||||
|
||||
void CalculatorManager::MemorizedNumberClear(_In_ unsigned int indexOfMemory)
|
||||
|
@ -570,27 +579,30 @@ namespace CalculationManager
|
|||
void CalculatorManager::MemorizedNumberSubtract(_In_ unsigned int indexOfMemory)
|
||||
{
|
||||
SaveMemoryCommand(MemoryCommand::MemorizedNumberSubtract, indexOfMemory);
|
||||
if (!(m_currentCalculatorEngine->FInErrorState()))
|
||||
|
||||
if (m_currentCalculatorEngine->FInErrorState())
|
||||
{
|
||||
// To add negative of the number on display to the memory -x = x - 2x
|
||||
if (m_memorizedNumbers.empty())
|
||||
{
|
||||
this->MemorizeNumber();
|
||||
this->MemorizedNumberSubtract(0);
|
||||
this->MemorizedNumberSubtract(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->MemorizedNumberSelect(indexOfMemory);
|
||||
m_currentCalculatorEngine->ProcessCommand(IDC_MMINUS);
|
||||
|
||||
this->MemorizedNumberChanged(indexOfMemory);
|
||||
|
||||
this->SetMemorizedNumbersString();
|
||||
}
|
||||
|
||||
m_displayCallback->MemoryItemChanged(indexOfMemory);
|
||||
return;
|
||||
}
|
||||
|
||||
// To add negative of the number on display to the memory -x = x - 2x
|
||||
if (m_memorizedNumbers.empty())
|
||||
{
|
||||
this->MemorizeNumber();
|
||||
this->MemorizedNumberSubtract(0);
|
||||
this->MemorizedNumberSubtract(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->MemorizedNumberSelect(indexOfMemory);
|
||||
m_currentCalculatorEngine->ProcessCommand(IDC_MMINUS);
|
||||
|
||||
this->MemorizedNumberChanged(indexOfMemory);
|
||||
|
||||
this->SetMemorizedNumbersString();
|
||||
}
|
||||
|
||||
m_displayCallback->MemoryItemChanged(indexOfMemory);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -613,11 +625,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())
|
||||
{
|
||||
auto memoryObject = m_memorizedNumbers.at(indexOfMemory);
|
||||
m_currentCalculatorEngine->PersistedMemObject(memoryObject);
|
||||
return;
|
||||
}
|
||||
|
||||
auto memoryObject = m_memorizedNumbers.at(indexOfMemory);
|
||||
m_currentCalculatorEngine->PersistedMemObject(memoryObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -627,13 +641,15 @@ 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())
|
||||
{
|
||||
auto memoryObject = m_currentCalculatorEngine->PersistedMemObject();
|
||||
if (memoryObject != nullptr)
|
||||
{
|
||||
m_memorizedNumbers.at(indexOfMemory) = *memoryObject;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
auto memoryObject = m_currentCalculatorEngine->PersistedMemObject();
|
||||
if (memoryObject != nullptr)
|
||||
{
|
||||
m_memorizedNumbers.at(indexOfMemory) = *memoryObject;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue