diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-10-05 15:54:01 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-10-05 14:35:29 +0000 |
commit | f0216a3c53d43918295f1bd81975b391f4e5ed3b (patch) | |
tree | b6311d48559bbdb4b657beed1bd8164d9157b03f /options/connector.cpp | |
parent | 39ea3871c1b3f594df846bc0b9a627c9880ecea4 (diff) |
options: don't use typeindex w/ lambdas
Rename traits' functions to be more explicit.
Most of the changes are pretty old and I can't read
them at this time, sorry.
Adjust usages.
Issue: #825
Reported-by: @DanielKinsman
Diffstat (limited to 'options/connector.cpp')
-rw-r--r-- | options/connector.cpp | 88 |
1 files changed, 22 insertions, 66 deletions
diff --git a/options/connector.cpp b/options/connector.cpp index 73aefed8..838a2e0e 100644 --- a/options/connector.cpp +++ b/options/connector.cpp @@ -9,99 +9,57 @@ #include "connector.hpp" #include "value.hpp" -#include <utility> - namespace options::detail { -static bool generic_is_equal(const QVariant& val1, const QVariant& val2) -{ - return val1 == val2; -} - +connector::connector() = default; connector::~connector() = default; -bool connector::is_equal(const QString& name, const QVariant& val1, const QVariant& val2) const +void connector::on_value_destructed(value_type val) { - QMutexLocker l(get_mtx()); + const QString& name = val->name(); - auto it = connected_values.find(name); - - if (it != connected_values.cend() && !std::get<0>((*it).second).empty()) - return std::get<1>((*it).second)(val1, val2); - else - return generic_is_equal(val1, val2); -} - -bool connector::on_value_destructed_impl(const QString& name, value_type val) -{ QMutexLocker l(get_mtx()); - auto it = connected_values.find(name); + const auto it = connected_values.find(name); if (it != connected_values.end()) { - std::vector<value_type>& values = std::get<0>((*it).second); - for (auto it = values.begin(); it != values.end(); it++) + value_vec& values = it->second; + for (auto it = values.begin(); it != values.end(); ) { if (*it == val) - { - values.erase(it); - return true; - } + it = values.erase(it); + else + it++; } } - return false; -} - -void connector::on_value_destructed(const QString& name, value_type val) -{ - if (!name.size()) - return; - - const bool ok = on_value_destructed_impl(name, val); - if (!ok) - qWarning() << "options/connector: value destructed without creating;" - << "bundle" - << val->b->name() - << "value-name" << name - << "value-ptr" << quintptr(val); + if (it != connected_values.end() && it->second.empty()) + connected_values.erase(it); } -void connector::on_value_created(const QString& name, value_type val) +void connector::on_value_created(value_type val) { - if (!name.size()) + const QString& name = val->name(); + + if (name.isEmpty()) return; QMutexLocker l(get_mtx()); - int i = 1; - while (on_value_destructed_impl(name, val)) - { - qWarning() << "options/connector: value created twice;" - << "cnt" << i++ - << "bundle" << val->b->name() - << "value-name" << name - << "value-ptr" << quintptr(val); - } - auto it = connected_values.find(name); if (it != connected_values.end()) { - tt& tmp = (*it).second; - std::type_index& typeidx = std::get<2>(tmp); - std::vector<value_type>& values = std::get<0>(tmp); - - if (typeidx != val->type_index) - std::get<1>((*it).second) = generic_is_equal; + value_vec& values = it->second; values.push_back(val); } else { - std::vector<value_type> vec; + value_vec vec; + vec.reserve(4); vec.push_back(val); - connected_values.emplace(name, tt(vec, val->cmp, val->type_index)); + connected_values.emplace(name, vec); } } @@ -109,17 +67,15 @@ void connector::notify_values(const QString& name) const { auto it = connected_values.find(name); if (it != connected_values.cend()) - for (value_type val : std::get<0>((*it).second)) + for (value_type val : it->second) val->bundle_value_changed(); } void connector::notify_all_values() const { - for (auto& [k, v] : connected_values) - for (value_type val : std::get<0>(v)) + for (const auto& [k, v] : connected_values) + for (value_type val : v) val->bundle_value_changed(); } -connector::connector() = default; - } // ns options::detail |