From 109b6dd280e5cc6129f9ea739f1ab4b545cd593a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 20 Aug 2016 11:46:42 +0200 Subject: options/connector: spew more warnings --- options/connector.cpp | 54 ++++++++++++++++++++++++++++++++++++--------------- options/connector.hpp | 1 + options/value.hpp | 1 + 3 files changed, 40 insertions(+), 16 deletions(-) (limited to 'options') diff --git a/options/connector.cpp b/options/connector.cpp index ba460b1f..c1bbce39 100644 --- a/options/connector.cpp +++ b/options/connector.cpp @@ -1,3 +1,4 @@ +#include "compat/util.hpp" #include "connector.hpp" #include "value.hpp" @@ -6,37 +7,58 @@ namespace detail { connector::~connector() {} -void connector::on_value_destructed(const QString& name, const base_value* val) +bool connector::on_value_destructed_impl(const QString& name, const base_value* val) { QMutexLocker l(get_mtx()); - auto it = connected_values.find(name); - - bool ok = false; + const bool ok = progn( + auto it = connected_values.find(name); - if (it != connected_values.end()) - { - std::vector& values = (*it).second; - for (auto it = values.begin(); it != values.end(); it++) + if (it != connected_values.end()) { - if (*it == val) + std::vector& values = (*it).second; + for (auto it = values.begin(); it != values.end(); it++) { - values.erase(it); - ok = true; - break; + if (*it == val) + { + values.erase(it); + return true; + } } } - } + return false; + ); + + return ok; +} + + + +void connector::on_value_destructed(const QString& name, const base_value* val) +{ + const bool ok = on_value_destructed_impl(name, val); if (!ok) - qWarning() << "connector: bundle destructed without creating;" - << "name" << name - << "ptr" << quintptr(val); + qWarning() << "options/connector: value destructed without creating;" + << "bundle" + << (val && val->b ? val->b->name() : "") + << "value-name" << name + << "value-ptr" << quintptr(val); } void connector::on_value_created(const QString& name, const base_value* val) { QMutexLocker l(get_mtx()); + + if (on_value_destructed_impl(name, val)) + { + qWarning() << "options/connector: value created twice;" + << "bundle" + << (val && val->b ? val->b->name() : "") + << "value-name" << name + << "value-ptr" << quintptr(val); + } + auto it = connected_values.find(name); if (it != connected_values.end()) diff --git a/options/connector.hpp b/options/connector.hpp index ef9e4dbf..504c636d 100644 --- a/options/connector.hpp +++ b/options/connector.hpp @@ -22,6 +22,7 @@ class OPENTRACK_OPTIONS_EXPORT connector void on_value_destructed(const QString& name, const base_value* val); void on_value_created(const QString& name, const base_value* val); + bool on_value_destructed_impl(const QString& name, const base_value* val); protected: void notify_values(const QString& name) const; diff --git a/options/value.hpp b/options/value.hpp index f0ecf0c7..4ed61f1c 100644 --- a/options/value.hpp +++ b/options/value.hpp @@ -27,6 +27,7 @@ template using value_type_t = typename value_type_traits::type; class OPENTRACK_OPTIONS_EXPORT base_value : public QObject { Q_OBJECT + friend class ::options::detail::connector; public: QString name() const { return self_name; } base_value(bundle b, const QString& name) : b(b), self_name(name) -- cgit v1.2.3