diff --git a/src/ipcgull b/src/ipcgull index 745329e..4f22a43 160000 --- a/src/ipcgull +++ b/src/ipcgull @@ -1 +1 @@ -Subproject commit 745329ed9d41051ddb6e4010229d4b54d868e1a4 +Subproject commit 4f22a43e3380dc1e9c0a490201f4d745390b623f diff --git a/src/logid/backend/hidpp/Device.h b/src/logid/backend/hidpp/Device.h index fb7ca02..838b9d6 100644 --- a/src/logid/backend/hidpp/Device.h +++ b/src/logid/backend/hidpp/Device.h @@ -38,24 +38,25 @@ namespace logid::backend::hidpp10 { namespace logid::backend::hidpp { struct DeviceConnectionEvent; - namespace { - template - class DeviceWrapper : public T { - friend class Device; - public: - template - explicit DeviceWrapper(Args... args) : T(std::forward(args)...) { } + template + class _deviceWrapper : public T { + friend class Device; - template - static std::shared_ptr make(Args... args) { - return std::make_shared(std::forward(args)...); - } - }; - } + public: + template + explicit _deviceWrapper(Args... args) : T(std::forward(args)...) {} + + template + static std::shared_ptr make(Args... args) { + return std::make_shared<_deviceWrapper>(std::forward(args)...); + } + }; class Device { - template - friend class DeviceWrapper; + template + friend + class _deviceWrapper; + public: struct EventHandler { std::function condition; @@ -102,7 +103,9 @@ namespace logid::backend::hidpp { [[nodiscard]] const std::shared_ptr& rawDevice() const; Device(const Device&) = delete; + Device(Device&&) = delete; + virtual ~Device() = default; protected: @@ -161,16 +164,16 @@ namespace logid::backend::hidpp { std::weak_ptr _self; protected: - template + template static std::shared_ptr makeDerived(Args... args) { - auto device = DeviceWrapper::make(std::forward(args)...); + auto device = _deviceWrapper::make(std::forward(args)...); device->_self = device; device->_setupReportsAndInit(); return device; } public: - template + template static std::shared_ptr make(Args... args) { return makeDerived(std::forward(args)...); } diff --git a/src/logid/backend/hidpp10/ReceiverMonitor.h b/src/logid/backend/hidpp10/ReceiverMonitor.h index 1dcd140..32b6df6 100644 --- a/src/logid/backend/hidpp10/ReceiverMonitor.h +++ b/src/logid/backend/hidpp10/ReceiverMonitor.h @@ -26,20 +26,19 @@ namespace logid::backend::hidpp10 { - namespace { - template - class ReceiverMonitorWrapper : public T { - friend class ReceiverMonitor; - public: - template - explicit ReceiverMonitorWrapper(Args... args) : T(std::forward(args)...) { } + template + class _receiverMonitorWrapper : public T { + friend class ReceiverMonitor; - template - static std::shared_ptr make(Args... args) { - return std::make_shared(std::forward(args)...); - } - }; - } + public: + template + explicit _receiverMonitorWrapper(Args... args) : T(std::forward(args)...) {} + + template + static std::shared_ptr make(Args... args) { + return std::make_shared<_receiverMonitorWrapper>(std::forward(args)...); + } + }; static constexpr int max_tries = 5; static constexpr int ready_backoff = 250; @@ -50,7 +49,9 @@ namespace logid::backend::hidpp10 { void enumerate(); ReceiverMonitor(const ReceiverMonitor&) = delete; + ReceiverMonitor(ReceiverMonitor&&) = delete; + protected: ReceiverMonitor(const std::string& path, const std::shared_ptr& monitor, @@ -101,9 +102,9 @@ namespace logid::backend::hidpp10 { std::weak_ptr _self; public: - template + template static std::shared_ptr make(Args... args) { - auto receiver_monitor = ReceiverMonitorWrapper::make(std::forward(args)...); + auto receiver_monitor = _receiverMonitorWrapper::make(std::forward(args)...); receiver_monitor->_self = receiver_monitor; receiver_monitor->_ready(); return receiver_monitor; diff --git a/src/logid/backend/raw/DeviceMonitor.h b/src/logid/backend/raw/DeviceMonitor.h index 6eadf8e..851a004 100644 --- a/src/logid/backend/raw/DeviceMonitor.h +++ b/src/logid/backend/raw/DeviceMonitor.h @@ -36,21 +36,19 @@ namespace logid::backend::raw { static constexpr int max_tries = 5; static constexpr int ready_backoff = 500; - namespace { - template - class DeviceMonitorWrapper : public T { - friend class Device; + template + class _deviceMonitorWrapper : public T { + friend class Device; - public: - template - explicit DeviceMonitorWrapper(Args... args) : T(std::forward(args)...) {} + public: + template + explicit _deviceMonitorWrapper(Args... args) : T(std::forward(args)...) {} - template - static std::shared_ptr make(Args... args) { - return std::make_shared(std::forward(args)...); - } - }; - } + template + static std::shared_ptr make(Args... args) { + return std::make_shared<_deviceMonitorWrapper>(std::forward(args)...); + } + }; class DeviceMonitor { public: @@ -62,7 +60,7 @@ namespace logid::backend::raw { template static std::shared_ptr make(Args... args) { - auto device_monitor = DeviceMonitorWrapper::make(std::forward(args)...); + auto device_monitor = _deviceMonitorWrapper::make(std::forward(args)...); device_monitor->_self = device_monitor; device_monitor->ready(); @@ -79,7 +77,7 @@ namespace logid::backend::raw { virtual void removeDevice(std::string device) = 0; - template + template [[nodiscard]] std::weak_ptr self() const { return std::dynamic_pointer_cast(_self.lock()); } diff --git a/src/logid/config/group.h b/src/logid/config/group.h index 79bcc25..e7b301a 100644 --- a/src/logid/config/group.h +++ b/src/logid/config/group.h @@ -38,55 +38,45 @@ namespace logid::config { template void append(libconfig::Setting& list, const T& t); - namespace { - template - struct group_io { - }; + template + struct group_io { + }; - template - struct group_io { - static inline void get( - [[maybe_unused]] const libconfig::Setting& s, - [[maybe_unused]] T* t, - [[maybe_unused]] const std::vector& names, - [[maybe_unused]] const std::size_t index) {} + template + struct group_io { + static void get(const libconfig::Setting&, T*, + const std::vector&, const std::size_t) {} - static inline void set( - [[maybe_unused]] libconfig::Setting& s, - [[maybe_unused]] const T* t, - [[maybe_unused]] const std::vector& names, - [[maybe_unused]] const std::size_t index) {} - }; + static void set(libconfig::Setting&, const T*, + const std::vector&, const std::size_t) {} + }; - template - struct group_io { - static inline void get( - const libconfig::Setting& s, T* t, - const std::vector& names, - const std::size_t index, A T::* arg, M T::*... rest) { - auto& x = t->*(arg); - A old{x}; - try { - x = config::get(s, names[index]); - group_io::get(s, t, names, index + 1, rest...); - } catch (libconfig::SettingTypeException& e) { - x = old; - throw; - } catch (libconfig::SettingException& e) { - x = old; - throw libconfig::SettingTypeException(s); - } + template + struct group_io { + static void get(const libconfig::Setting& s, T* t, + const std::vector& names, + const std::size_t index, A T::* arg, M T::*... rest) { + auto& x = t->*(arg); + A old{x}; + try { + x = config::get(s, names[index]); + group_io::get(s, t, names, index + 1, rest...); + } catch (libconfig::SettingTypeException& e) { + x = old; + throw; + } catch (libconfig::SettingException& e) { + x = old; + throw libconfig::SettingTypeException(s); } + } - static inline void set( - libconfig::Setting& s, const T* t, - const std::vector& names, - const std::size_t index, A T::* arg, M T::*... rest) { - config::set(s, names[index], t->*(arg)); - group_io::set(s, t, names, index + 1, rest...); - } - }; - } + static void set(libconfig::Setting& s, const T* t, + const std::vector& names, + const std::size_t index, A T::* arg, M T::*... rest) { + config::set(s, names[index], t->*(arg)); + group_io::set(s, t, names, index + 1, rest...); + } + }; template struct signed_group; @@ -149,22 +139,19 @@ namespace logid::config { } }; - namespace { - template - struct normalize_signature { - static inline const T& make(const T& ret) { return ret; } - }; + template + struct normalize_signature { + static const T& make(const T& ret) { return ret; } + }; - template<> - struct normalize_signature { - static inline std::string make(const std::string& data) { - std::string ret = data; - std::transform(ret.begin(), ret.end(), - ret.begin(), ::tolower); - return ret; - } - }; - } + template<> + struct normalize_signature { + static std::string make(const std::string& data) { + std::string ret = data; + std::transform(ret.begin(), ret.end(), ret.begin(), ::tolower); + return ret; + } + }; template struct signed_group : public group { diff --git a/src/logid/config/types.h b/src/logid/config/types.h index 70e41e3..ef17a75 100644 --- a/src/logid/config/types.h +++ b/src/logid/config/types.h @@ -33,416 +33,402 @@ namespace logid::config { void logError(const libconfig::Setting& setting, std::exception& e); - namespace { - template - struct config_io { - static_assert(std::is_base_of::value); + template + struct config_io { + static_assert(std::is_base_of::value); - static inline T get(const libconfig::Setting& parent, - const std::string& name) { - T t{}; - t._load(parent.lookup(name)); - return t; + static T get(const libconfig::Setting& parent, + const std::string& name) { + T t{}; + t._load(parent.lookup(name)); + return t; + } + + static T get(const libconfig::Setting& setting) { + T t{}; + t._load(setting); + return t; + } + + static void set(libconfig::Setting& parent, + const std::string& name, + const T& t) { + if (!parent.exists(name)) { + parent.add(name, libconfig::Setting::TypeGroup); + } else if (parent.lookup(name).getType() + != libconfig::Setting::TypeGroup) { + parent.remove(name); + parent.add(name, libconfig::Setting::TypeGroup); } + t._save(parent.lookup(name)); + } - static inline T get(const libconfig::Setting& setting) { - T t{}; - t._load(setting); - return t; + static void set(libconfig::Setting& setting, const T& t) { + t._save(setting); + } + + static void append(libconfig::Setting& list, const T& t) { + auto& x = list.add(libconfig::Setting::TypeGroup); + set(x, t); + } + }; + + template + struct config_io> : public config_io { + }; + + template + struct primitive_io { + static T get(const libconfig::Setting& parent, + const std::string& name) { + return parent.lookup(name); + } + + static T get(const libconfig::Setting& setting) { + return setting; + } + + static void set(libconfig::Setting& parent, + const std::string& name, + const T& t) { + if (!parent.exists(name)) { + parent.add(name, TypeEnum); + } else if (parent.lookup(name).getType() != TypeEnum) { + parent.remove(name); + parent.add(name, TypeEnum); } + set(parent.lookup(name), t); + } - static inline void set(libconfig::Setting& parent, - const std::string& name, - const T& t) { - if (!parent.exists(name)) { - parent.add(name, libconfig::Setting::TypeGroup); - } else if (parent.lookup(name).getType() - != libconfig::Setting::TypeGroup) { - parent.remove(name); - parent.add(name, libconfig::Setting::TypeGroup); - } - t._save(parent.lookup(name)); + static void set(libconfig::Setting& setting, const T& t) { + setting = t; + } + + static void append(libconfig::Setting& list, const T& t) { + auto& x = list.add(TypeEnum); + set(x, t); + } + }; + + template + struct reinterpret_io { + static T get(const libconfig::Setting& parent, + const std::string& name) { + return static_cast(primitive_io::get(parent, name)); + } + + static T get(const libconfig::Setting& setting) { + return static_cast(primitive_io::get(setting)); + } + + static void set(libconfig::Setting& parent, + const std::string& name, + const T& t) { + primitive_io::set(parent, name, + static_cast(t)); + } + + static void set(libconfig::Setting& setting, const T& t) { + primitive_io::set(setting, + static_cast(t)); + } + + [[maybe_unused]] + static void append(libconfig::Setting& list, const T& t) { + primitive_io::append(list, + static_cast(t)); + } + }; + + template<> + struct config_io : public primitive_io { + }; + template<> + struct config_io : public reinterpret_io { + }; + template<> + struct config_io : public reinterpret_io { + }; + template<> + struct config_io : public reinterpret_io { + }; + template<> + struct config_io : public reinterpret_io { + }; + template<> + struct config_io : public primitive_io { + }; + template<> + struct config_io : public reinterpret_io { + }; + template<> + struct config_io : public reinterpret_io { + }; + template<> + struct config_io : public reinterpret_io { + }; + template<> + struct config_io : public primitive_io { + }; + template<> + struct config_io : + public reinterpret_io { + }; + template<> + struct config_io : public primitive_io { + }; + template<> + struct config_io : public primitive_io { + }; + template<> + struct config_io : public primitive_io { + }; + + template + struct config_io> { + private: + template + static std::variant try_each(const libconfig::Setting& setting) { + return config_io::get(setting); + } + + template + static std::variant try_each(const libconfig::Setting& setting) { + try { + return config_io::get(setting); + } catch (libconfig::SettingException& e) { + return try_each(setting); } + } - static inline void set(libconfig::Setting& setting, const T& t) { - t._save(setting); - } + public: + static std::variant get(const libconfig::Setting& setting) { + return try_each(setting); + } - static inline void append(libconfig::Setting& list, const T& t) { - auto& x = list.add(libconfig::Setting::TypeGroup); - set(x, t); - } - }; + static std::variant get(const libconfig::Setting& parent, + const std::string& name) { + return get(parent.lookup(name)); + } - template - struct config_io> : public config_io { - }; + static void set(libconfig::Setting& setting, + const std::variant& t) { + std::visit([&setting](auto&& arg) { + config::set(setting, arg); + }, t); + } - template - struct primitive_io { - static inline T get(const libconfig::Setting& parent, - const std::string& name) { - return parent.lookup(name); - } + static void set(libconfig::Setting& parent, + const std::string& name, + const std::variant& t) { + std::visit([&parent, &name](auto&& arg) { + config::set(parent, name, arg); + }, t); + } - static inline T get(const libconfig::Setting& setting) { - return setting; - } + [[maybe_unused]] + static void append(libconfig::Setting& list, const std::variant& t) { + std::visit([&list](auto&& arg) { + config::append(list, arg); + }, t); + } + }; - static inline void set(libconfig::Setting& parent, - const std::string& name, - const T& t) { - if (!parent.exists(name)) { - parent.add(name, TypeEnum); - } else if (parent.lookup(name).getType() != TypeEnum) { - parent.remove(name); - parent.add(name, TypeEnum); - } - set(parent.lookup(name), t); - } - - static inline void set(libconfig::Setting& setting, const T& t) { - setting = t; - } - - static inline void append(libconfig::Setting& list, const T& t) { - auto& x = list.add(TypeEnum); - set(x, t); - } - }; - - template - struct reinterpret_io { - static inline T get(const libconfig::Setting& parent, - const std::string& name) { - return static_cast(primitive_io::get(parent, name)); - } - - static inline T get(const libconfig::Setting& setting) { - return static_cast(primitive_io::get(setting)); - } - - static inline void set(libconfig::Setting& parent, - const std::string& name, - const T& t) { - primitive_io::set(parent, name, - static_cast(t)); - } - - static inline void set(libconfig::Setting& setting, const T& t) { - primitive_io::set(setting, - static_cast(t)); - } - - [[maybe_unused]] - static inline void append(libconfig::Setting& list, const T& t) { - primitive_io::append(list, - static_cast(t)); - } - }; - - template<> - struct config_io : public primitive_io { - }; - template<> - struct config_io : public reinterpret_io { - }; - template<> - struct config_io : public reinterpret_io { - }; - template<> - struct config_io : public reinterpret_io { - }; - template<> - struct config_io : public reinterpret_io { - }; - template<> - struct config_io : public primitive_io { - }; - template<> - struct config_io : public reinterpret_io { - }; - template<> - struct config_io : public reinterpret_io { - }; - template<> - struct config_io : public reinterpret_io { - }; - template<> - struct config_io : public primitive_io { - }; - template<> - struct config_io : - public reinterpret_io { - }; - template<> - struct config_io : public primitive_io { - }; - template<> - struct config_io : public primitive_io { - }; - template<> - struct config_io : public primitive_io { - }; - - template - struct config_io> { - private: - template - static inline std::variant try_each( - const libconfig::Setting& setting) { - return config_io::get(setting); - } - - template - static inline std::variant try_each( - const libconfig::Setting& setting) { + template + struct config_io> { + static std::list get(const libconfig::Setting& setting) { + const auto size = setting.getLength(); + std::list t{}; + for (int i = 0; i < size; ++i) { try { - return config_io::get(setting); + t.emplace_back(config_io::get(setting[i])); + } catch (libconfig::SettingException& e) {} + } + return t; + } + + static std::list get(const libconfig::Setting& parent, const std::string& name) { + return get(parent.lookup(name)); + } + + static void set(libconfig::Setting& setting, const std::list& t) { + while (setting.getLength() != 0) + setting.remove((int) 0); + for (auto& x: t) { + config_io::append(setting, x); + } + } + + static void set(libconfig::Setting& parent, + const std::string& name, + const std::list& t) { + if (!parent.exists(name)) { + parent.add(name, libconfig::Setting::TypeList); + } else if (!parent.lookup(name).isList()) { + parent.remove(name); + parent.add(name, libconfig::Setting::TypeList); + } + set(parent.lookup(name), t); + } + + [[maybe_unused]] + static void append(libconfig::Setting& list, const std::list& t) { + auto& s = list.add(libconfig::Setting::TypeList); + set(s, t); + } + }; + + template + struct config_io> { + static std::set get(const libconfig::Setting& setting) { + const auto size = setting.getLength(); + std::set t; + for (int i = 0; i < size; ++i) { + try { + t.emplace(config_io::get(setting[i])); + } catch (libconfig::SettingException& e) {} + } + return t; + } + + static std::set get(const libconfig::Setting& parent, const std::string& name) { + return get(parent.lookup(name)); + } + + static void set(libconfig::Setting& setting, const std::set& t) { + while (setting.getLength() != 0) + setting.remove((int) 0); + for (auto& x: t) { + auto& s = setting.add(libconfig::Setting::TypeGroup); + config_io::set(s, x); + } + } + + static void set(libconfig::Setting& parent, + const std::string& name, + const std::set& t) { + if (!parent.exists(name)) { + parent.add(name, libconfig::Setting::TypeList); + } else if (!parent.lookup(name).isArray()) { + parent.remove(name); + parent.add(name, libconfig::Setting::TypeList); + } + set(parent.lookup(name), t); + } + + [[maybe_unused]] + static void append(libconfig::Setting& list, + const std::set& t) { + auto& s = list.add(libconfig::Setting::TypeList); + set(s, t); + } + }; + + template + struct config_io> { + static map get(const libconfig::Setting& setting) { + const auto size = setting.getLength(); + map t; + for (int i = 0; i < size; ++i) { + auto& s = setting[i]; + try { + t.emplace(config_io::get(s.lookup(KeyName::value)), + config_io::get(s)); + } catch (libconfig::SettingException& e) {} + } + return t; + } + + static map get( + const libconfig::Setting& parent, const std::string& name) { + return get(parent.lookup(name)); + } + + static void set(libconfig::Setting& setting, + const map& t) { + while (setting.getLength() != 0) + setting.remove((int) 0); + for (auto& x: t) { + auto& s = setting.add(libconfig::Setting::TypeGroup); + config_io::set(s, x.second); + config_io::set(s, KeyName::value, x.first); + } + } + + static void set(libconfig::Setting& parent, + const std::string& name, + const map& t) { + if (!parent.exists(name)) { + parent.add(name, libconfig::Setting::TypeList); + } else if (!parent.lookup(name).isArray()) { + parent.remove(name); + parent.add(name, libconfig::Setting::TypeList); + } + set(parent.lookup(name), t); + } + + [[maybe_unused]] + static void append(libconfig::Setting& list, const map& t) { + auto& s = list.add(libconfig::Setting::TypeList); + set(s, t); + } + }; + + template + struct config_io> { + static std::optional get(const libconfig::Setting& parent, + const std::string& name) { + if (parent.exists(name)) { + auto& setting = parent.lookup(name); + try { + return config_io::get(setting); } catch (libconfig::SettingException& e) { - return try_each(setting); + logError(setting, e); + return std::nullopt; } + } else { + return std::nullopt; } + } - public: - static inline std::variant get( - const libconfig::Setting& setting) { - return try_each(setting); - } + static void set(libconfig::Setting& parent, + const std::string& name, + const std::optional& t) { + if (t.has_value()) + config_io::set(parent, name, t.value()); + } + }; - static inline std::variant get( - const libconfig::Setting& parent, - const std::string& name) { - return get(parent.lookup(name)); - } + // Optionals may not appear as part of a list or array + template + struct config_io, Rest...>> { + static_assert(!sizeof(std::optional), "Invalid type"); + }; - static inline void set(libconfig::Setting& setting, - const std::variant& t) { - std::visit([&setting](auto&& arg) { - config::set(setting, arg); - }, t); - } + template + struct config_io>> { + static_assert(!sizeof(std::optional), "Invalid type"); + }; - static inline void set(libconfig::Setting& parent, - const std::string& name, - const std::variant& t) { - std::visit([&parent, &name](auto&& arg) { - config::set(parent, name, arg); - }, t); - } - - [[maybe_unused]] - static inline void append(libconfig::Setting& list, - const std::variant& t) { - std::visit([&list](auto&& arg) { - config::append(list, arg); - }, t); - } - }; - - template - struct config_io> { - static inline std::list get(const libconfig::Setting& setting) { - const auto size = setting.getLength(); - std::list t{}; - for (int i = 0; i < size; ++i) { - try { - t.emplace_back(config_io::get(setting[i])); - } catch (libconfig::SettingException& e) {} - } - return t; - } - - static inline std::list get(const libconfig::Setting& parent, - const std::string& name) { - return get(parent.lookup(name)); - } - - static inline void set(libconfig::Setting& setting, - const std::list& t) { - while (setting.getLength() != 0) - setting.remove((int) 0); - for (auto& x: t) { - config_io::append(setting, x); - } - } - - static inline void set(libconfig::Setting& parent, - const std::string& name, - const std::list& t) { - if (!parent.exists(name)) { - parent.add(name, libconfig::Setting::TypeList); - } else if (!parent.lookup(name).isList()) { - parent.remove(name); - parent.add(name, libconfig::Setting::TypeList); - } - set(parent.lookup(name), t); - } - - [[maybe_unused]] - static inline void append(libconfig::Setting& list, - const std::list& t) { - auto& s = list.add(libconfig::Setting::TypeList); - set(s, t); - } - }; - - template - struct config_io> { - static inline std::set get(const libconfig::Setting& setting) { - const auto size = setting.getLength(); - std::set t; - for (int i = 0; i < size; ++i) { - try { - t.emplace(config_io::get(setting[i])); - } catch (libconfig::SettingException& e) {} - } - return t; - } - - static inline std::set get(const libconfig::Setting& parent, - const std::string& name) { - return get(parent.lookup(name)); - } - - static inline void set(libconfig::Setting& setting, - const std::set& t) { - while (setting.getLength() != 0) - setting.remove((int) 0); - for (auto& x: t) { - auto& s = setting.add(libconfig::Setting::TypeGroup); - config_io::set(s, x); - } - } - - static inline void set(libconfig::Setting& parent, - const std::string& name, - const std::set& t) { - if (!parent.exists(name)) { - parent.add(name, libconfig::Setting::TypeList); - } else if (!parent.lookup(name).isArray()) { - parent.remove(name); - parent.add(name, libconfig::Setting::TypeList); - } - set(parent.lookup(name), t); - } - - [[maybe_unused]] - static inline void append(libconfig::Setting& list, - const std::set& t) { - auto& s = list.add(libconfig::Setting::TypeList); - set(s, t); - } - }; - - template - struct config_io> { - static inline map get( - const libconfig::Setting& setting) { - const auto size = setting.getLength(); - map t; - for (int i = 0; i < size; ++i) { - auto& s = setting[i]; - try { - t.emplace(config_io::get(s.lookup(KeyName::value)), - config_io::get(s)); - } catch (libconfig::SettingException& e) {} - } - return t; - } - - static inline map get( - const libconfig::Setting& parent, const std::string& name) { - return get(parent.lookup(name)); - } - - static inline void set(libconfig::Setting& setting, - const map& t) { - while (setting.getLength() != 0) - setting.remove((int) 0); - for (auto& x: t) { - auto& s = setting.add(libconfig::Setting::TypeGroup); - config_io::set(s, x.second); - config_io::set(s, KeyName::value, x.first); - } - } - - static inline void set(libconfig::Setting& parent, - const std::string& name, - const map& t) { - if (!parent.exists(name)) { - parent.add(name, libconfig::Setting::TypeList); - } else if (!parent.lookup(name).isArray()) { - parent.remove(name); - parent.add(name, libconfig::Setting::TypeList); - } - set(parent.lookup(name), t); - } - - [[maybe_unused]] - static inline void append(libconfig::Setting& list, - const map& t) { - auto& s = list.add(libconfig::Setting::TypeList); - set(s, t); - } - }; - - template - struct config_io> { - static inline std::optional get(const libconfig::Setting& parent, - const std::string& name) { - if (parent.exists(name)) { - auto& setting = parent.lookup(name); - try { - return config_io::get(setting); - } catch (libconfig::SettingException& e) { - logError(setting, e); - return {}; - } - } else { - return {}; - } - } - - static inline void set(libconfig::Setting& parent, - const std::string& name, - const std::optional& t) { - if (t.has_value()) - config_io::set(parent, name, t.value()); - } - }; - - // Optionals may not appear as part of a list or array - template - struct config_io, Rest...>> { - static_assert(!sizeof(std::optional), "Invalid type"); - }; - - template - struct config_io>> { - static_assert(!sizeof(std::optional), "Invalid type"); - }; - - template - struct config_io>> { - static_assert(!sizeof(std::optional), "Invalid type"); - }; - } + template + struct config_io>> { + static_assert(!sizeof(std::optional), "Invalid type"); + }; template void set(libconfig::Setting& parent, diff --git a/src/logid/features/DeviceFeature.h b/src/logid/features/DeviceFeature.h index 08621e2..f41bdf9 100644 --- a/src/logid/features/DeviceFeature.h +++ b/src/logid/features/DeviceFeature.h @@ -40,21 +40,19 @@ namespace logid::features { } }; - namespace { - template - class FeatureWrapper : public T { - friend class DeviceFeature; + template + class _featureWrapper : public T { + friend class DeviceFeature; - public: - template - explicit FeatureWrapper(Args... args) : T(std::forward(args)...) {} + public: + template + explicit _featureWrapper(Args... args) : T(std::forward(args)...) {} - template - static std::shared_ptr make(Args... args) { - return std::make_shared(std::forward(args)...); - } - }; - } + template + static std::shared_ptr make(Args... args) { + return std::make_shared<_featureWrapper>(std::forward(args)...); + } + }; class DeviceFeature { std::weak_ptr _self; @@ -68,7 +66,9 @@ namespace logid::features { virtual ~DeviceFeature() = default; DeviceFeature(const DeviceFeature&) = delete; + DeviceFeature(DeviceFeature&&) = delete; + protected: explicit DeviceFeature(Device* dev) : _device(dev) {} @@ -82,7 +82,7 @@ namespace logid::features { public: template static std::shared_ptr make(Args... args) { - auto feature = FeatureWrapper::make(std::forward(args)...); + auto feature = _featureWrapper::make(std::forward(args)...); feature->_self = feature; return feature;