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>
182 template <
typename T>
190 template <
typename T>
193 template <
typename TReturn,
typename TParam>
221 invocation =
other.invocation;
227 template <
typename TFunctor>
230 assign((
void*)(&instance), functor_stub<TFunctor>);
236 template <
typename TFunctor>
239 assign((
void*)(&instance), const_functor_stub<TFunctor>);
245 template <TReturn(*Method)(TParam)>
254 template <
typename TFunctor>
265 template <
typename TFunctor>
276 template <
typename T, TReturn(T::*Method)(TParam)>
285 template <
typename T, TReturn(T::*Method)(TParam) const>
294 template <
typename T, T& Instance, TReturn(T::*Method)(TParam)>
304 template <
typename T, TReturn(T::* Method)(TParam), T& Instance>
313 template <
typename T, T const& Instance, TReturn(T::*Method)(TParam) const>
323 template <
typename T, TReturn(T::* Method)(TParam) const, T const& Instance>
329#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
334 template <
typename T, T& Instance>
344 template <TReturn(*Method)(TParam)>
353 template <
typename TFunctor>
363 template <
typename TFunctor>
373 template <
typename T, TReturn(T::* Method)(TParam)>
382 template <
typename T, TReturn(T::* Method)(TParam) const>
391 template <
typename T, T& Instance, TReturn(T::* Method)(TParam)>
401 template <
typename T, TReturn(T::* Method)(TParam), T& Instance>
410 template <
typename T, T const& Instance, TReturn(T::* Method)(TParam) const>
420 template <
typename T, TReturn(T::* Method)(TParam) const, T const& Instance>
441 return (*invocation.stub)(invocation.object,
param);
448 template <
typename TAlternative>
453 return (*invocation.stub)(invocation.object,
param);
465 template <TReturn(*Method)(TParam)>
470 return (*invocation.stub)(invocation.object,
param);
483 invocation =
rhs.invocation;
490 template <
typename TFunctor>
501 template <
typename TFunctor>
514 return invocation ==
rhs.invocation;
522 return invocation !=
rhs.invocation;
530 return invocation.stub != ETL_NULLPTR;
548 struct invocation_element
551 : object(ETL_NULLPTR)
557 invocation_element(
void* object_, stub_type stub_)
564 bool operator ==(
const invocation_element& rhs)
const
566 return (rhs.stub == stub) && (rhs.object == object);
570 bool operator !=(
const invocation_element& rhs)
const
572 return (rhs.stub != stub) || (rhs.object != object);
576 ETL_CONSTEXPR14
void clear()
578 object = ETL_NULLPTR;
590 delegate(
void*
object, stub_type stub)
591 : invocation(object, stub)
598 delegate(stub_type stub)
599 : invocation(ETL_NULLPTR, stub)
606 void assign(
void*
object, stub_type stub)
608 invocation.object = object;
609 invocation.stub = stub;
615 template <
typename T, TReturn(T::*Method)(TParam)>
616 static TReturn method_stub(
void*
object, TParam param)
618 T* p =
static_cast<T*
>(object);
619 return (p->*Method)(param);
625 template <
typename T, TReturn(T::*Method)(TParam) const>
626 static TReturn const_method_stub(
void*
object, TParam param)
628 T*
const p =
static_cast<T*
>(object);
629 return (p->*Method)(param);
635 template <
typename T, TReturn(T::*Method)(TParam), T& Instance>
636 static TReturn method_instance_stub(
void*, TParam param)
638 return (Instance.*Method)(param);
644 template <
typename T, TReturn(T::*Method)(TParam) const, const T& Instance>
645 static TReturn const_method_instance_stub(
void*, TParam param)
647 return (Instance.*Method)(param);
650#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
654 template <
typename T, T& Instance>
655 static TReturn operator_instance_stub(
void*, TParam param)
657 return Instance.operator()(param);
664 template <TReturn(*Method)(TParam)>
665 static TReturn function_stub(
void*, TParam param)
667 return (Method)(param);
673 template <
typename TFunctor>
674 static TReturn functor_stub(
void*
object, TParam param)
676 TFunctor* p =
static_cast<TFunctor*
>(object);
677 return (p->operator())(param);
683 template <
typename TFunctor>
684 static TReturn const_functor_stub(
void*
object, TParam param)
686 const TFunctor* p =
static_cast<const TFunctor*
>(object);
687 return (p->operator())(param);
693 invocation_element invocation;
699 template <
typename TReturn>
726 invocation =
other.invocation;
732 template <
typename TFunctor>
735 assign((
void*)(&instance), functor_stub<TFunctor>);
741 template <
typename TFunctor>
744 assign((
void*)(&instance), const_functor_stub<TFunctor>);
750 template <TReturn(*Method)()>
759 template <
typename TFunctor>
770 template <
typename TFunctor>
781 template <
typename T, TReturn(T::* Method)()>
790 template <
typename T, TReturn(T::* Method)() const>
799 template <
typename T, T& Instance, TReturn(T::* Method)()>
809 template <
typename T, TReturn(T::* Method)(), T& Instance>
818 template <
typename T, T const& Instance, TReturn(T::* Method)() const>
828 template <
typename T, TReturn(T::* Method)() const, T const& Instance>
834#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
839 template <
typename T, T& Instance>
849 template <TReturn(*Method)()>
858 template <
typename TFunctor>
868 template <
typename TFunctor>
878 template <
typename T, TReturn(T::* Method)()>
887 template <
typename T, TReturn(T::* Method)() const>
896 template <
typename T, T& Instance, TReturn(T::* Method)()>
906 template <
typename T, TReturn(T::* Method)(), T& Instance>
915 template <
typename T, T const& Instance, TReturn(T::* Method)() const>
925 template <
typename T, TReturn(T::* Method)() const, T const& Instance>
946 return (*invocation.stub)(invocation.object);
953 template <
typename TAlternative>
958 return (*invocation.stub)(invocation.object);
970 template <TReturn(*Method)()>
975 return (*invocation.stub)(invocation.object);
988 invocation =
rhs.invocation;
995 template <
typename TFunctor>
1006 template <
typename TFunctor>
1019 return invocation ==
rhs.invocation;
1027 return invocation !=
rhs.invocation;
1035 return invocation.stub != ETL_NULLPTR;
1048 typedef TReturn(*stub_type)(
void* object);
1053 struct invocation_element
1055 invocation_element()
1056 : object(ETL_NULLPTR)
1062 invocation_element(
void* object_, stub_type stub_)
1069 bool operator ==(
const invocation_element& rhs)
const
1071 return (rhs.stub == stub) && (rhs.object == object);
1075 bool operator !=(
const invocation_element& rhs)
const
1077 return (rhs.stub != stub) || (rhs.object != object);
1081 ETL_CONSTEXPR14
void clear()
1083 object = ETL_NULLPTR;
1095 delegate(
void*
object, stub_type stub)
1096 : invocation(object, stub)
1103 delegate(stub_type stub)
1104 : invocation(ETL_NULLPTR, stub)
1111 void assign(
void*
object, stub_type stub)
1113 invocation.object = object;
1114 invocation.stub = stub;
1120 template <
typename T, TReturn(T::* Method)()>
1121 static TReturn method_stub(
void*
object)
1123 T* p =
static_cast<T*
>(object);
1124 return (p->*Method)();
1130 template <
typename T, TReturn(T::* Method)() const>
1131 static TReturn const_method_stub(
void*
object)
1133 T*
const p =
static_cast<T*
>(object);
1134 return (p->*Method)();
1140 template <
typename T, TReturn(T::* Method)(), T& Instance>
1141 static TReturn method_instance_stub(
void*)
1143 return (Instance.*Method)();
1149 template <
typename T, TReturn(T::* Method)() const, const T& Instance>
1150 static TReturn const_method_instance_stub(
void*)
1152 return (Instance.*Method)();
1155#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
1159 template <
typename T, T& Instance>
1160 static TReturn operator_instance_stub(
void*)
1162 return Instance.operator()();
1169 template <TReturn(*Method)()>
1170 static TReturn function_stub(
void*)
1178 template <
typename TFunctor>
1179 static TReturn functor_stub(
void*
object)
1181 TFunctor* p =
static_cast<TFunctor*
>(object);
1182 return (p->operator())();
1188 template <
typename TFunctor>
1189 static TReturn const_functor_stub(
void*
object)
1191 const TFunctor* p =
static_cast<const TFunctor*
>(object);
1192 return (p->operator())();
1198 invocation_element invocation;
Definition delegate_cpp03.h:196
void set()
Set from function (Compile time).
Definition delegate_cpp03.h:345
etl::enable_if< etl::is_class< TFunctor >::value &&!is_delegate< TFunctor >::value, void >::type set(TFunctor &instance)
Set from Functor.
Definition delegate_cpp03.h:355
static etl::enable_if< etl::is_class< TFunctor >::value &&!is_delegate< TFunctor >::value, delegate >::type create(TFunctor &instance)
Create from a Functor.
Definition delegate_cpp03.h:257
static delegate create(T &instance)
Create from instance method (Run time).
Definition delegate_cpp03.h:277
static delegate create()
Create from instance method (Compile time).
Definition delegate_cpp03.h:295
TReturn call_or(TParam param) const
Definition delegate_cpp03.h:466
static delegate create()
Create from function (Compile time).
Definition delegate_cpp03.h:246
etl::enable_if< etl::is_class< TFunctor >::value &&!is_delegate< TFunctor >::value, void >::type set(const TFunctor &instance)
Set from const Functor.
Definition delegate_cpp03.h:365
delegate()
Default constructor.
Definition delegate_cpp03.h:212
void set(T &instance)
Set from instance method (Run time).
Definition delegate_cpp03.h:374
TReturn operator()(TParam param) const
Execute the delegate.
Definition delegate_cpp03.h:437
TReturn call_or(TAlternative alternative, TParam param) const
Definition delegate_cpp03.h:449
static delegate create(const T &instance)
Create from const instance method (Run time).
Definition delegate_cpp03.h:286
ETL_CONSTEXPR14 void clear()
Clear the delegate.
Definition delegate_cpp03.h:429
bool is_valid() const
Returns true if the delegate is valid.
Definition delegate_cpp03.h:528
static delegate create()
Definition delegate_cpp03.h:335
void set()
Set from instance method (Compile time).
Definition delegate_cpp03.h:392
static etl::enable_if< etl::is_class< TFunctor >::value &&!is_delegate< TFunctor >::value, delegate >::type create(const TFunctor &instance)
Create from a const Functor.
Definition delegate_cpp03.h:268
Specialisation for void parameter.
Definition delegate_cpp03.h:701
static etl::enable_if< etl::is_class< TFunctor >::value &&!is_delegate< TFunctor >::value, delegate >::type create(TFunctor &instance)
Create from Functor.
Definition delegate_cpp03.h:762
static delegate create(const T &instance)
Create from const instance method (Run time).
Definition delegate_cpp03.h:791
bool is_valid() const
Returns true if the delegate is valid.
Definition delegate_cpp03.h:1033
TReturn call_or(TAlternative alternative) const
Definition delegate_cpp03.h:954
delegate()
Default constructor.
Definition delegate_cpp03.h:717
static delegate create()
Create from function (Compile time).
Definition delegate_cpp03.h:751
void set()
Set from function (Compile time).
Definition delegate_cpp03.h:850
static delegate create(T &instance)
Create from instance method (Run time).
Definition delegate_cpp03.h:782
void set(T &instance)
Set from instance method (Run time).
Definition delegate_cpp03.h:879
static delegate create()
Definition delegate_cpp03.h:840
TReturn operator()() const
Execute the delegate.
Definition delegate_cpp03.h:942
etl::enable_if< etl::is_class< TFunctor >::value &&!is_delegate< TFunctor >::value, void >::type set(TFunctor &instance)
Set from Functor.
Definition delegate_cpp03.h:860
etl::enable_if< etl::is_class< TFunctor >::value &&!is_delegate< TFunctor >::value, void >::type set(const TFunctor &instance)
Set from const Functor.
Definition delegate_cpp03.h:870
static etl::enable_if< etl::is_class< TFunctor >::value &&!is_delegate< TFunctor >::value, delegate >::type create(const TFunctor &instance)
Create from const Functor.
Definition delegate_cpp03.h:773
void set()
Set from instance method (Compile time).
Definition delegate_cpp03.h:897
static delegate create()
Create from instance method (Compile time).
Definition delegate_cpp03.h:800
TReturn call_or() const
Definition delegate_cpp03.h:971
ETL_CONSTEXPR14 void clear()
Clear the delegate.
Definition delegate_cpp03.h:934
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:191
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:968
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition exception.h:47
enable_if
Definition type_traits_generator.h:1186
bitset_ext
Definition absolute.h:38
Definition type_traits_generator.h:844
Definition delegate_cpp03.h:176
is_class
Definition type_traits_generator.h:1256
is_delegate
Definition delegate_cpp03.h:184
pair holds two objects of arbitrary type
Definition utility.h:164
Definition delegate_cpp03.h:69