29#ifndef ETL_MESSAGE_ROUTER_REGISTRY_INCLUDED
30#define ETL_MESSAGE_ROUTER_REGISTRY_INCLUDED
34#include "message_router.h"
52 message_router_registry_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
65 message_router_registry_full(string_type file_name_, numeric_type line_number_)
66 : message_router_registry_exception(ETL_ERROR_TEXT(
"message router registry:full", ETL_MESSAGE_ROUTER_REGISTRY_FILE_ID
"A"), file_name_, line_number_)
74 class imessage_router_registry
87 class iterator :
public etl::iterator<ETL_OR_STD::forward_iterator_tag, etl::imessage_router*>
91 friend class imessage_router_registry;
92 friend class const_iterator;
100 iterator(
const iterator& other)
106 iterator& operator =(
const iterator& other)
115 return *(itr->second);
121 return *(itr->second);
137 iterator& operator ++()
144 iterator operator ++(
int)
146 iterator temp(*
this);
152 friend bool operator ==(
const iterator& lhs,
const iterator& rhs)
154 return lhs.itr == rhs.itr;
158 friend bool operator !=(
const iterator& lhs,
const iterator& rhs)
160 return !(lhs == rhs);
166 iterator(IRegistry::iterator itr_)
171 IRegistry::iterator itr;
177 class const_iterator :
etl::iterator<ETL_OR_STD::forward_iterator_tag, const etl::imessage_router*>
181 friend class imessage_router_registry;
195 const_iterator(
const const_iterator& other)
201 const_iterator& operator =(
const const_iterator& other)
210 return *(itr->second);
220 const_iterator& operator ++()
227 const_iterator operator ++(
int)
229 const_iterator temp(*
this);
235 friend bool operator ==(
const const_iterator& lhs,
const const_iterator& rhs)
237 return lhs.itr == rhs.itr;
241 friend bool operator !=(
const const_iterator& lhs,
const const_iterator& rhs)
243 return !(lhs == rhs);
249 const_iterator(IRegistry::const_iterator itr_)
254 IRegistry::const_iterator itr;
270 const_iterator cbegin()
const
272 return const_iterator(registry.
cbegin());
288 const_iterator cend()
const
290 return const_iterator(registry.
cend());
298 IRegistry::iterator itr = registry.find(
id);
300 if (registry.find(
id) != registry.end())
312 IRegistry::const_iterator itr = registry.
find(
id);
314 if (registry.
find(
id) != registry.
end())
329 return iterator(registry.lower_bound(
id));
342 return iterator(registry.upper_bound(
id));
356 if (!registry.full() && !
contains(router))
358 IRegistry::value_type element(router.get_message_router_id(), &router);
360 registry.insert(element);
374 if (p_router != ETL_NULLPTR)
384 template <
typename TIterator>
385 void add(TIterator first,
const TIterator& last)
387 while (first != last)
406 bool contains(
const etl::message_router_id_t
id)
const
408 return find(
id) != ETL_NULLPTR;
420 if (p_router == ETL_NULLPTR)
425 IRegistry::const_iterator irouter = registry.find(p_router->get_message_router_id());
427 return (irouter != registry.cend()) && (irouter->second == p_router);
436 IRegistry::const_iterator irouter = registry.find(router.get_message_router_id());
438 return (irouter != registry.cend()) && (irouter->second == &router);
444 size_t count(
const etl::message_router_id_t
id)
const
446 return registry.count(
id);
454 return registry.empty();
462 return registry.full();
470 return registry.size();
478 return registry.available();
486 return registry.max_size();
495 : registry(registry_)
507 template <
size_t MaxRouters>
515 message_router_registry()
516 : imessage_router_registry(registry)
524 template <
typename TIterator>
526 : imessage_router_registry(registry)
528 while (first != last)
535#if ETL_HAS_INITIALIZER_LIST
542 std::initializer_list<etl::imessage_router*>::const_iterator itr = init.
begin();
544 while (itr != init.end())
555 message_router_registry(
const message_router_registry& rhs)
556 : imessage_router_registry(registry)
558 registry = rhs.registry;
564 message_router_registry& operator =(
const message_router_registry& rhs)
566 registry = rhs.registry;
573 typedef etl::flat_multimap<etl::message_router_id_t, etl::imessage_router*, MaxRouters> Registry;
Const Iterator.
Definition message_router_registry.h:178
Iterator.
Definition message_router_registry.h:88
This is the base of all message router registries.
Definition message_router_registry.h:75
void add(etl::imessage_router *p_router)
Definition message_router_registry.h:372
iterator lower_bound(etl::message_router_id_t id)
Get the lower bound in the registry with the specified ID.
Definition message_router_registry.h:327
bool contains(const etl::message_router_id_t id) const
Definition message_router_registry.h:406
bool contains(const etl::imessage_router &router) const
Definition message_router_registry.h:434
bool full() const
Returns true if the registry is full, otherwise false.
Definition message_router_registry.h:460
etl::imessage_router * find(etl::message_router_id_t id)
Get the first router in the registry with the specified ID.
Definition message_router_registry.h:296
bool empty() const
Returns true if the registry is empty, otherwise false.
Definition message_router_registry.h:452
void add(TIterator first, const TIterator &last)
Definition message_router_registry.h:385
size_t size() const
Returns the size of the registry.
Definition message_router_registry.h:468
size_t available() const
Returns the available size of the registry.
Definition message_router_registry.h:476
iterator upper_bound(etl::message_router_id_t id)
Get the upper bound in the registry with the specified ID.
Definition message_router_registry.h:340
bool contains(const etl::imessage_router *const p_router) const
Definition message_router_registry.h:418
size_t max_size() const
Returns the maximum size of the registry.
Definition message_router_registry.h:484
iterator end()
Get the end of the registry.
Definition message_router_registry.h:278
void add(etl::imessage_router &router)
Definition message_router_registry.h:354
iterator begin()
Get the beginning of the registry.
Definition message_router_registry.h:260
void remove(etl::message_router_id_t id)
Unregisters a router.
Definition message_router_registry.h:397
size_t count(const etl::message_router_id_t id) const
Returns the number of routers with the specified ID.
Definition message_router_registry.h:444
This is the base of all message routers.
Definition message_router_generator.h:121
Base exception class for message router registry.
Definition message_router_registry.h:49
The registry is full.
Definition message_router_registry.h:62
Message router registry.
Definition message_router_registry.h:509
message_router_registry(TIterator first, const TIterator &last)
Definition message_router_registry.h:525
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:962
Definition exception.h:47
iterator end()
Definition flat_multimap.h:145
const_iterator cbegin() const
Definition flat_multimap.h:163
const_iterator cend() const
Definition flat_multimap.h:172
iterator upper_bound(const_key_reference key)
Definition flat_multimap.h:671
iterator find(const_key_reference key)
Definition flat_multimap.h:576
iterator lower_bound(const_key_reference key)
Definition flat_multimap.h:633
Definition flat_multimap.h:62
bitset_ext
Definition absolute.h:39
iterator
Definition iterator.h:399