27#include <unordered_set>
30#include <boost/functional/hash.hpp>
40template <
class MessageT>
56 using UidSet = std::unordered_set<::boost::uuids::uuid, boost::hash<boost::uuids::uuid>>;
85 size_t remove_sender(
const UID &uid) {
return senders_.erase(
static_cast<boost::uuids::uuid
>(uid)); }
93 size_t add_sender(
const UID &uid) {
return senders_.insert(
static_cast<boost::uuids::uuid
>(uid)).second; }
102 size_t size_before = senders_.size();
103 std::copy(senders.begin(), senders.end(), std::inserter(senders_, senders_.end()));
104 return senders_.size() - size_before;
114 return senders_.find(
static_cast<boost::uuids::uuid
>(uid)) != senders_.end();
154 std::unordered_set<::boost::uuids::uuid, boost::hash<boost::uuids::uuid>> senders_;
The Subscription class is used for message exchange between the network entities.
UID get_receiver_uid() const
Get UID of the entity that receives messages via the subscription.
std::vector< MessageType > MessageContainerType
Internal container for messages of the specified message type.
const MessageContainerType & get_messages() const
Get all messages.
std::unordered_set<::boost::uuids::uuid, boost::hash< boost::uuids::uuid > > UidSet
Internal container for UIDs.
Subscription(const UID &receiver, const std::vector< UID > &senders)
Subscription constructor.
const UidSet & get_senders() const
Get list of sender UIDs.
size_t remove_sender(const UID &uid)
Unsubscribe from a sender.
MessageContainerType & get_messages()
Get all messages.
void add_message(MessageType &&message)
Add a message to the subscription.
size_t add_sender(const UID &uid)
Add a sender with the given UID to the subscription.
size_t add_senders(const std::vector< UID > &senders)
Add several senders to the subscription.
void clear_messages()
Remove all stored messages.
bool has_sender(const UID &uid) const
Check if a sender with the given UID exists.
MessageT MessageType
Message type.
void add_message(const MessageType &message)
Add a message to the subscription.