diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-21 22:22:51 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-23 00:05:15 +0200 |
commit | 321501ad58dad2688bde42992b61adcda5a313e0 (patch) | |
tree | 5024dea40ea91dedf379ae2a7f06fe069a6d3e9d /options/bundle.hpp | |
parent | e425135768da9c18199ebe58e93a5b245db5ee79 (diff) |
options/bundle: simplify mutex const-dropping
Diffstat (limited to 'options/bundle.hpp')
-rw-r--r-- | options/bundle.hpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/options/bundle.hpp b/options/bundle.hpp index f83e6800..78c40ea2 100644 --- a/options/bundle.hpp +++ b/options/bundle.hpp @@ -26,16 +26,23 @@ namespace detail { class OPENTRACK_OPTIONS_EXPORT bundle final : public QObject, public virtual connector { + class OPENTRACK_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)); } + }; + Q_OBJECT private: - QMutex mtx; + mutex mtx; const QString group_name; group saved; group transient; bundle(const bundle&) = delete; bundle& operator=(const bundle&) = delete; - QMutex* get_mtx() override { return &mtx; } + QMutex* get_mtx() const override; signals: void reloading(); @@ -50,12 +57,12 @@ public: bool contains(const QString& name) const; void save(); void save_deferred(QSettings& s); - bool modifiedp() const; + bool is_modified() const; template<typename t> t get(const QString& name) const { - QMutexLocker l(const_cast<QMutex*>(&mtx)); + QMutexLocker l(mtx); return transient.get<t>(name); } }; @@ -85,6 +92,6 @@ OPENTRACK_OPTIONS_EXPORT bundler& singleton(); using bundle_type = detail::bundle; using bundle = std::shared_ptr<bundle_type>; -OPENTRACK_OPTIONS_EXPORT bundle make_bundle(const QString& name); +OPENTRACK_OPTIONS_EXPORT std::shared_ptr<bundle_type> make_bundle(const QString& name); } |