summaryrefslogtreecommitdiffhomepage
path: root/options/bundle.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-08-17 21:28:45 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-08-17 21:34:53 +0200
commitcb33be1c50b68d6022f344ddac923c7aac3a11d5 (patch)
tree1840e3f9829aa69f10f81804f655e97be3f2eca8 /options/bundle.hpp
parent41ba8aa5329c16a797140dc23650ef45f42753a3 (diff)
move options framework into its own library
- adjust usages - add support for QList signals and metatype
Diffstat (limited to 'options/bundle.hpp')
-rw-r--r--options/bundle.hpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/options/bundle.hpp b/options/bundle.hpp
new file mode 100644
index 00000000..56d48f60
--- /dev/null
+++ b/options/bundle.hpp
@@ -0,0 +1,84 @@
+#pragma once
+
+#include <memory>
+#include <tuple>
+#include <map>
+#include <memory>
+
+#include <QObject>
+#include <QString>
+#include <QVariant>
+#include <QMutex>
+#include <QMutexLocker>
+
+#include <QDebug>
+
+#include "group.hpp"
+#include "compat/util.hpp"
+#include "export.hpp"
+
+namespace options {
+
+namespace detail {
+
+class OPENTRACK_OPTIONS_EXPORT bundle final : public QObject
+{
+ Q_OBJECT
+protected:
+ QMutex mtx;
+ const QString group_name;
+ group saved;
+ group transient;
+ bundle(const bundle&) = delete;
+ bundle& operator=(const bundle&) = delete;
+signals:
+ void reloading();
+ void saving() const;
+public:
+ bundle(const QString& group_name);
+ QString name() { return group_name; }
+ void reload();
+ void store_kv(const QString& name, const QVariant& datum);
+ bool contains(const QString& name) const;
+ void save();
+ bool modifiedp() const;
+
+ template<typename t>
+ t get(const QString& name) const
+ {
+ QMutexLocker l(const_cast<QMutex*>(&mtx));
+ return transient.get<t>(name);
+ }
+};
+
+struct OPENTRACK_OPTIONS_EXPORT bundler
+{
+public:
+ using k = QString;
+ using v = bundle;
+ using cnt = int;
+ using tt = std::tuple<cnt, std::weak_ptr<v>>;
+private:
+ QMutex implsgl_mtx;
+ std::map<k, tt> implsgl_data;
+ void after_profile_changed_();
+public:
+ bundler();
+ ~bundler();
+ std::shared_ptr<v> make_bundle(const k& key);
+ void bundle_decf(const k& key);
+ static void refresh_all_bundles();
+};
+
+OPENTRACK_OPTIONS_EXPORT bundler& singleton();
+}
+
+using bundle_type = detail::bundle;
+using bundle = std::shared_ptr<bundle_type>;
+
+inline bundle make_bundle(const QString& name)
+{
+ return detail::singleton().make_bundle(name);
+}
+
+}