Skip to content

Commit

Permalink
Merge pull request #8138 from lioncash/input-string
Browse files Browse the repository at this point in the history
ControllerInterface/Device: Minor cleanup
  • Loading branch information
leoetlino committed May 30, 2019
2 parents 4e7a790 + 0263435 commit 00ecfb3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
16 changes: 8 additions & 8 deletions Source/Core/InputCommon/ControllerInterface/Device.cpp
Expand Up @@ -52,7 +52,7 @@ std::string Device::GetQualifiedName() const
return StringFromFormat("%s/%i/%s", this->GetSource().c_str(), GetId(), this->GetName().c_str()); return StringFromFormat("%s/%i/%s", this->GetSource().c_str(), GetId(), this->GetName().c_str());
} }


Device::Input* Device::FindInput(const std::string& name) const Device::Input* Device::FindInput(std::string_view name) const
{ {
for (Input* input : m_inputs) for (Input* input : m_inputs)
{ {
Expand All @@ -63,7 +63,7 @@ Device::Input* Device::FindInput(const std::string& name) const
return nullptr; return nullptr;
} }


Device::Output* Device::FindOutput(const std::string& name) const Device::Output* Device::FindOutput(std::string_view name) const
{ {
for (Output* output : m_outputs) for (Output* output : m_outputs)
{ {
Expand All @@ -74,7 +74,7 @@ Device::Output* Device::FindOutput(const std::string& name) const
return nullptr; return nullptr;
} }


bool Device::Control::IsMatchingName(const std::string& name) const bool Device::Control::IsMatchingName(std::string_view name) const
{ {
return GetName() == name; return GetName() == name;
} }
Expand All @@ -90,7 +90,7 @@ std::string Device::FullAnalogSurface::GetName() const
return "Full " + m_high.GetName(); return "Full " + m_high.GetName();
} }


bool Device::FullAnalogSurface::IsMatchingName(const std::string& name) const bool Device::FullAnalogSurface::IsMatchingName(std::string_view name) const
{ {
if (Control::IsMatchingName(name)) if (Control::IsMatchingName(name))
return true; return true;
Expand Down Expand Up @@ -218,7 +218,7 @@ std::string DeviceContainer::GetDefaultDeviceString() const
return device_qualifier.ToString(); return device_qualifier.ToString();
} }


Device::Input* DeviceContainer::FindInput(const std::string& name, const Device* def_dev) const Device::Input* DeviceContainer::FindInput(std::string_view name, const Device* def_dev) const
{ {
if (def_dev) if (def_dev)
{ {
Expand All @@ -239,7 +239,7 @@ Device::Input* DeviceContainer::FindInput(const std::string& name, const Device*
return nullptr; return nullptr;
} }


Device::Output* DeviceContainer::FindOutput(const std::string& name, const Device* def_dev) const Device::Output* DeviceContainer::FindOutput(std::string_view name, const Device* def_dev) const
{ {
return def_dev->FindOutput(name); return def_dev->FindOutput(name);
} }
Expand All @@ -256,7 +256,7 @@ bool DeviceContainer::HasConnectedDevice(const DeviceQualifier& qualifier) const
// and also properly handles detection when using "FullAnalogSurface" inputs. // and also properly handles detection when using "FullAnalogSurface" inputs.
// Upon input, return the detected Device and Input, else return nullptrs // Upon input, return the detected Device and Input, else return nullptrs
std::pair<std::shared_ptr<Device>, Device::Input*> std::pair<std::shared_ptr<Device>, Device::Input*>
DeviceContainer::DetectInput(u32 wait_ms, std::vector<std::string> device_strings) DeviceContainer::DetectInput(u32 wait_ms, const std::vector<std::string>& device_strings) const
{ {
struct InputState struct InputState
{ {
Expand All @@ -273,7 +273,7 @@ DeviceContainer::DetectInput(u32 wait_ms, std::vector<std::string> device_string


// Acquire devices and initial input states. // Acquire devices and initial input states.
std::vector<DeviceState> device_states; std::vector<DeviceState> device_states;
for (auto& device_string : device_strings) for (const auto& device_string : device_strings)
{ {
DeviceQualifier dq; DeviceQualifier dq;
dq.FromString(device_string); dq.FromString(device_string);
Expand Down
21 changes: 11 additions & 10 deletions Source/Core/InputCommon/ControllerInterface/Device.h
Expand Up @@ -8,6 +8,7 @@
#include <mutex> #include <mutex>
#include <optional> #include <optional>
#include <string> #include <string>
#include <string_view>
#include <vector> #include <vector>


#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
Expand Down Expand Up @@ -42,14 +43,14 @@ class Device
class Control // input or output class Control // input or output
{ {
public: public:
virtual ~Control() = default;
virtual std::string GetName() const = 0; virtual std::string GetName() const = 0;
virtual ~Control() {}
virtual Input* ToInput() { return nullptr; } virtual Input* ToInput() { return nullptr; }
virtual Output* ToOutput() { return nullptr; } virtual Output* ToOutput() { return nullptr; }


// May be overridden to allow multiple valid names. // May be overridden to allow multiple valid names.
// Useful for backwards-compatible configurations when names change. // Useful for backwards-compatible configurations when names change.
virtual bool IsMatchingName(const std::string& name) const; virtual bool IsMatchingName(std::string_view name) const;
}; };


// //
Expand Down Expand Up @@ -111,8 +112,8 @@ class Device
const std::vector<Input*>& Inputs() const { return m_inputs; } const std::vector<Input*>& Inputs() const { return m_inputs; }
const std::vector<Output*>& Outputs() const { return m_outputs; } const std::vector<Output*>& Outputs() const { return m_outputs; }


Input* FindInput(const std::string& name) const; Input* FindInput(std::string_view name) const;
Output* FindOutput(const std::string& name) const; Output* FindOutput(std::string_view name) const;


protected: protected:
void AddInput(Input* const i); void AddInput(Input* const i);
Expand All @@ -124,7 +125,7 @@ class Device
FullAnalogSurface(Input* low, Input* high) : m_low(*low), m_high(*high) {} FullAnalogSurface(Input* low, Input* high) : m_low(*low), m_high(*high) {}
ControlState GetState() const override; ControlState GetState() const override;
std::string GetName() const override; std::string GetName() const override;
bool IsMatchingName(const std::string& name) const override; bool IsMatchingName(std::string_view name) const override;


private: private:
Input& m_low; Input& m_low;
Expand Down Expand Up @@ -155,8 +156,8 @@ class DeviceQualifier
{ {
public: public:
DeviceQualifier() : cid(-1) {} DeviceQualifier() : cid(-1) {}
DeviceQualifier(const std::string& _source, const int _id, const std::string& _name) DeviceQualifier(std::string source_, const int id_, std::string name_)
: source(_source), cid(_id), name(_name) : source(std::move(source_)), cid(id_), name(std::move(name_))
{ {
} }
void FromDevice(const Device* const dev); void FromDevice(const Device* const dev);
Expand All @@ -177,8 +178,8 @@ class DeviceQualifier
class DeviceContainer class DeviceContainer
{ {
public: public:
Device::Input* FindInput(const std::string& name, const Device* def_dev) const; Device::Input* FindInput(std::string_view name, const Device* def_dev) const;
Device::Output* FindOutput(const std::string& name, const Device* def_dev) const; Device::Output* FindOutput(std::string_view name, const Device* def_dev) const;


std::vector<std::string> GetAllDeviceStrings() const; std::vector<std::string> GetAllDeviceStrings() const;
std::string GetDefaultDeviceString() const; std::string GetDefaultDeviceString() const;
Expand All @@ -187,7 +188,7 @@ class DeviceContainer
bool HasConnectedDevice(const DeviceQualifier& qualifier) const; bool HasConnectedDevice(const DeviceQualifier& qualifier) const;


std::pair<std::shared_ptr<Device>, Device::Input*> std::pair<std::shared_ptr<Device>, Device::Input*>
DetectInput(u32 wait_ms, std::vector<std::string> device_strings); DetectInput(u32 wait_ms, const std::vector<std::string>& device_strings) const;


protected: protected:
mutable std::mutex m_devices_mutex; mutable std::mutex m_devices_mutex;
Expand Down

0 comments on commit 00ecfb3

Please sign in to comment.