48#ifndef ETL_DELEGATE_CPP03_INCLUDED
49#define ETL_DELEGATE_CPP03_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"
58#if defined(ETL_IN_DELEGATE_CPP03_UNIT_TEST)
64 namespace private_delegate
67 template <
typename TDelegate,
typename TReturn,
typename TParam>
86 template <
typename TDelegate>
106 template <
typename TDelegate,
typename TReturn>
125 template <
typename TDelegate,
typename TParam>
174 template <
typename T>
177 template <
typename TReturn,
typename TParam>
200 invocation =
other.invocation;
206 template <
typename TFunctor>
209 assign((
void*)(&instance), functor_stub<TFunctor>);
215 template <
typename TFunctor>
218 assign((
void*)(&instance), const_functor_stub<TFunctor>);
224 template <TReturn(*Method)(TParam)>
233 template <
typename TFunctor>
244 template <
typename TFunctor>
255 template <
typename T, TReturn(T::*Method)(TParam)>
264 template <
typename T, TReturn(T::*Method)(TParam) const>
273 template <
typename T, T& Instance, TReturn(T::*Method)(TParam)>
282 template <
typename T, T const& Instance, TReturn(T::*Method)(TParam) const>
288#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
293 template <
typename T, T& Instance>
303 template <TReturn(*Method)(TParam)>
312 template <
typename TFunctor>
322 template <
typename TFunctor>
332 template <
typename T, TReturn(T::* Method)(TParam)>
341 template <
typename T, TReturn(T::* Method)(TParam) const>
350 template <
typename T, T& Instance, TReturn(T::* Method)(TParam)>
359 template <
typename T, T const& Instance, TReturn(T::* Method)(TParam) const>
380 return (*invocation.stub)(invocation.object,
param);
387 template <
typename TAlternative>
392 return (*invocation.stub)(invocation.object,
param);
404 template <TReturn(*Method)(TParam)>
409 return (*invocation.stub)(invocation.object,
param);
422 invocation =
rhs.invocation;
429 template <
typename TFunctor>
440 template <
typename TFunctor>
453 return invocation ==
rhs.invocation;
461 return invocation !=
rhs.invocation;
469 return invocation.stub != ETL_NULLPTR;
487 struct invocation_element
490 : object(ETL_NULLPTR)
496 invocation_element(
void* object_, stub_type stub_)
503 bool operator ==(
const invocation_element& rhs)
const
505 return (rhs.stub == stub) && (rhs.object == object);
509 bool operator !=(
const invocation_element& rhs)
const
511 return (rhs.stub != stub) || (rhs.object != object);
515 ETL_CONSTEXPR14
void clear()
517 object = ETL_NULLPTR;
529 delegate(
void*
object, stub_type stub)
530 : invocation(object, stub)
537 delegate(stub_type stub)
538 : invocation(ETL_NULLPTR, stub)
545 void assign(
void*
object, stub_type stub)
547 invocation.object = object;
548 invocation.stub = stub;
554 template <
typename T, TReturn(T::*Method)(TParam)>
555 static TReturn method_stub(
void*
object, TParam param)
557 T* p =
static_cast<T*
>(object);
558 return (p->*Method)(param);
564 template <
typename T, TReturn(T::*Method)(TParam) const>
565 static TReturn const_method_stub(
void*
object, TParam param)
567 T*
const p =
static_cast<T*
>(object);
568 return (p->*Method)(param);
574 template <
typename T, T& Instance, TReturn(T::*Method)(TParam)>
575 static TReturn method_instance_stub(
void*, TParam param)
577 return (Instance.*Method)(param);
583 template <
typename T, const T& Instance, TReturn(T::*Method)(TParam) const>
584 static TReturn const_method_instance_stub(
void*, TParam param)
586 return (Instance.*Method)(param);
589#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
593 template <
typename T, T& Instance>
594 static TReturn operator_instance_stub(
void*, TParam param)
596 return Instance.operator()(param);
603 template <TReturn(*Method)(TParam)>
604 static TReturn function_stub(
void*, TParam param)
606 return (Method)(param);
612 template <
typename TFunctor>
613 static TReturn functor_stub(
void*
object, TParam param)
615 TFunctor* p =
static_cast<TFunctor*
>(object);
616 return (p->operator())(param);
622 template <
typename TFunctor>
623 static TReturn const_functor_stub(
void*
object, TParam param)
625 const TFunctor* p =
static_cast<const TFunctor*
>(object);
626 return (p->operator())(param);
632 invocation_element invocation;
638 template <
typename TReturn>
661 invocation =
other.invocation;
667 template <
typename TFunctor>
670 assign((
void*)(&instance), functor_stub<TFunctor>);
676 template <
typename TFunctor>
679 assign((
void*)(&instance), const_functor_stub<TFunctor>);
685 template <TReturn(*Method)()>
694 template <
typename TFunctor>
705 template <
typename TFunctor>
716 template <
typename T, TReturn(T::* Method)()>
725 template <
typename T, TReturn(T::* Method)() const>
734 template <
typename T, T& Instance, TReturn(T::* Method)()>
743 template <
typename T, T const& Instance, TReturn(T::* Method)() const>
749#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
754 template <
typename T, T& Instance>
764 template <TReturn(*Method)()>
773 template <
typename TFunctor>
783 template <
typename TFunctor>
793 template <
typename T, TReturn(T::* Method)()>
802 template <
typename T, TReturn(T::* Method)() const>
811 template <
typename T, T& Instance, TReturn(T::* Method)()>
820 template <
typename T, T const& Instance, TReturn(T::* Method)() const>
841 return (*invocation.stub)(invocation.object);
848 template <
typename TAlternative>
853 return (*invocation.stub)(invocation.object);
865 template <TReturn(*Method)()>
870 return (*invocation.stub)(invocation.object);
883 invocation =
rhs.invocation;
890 template <
typename TFunctor>
901 template <
typename TFunctor>
914 return invocation ==
rhs.invocation;
922 return invocation !=
rhs.invocation;
930 return invocation.stub != ETL_NULLPTR;
943 typedef TReturn(*stub_type)(
void* object);
948 struct invocation_element
951 : object(ETL_NULLPTR)
957 invocation_element(
void* object_, stub_type stub_)
964 bool operator ==(
const invocation_element& rhs)
const
966 return (rhs.stub == stub) && (rhs.object == object);
970 bool operator !=(
const invocation_element& rhs)
const
972 return (rhs.stub != stub) || (rhs.object != object);
976 ETL_CONSTEXPR14
void clear()
978 object = ETL_NULLPTR;
990 delegate(
void*
object, stub_type stub)
991 : invocation(object, stub)
998 delegate(stub_type stub)
999 : invocation(ETL_NULLPTR, stub)
1006 void assign(
void*
object, stub_type stub)
1008 invocation.object = object;
1009 invocation.stub = stub;
1015 template <
typename T, TReturn(T::* Method)()>
1016 static TReturn method_stub(
void*
object)
1018 T* p =
static_cast<T*
>(object);
1019 return (p->*Method)();
1025 template <
typename T, TReturn(T::* Method)() const>
1026 static TReturn const_method_stub(
void*
object)
1028 T*
const p =
static_cast<T*
>(object);
1029 return (p->*Method)();
1035 template <
typename T, T& Instance, TReturn(T::* Method)()>
1036 static TReturn method_instance_stub(
void*)
1038 return (Instance.*Method)();
1044 template <
typename T, const T& Instance, TReturn(T::* Method)() const>
1045 static TReturn const_method_instance_stub(
void*)
1047 return (Instance.*Method)();
1050#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
1054 template <
typename T, T& Instance>
1055 static TReturn operator_instance_stub(
void*)
1057 return Instance.operator()();
1064 template <TReturn(*Method)()>
1065 static TReturn function_stub(
void*)
1073 template <
typename TFunctor>
1074 static TReturn functor_stub(
void*
object)
1076 TFunctor* p =
static_cast<TFunctor*
>(object);
1077 return (p->operator())();
1083 template <
typename TFunctor>
1084 static TReturn const_functor_stub(
void*
object)
1086 const TFunctor* p =
static_cast<const TFunctor*
>(object);
1087 return (p->operator())();
1093 invocation_element invocation;
Definition delegate_cpp03.h:179
void set()
Set from function (Compile time).
Definition delegate_cpp03.h:304
static etl::enable_if< etl::is_class< TFunctor >::value &&!etl::is_same< delegate_type, TFunctor >::value, delegate >::type create(const TFunctor &instance)
Create from a const Functor.
Definition delegate_cpp03.h:247
static delegate create(T &instance)
Create from instance method (Run time).
Definition delegate_cpp03.h:256
static delegate create()
Create from instance method (Compile time).
Definition delegate_cpp03.h:274
TReturn call_or(TParam param) const
Definition delegate_cpp03.h:405
static delegate create()
Create from function (Compile time).
Definition delegate_cpp03.h:225
etl::enable_if< etl::is_class< TFunctor >::value &&!etl::is_same< delegate_type, TFunctor >::value, void >::type set(const TFunctor &instance)
Set from const Functor.
Definition delegate_cpp03.h:324
etl::enable_if< etl::is_class< TFunctor >::value &&!etl::is_same< delegate_type, TFunctor >::value, void >::type set(TFunctor &instance)
Set from Functor.
Definition delegate_cpp03.h:314
static etl::enable_if< etl::is_class< TFunctor >::value &&!etl::is_same< delegate_type, TFunctor >::value, delegate >::type create(TFunctor &instance)
Create from a Functor.
Definition delegate_cpp03.h:236
delegate()
Default constructor.
Definition delegate_cpp03.h:191
void set(T &instance)
Set from instance method (Run time).
Definition delegate_cpp03.h:333
TReturn operator()(TParam param) const
Execute the delegate.
Definition delegate_cpp03.h:376
TReturn call_or(TAlternative alternative, TParam param) const
Definition delegate_cpp03.h:388
static delegate create(const T &instance)
Create from const instance method (Run time).
Definition delegate_cpp03.h:265
ETL_CONSTEXPR14 void clear()
Clear the delegate.
Definition delegate_cpp03.h:368
bool is_valid() const
Returns true if the delegate is valid.
Definition delegate_cpp03.h:467
static delegate create()
Definition delegate_cpp03.h:294
void set()
Set from instance method (Compile time).
Definition delegate_cpp03.h:351
Specialisation for void parameter.
Definition delegate_cpp03.h:640
etl::enable_if< etl::is_class< TFunctor >::value &&!etl::is_same< delegate_type, TFunctor >::value, void >::type set(TFunctor &instance)
Set from Functor.
Definition delegate_cpp03.h:775
static delegate create(const T &instance)
Create from const instance method (Run time).
Definition delegate_cpp03.h:726
static etl::enable_if< etl::is_class< TFunctor >::value &&!etl::is_same< delegate_type, TFunctor >::value, delegate >::type create(TFunctor &instance)
Create from Functor.
Definition delegate_cpp03.h:697
bool is_valid() const
Returns true if the delegate is valid.
Definition delegate_cpp03.h:928
TReturn call_or(TAlternative alternative) const
Definition delegate_cpp03.h:849
delegate()
Default constructor.
Definition delegate_cpp03.h:652
static delegate create()
Create from function (Compile time).
Definition delegate_cpp03.h:686
static etl::enable_if< etl::is_class< TFunctor >::value &&!etl::is_same< delegate_type, TFunctor >::value, delegate >::type create(const TFunctor &instance)
Create from const Functor.
Definition delegate_cpp03.h:708
void set()
Set from function (Compile time).
Definition delegate_cpp03.h:765
etl::enable_if< etl::is_class< TFunctor >::value &&!etl::is_same< delegate_type, TFunctor >::value, void >::type set(const TFunctor &instance)
Set from const Functor.
Definition delegate_cpp03.h:785
static delegate create(T &instance)
Create from instance method (Run time).
Definition delegate_cpp03.h:717
void set(T &instance)
Set from instance method (Run time).
Definition delegate_cpp03.h:794
static delegate create()
Definition delegate_cpp03.h:755
TReturn operator()() const
Execute the delegate.
Definition delegate_cpp03.h:837
void set()
Set from instance method (Compile time).
Definition delegate_cpp03.h:812
static delegate create()
Create from instance method (Compile time).
Definition delegate_cpp03.h:735
TReturn call_or() const
Definition delegate_cpp03.h:866
ETL_CONSTEXPR14 void clear()
Clear the delegate.
Definition delegate_cpp03.h:829
The base class for delegate exceptions.
Definition delegate_cpp03.h:149
The exception thrown when the delegate is uninitialised.
Definition delegate_cpp03.h:162
Declaration.
Definition delegate_cpp03.h:175
ETL_CONSTEXPR14 bool operator==(const etl::unexpected< TError > &lhs, const etl::unexpected< TError > &rhs)
Equivalence operator.
Definition expected.h:950
#define ETL_ASSERT(b, e)
Definition error_handler.h:316
Definition exception.h:47
enable_if
Definition type_traits_generator.h:1191
is_same
Definition type_traits_generator.h:1041
bitset_ext
Definition absolute.h:38
is_class
Definition type_traits_generator.h:1261
pair holds two objects of arbitrary type
Definition utility.h:164
Definition delegate_cpp03.h:69
ETL_CONSTEXPR14 bool operator!=(const etl::to_arithmetic_result< T > &lhs, const etl::to_arithmetic_result< T > &rhs)
Inequality test for etl::to_arithmetic_result.
Definition to_arithmetic.h:1017