Skip to content
Permalink
Browse files

ExpressionParser: Add optional 2nd argument to toggle function which …

…clears state.
  • Loading branch information...
jordan-woyak committed Jan 26, 2019
1 parent fd07ae8 commit 6a2096c41977d6c33c2ca20494d9f623bed221ff
@@ -32,7 +32,8 @@ class ToggleExpression : public FunctionExpression
private:
virtual bool ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
return 1 == args.size();
// Optional 2nd argument for clearing state:
return 1 == args.size() || 2 == args.size();
}

ControlState GetValue() const override
@@ -49,6 +50,11 @@ class ToggleExpression : public FunctionExpression
m_state ^= true;
}

if (2 == GetArgCount() && GetArg(1).GetValue() > CONDITION_THRESHOLD)
{
m_state = false;
}

return m_state;
}

@@ -257,5 +263,10 @@ const Expression& FunctionExpression::GetArg(u32 number) const
return *m_args[number];
}

u32 FunctionExpression::GetArgCount() const
{
return u32(m_args.size());
}

} // namespace ExpressionParser
} // namespace ciface
@@ -30,6 +30,7 @@ class FunctionExpression : public Expression

Expression& GetArg(u32 number);
const Expression& GetArg(u32 number) const;
u32 GetArgCount() const;

private:
std::vector<std::unique_ptr<Expression>> m_args;

0 comments on commit 6a2096c

Please sign in to comment.
You can’t perform that action at this time.