From cf44a59ca38ebda832bdab9c6cb8f5b1f2bda2de Mon Sep 17 00:00:00 2001 From: Dawid Drozd Date: Sat, 29 Jun 2019 11:10:02 +0200 Subject: [PATCH] Rename Dexode::Internal::type_id to Dexode::Internal::event_id --- lib/include/eventbus/AsyncEventBus.h | 8 ++++---- lib/include/eventbus/EventBus.h | 8 ++++---- lib/include/eventbus/internal/common.h | 4 ++-- test/src/EventIdTest.cpp | 17 +++++++++-------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/include/eventbus/AsyncEventBus.h b/lib/include/eventbus/AsyncEventBus.h index 11ec1c4..b8b7ea8 100644 --- a/lib/include/eventbus/AsyncEventBus.h +++ b/lib/include/eventbus/AsyncEventBus.h @@ -80,7 +80,7 @@ public: assert(callback && "callback should be valid"); //Check for valid object std::unique_ptr& vector = - _callbacks[Internal::type_id()]; + _callbacks[Internal::event_id()]; if(vector == nullptr) { vector.reset(new Vector {}); @@ -125,7 +125,7 @@ public: _commandsQueue.push_back([this, token]() { std::lock_guard guard {_callbacksMutex}; - auto found = _callbacks.find(Internal::type_id); + auto found = _callbacks.find(Internal::event_id); if(found != _callbacks.end()) { found->second->remove(token); @@ -149,7 +149,7 @@ public: std::lock_guard guard {_callbacksMutex}; using Vector = Internal::AsyncCallbackVector; - auto found = _callbacks.find(Internal::type_id()); + auto found = _callbacks.find(Internal::event_id()); if(found == _callbacks.end()) { return; // no such notifications @@ -205,7 +205,7 @@ private: std::size_t processCommandsAndGetQueuedEventsCount(); int _tokener = 0; - std::map> _callbacks; + std::map> _callbacks; mutable std::mutex _callbacksMutex; mutable std::mutex _eventMutex; diff --git a/lib/include/eventbus/EventBus.h b/lib/include/eventbus/EventBus.h index 5a20033..b0fd684 100644 --- a/lib/include/eventbus/EventBus.h +++ b/lib/include/eventbus/EventBus.h @@ -59,7 +59,7 @@ public: assert(callback && "callback should be valid"); //Check for valid object - std::unique_ptr& vector = _callbacks[Internal::type_id()]; + std::unique_ptr& vector = _callbacks[Internal::event_id()]; if(vector == nullptr) { vector.reset(new Vector {}); @@ -89,7 +89,7 @@ public: { static_assert(Internal::validateEvent(), "Invalid event"); - auto found = _callbacks.find(Internal::type_id()); + auto found = _callbacks.find(Internal::event_id()); if(found != _callbacks.end()) { found->second->remove(token); @@ -108,7 +108,7 @@ public: static_assert(Internal::validateEvent(), "Invalid event"); using Vector = Internal::TransactionCallbackVector; - auto found = _callbacks.find(Internal::type_id()); + auto found = _callbacks.find(Internal::event_id()); if(found == _callbacks.end()) { return; // no such notifications @@ -128,7 +128,7 @@ public: private: int _tokener = 0; - std::map> _callbacks; + std::map> _callbacks; }; } /* namespace Dexode */ diff --git a/lib/include/eventbus/internal/common.h b/lib/include/eventbus/internal/common.h index bac1487..04acee1 100644 --- a/lib/include/eventbus/internal/common.h +++ b/lib/include/eventbus/internal/common.h @@ -7,10 +7,10 @@ namespace Dexode namespace Internal { -using type_id_t = std::size_t; +using event_id_t = std::size_t; template -type_id_t type_id() // Helper for getting "type id" +constexpr event_id_t event_id() // Helper for getting "type id" { return typeid(T).hash_code(); } diff --git a/test/src/EventIdTest.cpp b/test/src/EventIdTest.cpp index 7ec8e87..716452d 100644 --- a/test/src/EventIdTest.cpp +++ b/test/src/EventIdTest.cpp @@ -33,18 +33,19 @@ struct TestA } // namespace Test -TEST_CASE("Should return unique id for each event When using Internal::type_id", "[EventId]") +TEST_CASE("Should return unique id for each event When using Internal::event_id", + "[EventId]") { - std::set unique; + std::set unique; - REQUIRE(unique.insert(Dexode::Internal::type_id()).second); - REQUIRE_FALSE(unique.insert(Dexode::Internal::type_id()).second); //already there + REQUIRE(unique.insert(Dexode::Internal::event_id()).second); + REQUIRE_FALSE(unique.insert(Dexode::Internal::event_id()).second); //already there struct TestA {}; - REQUIRE(unique.insert(Dexode::Internal::type_id()).second); - REQUIRE(unique.insert(Dexode::Internal::type_id<::TestA>()).second); - REQUIRE(unique.insert(Dexode::Internal::type_id()).second); - REQUIRE(unique.insert(Dexode::Internal::type_id()).second); + REQUIRE(unique.insert(Dexode::Internal::event_id()).second); + REQUIRE(unique.insert(Dexode::Internal::event_id<::TestA>()).second); + REQUIRE(unique.insert(Dexode::Internal::event_id()).second); + REQUIRE(unique.insert(Dexode::Internal::event_id()).second); }