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
|
|
|
|
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
|
|
|
|
|
|
|
namespace ciface
|
|
|
|
{
|
|
|
|
namespace ExpressionParser
|
|
|
|
{
|
|
|
|
class ControlQualifier
|
|
|
|
{
|
|
|
|
public:
|
2016-06-24 02:43:46 -06:00
|
|
|
bool has_device;
|
|
|
|
Core::DeviceQualifier device_qualifier;
|
|
|
|
std::string control_name;
|
2013-06-13 21:09:55 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
ControlQualifier() : has_device(false) {}
|
2017-02-26 00:04:16 -07:00
|
|
|
operator std::string() const
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
if (has_device)
|
|
|
|
return device_qualifier.ToString() + ":" + control_name;
|
|
|
|
else
|
|
|
|
return control_name;
|
|
|
|
}
|
2013-06-13 21:09:55 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
class ControlFinder
|
|
|
|
{
|
|
|
|
public:
|
2016-06-24 02:43:46 -06:00
|
|
|
ControlFinder(const Core::DeviceContainer& container_, const Core::DeviceQualifier& default_,
|
|
|
|
const bool is_input_)
|
|
|
|
: container(container_), default_device(default_), is_input(is_input_)
|
|
|
|
{
|
|
|
|
}
|
2017-02-26 00:04:16 -07:00
|
|
|
std::shared_ptr<Core::Device> FindDevice(ControlQualifier qualifier) const;
|
|
|
|
Core::Device::Control* FindControl(ControlQualifier qualifier) const;
|
2013-06-13 21:09:55 -06:00
|
|
|
|
|
|
|
private:
|
2016-06-24 02:43:46 -06:00
|
|
|
const Core::DeviceContainer& container;
|
|
|
|
const Core::DeviceQualifier& default_device;
|
|
|
|
bool is_input;
|
2013-06-13 21:09:55 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
class ExpressionNode;
|
|
|
|
class Expression
|
|
|
|
{
|
|
|
|
public:
|
2017-06-07 16:29:00 -06:00
|
|
|
explicit Expression(std::unique_ptr<ExpressionNode>&& node = {});
|
2016-06-24 02:43:46 -06:00
|
|
|
~Expression();
|
2017-02-26 00:04:16 -07:00
|
|
|
ControlState GetValue() const;
|
2016-06-24 02:43:46 -06:00
|
|
|
void SetValue(ControlState state);
|
|
|
|
int num_controls;
|
2017-06-07 16:29:00 -06:00
|
|
|
std::unique_ptr<ExpressionNode> node;
|
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,
|
|
|
|
NoDevice,
|
2013-06-13 21:09:55 -06:00
|
|
|
};
|
|
|
|
|
2017-06-07 16:29:00 -06:00
|
|
|
std::pair<ParseStatus, std::unique_ptr<Expression>> ParseExpression(const std::string& expr,
|
|
|
|
ControlFinder& finder);
|
2013-06-13 21:09:55 -06:00
|
|
|
}
|
|
|
|
}
|