dolphin/Source/Core/InputCommon/ControlReference/ExpressionParser.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.0 KiB
C
Raw Normal View History

// Copyright 2013 Dolphin Emulator Project
2015-05-17 23:08:10 +00:00
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <string>
2017-06-07 21:53:41 +00:00
#include <utility>
#include "InputCommon/ControllerInterface/Device.h"
namespace ciface::ExpressionParser
{
class ControlQualifier
{
public:
bool has_device;
Core::DeviceQualifier device_qualifier;
std::string control_name;
ControlQualifier() : has_device(false) {}
operator std::string() const
{
if (has_device)
return device_qualifier.ToString() + ":" + control_name;
else
return control_name;
}
void FromString(const std::string& str)
{
const auto col_pos = str.find_last_of(':');
has_device = (str.npos != col_pos);
if (has_device)
{
device_qualifier.FromString(str.substr(0, col_pos));
control_name = str.substr(col_pos + 1);
}
else
{
device_qualifier.FromString("");
control_name = str;
}
}
};
class ControlFinder
{
public:
ControlFinder(const Core::DeviceContainer& container_, const Core::DeviceQualifier& default_,
const bool is_input_)
: container(container_), default_device(default_), is_input(is_input_)
{
}
std::shared_ptr<Core::Device> FindDevice(ControlQualifier qualifier) const;
Core::Device::Control* FindControl(ControlQualifier qualifier) const;
private:
const Core::DeviceContainer& container;
const Core::DeviceQualifier& default_device;
bool is_input;
};
class Expression
{
public:
virtual ~Expression() = default;
virtual ControlState GetValue() const = 0;
virtual void SetValue(ControlState state) = 0;
virtual int CountNumControls() const = 0;
virtual void UpdateReferences(ControlFinder& finder) = 0;
virtual operator std::string() const = 0;
};
enum class ParseStatus
{
Successful,
SyntaxError,
EmptyExpression,
};
std::pair<ParseStatus, std::unique_ptr<Expression>> ParseExpression(const std::string& expr);
} // namespace ciface::ExpressionParser