Some more refactoring

This commit is contained in:
Cyril Garsaud 2019-03-08 13:03:43 +01:00
commit 874e049532
3 changed files with 44 additions and 36 deletions

View file

@ -409,34 +409,36 @@ 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)
{ {
unsigned int size; return;
IFT(m_spTokens->GetSize(&size)); }
for (unsigned int i = 0; i < size; ++i) unsigned int size;
IFT(m_spTokens->GetSize(&size));
for (unsigned int i = 0; i < size; ++i)
{
std::pair<std::wstring, int> token;
IFT(m_spTokens->GetAt(i, &token));
int commandPosition = token.second;
if (commandPosition != -1)
{ {
std::pair<std::wstring, int> token; std::shared_ptr<IExpressionCommand> expCommand;
IFT(m_spTokens->GetAt(i, &token)); IFT(m_spCommands->GetAt(commandPosition, &expCommand));
int commandPosition = token.second; if (expCommand != nullptr && CalculationManager::CommandType::OperandCommand == expCommand->GetCommandType())
if (commandPosition != -1)
{ {
std::shared_ptr<IExpressionCommand> expCommand; std::shared_ptr<COpndCommand> opndCommand = std::static_pointer_cast<COpndCommand>(expCommand);
IFT(m_spCommands->GetAt(commandPosition, &expCommand)); if (opndCommand != nullptr)
if (expCommand != nullptr && CalculationManager::CommandType::OperandCommand == expCommand->GetCommandType())
{ {
std::shared_ptr<COpndCommand> opndCommand = std::static_pointer_cast<COpndCommand>(expCommand); token.first = opndCommand->GetString(radix, precision, m_decimalSymbol);
if (opndCommand != nullptr) IFT(m_spTokens->SetAt(i, token));
{ opndCommand->SetCommands(GetOperandCommandsFromString(token.first));
token.first = opndCommand->GetString(radix, precision, m_decimalSymbol);
IFT(m_spTokens->SetAt(i, token));
opndCommand->SetCommands(GetOperandCommandsFromString(token.first));
}
} }
} }
} }
SetExpressionDisplay();
} }
SetExpressionDisplay();
} }
void CHistoryCollector::SetDecimalSymbol(wchar_t decimalSymbol) void CHistoryCollector::SetDecimalSymbol(wchar_t decimalSymbol)

View file

@ -484,7 +484,8 @@ namespace CalculationManager
{ {
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; return;
} }
@ -512,7 +513,8 @@ namespace CalculationManager
{ {
SaveMemoryCommand(MemoryCommand::MemorizedNumberLoad, indexOfMemory); SaveMemoryCommand(MemoryCommand::MemorizedNumberLoad, indexOfMemory);
if (m_currentCalculatorEngine->FInErrorState()) { if (m_currentCalculatorEngine->FInErrorState())
{
return; return;
} }
@ -530,7 +532,8 @@ namespace CalculationManager
{ {
SaveMemoryCommand(MemoryCommand::MemorizedNumberAdd, indexOfMemory); SaveMemoryCommand(MemoryCommand::MemorizedNumberAdd, indexOfMemory);
if (m_currentCalculatorEngine->FInErrorState()) { if (m_currentCalculatorEngine->FInErrorState())
{
return; return;
} }
@ -570,7 +573,8 @@ namespace CalculationManager
{ {
SaveMemoryCommand(MemoryCommand::MemorizedNumberSubtract, indexOfMemory); SaveMemoryCommand(MemoryCommand::MemorizedNumberSubtract, indexOfMemory);
if (m_currentCalculatorEngine->FInErrorState()) { if (m_currentCalculatorEngine->FInErrorState())
{
return; return;
} }
@ -614,7 +618,8 @@ 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; return;
} }
@ -629,7 +634,8 @@ 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; return;
} }

View file

@ -338,7 +338,7 @@ void UnitConverter::DeSerialize(const wstring& serializedData)
{ {
Reset(); Reset();
if (!serializedData.empty()) if (serializedData.empty())
{ {
return; return;
} }