ExpressionParser: Add optional 2nd argument to toggle function which clears state.

This commit is contained in:
Jordan Woyak 2019-01-26 13:18:20 -06:00
parent fd07ae8cec
commit 6a2096c419
2 changed files with 13 additions and 1 deletions

View File

@ -32,7 +32,8 @@ class ToggleExpression : public FunctionExpression
private: private:
virtual bool ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override 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 ControlState GetValue() const override
@ -49,6 +50,11 @@ private:
m_state ^= true; m_state ^= true;
} }
if (2 == GetArgCount() && GetArg(1).GetValue() > CONDITION_THRESHOLD)
{
m_state = false;
}
return m_state; return m_state;
} }
@ -257,5 +263,10 @@ const Expression& FunctionExpression::GetArg(u32 number) const
return *m_args[number]; return *m_args[number];
} }
u32 FunctionExpression::GetArgCount() const
{
return u32(m_args.size());
}
} // namespace ExpressionParser } // namespace ExpressionParser
} // namespace ciface } // namespace ciface

View File

@ -30,6 +30,7 @@ protected:
Expression& GetArg(u32 number); Expression& GetArg(u32 number);
const Expression& GetArg(u32 number) const; const Expression& GetArg(u32 number) const;
u32 GetArgCount() const;
private: private:
std::vector<std::unique_ptr<Expression>> m_args; std::vector<std::unique_ptr<Expression>> m_args;