diff options
Diffstat (limited to 'options')
-rw-r--r-- | options/metatype.cpp | 19 | ||||
-rw-r--r-- | options/scoped.cpp | 13 | ||||
-rw-r--r-- | options/scoped.hpp | 9 | ||||
-rw-r--r-- | options/slider.hpp | 4 | ||||
-rw-r--r-- | options/value.hpp | 2 |
5 files changed, 21 insertions, 26 deletions
diff --git a/options/metatype.cpp b/options/metatype.cpp index a4629aa6..3b8ec690 100644 --- a/options/metatype.cpp +++ b/options/metatype.cpp @@ -1,4 +1,5 @@ #include <QMetaType> +#include "compat/macros.hpp" namespace options::detail { @@ -13,19 +14,15 @@ int declare_metatype_for_type(const char* str) } // ns options::detail -#define OPENTRACK_DEFINE_METATYPE2(t, ctr) \ - OPENTRACK_DEFINE_METATYPE3(t, ctr) - -#define OPENTRACK_DEFINE_METATYPE3(t, ctr) \ - OPENTRACK_DEFINE_METATYPE4(t, init_metatype_ ## ctr) - -#define OPENTRACK_DEFINE_METATYPE4(t, sym) \ - class sym { /* NOLINT */ \ - static const int dribble; \ - } sym; /* NOLINT */ \ +#define OPENTRACK_DEFINE_METATYPE2(t, sym) \ + class sym { /* NOLINT */ \ + static const int dribble; \ + }; /* NOLINT */ \ + static sym sym; \ const int sym :: dribble = ::options::detail::declare_metatype_for_type<t>(#t); -#define OPENTRACK_DEFINE_METATYPE(t) OPENTRACK_DEFINE_METATYPE2(t, __COUNTER__) +#define OPENTRACK_DEFINE_METATYPE(t) \ + OPENTRACK_DEFINE_METATYPE2(t, PP_CAT(init, __COUNTER__)) #define OPENTRACK_METATYPE_(x) OPENTRACK_DEFINE_METATYPE(x) #include "metatype.hpp" diff --git a/options/scoped.cpp b/options/scoped.cpp index 8f1ef202..ef5b94d6 100644 --- a/options/scoped.cpp +++ b/options/scoped.cpp @@ -10,17 +10,17 @@ namespace options { // XXX hack: the flag shouldn't be here as action at distance -sh 20160926 -static std::atomic_bool teardown_flag(false); -static void set_teardown_flag(bool value); +static std::atomic<bool> teardown_flag{false}; +[[nodiscard]] static bool set_teardown_flag(bool value); static void ensure_thread(); static bool is_tracker_teardown(); -static void set_teardown_flag(bool value) +static bool set_teardown_flag(bool value) { // flag being set means "opts" is about to go out of scope due to tracker stop // in this case we don't reload options. we only want to reload when cancel is pressed. ensure_thread(); - teardown_flag = value; + return teardown_flag.exchange(value); } static void ensure_thread() @@ -59,14 +59,13 @@ opts::opts(const QString &name) : b(make_bundle(name)) { } -with_tracker_teardown::with_tracker_teardown() : old_value(teardown_flag) +with_tracker_teardown::with_tracker_teardown() : old_value{set_teardown_flag(true)} { - set_teardown_flag(true); } with_tracker_teardown::~with_tracker_teardown() { - set_teardown_flag(old_value); + (void)set_teardown_flag(old_value); } } // ns options diff --git a/options/scoped.hpp b/options/scoped.hpp index 452708f4..dd7dbacf 100644 --- a/options/scoped.hpp +++ b/options/scoped.hpp @@ -6,8 +6,6 @@ #include "export.hpp" -#include <atomic> - namespace options { struct OTR_OPTIONS_EXPORT with_tracker_teardown final @@ -26,11 +24,12 @@ struct OTR_OPTIONS_EXPORT opts bundle b; - virtual ~opts(); - explicit opts(const QString& name); - opts& operator=(const opts&) = delete; opts(const opts&) = delete; + +protected: + explicit opts(const QString& name); + ~opts(); }; } diff --git a/options/slider.hpp b/options/slider.hpp index 1dd9ec7c..abf39685 100644 --- a/options/slider.hpp +++ b/options/slider.hpp @@ -34,11 +34,11 @@ namespace options slider_value& operator=(const slider_value& v) = default; slider_value(const slider_value& v) = default; - slider_value() : slider_value{0, 0, 0} {}; + slider_value() : slider_value{0, 0, 0} {} bool operator==(const slider_value& v) const; bool operator!=(const slider_value& v) const; - operator double() const { return cur_; } + constexpr operator double() const { return cur_; } double cur() const { return cur_; } double min() const { return min_; } double max() const { return max_; } diff --git a/options/value.hpp b/options/value.hpp index ea180b27..3a58f74c 100644 --- a/options/value.hpp +++ b/options/value.hpp @@ -110,7 +110,7 @@ public: operator t() const { return get(); } // NOLINT - template<typename w, typename = decltype(static_cast<w>(std::declval<t>()))> + template<typename w> explicit cc_forceinline operator w() const { return to<w>(); } auto operator->() const |