31#ifndef ETL_SIGNAL_INCLUDED
32#define ETL_SIGNAL_INCLUDED
38#if ETL_NOT_USING_CPP11 && !defined(ETL_IN_UNIT_TEST)
39#error NOT SUPPORTED FOR C++03 OR BELOW
69 signal_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
70 : exception{reason_, file_name_, line_number_}
79 class signal_full :
public signal_exception
82 signal_full(string_type file_name_, numeric_type line_number_)
83 : signal_exception{ETL_ERROR_TEXT(
"signal:full", ETL_SIGNAL_FILE_ID
"A"), file_name_, line_number_}
98 template <
typename TFunction,
size_t Size,
typename TSlot = etl::delegate<TFunction>>
103 using slot_type = TSlot;
104 using size_type = size_t;
105 using span_type = etl::span<const slot_type>;
112 template <
typename... TSlots>
113 ETL_CONSTEXPR14
explicit signal(TSlots&&... slots) ETL_NOEXCEPT
114 : slot_list{etl::forward<TSlots>(slots)...}
115 , slot_list_end{slot_list +
sizeof...(slots)}
117 static_assert((etl::are_all_same<slot_type, etl::decay_t<TSlots>...>::value),
"All slots must be slot_type");
118 static_assert(
sizeof...(slots) <= Size,
"Number of slots exceeds capacity");
128 bool connect(
const slot_type& slot) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
130 if (!connected(slot))
132 ETL_ASSERT_OR_RETURN_VALUE(!full(), ETL_ERROR(signal_full),
false);
139#if ETL_HAS_INITIALIZER_LIST && ETL_USING_CPP17
147 bool connect(std::initializer_list<const slot_type> slots) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
149 for (
const slot_type& slot : slots)
151 if (!connected(slot))
153 ETL_ASSERT_OR_RETURN_VALUE(!full(), ETL_ERROR(signal_full),
false);
169 bool connect(
const span_type slots) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
171 for (
const slot_type& slot : slots)
173 if (!connected(slot))
175 ETL_ASSERT_OR_RETURN_VALUE(!full(), ETL_ERROR(signal_full),
false);
188 void disconnect(
const slot_type& slot) ETL_NOEXCEPT
190 const auto end_itr =
end();
191 const auto itr = etl::find(
begin(), end_itr, slot);
196 etl::copy(etl::next(itr), end_itr, itr);
197 slot_list_end = etl::prev(slot_list_end);
201#if ETL_HAS_INITIALIZER_LIST && ETL_USING_CPP17
207 void disconnect(std::initializer_list<const slot_type> slots) ETL_NOEXCEPT
209 for (
const slot_type& slot : slots)
221 void disconnect(
const span_type slots) ETL_NOEXCEPT
223 for (
const slot_type& slot : slots)
232 void disconnect_all() ETL_NOEXCEPT
234 slot_list_end =
begin();
243 ETL_CONSTEXPR14
bool connected(
const slot_type& slot)
const ETL_NOEXCEPT
251 ETL_CONSTEXPR14
bool empty() const ETL_NOEXCEPT
259 ETL_CONSTEXPR14
bool full() const ETL_NOEXCEPT
267 ETL_CONSTEXPR14 size_type
max_size() const ETL_NOEXCEPT
275 ETL_CONSTEXPR14 size_type
size() const ETL_NOEXCEPT
277 return etl::distance(
begin(),
end());
283 ETL_CONSTEXPR14 size_type available() const ETL_NOEXCEPT
294 template <
typename... TArgs>
295 void operator()(TArgs&&... args)
const ETL_NOEXCEPT
297 for (
const slot_type& slot : *
this)
299 if (slot_is_valid(slot))
301 slot(etl::forward<TArgs>(args)...);
308 using iterator = slot_type*;
309 using const_iterator =
const slot_type*;
311 slot_type slot_list[Size];
312 iterator slot_list_end;
317 void append_slot(
const slot_type& slot) ETL_NOEXCEPT
319 (*slot_list_end) = slot;
320 slot_list_end = etl::next(slot_list_end);
326 template <
typename TSlotType,
typename... TArgs>
328 typename etl::enable_if_t<etl::is_delegate<TSlotType>::value,
bool>
329 slot_is_valid(
const TSlotType& s) ETL_NOEXCEPT
337 template <
typename TSlotType,
typename... TArgs>
339 typename etl::enable_if_t<!etl::is_delegate<TSlotType>::value,
bool>
340 slot_is_valid(
const TSlotType&) ETL_NOEXCEPT
348 ETL_CONSTEXPR14 iterator
begin() ETL_NOEXCEPT
356 ETL_CONSTEXPR14 const_iterator
begin() const ETL_NOEXCEPT
364 ETL_CONSTEXPR14 iterator
end() ETL_NOEXCEPT
366 return slot_list_end;
372 ETL_CONSTEXPR14 const_iterator
end() const ETL_NOEXCEPT
374 return slot_list_end;
ETL_NODISCARD ETL_CONSTEXPR14 bool any_of(TIterator begin, TIterator end, TUnaryPredicate predicate)
Definition algorithm.h:2116
Definition exception.h:47
bitset_ext
Definition absolute.h:39
size_t max_size() const
Returns the maximum number of items in the variant_pool.
Definition variant_pool_generator.h:395
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1187
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition iterator.h:962
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition iterator.h:992