Skip to content
Permalink
Browse files

InputCommon/FunctionExpression: Use Yoda conditions, we do not

The general convention in the codebase is to compare the non-constant
value/string with the constant value/string, not the other way around.
  • Loading branch information
lioncash committed Nov 22, 2019
1 parent 1f60779 commit 814fd165af56289401124989806201a4d110bc08
Showing with 25 additions and 25 deletions.
  1. +25 −25 Source/Core/InputCommon/ControlReference/FunctionExpression.cpp
@@ -23,7 +23,7 @@ class ToggleExpression : public FunctionExpression
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
// Optional 2nd argument for clearing state:
if (1 == args.size() || 2 == args.size())
if (args.size() == 1 || args.size() == 2)
return ArgumentsAreValid{};
else
return ExpectedArguments{"toggle_state_input, [clear_state_input]"};
@@ -62,7 +62,7 @@ class NotExpression : public FunctionExpression
ArgumentValidation
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
if (1 == args.size())
if (args.size() == 1)
return ArgumentsAreValid{};
else
return ExpectedArguments{"expression"};
@@ -79,7 +79,7 @@ class SinExpression : public FunctionExpression
ArgumentValidation
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
if (1 == args.size())
if (args.size() == 1)
return ArgumentsAreValid{};
else
return ExpectedArguments{"expression"};
@@ -95,7 +95,7 @@ class TimerExpression : public FunctionExpression
ArgumentValidation
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
if (1 == args.size())
if (args.size() == 1)
return ArgumentsAreValid{};
else
return ExpectedArguments{"seconds"};
@@ -138,7 +138,7 @@ class IfExpression : public FunctionExpression
ArgumentValidation
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
if (3 == args.size())
if (args.size() == 3)
return ArgumentsAreValid{};
else
return ExpectedArguments{"condition, true_expression, false_expression"};
@@ -158,7 +158,7 @@ class UnaryMinusExpression : public FunctionExpression
ArgumentValidation
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
if (1 == args.size())
if (args.size() == 1)
return ArgumentsAreValid{};
else
return ExpectedArguments{"expression"};
@@ -177,7 +177,7 @@ class DeadzoneExpression : public FunctionExpression
ArgumentValidation
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
if (2 == args.size())
if (args.size() == 2)
return ArgumentsAreValid{};
else
return ExpectedArguments{"input, amount"};
@@ -198,7 +198,7 @@ class SmoothExpression : public FunctionExpression
ArgumentValidation
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
if (2 == args.size() || 3 == args.size())
if (args.size() == 2 || args.size() == 3)
return ArgumentsAreValid{};
else
return ExpectedArguments{"input, seconds_up, seconds_down = seconds_up"};
@@ -213,7 +213,7 @@ class SmoothExpression : public FunctionExpression
const ControlState desired_value = GetArg(0).GetValue();

const ControlState smooth_up = GetArg(1).GetValue();
const ControlState smooth_down = (3 == GetArgCount() ? GetArg(2).GetValue() : smooth_up);
const ControlState smooth_down = GetArgCount() == 3 ? GetArg(2).GetValue() : smooth_up;

const ControlState smooth = (desired_value < m_value) ? smooth_down : smooth_up;
const ControlState max_move = std::chrono::duration_cast<FSec>(elapsed).count() / smooth;
@@ -242,7 +242,7 @@ class HoldExpression : public FunctionExpression
ArgumentValidation
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
if (2 == args.size())
if (args.size() == 2)
return ArgumentsAreValid{};
else
return ExpectedArguments{"input, seconds"};
@@ -281,7 +281,7 @@ class TapExpression : public FunctionExpression
ArgumentValidation
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
if (2 == args.size() || 3 == args.size())
if (args.size() == 2 || args.size() == 3)
return ArgumentsAreValid{};
else
return ExpectedArguments{"input, seconds, taps = 2"};
@@ -298,7 +298,7 @@ class TapExpression : public FunctionExpression

const bool is_time_up = elapsed > seconds;

const u32 desired_taps = (3 == GetArgCount()) ? u32(GetArg(2).GetValue() + 0.5) : 2;
const u32 desired_taps = GetArgCount() == 3 ? u32(GetArg(2).GetValue() + 0.5) : 2;

if (input < CONDITION_THRESHOLD)
{
@@ -400,7 +400,7 @@ class PulseExpression : public FunctionExpression
ArgumentValidation
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
if (2 == args.size())
if (args.size() == 2)
return ArgumentsAreValid{};
else
return ExpectedArguments{"input, seconds"};
@@ -449,29 +449,29 @@ class PulseExpression : public FunctionExpression

std::unique_ptr<FunctionExpression> MakeFunctionExpression(std::string_view name)
{
if ("not" == name)
if (name == "not")
return std::make_unique<NotExpression>();
if ("if" == name)
if (name == "if")
return std::make_unique<IfExpression>();
if ("sin" == name)
if (name == "sin")
return std::make_unique<SinExpression>();
if ("timer" == name)
if (name == "timer")
return std::make_unique<TimerExpression>();
if ("toggle" == name)
if (name == "toggle")
return std::make_unique<ToggleExpression>();
if ("minus" == name)
if (name == "minus")
return std::make_unique<UnaryMinusExpression>();
if ("deadzone" == name)
if (name == "deadzone")
return std::make_unique<DeadzoneExpression>();
if ("smooth" == name)
if (name == "smooth")
return std::make_unique<SmoothExpression>();
if ("hold" == name)
if (name == "hold")
return std::make_unique<HoldExpression>();
if ("tap" == name)
if (name == "tap")
return std::make_unique<TapExpression>();
if ("relative" == name)
if (name == "relative")
return std::make_unique<RelativeExpression>();
if ("pulse" == name)
if (name == "pulse")
return std::make_unique<PulseExpression>();

return nullptr;

0 comments on commit 814fd16

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