ControlReference: put parsed_expression in a unique_ptr

This commit is contained in:
Michael Maltese 2016-12-09 13:57:01 -08:00
parent 492d5b6ac7
commit 2d51bf579f
2 changed files with 13 additions and 18 deletions

View File

@ -29,22 +29,16 @@ bool ControlReference::InputGateOn()
void ControlReference::UpdateReference(ciface::Core::DeviceContainer& devices, void ControlReference::UpdateReference(ciface::Core::DeviceContainer& devices,
const ciface::Core::DeviceQualifier& default_device) const ciface::Core::DeviceQualifier& default_device)
{ {
delete parsed_expression; Expression* expr;
parsed_expression = nullptr;
ControlFinder finder(devices, default_device, IsInput()); ControlFinder finder(devices, default_device, IsInput());
m_parse_status = ParseExpression(expression, finder, &parsed_expression); m_parse_status = ParseExpression(expression, finder, &expr);
} m_parsed_expression.reset(expr);
ControlReference::~ControlReference()
{
delete parsed_expression;
} }
int ControlReference::BoundCount() const int ControlReference::BoundCount() const
{ {
if (parsed_expression) if (m_parsed_expression)
return parsed_expression->num_controls; return m_parsed_expression->num_controls;
else else
return 0; return 0;
} }
@ -54,7 +48,7 @@ ExpressionParseStatus ControlReference::GetParseStatus() const
return m_parse_status; return m_parse_status;
} }
ControlReference::ControlReference() : range(1), parsed_expression(nullptr) ControlReference::ControlReference() : range(1), m_parsed_expression(nullptr)
{ {
} }
@ -83,8 +77,8 @@ bool OutputReference::IsInput() const
// //
ControlState InputReference::State(const ControlState ignore) ControlState InputReference::State(const ControlState ignore)
{ {
if (parsed_expression && InputGateOn()) if (m_parsed_expression && InputGateOn())
return parsed_expression->GetValue() * range; return m_parsed_expression->GetValue() * range;
return 0.0; return 0.0;
} }
@ -98,8 +92,8 @@ ControlState InputReference::State(const ControlState ignore)
// //
ControlState OutputReference::State(const ControlState state) ControlState OutputReference::State(const ControlState state)
{ {
if (parsed_expression && InputGateOn()) if (m_parsed_expression && InputGateOn())
parsed_expression->SetValue(state); m_parsed_expression->SetValue(state);
return 0.0; return 0.0;
} }

View File

@ -4,6 +4,8 @@
#pragma once #pragma once
#include <memory>
#include "InputCommon/ControlReference/ExpressionParser.h" #include "InputCommon/ControlReference/ExpressionParser.h"
#include "InputCommon/ControllerInterface/Device.h" #include "InputCommon/ControllerInterface/Device.h"
@ -22,7 +24,6 @@ class ControlReference
public: public:
static bool InputGateOn(); static bool InputGateOn();
virtual ~ControlReference();
virtual ControlState State(const ControlState state = 0) = 0; virtual ControlState State(const ControlState state = 0) = 0;
virtual ciface::Core::Device::Control* Detect(const unsigned int ms, virtual ciface::Core::Device::Control* Detect(const unsigned int ms,
ciface::Core::Device* const device) = 0; ciface::Core::Device* const device) = 0;
@ -38,7 +39,7 @@ public:
protected: protected:
ControlReference(); ControlReference();
ciface::ExpressionParser::Expression* parsed_expression; std::unique_ptr<ciface::ExpressionParser::Expression> m_parsed_expression;
ciface::ExpressionParser::ExpressionParseStatus m_parse_status; ciface::ExpressionParser::ExpressionParseStatus m_parse_status;
}; };