diff options
| -rw-r--r-- | include/parsingtoolbox.h | 2 | ||||
| -rw-r--r-- | parsingtoolbox.cpp | 37 |
2 files changed, 18 insertions, 21 deletions
diff --git a/include/parsingtoolbox.h b/include/parsingtoolbox.h index f8e88af..f3031f2 100644 --- a/include/parsingtoolbox.h +++ b/include/parsingtoolbox.h @@ -381,7 +381,7 @@ private: QMap<QString, BooleanCondition::LogicOperator> m_logicOp; QMap<QString, ValidatorList::LogicOperation> m_logicOperation; QMap<QString, OperationCondition::ConditionOperator> m_conditionOperation; - QHash<QString, Die::ArithmeticOperator> m_arithmeticOperation; + std::vector<std::pair<QString, Die::ArithmeticOperator>> m_arithmeticOperation; QMap<QString, DiceOperator> m_mapDiceOp; QMap<QString, OptionOperator> m_OptionOp; QMap<QString, NodeAction> m_nodeActionMap; diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index e53cf96..e0b1df0 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -74,14 +74,14 @@ ParsingToolBox::ParsingToolBox() m_conditionOperation.insert("%", OperationCondition::Modulo); // m_arithmeticOperation = new QHash<QString,ScalarOperatorNode::ArithmeticOperator>(); - m_arithmeticOperation.insert(QStringLiteral("+"), Die::PLUS); - m_arithmeticOperation.insert(QStringLiteral("-"), Die::MINUS); - m_arithmeticOperation.insert(QStringLiteral("**"), Die::POW); - m_arithmeticOperation.insert(QStringLiteral("*"), Die::MULTIPLICATION); - m_arithmeticOperation.insert(QStringLiteral("x"), Die::MULTIPLICATION); - m_arithmeticOperation.insert(QStringLiteral("|"), Die::INTEGER_DIVIDE); - m_arithmeticOperation.insert(QStringLiteral("/"), Die::DIVIDE); - m_arithmeticOperation.insert(QStringLiteral("÷"), Die::DIVIDE); + m_arithmeticOperation.push_back({QStringLiteral("**"), Die::POW}); + m_arithmeticOperation.push_back({QStringLiteral("+"), Die::PLUS}); + m_arithmeticOperation.push_back({QStringLiteral("-"), Die::MINUS}); + m_arithmeticOperation.push_back({QStringLiteral("*"), Die::MULTIPLICATION}); + m_arithmeticOperation.push_back({QStringLiteral("x"), Die::MULTIPLICATION}); + m_arithmeticOperation.push_back({QStringLiteral("|"), Die::INTEGER_DIVIDE}); + m_arithmeticOperation.push_back({QStringLiteral("/"), Die::DIVIDE}); + m_arithmeticOperation.push_back({QStringLiteral("÷"), Die::DIVIDE}); m_mapDiceOp.insert(QStringLiteral("D"), D); m_mapDiceOp.insert(QStringLiteral("L"), L); @@ -177,19 +177,16 @@ bool ParsingToolBox::readDiceLogicOperator(QString& str, OperationCondition::Con bool ParsingToolBox::readArithmeticOperator(QString& str, Die::ArithmeticOperator& op) { - bool found= false; - // QHash<QString,ScalarOperatorNode::ArithmeticOperator>::Iterator - for(auto i= m_arithmeticOperation.begin(); i != m_arithmeticOperation.end() && !found; ++i) - { - if(str.startsWith(i.key())) - { - op= i.value(); - str= str.remove(0, i.key().size()); - found= true; - } - } - return found; + auto it= std::find_if( + m_arithmeticOperation.begin(), m_arithmeticOperation.end(), + [str](const std::pair<QString, Die::ArithmeticOperator>& pair) { return str.startsWith(pair.first); }); + if(it == m_arithmeticOperation.end()) + return false; + + op= it->second; + str= str.remove(0, it->first.size()); + return true; } bool ParsingToolBox::readLogicOperator(QString& str, BooleanCondition::LogicOperator& op) |