diff options
Diffstat (limited to 'options/bundle.hpp')
-rw-r--r-- | options/bundle.hpp | 102 |
1 files changed, 53 insertions, 49 deletions
diff --git a/options/bundle.hpp b/options/bundle.hpp index 9b7b7f02..158fcef9 100644 --- a/options/bundle.hpp +++ b/options/bundle.hpp @@ -10,10 +10,11 @@ #include "group.hpp" #include "connector.hpp" +#include "compat/qhash.hpp" #include <memory> #include <tuple> -#include <map> +#include <unordered_map> #include <memory> #include <vector> @@ -21,93 +22,96 @@ #include <QString> #include <QVariant> #include <QMutex> -#include <QMutexLocker> #include <QDebug> #include "export.hpp" -namespace options { - -namespace detail { +namespace options::detail { + class bundle; + struct bundler; +} // ns options::detail -void set_base_value_to_default(base_value* val); +namespace options { + using bundle_ = detail::bundle; + using bundle = std::shared_ptr<bundle_>; + OTR_OPTIONS_EXPORT std::shared_ptr<detail::bundle> make_bundle(const QString& name); +} // ns options -struct bundler; +namespace options::detail { class OTR_OPTIONS_EXPORT bundle final : public QObject, public connector { Q_OBJECT - class OTR_OPTIONS_EXPORT mutex final : public QMutex - { - public: - mutex(QMutex::RecursionMode mode) : QMutex(mode) {} - operator QMutex*() const { return const_cast<QMutex*>(static_cast<const QMutex*>(this)); } - }; + friend struct bundler; -private: - mutex mtx; + mutable QMutex mtx { QMutex::Recursive }; const QString group_name; group saved; group transient; - bundle(const bundle&) = delete; - bundle(bundle&&) = delete; - bundle& operator=(bundle&&) = delete; - bundle& operator=(const bundle&) = delete; - QMutex* get_mtx() const override; + void reload_no_notify(); signals: void reloading(); void saving() const; void changed() const; + public: - never_inline bundle(const QString& group_name); - never_inline ~bundle() override; + bundle(const bundle&) = delete; + bundle& operator=(const bundle&) = delete; + + QMutex* get_mtx() const override { return &mtx; } QString name() const { return group_name; } - never_inline void store_kv(const QString& name, const QVariant& datum); - never_inline bool contains(const QString& name) const; - never_inline bool is_modified() const; - - template<typename t> - t get(const QString& name) const - { - QMutexLocker l(mtx); - return transient.get<t>(name); - } + + explicit bundle(const QString& group_name); + ~bundle() override; + + void store_kv(const QString& name, QVariant&& datum); + void store_kv(const QString& name, const QVariant& datum); + bool contains(const QString& name) const; + + QVariant get_variant(const QString& name) const; + void notify(); + public slots: void save(); void reload(); void set_all_to_default(); }; -OTR_OPTIONS_EXPORT bundler& singleton(); - -struct OTR_OPTIONS_EXPORT bundler +struct OTR_OPTIONS_EXPORT bundler final { -public: using k = QString; using v = bundle; using weak = std::weak_ptr<v>; using shared = std::shared_ptr<v>; + + static void notify(); + static void reload_no_notify(); + static void reload(); + private: - QMutex implsgl_mtx; - std::map<k, weak> implsgl_data; - void after_profile_changed_(); -public: + QMutex implsgl_mtx { QMutex::Recursive }; + std::unordered_map<k, weak> implsgl_data {}; + + void notify_(); + void reload_no_notify_(); + + void reload_(); + + friend OTR_OPTIONS_EXPORT + std::shared_ptr<v> options::make_bundle(const QString& name); + + std::shared_ptr<v> make_bundle_(const k& key); + static bundler& singleton(); + bundler(); ~bundler(); - std::shared_ptr<v> make_bundle(const k& key); - static void refresh_all_bundles(); }; -OTR_OPTIONS_EXPORT bundler& singleton(); -} // ns options::detail +void set_value_to_default(value_* val); -using bundle_ = detail::bundle; -using bundle = std::shared_ptr<bundle_>; - -OTR_OPTIONS_EXPORT std::shared_ptr<bundle_> make_bundle(const QString& name); +} // ns options::detail -} // ns options |