Rename Dexode::Internal::type_id to Dexode::Internal::event_id

This commit is contained in:
Dawid Drozd 2019-06-29 11:10:02 +02:00
parent cb4438bee1
commit cf44a59ca3
4 changed files with 19 additions and 18 deletions

View File

@ -80,7 +80,7 @@ public:
assert(callback && "callback should be valid"); //Check for valid object
std::unique_ptr<Internal::CallbackVector>& vector =
_callbacks[Internal::type_id<Event>()];
_callbacks[Internal::event_id<Event>()];
if(vector == nullptr)
{
vector.reset(new Vector {});
@ -125,7 +125,7 @@ public:
_commandsQueue.push_back([this, token]() {
std::lock_guard<std::mutex> guard {_callbacksMutex};
auto found = _callbacks.find(Internal::type_id<Event>);
auto found = _callbacks.find(Internal::event_id<Event>);
if(found != _callbacks.end())
{
found->second->remove(token);
@ -149,7 +149,7 @@ public:
std::lock_guard<std::mutex> guard {_callbacksMutex};
using Vector = Internal::AsyncCallbackVector<Event>;
auto found = _callbacks.find(Internal::type_id<Event>());
auto found = _callbacks.find(Internal::event_id<Event>());
if(found == _callbacks.end())
{
return; // no such notifications
@ -205,7 +205,7 @@ private:
std::size_t processCommandsAndGetQueuedEventsCount();
int _tokener = 0;
std::map<Internal::type_id_t, std::unique_ptr<Internal::CallbackVector>> _callbacks;
std::map<Internal::event_id_t, std::unique_ptr<Internal::CallbackVector>> _callbacks;
mutable std::mutex _callbacksMutex;
mutable std::mutex _eventMutex;

View File

@ -59,7 +59,7 @@ public:
assert(callback && "callback should be valid"); //Check for valid object
std::unique_ptr<Internal::CallbackVector>& vector = _callbacks[Internal::type_id<Event>()];
std::unique_ptr<Internal::CallbackVector>& vector = _callbacks[Internal::event_id<Event>()];
if(vector == nullptr)
{
vector.reset(new Vector {});
@ -89,7 +89,7 @@ public:
{
static_assert(Internal::validateEvent<Event>(), "Invalid event");
auto found = _callbacks.find(Internal::type_id<Event>());
auto found = _callbacks.find(Internal::event_id<Event>());
if(found != _callbacks.end())
{
found->second->remove(token);
@ -108,7 +108,7 @@ public:
static_assert(Internal::validateEvent<Event>(), "Invalid event");
using Vector = Internal::TransactionCallbackVector<CleanEventType>;
auto found = _callbacks.find(Internal::type_id<CleanEventType>());
auto found = _callbacks.find(Internal::event_id<CleanEventType>());
if(found == _callbacks.end())
{
return; // no such notifications
@ -128,7 +128,7 @@ public:
private:
int _tokener = 0;
std::map<Internal::type_id_t, std::unique_ptr<Internal::CallbackVector>> _callbacks;
std::map<Internal::event_id_t, std::unique_ptr<Internal::CallbackVector>> _callbacks;
};
} /* namespace Dexode */

View File

@ -7,10 +7,10 @@ namespace Dexode
namespace Internal
{
using type_id_t = std::size_t;
using event_id_t = std::size_t;
template <typename T>
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();
}

View File

@ -33,18 +33,19 @@ struct TestA
} // namespace Test
TEST_CASE("Should return unique id for each event When using Internal::type_id<Event>", "[EventId]")
TEST_CASE("Should return unique id for each event When using Internal::event_id<Event>",
"[EventId]")
{
std::set<Dexode::Internal::type_id_t> unique;
std::set<Dexode::Internal::event_id_t> unique;
REQUIRE(unique.insert(Dexode::Internal::type_id<Anonymous>()).second);
REQUIRE_FALSE(unique.insert(Dexode::Internal::type_id<Anonymous>()).second); //already there
REQUIRE(unique.insert(Dexode::Internal::event_id<Anonymous>()).second);
REQUIRE_FALSE(unique.insert(Dexode::Internal::event_id<Anonymous>()).second); //already there
struct TestA
{};
REQUIRE(unique.insert(Dexode::Internal::type_id<TestA>()).second);
REQUIRE(unique.insert(Dexode::Internal::type_id<::TestA>()).second);
REQUIRE(unique.insert(Dexode::Internal::type_id<Test::TestA>()).second);
REQUIRE(unique.insert(Dexode::Internal::type_id<Test::TestN::TestA>()).second);
REQUIRE(unique.insert(Dexode::Internal::event_id<TestA>()).second);
REQUIRE(unique.insert(Dexode::Internal::event_id<::TestA>()).second);
REQUIRE(unique.insert(Dexode::Internal::event_id<Test::TestA>()).second);
REQUIRE(unique.insert(Dexode::Internal::event_id<Test::TestN::TestA>()).second);
}