rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
address_mapping.h
1#pragma once
2
3//
4// Copyright (c) 2019-2022 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
5//
6// Distributed under the MIT Software License
7//
8
9#include "arc.hpp"
10#include "subscription.h"
11#include <unordered_map>
12#include <vector>
13
14#if defined(_MSC_VER)
15#pragma warning(push)
16#pragma warning(disable : 4251)
17#endif
18
19namespace rotor {
20
33struct ROTOR_API address_mapping_t {
44 void set(actor_base_t &actor, const subscription_info_ptr_t &info) noexcept;
45
47 address_ptr_t get_mapped_address(actor_base_t &actor, const void *) noexcept;
48
50 template <typename Fn> void each_subscription(const actor_base_t &actor, Fn &&fn) const noexcept {
51 auto it_mappings = actor_map.find(static_cast<const void *>(&actor));
52 for (auto it : it_mappings->second) {
53 fn(it.second);
54 }
55 }
56
58 bool has_subscriptions(const actor_base_t &actor) const noexcept;
59
61 bool empty() const noexcept { return actor_map.empty(); }
62
64 void remove(const subscription_point_t &point) noexcept;
65
66 private:
67 using point_map_t = std::unordered_map<const void *, subscription_info_ptr_t>;
68 using actor_map_t = std::unordered_map<const void *, point_map_t>;
69 actor_map_t actor_map;
70};
71
72} // namespace rotor
73
74#if defined(_MSC_VER)
75#pragma warning(pop)
76#endif
Basic namespace for all rotor functionalities.
Definition rotor.hpp:21
intrusive_ptr_t< address_t > address_ptr_t
intrusive pointer for address
Definition address.hpp:57
intrusive_ptr_t< subscription_info_t > subscription_info_ptr_t
intrusive pointer for subscription_info_t
Definition subscription_point.h:127
universal primitive of concurrent computation
Definition actor_base.h:47
NAT mechanism for rotor
Definition address_mapping.h:33
bool has_subscriptions(const actor_base_t &actor) const noexcept
checks whether an actor has any subscriptions
address_ptr_t get_mapped_address(actor_base_t &actor, const void *) noexcept
returns temporal destination address for the actor/message type
void remove(const subscription_point_t &point) noexcept
forgets subscription point
bool empty() const noexcept
returns true if there is no any subscription for any actor
Definition address_mapping.h:61
void set(actor_base_t &actor, const subscription_info_ptr_t &info) noexcept
associates temporal destination point with actor's message type
void each_subscription(const actor_base_t &actor, Fn &&fn) const noexcept
iterates on all subscriptions for an actor
Definition address_mapping.h:50
pair of handler_base_t linked to particular address_t
Definition subscription_point.h:50