Add equals operation to simpleexpressionvalue to check if an expression is the same as another one

This commit is contained in:
Jan
2021-12-27 14:15:44 +01:00
parent cc88fb0a5a
commit 245a2ed642
11 changed files with 73 additions and 0 deletions

View File

@ -7,6 +7,29 @@ CommonExpressionFunctionCall::CommonExpressionFunctionCall(std::string functionN
{
}
bool CommonExpressionFunctionCall::Equals(const ISimpleExpression* other) const
{
const auto otherFunctionCall = dynamic_cast<const CommonExpressionFunctionCall*>(other);
if (!otherFunctionCall
|| m_function_name != otherFunctionCall->m_function_name
|| m_args.size() != otherFunctionCall->m_args.size())
{
return false;
}
for(auto i = 0u; i < m_args.size(); i++)
{
const auto* arg = m_args[i].get();
const auto* otherArg = otherFunctionCall->m_args[i].get();
if (!arg->Equals(otherArg))
return false;
}
return true;
}
bool CommonExpressionFunctionCall::IsStatic() const
{
return false;

View File

@ -13,6 +13,7 @@ namespace menu
explicit CommonExpressionFunctionCall(std::string functionName);
_NODISCARD bool Equals(const ISimpleExpression* other) const override;
_NODISCARD bool IsStatic() const override;
_NODISCARD SimpleExpressionValue Evaluate() const override;
};