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
70 signal_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
71 : exception{reason_, file_name_, line_number_}
80 class signal_full :
public signal_exception
84 signal_full(string_type file_name_, numeric_type line_number_)
85 : signal_exception{ETL_ERROR_TEXT(
"signal:full", ETL_SIGNAL_FILE_ID
"A"), file_name_, line_number_}
101 template <
typename TFunction,
size_t Size,
typename TSlot = etl::delegate<TFunction>>
106 using slot_type = TSlot;
107 using size_type = size_t;
108 using span_type = etl::span<const slot_type>;
115 template <
typename... TSlots>
116 ETL_CONSTEXPR14
explicit signal(TSlots&&... slots) ETL_NOEXCEPT
117 : slot_list{etl::forward<TSlots>(slots)...}
118 , slot_list_end{slot_list +
sizeof...(slots)}
120 static_assert((etl::are_all_same<slot_type, etl::decay_t<TSlots>...>::value),
"All slots must be slot_type");
121 static_assert(
sizeof...(slots) <= Size,
"Number of slots exceeds capacity");
131 bool connect(
const slot_type& slot) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
133 if (!connected(slot))
135 ETL_ASSERT_OR_RETURN_VALUE(!full(), ETL_ERROR(signal_full),
false);
142 #if ETL_HAS_INITIALIZER_LIST && ETL_USING_CPP17
150 bool connect(std::initializer_list<const slot_type> slots) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
152 for (
const slot_type& slot : slots)
154 if (!connected(slot))
156 ETL_ASSERT_OR_RETURN_VALUE(!full(), ETL_ERROR(signal_full),
false);
172 bool connect(
const span_type slots) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
174 for (
const slot_type& slot : slots)
176 if (!connected(slot))
178 ETL_ASSERT_OR_RETURN_VALUE(!full(), ETL_ERROR(signal_full),
false);
191 void disconnect(
const slot_type& slot) ETL_NOEXCEPT
193 const auto end_itr =
end();
194 const auto itr = etl::find(
begin(), end_itr, slot);
199 etl::copy(etl::next(itr), end_itr, itr);
200 slot_list_end = etl::prev(slot_list_end);
204 #if ETL_HAS_INITIALIZER_LIST && ETL_USING_CPP17
210 void disconnect(std::initializer_list<const slot_type> slots) ETL_NOEXCEPT
212 for (
const slot_type& slot : slots)
224 void disconnect(
const span_type slots) ETL_NOEXCEPT
226 for (
const slot_type& slot : slots)
235 void disconnect_all() ETL_NOEXCEPT
237 slot_list_end =
begin();
246 ETL_CONSTEXPR14
bool connected(
const slot_type& slot)
const ETL_NOEXCEPT
254 ETL_CONSTEXPR14
bool empty() const ETL_NOEXCEPT
263 ETL_CONSTEXPR14
bool full() const ETL_NOEXCEPT
265 return size() == max_size();
271 ETL_CONSTEXPR14 size_type max_size() const ETL_NOEXCEPT
279 ETL_CONSTEXPR14 size_type
size() const ETL_NOEXCEPT
281 return static_cast<size_type
>(etl::distance(
begin(),
end()));
287 ETL_CONSTEXPR14 size_type available() const ETL_NOEXCEPT
289 return max_size() -
size();
298 template <
typename... TArgs>
299 void operator()(TArgs&&... args)
const ETL_NOEXCEPT
301 for (
const slot_type& slot : *
this)
303 if (slot_is_valid(slot))
305 slot(etl::forward<TArgs>(args)...);
312 using iterator = slot_type*;
313 using const_iterator =
const slot_type*;
315 slot_type slot_list[Size];
316 iterator slot_list_end;
321 void append_slot(
const slot_type& slot) ETL_NOEXCEPT
323 (*slot_list_end) = slot;
324 slot_list_end = etl::next(slot_list_end);
330 template <
typename TSlotType,
typename... TArgs>
331 static typename etl::enable_if_t<etl::is_delegate<TSlotType>::value,
bool> slot_is_valid(
const TSlotType& s) ETL_NOEXCEPT
339 template <
typename TSlotType,
typename... TArgs>
340 static typename etl::enable_if_t<!etl::is_delegate<TSlotType>::value,
bool> 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:2173
Definition exception.h:59
bitset_ext
Definition absolute.h:40
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1192
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition iterator.h:967
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition iterator.h:997