summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-11-01 11:29:24 +0100
committerStanislaw Halik <sthalik@misaki.pl>2015-11-01 11:29:24 +0100
commitbe36337e46218c6f843a478036497a3f494502ed (patch)
treedbb9dcb91f8a0233d3facb91e7d860c23a97ca4c
parent0424a2802aec3600774ba9347c49312bb09b8cfe (diff)
options: don't define options singleton in every module
Instead, define in opentrack-api.so only. Also, move to opentrack-compat to break a circular dependency
-rw-r--r--opentrack-compat/options.cpp16
-rw-r--r--opentrack-compat/options.hpp (renamed from opentrack/options.hpp)38
2 files changed, 37 insertions, 17 deletions
diff --git a/opentrack-compat/options.cpp b/opentrack-compat/options.cpp
new file mode 100644
index 00000000..91cd3664
--- /dev/null
+++ b/opentrack-compat/options.cpp
@@ -0,0 +1,16 @@
+#include "options.hpp"
+
+namespace options
+{
+
+namespace detail
+{
+OPENTRACK_COMPAT_EXPORT opt_singleton& singleton()
+{
+ static auto ret = std::make_shared<opt_singleton>();
+ return *ret;
+}
+
+}
+
+}
diff --git a/opentrack/options.hpp b/opentrack-compat/options.hpp
index f8475877..be8c688c 100644
--- a/opentrack/options.hpp
+++ b/opentrack-compat/options.hpp
@@ -37,6 +37,13 @@
#include <QDebug>
#include <memory>
+
+#ifdef BUILD_compat
+# include "compat-export.hpp"
+#else
+# include "compat-import.hpp"
+#endif
+
template<typename t> using mem = std::shared_ptr<t>;
#define OPENTRACK_CONFIG_FILENAME_KEY "settings-filename"
@@ -176,7 +183,7 @@ namespace options {
}
};
- class impl_bundle : public QObject {
+ class OPENTRACK_COMPAT_EXPORT impl_bundle : public QObject {
Q_OBJECT
protected:
QMutex mtx;
@@ -252,12 +259,14 @@ namespace options {
class opt_bundle;
- namespace
+ namespace detail
{
- template<typename k, typename v, typename cnt = int>
- struct opt_singleton
+ struct OPENTRACK_COMPAT_EXPORT opt_singleton
{
public:
+ using k = std::string;
+ using v = opt_bundle;
+ using cnt = int;
using pbundle = std::shared_ptr<v>;
using tt = std::tuple<cnt, std::weak_ptr<v>>;
private:
@@ -266,12 +275,6 @@ namespace options {
public:
opt_singleton() : implsgl_mtx(QMutex::Recursive) {}
- static opt_singleton<k, v>& datum()
- {
- static auto ret = std::make_shared<opt_singleton<k, v>>();
- return *ret;
- }
-
pbundle bundle(const k& key)
{
QMutexLocker l(&implsgl_mtx);
@@ -298,12 +301,13 @@ namespace options {
implsgl_data.erase(key);
}
};
-
- using pbundle = std::shared_ptr<opt_bundle>;
- using t_fact = opt_singleton<string, opt_bundle>;
+
+ OPENTRACK_COMPAT_EXPORT opt_singleton& singleton();
}
-
- static inline t_fact::pbundle bundle(const string name) { return t_fact::datum().bundle(name); }
+
+ using pbundle = std::shared_ptr<opt_bundle>;
+
+ static inline pbundle bundle(const string name) { return detail::singleton().bundle(name); }
class opt_bundle : public impl_bundle
{
@@ -316,11 +320,11 @@ namespace options {
~opt_bundle()
{
qDebug() << "bundle -" << QString::fromStdString(group_name);
- t_fact::datum().bundle_decf(group_name);
+ detail::singleton().bundle_decf(group_name);
}
};
- class base_value : public QObject
+ class OPENTRACK_COMPAT_EXPORT base_value : public QObject
{
Q_OBJECT
#define DEFINE_SLOT(t) void setValue(t datum) { store(datum); }