summaryrefslogtreecommitdiffhomepage
path: root/options/connector.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-08-18 14:53:00 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-08-18 17:05:13 +0200
commita18ca7764abbe24b601885ef06fcc98f0b7ed10b (patch)
tree1381ca22c6b2e68f5e43f0443435863eb3578c77 /options/connector.cpp
parent132a1925340bcd75a88f831a3487044736dccb4a (diff)
options: factor out connector out of bundle
Diffstat (limited to 'options/connector.cpp')
-rw-r--r--options/connector.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/options/connector.cpp b/options/connector.cpp
new file mode 100644
index 00000000..4ba532d4
--- /dev/null
+++ b/options/connector.cpp
@@ -0,0 +1,71 @@
+#include "connector.hpp"
+#include "value.hpp"
+
+namespace options {
+namespace detail {
+
+connector::~connector() {}
+
+void connector::on_bundle_destructed(const QString& name, const base_value* val)
+{
+ QMutexLocker l(get_mtx());
+
+ auto it = connected_values.find(name);
+ if (it != connected_values.end())
+ {
+ std::vector<const base_value*>& values = (*it).second;
+ for (auto it = values.begin(); it != values.end(); )
+ {
+ if (*it == val)
+ {
+ values.erase(it);
+ break;
+ }
+ }
+ }
+}
+
+void connector::on_bundle_created(const QString& name, const base_value* val)
+{
+ QMutexLocker l(get_mtx());
+ auto it = connected_values.find(name);
+
+ if (it != connected_values.end())
+ {
+ std::vector<const base_value*>& values = (*it).second;
+ values.push_back(val);
+ }
+ else
+ {
+ std::vector<const base_value*> vec;
+ vec.push_back(val);
+ connected_values[name] = vec;
+ }
+}
+
+void connector::notify_values(const QString& name) const
+{
+ auto it = connected_values.find(name);
+ if (it != connected_values.end())
+ {
+ for (const base_value* val : (*it).second)
+ {
+ val->bundle_value_changed();
+ }
+ }
+}
+
+void connector::notify_all_values() const
+{
+ for (auto& pair : connected_values)
+ for (const base_value* val : pair.second)
+ val->bundle_value_changed();
+}
+
+connector::connector()
+{
+}
+
+}
+
+}