From 0945fa1fe859ca06580d3e3a475cdf20b1d41b80 Mon Sep 17 00:00:00 2001 From: pixl Date: Wed, 3 May 2023 17:35:56 -0400 Subject: [PATCH] Fix c++2a compatibility Adds gcc 9 support. --- README.md | 8 ++++---- src/logid/CMakeLists.txt | 2 +- src/logid/config/{util.cpp => config.cpp} | 6 +++++- src/logid/config/map.h | 14 +++++++------- src/logid/config/schema.h | 13 +++++++++---- src/logid/config/types.h | 6 +++--- 6 files changed, 29 insertions(+), 20 deletions(-) rename src/logid/config/{util.cpp => config.cpp} (84%) diff --git a/README.md b/README.md index bd0f16d4..49a8db4d 100644 --- a/README.md +++ b/README.md @@ -13,18 +13,18 @@ Default location for the configuration file is /etc/logid.cfg, but another can b ## Dependencies -This project requires a C++17 compiler, `cmake`, `libevdev`, `libudev`, `glib`, and `libconfig`. +This project requires a C++20 compiler, `cmake`, `libevdev`, `libudev`, `glib`, and `libconfig`. For popular distributions, I've included commands below. -**Arch Linux:** `sudo pacman -S cmake libevdev libconfig pkgconf glib2` +**Arch Linux:** `sudo pacman -S base-devel cmake g++ libevdev libconfig pkgconf glib2` -**Debian/Ubuntu:** `sudo apt install cmake libevdev-dev libudev-dev libconfig++-dev libglib2.0` +**Debian/Ubuntu:** `sudo apt install git cmake g++ libevdev-dev libudev-dev libconfig++-dev libglib2.0-dev` **Fedora:** `sudo dnf install cmake libevdev-devel systemd-devel libconfig-devel gcc-c++ glib2` **Gentoo Linux:** `sudo emerge dev-libs/libconfig dev-libs/libevdev dev-libs/glib dev-util/cmake virtual/libudev` -**Solus:** `sudo eopkg install libevdev-devel libconfig-devel libgudev-devel glib2` +**Solus:** `sudo eopkg install cmake libevdev-devel libconfig-devel libgudev-devel glib2` **openSUSE:** `sudo zypper install cmake libevdev-devel systemd-devel libconfig-devel gcc-c++ libconfig++-devel libudev-devel glib2` diff --git a/src/logid/CMakeLists.txt b/src/logid/CMakeLists.txt index 10a2f20c..d41b7c38 100644 --- a/src/logid/CMakeLists.txt +++ b/src/logid/CMakeLists.txt @@ -13,7 +13,7 @@ find_package(PkgConfig REQUIRED) add_executable(logid logid.cpp util/log.cpp - config/util.cpp + config/config.cpp InputDevice.cpp DeviceManager.cpp Device.cpp diff --git a/src/logid/config/util.cpp b/src/logid/config/config.cpp similarity index 84% rename from src/logid/config/util.cpp rename to src/logid/config/config.cpp index dce46829..1e4f1308 100644 --- a/src/logid/config/util.cpp +++ b/src/logid/config/config.cpp @@ -16,11 +16,15 @@ * */ -#include +#include #include using namespace logid; +const char config::keys::name[] = "name"; +const char config::keys::cid[] = "cid"; +const char config::keys::direction[] = "direction"; + void config::logError(const libconfig::Setting& setting, std::exception& e) { logPrintf(WARN, "Error at line %d: %s", setting.getSourceLine(), e.what()); } \ No newline at end of file diff --git a/src/logid/config/map.h b/src/logid/config/map.h index b5d109eb..13d1751f 100644 --- a/src/logid/config/map.h +++ b/src/logid/config/map.h @@ -24,13 +24,11 @@ #include namespace logid::config { - template - struct string_literal { - constexpr string_literal(const char (& str)[N]) { - std::copy_n(str, N, value); - } + struct string_literal { }; - char value[N]{}; + template + struct string_literal_of : public string_literal { + constexpr static const char* value = str; }; template @@ -46,10 +44,12 @@ namespace logid::config { }; // Warning: map must be a variant of groups or a group - template::key_compare, typename Allocator=typename std::map::allocator_type> class map : public std::map { + static_assert(std::is_base_of::value, + "KeyName must be a string_literal"); public: template explicit map(Args... args) : diff --git a/src/logid/config/schema.h b/src/logid/config/schema.h index 6ae249aa..6f75699d 100644 --- a/src/logid/config/schema.h +++ b/src/logid/config/schema.h @@ -51,6 +51,11 @@ namespace logid::actions { } namespace logid::config { + struct keys { + static const char name[]; + static const char cid[]; + static const char direction[]; + }; struct NoAction : public signed_group { typedef actions::NullAction action; @@ -213,7 +218,7 @@ namespace logid::config { struct GestureAction : public signed_group { typedef actions::GestureAction action; - std::optional, less_caseless>> gestures; GestureAction() : signed_group( @@ -284,7 +289,7 @@ namespace logid::config { &ThumbWheel::tap) {} }; - typedef map RemapButton; + typedef map> RemapButton; struct Profile : public group { std::optional dpi; @@ -302,7 +307,7 @@ namespace logid::config { struct Device : public group { ipcgull::property default_profile; - map profiles; + map> profiles; Device() : group({"default_profile", "profiles"}, &Device::default_profile, @@ -313,7 +318,7 @@ namespace logid::config { struct Config : public group { std::optional, "name">> devices; + std::variant, string_literal_of>> devices; std::optional> ignore; std::optional io_timeout; std::optional workers; diff --git a/src/logid/config/types.h b/src/logid/config/types.h index 4beb345b..70e41e37 100644 --- a/src/logid/config/types.h +++ b/src/logid/config/types.h @@ -349,7 +349,7 @@ namespace logid::config { } }; - template struct config_io> { static inline map get( @@ -359,7 +359,7 @@ namespace logid::config { for (int i = 0; i < size; ++i) { auto& s = setting[i]; try { - t.emplace(config_io::get(s.lookup(KeyName.value)), + t.emplace(config_io::get(s.lookup(KeyName::value)), config_io::get(s)); } catch (libconfig::SettingException& e) {} } @@ -378,7 +378,7 @@ namespace logid::config { 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); + config_io::set(s, KeyName::value, x.first); } }