From f1ff1e3d084c1dd8ae28f2dd8cc409949e378334 Mon Sep 17 00:00:00 2001 From: Michael M Date: Wed, 7 Jun 2017 15:54:59 -0700 Subject: [PATCH] ExpressionParser: clean up ControlExpression --- .../ControlReference/ExpressionParser.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp index 4f498d6f37..277cfb3c70 100644 --- a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp +++ b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp @@ -234,19 +234,19 @@ class ControlExpression : public ExpressionNode public: ControlQualifier qualifier; Device::Control* control; + // Keep a shared_ptr to the device so the control pointer doesn't become invalid + std::shared_ptr m_device; ControlExpression(ControlQualifier qualifier_, std::shared_ptr device, Device::Control* control_) - : qualifier(qualifier_), control(control_), m_device(device) + : qualifier(qualifier_), control(control_), m_device(std::move(device)) { } ControlState GetValue() const override { return control->ToInput()->GetState(); } void SetValue(ControlState value) override { control->ToOutput()->SetState(value); } int CountNumControls() const override { return 1; } - operator std::string() const override { return "`" + (std::string)qualifier + "`"; } -private: - std::shared_ptr m_device; + operator std::string() const override { return "`" + static_cast(qualifier) + "`"; } }; class BinaryExpression : public ExpressionNode @@ -405,7 +405,7 @@ private: return {ParseStatus::NoDevice, std::make_unique(tok.qualifier)}; return {ParseStatus::Successful, - std::make_unique(tok.qualifier, device, control)}; + std::make_unique(tok.qualifier, std::move(device), control)}; } case TOK_LPAREN: return Paren(); @@ -550,8 +550,8 @@ std::pair> ParseExpression(const std::s if (control) { return std::make_pair(ParseStatus::Successful, - std::make_unique( - std::make_unique(qualifier, device, control))); + std::make_unique(std::make_unique( + qualifier, std::move(device), control))); } return ParseExpressionInner(str, finder);