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)>
283 template <
typename T, TReturn(T::* Method)(TParam), T& Instance>
292 template <
typename T, T const& Instance, TReturn(T::*Method)(TParam) const>
302 template <
typename T, TReturn(T::* Method)(TParam) const, T const& Instance>
308#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
313 template <
typename T, T& Instance>
323 template <TReturn(*Method)(TParam)>
332 template <
typename TFunctor>
342 template <
typename TFunctor>
352 template <
typename T, TReturn(T::* Method)(TParam)>
361 template <
typename T, TReturn(T::* Method)(TParam) const>
370 template <
typename T, T& Instance, TReturn(T::* Method)(TParam)>
380 template <
typename T, TReturn(T::* Method)(TParam), T& Instance>
389 template <
typename T, T const& Instance, TReturn(T::* Method)(TParam) const>
399 template <
typename T, TReturn(T::* Method)(TParam) const, T const& Instance>
420 return (*invocation.stub)(invocation.object,
param);
427 template <
typename TAlternative>
432 return (*invocation.stub)(invocation.object,
param);
444 template <TReturn(*Method)(TParam)>
449 return (*invocation.stub)(invocation.object,
param);
462 invocation =
rhs.invocation;
469 template <
typename TFunctor>
480 template <
typename TFunctor>
493 return invocation ==
rhs.invocation;
501 return invocation !=
rhs.invocation;
509 return invocation.stub != ETL_NULLPTR;
527 struct invocation_element
530 : object(ETL_NULLPTR)
536 invocation_element(
void* object_, stub_type stub_)
543 bool operator ==(
const invocation_element& rhs)
const
545 return (rhs.stub == stub) && (rhs.object == object);
549 bool operator !=(
const invocation_element& rhs)
const
551 return (rhs.stub != stub) || (rhs.object != object);
555 ETL_CONSTEXPR14
void clear()
557 object = ETL_NULLPTR;
569 delegate(
void*
object, stub_type stub)
570 : invocation(object, stub)
577 delegate(stub_type stub)
578 : invocation(ETL_NULLPTR, stub)
585 void assign(
void*
object, stub_type stub)
587 invocation.object = object;
588 invocation.stub = stub;
594 template <
typename T, TReturn(T::*Method)(TParam)>
595 static TReturn method_stub(
void*
object, TParam param)
597 T* p =
static_cast<T*
>(object);
598 return (p->*Method)(param);
604 template <
typename T, TReturn(T::*Method)(TParam) const>
605 static TReturn const_method_stub(
void*
object, TParam param)
607 T*
const p =
static_cast<T*
>(object);
608 return (p->*Method)(param);
614 template <
typename T, TReturn(T::*Method)(TParam), T& Instance>
615 static TReturn method_instance_stub(
void*, TParam param)
617 return (Instance.*Method)(param);
623 template <
typename T, TReturn(T::*Method)(TParam) const, const T& Instance>
624 static TReturn const_method_instance_stub(
void*, TParam param)
626 return (Instance.*Method)(param);
629#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
633 template <
typename T, T& Instance>
634 static TReturn operator_instance_stub(
void*, TParam param)
636 return Instance.operator()(param);
643 template <TReturn(*Method)(TParam)>
644 static TReturn function_stub(
void*, TParam param)
646 return (Method)(param);
652 template <
typename TFunctor>
653 static TReturn functor_stub(
void*
object, TParam param)
655 TFunctor* p =
static_cast<TFunctor*
>(object);
656 return (p->operator())(param);
662 template <
typename TFunctor>
663 static TReturn const_functor_stub(
void*
object, TParam param)
665 const TFunctor* p =
static_cast<const TFunctor*
>(object);
666 return (p->operator())(param);
672 invocation_element invocation;
678 template <
typename TReturn>
701 invocation =
other.invocation;
707 template <
typename TFunctor>
710 assign((
void*)(&instance), functor_stub<TFunctor>);
716 template <
typename TFunctor>
719 assign((
void*)(&instance), const_functor_stub<TFunctor>);
725 template <TReturn(*Method)()>
734 template <
typename TFunctor>
745 template <
typename TFunctor>
756 template <
typename T, TReturn(T::* Method)()>
765 template <
typename T, TReturn(T::* Method)() const>
774 template <
typename T, T& Instance, TReturn(T::* Method)()>
784 template <
typename T, TReturn(T::* Method)(), T& Instance>
793 template <
typename T, T const& Instance, TReturn(T::* Method)() const>
803 template <
typename T, TReturn(T::* Method)() const, T const& Instance>
809#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
814 template <
typename T, T& Instance>
824 template <TReturn(*Method)()>
833 template <
typename TFunctor>
843 template <
typename TFunctor>
853 template <
typename T, TReturn(T::* Method)()>
862 template <
typename T, TReturn(T::* Method)() const>
871 template <
typename T, T& Instance, TReturn(T::* Method)()>
881 template <
typename T, TReturn(T::* Method)(), T& Instance>
890 template <
typename T, T const& Instance, TReturn(T::* Method)() const>
900 template <
typename T, TReturn(T::* Method)() const, T const& Instance>
921 return (*invocation.stub)(invocation.object);
928 template <
typename TAlternative>
933 return (*invocation.stub)(invocation.object);
945 template <TReturn(*Method)()>
950 return (*invocation.stub)(invocation.object);
963 invocation =
rhs.invocation;
970 template <
typename TFunctor>
981 template <
typename TFunctor>
994 return invocation ==
rhs.invocation;
1002 return invocation !=
rhs.invocation;
1010 return invocation.stub != ETL_NULLPTR;
1023 typedef TReturn(*stub_type)(
void* object);
1028 struct invocation_element
1030 invocation_element()
1031 : object(ETL_NULLPTR)
1037 invocation_element(
void* object_, stub_type stub_)
1044 bool operator ==(
const invocation_element& rhs)
const
1046 return (rhs.stub == stub) && (rhs.object == object);
1050 bool operator !=(
const invocation_element& rhs)
const
1052 return (rhs.stub != stub) || (rhs.object != object);
1056 ETL_CONSTEXPR14
void clear()
1058 object = ETL_NULLPTR;
1070 delegate(
void*
object, stub_type stub)
1071 : invocation(object, stub)
1078 delegate(stub_type stub)
1079 : invocation(ETL_NULLPTR, stub)
1086 void assign(
void*
object, stub_type stub)
1088 invocation.object = object;
1089 invocation.stub = stub;
1095 template <
typename T, TReturn(T::* Method)()>
1096 static TReturn method_stub(
void*
object)
1098 T* p =
static_cast<T*
>(object);
1099 return (p->*Method)();
1105 template <
typename T, TReturn(T::* Method)() const>
1106 static TReturn const_method_stub(
void*
object)
1108 T*
const p =
static_cast<T*
>(object);
1109 return (p->*Method)();
1115 template <
typename T, TReturn(T::* Method)(), T& Instance>
1116 static TReturn method_instance_stub(
void*)
1118 return (Instance.*Method)();
1124 template <
typename T, TReturn(T::* Method)() const, const T& Instance>
1125 static TReturn const_method_instance_stub(
void*)
1127 return (Instance.*Method)();
1130#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
1134 template <
typename T, T& Instance>
1135 static TReturn operator_instance_stub(
void*)
1137 return Instance.operator()();
1144 template <TReturn(*Method)()>
1145 static TReturn function_stub(
void*)
1153 template <
typename TFunctor>
1154 static TReturn functor_stub(
void*
object)
1156 TFunctor* p =
static_cast<TFunctor*
>(object);
1157 return (p->operator())();
1163 template <
typename TFunctor>
1164 static TReturn const_functor_stub(
void*
object)
1166 const TFunctor* p =
static_cast<const TFunctor*
>(object);
1167 return (p->operator())();
1173 invocation_element invocation;
Definition delegate_cpp03.h:179
void set()
Set from function (Compile time).
Definition delegate_cpp03.h:324
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:445
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:344
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:334
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:353
TReturn operator()(TParam param) const
Execute the delegate.
Definition delegate_cpp03.h:416
TReturn call_or(TAlternative alternative, TParam param) const
Definition delegate_cpp03.h:428
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:408
bool is_valid() const
Returns true if the delegate is valid.
Definition delegate_cpp03.h:507
static delegate create()
Definition delegate_cpp03.h:314
void set()
Set from instance method (Compile time).
Definition delegate_cpp03.h:371
Specialisation for void parameter.
Definition delegate_cpp03.h:680
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:835
static delegate create(const T &instance)
Create from const instance method (Run time).
Definition delegate_cpp03.h:766
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:737
bool is_valid() const
Returns true if the delegate is valid.
Definition delegate_cpp03.h:1008
TReturn call_or(TAlternative alternative) const
Definition delegate_cpp03.h:929
delegate()
Default constructor.
Definition delegate_cpp03.h:692
static delegate create()
Create from function (Compile 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(const TFunctor &instance)
Create from const Functor.
Definition delegate_cpp03.h:748
void set()
Set from function (Compile time).
Definition delegate_cpp03.h:825
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:845
static delegate create(T &instance)
Create from instance method (Run time).
Definition delegate_cpp03.h:757
void set(T &instance)
Set from instance method (Run time).
Definition delegate_cpp03.h:854
static delegate create()
Definition delegate_cpp03.h:815
TReturn operator()() const
Execute the delegate.
Definition delegate_cpp03.h:917
void set()
Set from instance method (Compile time).
Definition delegate_cpp03.h:872
static delegate create()
Create from instance method (Compile time).
Definition delegate_cpp03.h:775
TReturn call_or() const
Definition delegate_cpp03.h:946
ETL_CONSTEXPR14 void clear()
Clear the delegate.
Definition delegate_cpp03.h:909
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::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
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