From 7f42432f4205185f474733335c8a4eef26992454 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 28 Nov 2022 09:11:56 -0500 Subject: common/input: Pass ParamPackage by const reference in CreateDevice This was previously being passed by value, which was unnecessary and created more allocations than necessary. --- src/common/input.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/common/input.h') diff --git a/src/common/input.h b/src/common/input.h index cb30b7254..4030ad2e5 100644 --- a/src/common/input.h +++ b/src/common/input.h @@ -417,12 +417,12 @@ std::unique_ptr CreateDeviceFromString(const std::string& param } /** - * Create an input device from given paramters. + * Create an input device from given parameters. * @tparam InputDeviceType the type of input devices to create - * @param A ParamPackage that contains all parameters for creating the device + * @param package A ParamPackage that contains all parameters for creating the device */ template -std::unique_ptr CreateDevice(const Common::ParamPackage package) { +std::unique_ptr CreateDevice(const ParamPackage& package) { const std::string engine = package.Get("engine", "null"); const auto& factory_list = Impl::FactoryList::list; const auto pair = factory_list.find(engine); -- cgit v1.2.3 From 2ec7d0b5fda0fe6cbafcc235e3d8cc91b0dc81e0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 28 Nov 2022 09:19:01 -0500 Subject: common/input: Add helpers functions for creating input and output devices Avoids the redundancy of needing to explictly specify the common namespace and the type. --- src/common/input.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/common/input.h') diff --git a/src/common/input.h b/src/common/input.h index 4030ad2e5..449e0193f 100644 --- a/src/common/input.h +++ b/src/common/input.h @@ -383,6 +383,16 @@ void RegisterFactory(const std::string& name, std::shared_ptr> factory) { + RegisterFactory(name, std::move(factory)); +} + +inline void RegisterOutputFactory(const std::string& name, + std::shared_ptr> factory) { + RegisterFactory(name, std::move(factory)); +} + /** * Unregisters an input device factory. * @tparam InputDeviceType the type of input devices the factory can create @@ -395,6 +405,14 @@ void UnregisterFactory(const std::string& name) { } } +inline void UnregisterInputFactory(const std::string& name) { + UnregisterFactory(name); +} + +inline void UnregisterOutputFactory(const std::string& name) { + UnregisterFactory(name); +} + /** * Create an input device from given paramters. * @tparam InputDeviceType the type of input devices to create @@ -416,6 +434,14 @@ std::unique_ptr CreateDeviceFromString(const std::string& param return pair->second->Create(package); } +inline std::unique_ptr CreateInputDeviceFromString(const std::string& params) { + return CreateDeviceFromString(params); +} + +inline std::unique_ptr CreateOutputDeviceFromString(const std::string& params) { + return CreateDeviceFromString(params); +} + /** * Create an input device from given parameters. * @tparam InputDeviceType the type of input devices to create @@ -435,4 +461,12 @@ std::unique_ptr CreateDevice(const ParamPackage& package) { return pair->second->Create(package); } +inline std::unique_ptr CreateInputDevice(const ParamPackage& package) { + return CreateDevice(package); +} + +inline std::unique_ptr CreateOutputDevice(const ParamPackage& package) { + return CreateDevice(package); +} + } // namespace Common::Input -- cgit v1.2.3