mirror of
https://github.com/gelldur/EventBus.git
synced 2025-01-14 01:07:59 +08:00
Rename Dexode::Internal::type_id to Dexode::Internal::event_id
This commit is contained in:
parent
cb4438bee1
commit
cf44a59ca3
@ -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;
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user