2014-02-10 11:54:46 -07:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2014-02-10 11:54:46 -07:00
|
|
|
// Refer to the license.txt file included.
|
2013-06-13 21:09:55 -06:00
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2013-06-13 21:09:55 -06:00
|
|
|
|
2018-12-30 15:06:29 -07:00
|
|
|
#include <map>
|
2016-06-25 21:34:09 -06:00
|
|
|
#include <memory>
|
2013-06-13 21:09:55 -06:00
|
|
|
#include <string>
|
2017-06-07 15:53:41 -06:00
|
|
|
#include <utility>
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
2013-06-13 21:09:55 -06:00
|
|
|
|
2019-06-17 14:39:24 -06:00
|
|
|
namespace ciface::ExpressionParser
|
2013-06-13 21:09:55 -06:00
|
|
|
{
|
|
|
|
class ControlQualifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool has_device;
|
|
|
|
Core::DeviceQualifier device_qualifier;
|
|
|
|
std::string control_name;
|
|
|
|
|
|
|
|
ControlQualifier() : has_device(false) {}
|
2018-12-30 09:37:23 -07:00
|
|
|
|
2017-02-26 00:04:16 -07:00
|
|
|
operator std::string() const
|
2013-06-13 21:09:55 -06:00
|
|
|
{
|
|
|
|
if (has_device)
|
|
|
|
return device_qualifier.ToString() + ":" + control_name;
|
|
|
|
else
|
|
|
|
return control_name;
|
|
|
|
}
|
2018-12-30 09:37:23 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2013-06-13 21:09:55 -06:00
|
|
|
};
|
|
|
|
|
2018-12-30 15:06:29 -07:00
|
|
|
class ControlEnvironment
|
2013-06-13 21:09:55 -06:00
|
|
|
{
|
|
|
|
public:
|
2018-12-30 15:06:29 -07:00
|
|
|
using VariableContainer = std::map<std::string, ControlState>;
|
|
|
|
|
|
|
|
ControlEnvironment(const Core::DeviceContainer& container_, const Core::DeviceQualifier& default_,
|
|
|
|
VariableContainer& vars)
|
|
|
|
: m_variables(vars), container(container_), default_device(default_)
|
2013-06-13 21:09:55 -06:00
|
|
|
{
|
|
|
|
}
|
2018-12-30 15:06:29 -07:00
|
|
|
|
2017-02-26 00:04:16 -07:00
|
|
|
std::shared_ptr<Core::Device> FindDevice(ControlQualifier qualifier) const;
|
2018-12-30 15:06:29 -07:00
|
|
|
Core::Device::Input* FindInput(ControlQualifier qualifier) const;
|
|
|
|
Core::Device::Output* FindOutput(ControlQualifier qualifier) const;
|
|
|
|
ControlState* GetVariablePtr(const std::string& name);
|
2013-06-13 21:09:55 -06:00
|
|
|
|
|
|
|
private:
|
2018-12-30 15:06:29 -07:00
|
|
|
VariableContainer& m_variables;
|
2013-06-13 21:09:55 -06:00
|
|
|
const Core::DeviceContainer& container;
|
|
|
|
const Core::DeviceQualifier& default_device;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Expression
|
|
|
|
{
|
|
|
|
public:
|
2017-06-07 18:30:07 -06:00
|
|
|
virtual ~Expression() = default;
|
|
|
|
virtual ControlState GetValue() const = 0;
|
|
|
|
virtual void SetValue(ControlState state) = 0;
|
|
|
|
virtual int CountNumControls() const = 0;
|
2018-12-30 15:06:29 -07:00
|
|
|
virtual void UpdateReferences(ControlEnvironment& finder) = 0;
|
2017-06-07 18:30:07 -06:00
|
|
|
virtual operator std::string() const = 0;
|
2013-06-13 21:09:55 -06:00
|
|
|
};
|
|
|
|
|
2017-02-28 02:58:03 -07:00
|
|
|
enum class ParseStatus
|
2013-06-13 21:09:55 -06:00
|
|
|
{
|
2017-04-02 04:13:12 -06:00
|
|
|
Successful,
|
2017-02-28 02:58:03 -07:00
|
|
|
SyntaxError,
|
2017-06-07 17:03:36 -06:00
|
|
|
EmptyExpression,
|
2013-06-13 21:09:55 -06:00
|
|
|
};
|
|
|
|
|
2017-06-07 19:48:17 -06:00
|
|
|
std::pair<ParseStatus, std::unique_ptr<Expression>> ParseExpression(const std::string& expr);
|
2019-06-17 14:39:24 -06:00
|
|
|
} // namespace ciface::ExpressionParser
|