From fa1801471c2708ed8266ec7b99bd4cec886ccc1b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 8 Jul 2018 23:29:49 +0200 Subject: options: fix 2 issues 1. Calling valueChanged didn't invoke machinery in value, only base_value aka value_. There's a fast path in value::type() despite the pessimization. 2. Split global scope stuff into options::globals from the options::globals stuff 3. Adjust usages --- options/group.hpp | 113 ++++++++++++++++-------------------------------------- 1 file changed, 33 insertions(+), 80 deletions(-) (limited to 'options/group.hpp') diff --git a/options/group.hpp b/options/group.hpp index f191fdd5..ef9f1121 100644 --- a/options/group.hpp +++ b/options/group.hpp @@ -1,96 +1,49 @@ #pragma once +#include "options/defs.hpp" + +#include "compat/base-path.hpp" +#include "compat/library-path.hpp" +#include "compat/qhash.hpp" #include "compat/macros.hpp" #include "export.hpp" -// included here to propagate into callers of options::group -#include "metatype.hpp" +#include +#include -#include -#include +#include #include -#include +#include +#include +#include +#include #include #include -#include +#include // XXX TODO remove qsettings usage -sh 20180624 -namespace options { - -// snapshot of qsettings group at given time -class OTR_OPTIONS_EXPORT group final -{ - QString name; - - static QString cur_ini_pathname; - - static std::shared_ptr cur_ini; - static int ini_refcount; - static bool ini_modifiedp; - static QMutex cur_ini_mtx; - - static std::shared_ptr cur_global_ini; - static int global_ini_refcount; - static bool global_ini_modifiedp; - static QMutex global_ini_mtx; - - struct OTR_OPTIONS_EXPORT saver_ final +namespace options::detail { + // snapshot of qsettings group at given time + class OTR_OPTIONS_EXPORT group final { - QSettings& s; - int& refcount; - bool& modifiedp; - - cc_noinline ~saver_(); - cc_noinline saver_(QSettings& s, int& refcount, bool& modifiedp); + QString name; + + public: + std::unordered_map kvs; + explicit group(const QString& name); + void save() const; + void put(const QString& s, const QVariant& d); + bool contains(const QString& s) const; + + template + cc_noinline t get(const QString& k) const + { + return get_variant(k).value(); + } + + cc_noinline QVariant get_variant(const QString& name) const; }; - static std::shared_ptr cur_settings_object(); - static std::shared_ptr cur_global_settings_object(); - -public: - std::map kvs; - group(const QString& name); - void save() const; - void put(const QString& s, const QVariant& d); - bool contains(const QString& s) const; - static QString ini_directory(); - static QString ini_filename(); - static QString ini_pathname(); - static QString ini_combine(const QString& filename); - static QStringList ini_list(); - static bool is_portable_installation(); - - static void mark_ini_modified(); - - template - cc_noinline - t get(const QString& k) const - { - auto value = kvs.find(k); - if (value != kvs.cend()) - return value->second.value(); - return t(); - } - - template - cc_noinline - static auto with_settings_object(F&& fun) - { - QMutexLocker l(&cur_ini_mtx); - saver_ saver { *cur_settings_object(), ini_refcount, ini_modifiedp }; - - return fun(saver.s); - } - - template - static auto with_global_settings_object(F&& fun) - { - QMutexLocker l(&global_ini_mtx); - saver_ saver { *cur_global_settings_object(), global_ini_refcount, global_ini_modifiedp }; - global_ini_modifiedp = true; +} // ns options::detail - return fun(saver.s); - } -}; -} -- cgit v1.2.3