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

View File

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