48#ifndef ETL_DELEGATE_CPP11_INCLUDED
49#define ETL_DELEGATE_CPP11_INCLUDED
51#include "../platform.h"
52#include "../error_handler.h"
53#include "../exception.h"
54#include "../type_traits.h"
55#include "../utility.h"
56#include "../optional.h"
63 class delegate_exception :
public exception
67 delegate_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
68 :
exception(reason_, file_name_, line_number_)
76 class delegate_uninitialised :
public delegate_exception
80 delegate_uninitialised(string_type file_name_, numeric_type line_number_)
81 : delegate_exception(ETL_ERROR_TEXT(
"delegate:uninitialised", ETL_DELEGATE_FILE_ID
"A"), file_name_, line_number_)
89 template <
typename T>
class delegate;
94 template <
typename TReturn,
typename... TParams>
123 template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value && !
etl::is_same<
etl::delegate<TReturn(TParams...)>, TLambda>::value,
void>>
124 ETL_CONSTEXPR14 delegate(
const TLambda& instance)
126 assign((
void*)(&instance), const_lambda_stub<TLambda>);
132 template <TReturn(*Method)(TParams...)>
235#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
240 template <
typename T, T& Instance>
252 ETL_CONSTEXPR14
void set()
353 template <
typename TRet = TReturn>
373 template <
typename TRet = TReturn>
392 template <
typename TAlternative>
452 return invocation ==
rhs.invocation;
460 return invocation !=
rhs.invocation;
469 return invocation.stub != ETL_NULLPTR;
475 ETL_CONSTEXPR14
operator bool()
const
487 struct invocation_element
489 invocation_element() =
default;
492 ETL_CONSTEXPR14 invocation_element(
void*
object_, stub_type
stub_)
499 ETL_CONSTEXPR14
bool operator ==(
const invocation_element& rhs)
const
501 return (rhs.stub == stub) && (rhs.object == object);
505 ETL_CONSTEXPR14
bool operator !=(
const invocation_element& rhs)
const
507 return (rhs.stub != stub) || (rhs.object != object);
511 ETL_CONSTEXPR14
void clear()
513 object = ETL_NULLPTR;
518 void*
object = ETL_NULLPTR;
519 stub_type stub = ETL_NULLPTR;
525 ETL_CONSTEXPR14 delegate(
void*
object, stub_type stub)
526 : invocation(object, stub)
533 ETL_CONSTEXPR14 delegate(stub_type stub)
534 : invocation(ETL_NULLPTR, stub)
541 ETL_CONSTEXPR14
void assign(
void*
object, stub_type stub)
543 invocation.object = object;
544 invocation.stub = stub;
550 template <
typename T, TReturn(T::*Method)(TParams...)>
551 static ETL_CONSTEXPR14 TReturn method_stub(void* object, TParams... params)
553 T* p =
static_cast<T*
>(object);
560 template <
typename T, TReturn(T::*Method)(TParams...) const>
561 static ETL_CONSTEXPR14 TReturn const_method_stub(void* object, TParams... params)
563 T*
const p =
static_cast<T*
>(object);
570 template <
typename T, TReturn(T::*Method)(TParams...), T& Instance>
571 static ETL_CONSTEXPR14 TReturn method_instance_stub(void*, TParams... params)
579 template <
typename T, TReturn(T::*Method)(TParams...) const, const T& Instance>
580 static ETL_CONSTEXPR14 TReturn const_method_instance_stub(void*, TParams... params)
585#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
589 template <
typename T, T& Instance>
590 static ETL_CONSTEXPR14 TReturn operator_instance_stub(
void*, TParams... params)
599 template <TReturn(*Method)(TParams...)>
600 static ETL_CONSTEXPR14 TReturn function_stub(
void*, TParams... params)
608 template <
typename TLambda>
609 static ETL_CONSTEXPR14 TReturn lambda_stub(
void*
object, TParams... arg)
611 TLambda* p =
static_cast<TLambda*
>(object);
618 template <
typename TLambda>
619 static ETL_CONSTEXPR14 TReturn const_lambda_stub(
void*
object, TParams... arg)
621 const TLambda* p =
static_cast<const TLambda*
>(object);
628 invocation_element invocation;
ETL_CONSTEXPR14 void set()
Set from function (Compile time).
Definition delegate_cpp11.h:252
static ETL_NODISCARD ETL_CONSTEXPR14 delegate create(const TLambda &instance)
Create from const Lambda or Functor.
Definition delegate_cpp11.h:154
static ETL_NODISCARD ETL_CONSTEXPR14 delegate create()
Definition delegate_cpp11.h:242
ETL_CONSTEXPR14 etl::enable_if_t< etl::is_same< TRet, void >::value, bool > call_if(TParams... args) const
Definition delegate_cpp11.h:356
ETL_CONSTEXPR14 void set(const TLambda &instance)
Set from const Lambda or Functor.
Definition delegate_cpp11.h:270
ETL_CONSTEXPR14 void set(TLambda &instance)
Set from Lambda or Functor.
Definition delegate_cpp11.h:261
ETL_CONSTEXPR14 delegate()
Default constructor.
Definition delegate_cpp11.h:102
TReturn operator()(TParams... args) const
Execute the delegate.
Definition delegate_cpp11.h:342
ETL_CONSTEXPR14 void clear()
Clear the delegate.
Definition delegate_cpp11.h:334
TReturn call_or(TAlternative alternative, TParams... args) const
Definition delegate_cpp11.h:393
TReturn call_or(TParams... args) const
Definition delegate_cpp11.h:410
static ETL_NODISCARD ETL_CONSTEXPR14 delegate create(TLambda &instance)
Create from Lambda or Functor.
Definition delegate_cpp11.h:144
ETL_CONSTEXPR14 etl::enable_if_t<!etl::is_same< TRet, void >::value, etl::optional< TReturn > > call_if(TParams... args) const
Definition delegate_cpp11.h:376
ETL_NODISCARD ETL_CONSTEXPR14 bool is_valid() const
Returns true if the delegate is valid.
Definition delegate_cpp11.h:467
static ETL_NODISCARD ETL_CONSTEXPR14 delegate create()
Create from function (Compile time).
Definition delegate_cpp11.h:134
The exception thrown when the delegate is uninitialised.
Definition delegate_cpp03.h:162
Declaration.
Definition delegate_cpp03.h:175
A templated set implementation that uses a fixed size buffer.
Definition set.h:2548
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:966
#define ETL_ASSERT(b, e)
Definition error_handler.h:316
ETL_CONSTEXPR exception(string_type reason_, string_type, numeric_type line_)
Constructor.
Definition exception.h:69
is_same
Definition type_traits_generator.h:1041
bitset_ext
Definition absolute.h:38
T * create(Args &&... args)
Creates the object from a type. Variadic parameter constructor.
Definition variant_pool_generator.h:348
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:654
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:642
pair holds two objects of arbitrary type
Definition utility.h:164