Soldered 125kHz RFID board Arduino library 1.0.0
Library for Soldered 125kHz RFID board.
Loading...
Searching...
No Matches
Delegate.h
Go to the documentation of this file.
1/*
2Delegate.h - An efficient interchangeable C function ptr and C++ std::function delegate
3Copyright (c) 2019 Dirk O. Kaar. All rights reserved.
4
5This library is free software; you can redistribute it and/or
6modify it under the terms of the GNU Lesser General Public
7License as published by the Free Software Foundation; either
8version 2.1 of the License, or (at your option) any later version.
9
10This library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public
16License along with this library; if not, write to the Free Software
17Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#ifndef __Delegate_h
21#define __Delegate_h
22
23#if defined(ESP8266)
24#include <c_types.h>
25#elif defined(ESP32)
26#include <esp_attr.h>
27#else
28#define IRAM_ATTR
29#endif
30
31#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
32#include <functional>
33#include <cstddef>
34#else
36#endif
37
38namespace
39{
40
41 template<typename R, typename... P>
42 R IRAM_ATTR vPtrToFunPtrExec(void* fn, P... args)
43 {
44 using target_type = R(P...);
45 return reinterpret_cast<target_type*>(fn)(std::forward<P...>(args...));
46 }
47
48}
49
50namespace delegate
51{
52 namespace detail
53 {
54
55#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
56 template<typename A, typename R, typename... P>
57 class DelegatePImpl {
58 public:
59 using target_type = R(P...);
60 protected:
62 using FunAPtr = R(*)(A, P...);
63 using FunVPPtr = R(*)(void*, P...);
65 public:
67 {
68 kind = FP;
69 fn = nullptr;
70 }
71
73 {
74 kind = FP;
75 fn = nullptr;
76 }
77
79 {
80 if (FUNC == kind)
81 functional.~FunctionType();
82 else if (FPA == kind)
83 obj.~A();
84 }
85
87 {
88 kind = del.kind;
89 if (FUNC == del.kind)
90 {
92 }
93 else if (FPA == del.kind)
94 {
95 fnA = del.fnA;
96 new (&obj) A(del.obj);
97 }
98 else
99 {
100 fn = del.fn;
101 }
102 }
103
105 {
106 kind = del.kind;
107 if (FUNC == del.kind)
108 {
109 new (&functional) FunctionType(std::move(del.functional));
110 }
111 else if (FPA == del.kind)
112 {
113 fnA = del.fnA;
114 new (&obj) A(std::move(del.obj));
115 }
116 else
117 {
118 fn = del.fn;
119 }
120 }
121
123 {
124 kind = FPA;
126 new (&this->obj) A(obj);
127 }
128
130 {
131 kind = FPA;
133 new (&this->obj) A(std::move(obj));
134 }
135
137 {
138 kind = FP;
140 }
141
142 template<typename F> DelegatePImpl(F functional)
143 {
144 kind = FUNC;
145 new (&this->functional) FunctionType(std::forward<F>(functional));
146 }
147
149 {
150 if (this == &del) return *this;
151 if (kind != del.kind)
152 {
153 if (FUNC == kind)
154 {
155 functional.~FunctionType();
156 }
157 else if (FPA == kind)
158 {
159 obj.~A();
160 }
161 if (FUNC == del.kind)
162 {
163 new (&this->functional) FunctionType();
164 }
165 else if (FPA == del.kind)
166 {
167 new (&obj) A;
168 }
169 kind = del.kind;
170 }
171 if (FUNC == del.kind)
172 {
174 }
175 else if (FPA == del.kind)
176 {
177 fnA = del.fnA;
178 obj = del.obj;
179 }
180 else
181 {
182 fn = del.fn;
183 }
184 return *this;
185 }
186
188 {
189 if (this == &del) return *this;
190 if (kind != del.kind)
191 {
192 if (FUNC == kind)
193 {
194 functional.~FunctionType();
195 }
196 else if (FPA == kind)
197 {
198 obj.~A();
199 }
200 if (FUNC == del.kind)
201 {
202 new (&this->functional) FunctionType();
203 }
204 else if (FPA == del.kind)
205 {
206 new (&obj) A;
207 }
208 kind = del.kind;
209 }
210 if (FUNC == del.kind)
211 {
212 functional = std::move(del.functional);
213 }
214 else if (FPA == del.kind)
215 {
216 fnA = del.fnA;
217 obj = std::move(del.obj);
218 }
219 else
220 {
221 fn = del.fn;
222 }
223 return *this;
224 }
225
227 {
228 if (FUNC == kind)
229 {
230 functional.~FunctionType();
231 }
232 else if (FPA == kind)
233 {
234 obj.~A();
235 }
236 kind = FP;
237 this->fn = fn;
238 return *this;
239 }
240
242 {
243 if (FUNC == kind)
244 {
245 functional.~FunctionType();
246 }
247 else if (FPA == kind)
248 {
249 obj.~A();
250 }
251 kind = FP;
252 fn = nullptr;
253 return *this;
254 }
255
256 operator bool() const
257 {
258 if (FP == kind)
259 {
260 return fn;
261 }
262 else if (FPA == kind)
263 {
264 return fnA;
265 }
266 else
267 {
268 return functional ? true : false;
269 }
270 }
271
272 static R IRAM_ATTR vPtrToFunAPtrExec(void* self, P... args)
273 {
274 return static_cast<DelegatePImpl*>(self)->fnA(
275 static_cast<DelegatePImpl*>(self)->obj,
276 std::forward<P...>(args...));
277 };
278
279 operator FunVPPtr() const
280 {
281 if (FP == kind)
282 {
283 return vPtrToFunPtrExec<R, P...>;
284 }
285 else if (FPA == kind)
286 {
287 return vPtrToFunAPtrExec;
288 }
289 else
290 {
291 return [](void* self, P... args) -> R
292 {
293 return static_cast<DelegatePImpl*>(self)->functional(std::forward<P...>(args...));
294 };
295 }
296 }
297
298 void* arg() const
299 {
300 if (FP == kind)
301 {
302 return reinterpret_cast<void*>(fn);
303 }
304 else
305 {
306 return const_cast<DelegatePImpl*>(this);
307 }
308 }
309
310 operator FunctionType() const
311 {
312 if (FP == kind)
313 {
314 return fn;
315 }
316 else if (FPA == kind)
317 {
318 return [this](P... args) { return fnA(obj, std::forward<P...>(args...)); };
319 }
320 else
321 {
322 return functional;
323 }
324 }
325
326 R IRAM_ATTR operator()(P... args) const
327 {
328 if (FP == kind)
329 {
330 return fn(std::forward<P...>(args...));
331 }
332 else if (FPA == kind)
333 {
334 return fnA(obj, std::forward<P...>(args...));
335 }
336 else
337 {
338 return functional(std::forward<P...>(args...));
339 }
340 }
341
342 protected:
343 union {
346 struct {
349 };
350 };
351 enum { FUNC, FP, FPA } kind;
352 };
353#else
354 template<typename A, typename R, typename... P>
356 public:
357 using target_type = R(P...);
358 protected:
359 using FunPtr = target_type*;
360 using FunAPtr = R(*)(A, P...);
361 using FunVPPtr = R(*)(void*, P...);
362 public:
364 {
365 kind = FP;
366 fn = nullptr;
367 }
368
370 {
371 kind = FP;
372 fn = nullptr;
373 }
374
376 {
377 kind = del.kind;
378 if (FPA == del.kind)
379 {
380 fnA = del.fnA;
381 obj = del.obj;
382 }
383 else
384 {
385 fn = del.fn;
386 }
387 }
388
390 {
391 kind = del.kind;
392 if (FPA == del.kind)
393 {
394 fnA = del.fnA;
395 obj = std::move(del.obj);
396 }
397 else
398 {
399 fn = del.fn;
400 }
401 }
402
404 {
405 kind = FPA;
407 this->obj = obj;
408 }
409
411 {
412 kind = FPA;
414 this->obj = std::move(obj);
415 }
416
418 {
419 kind = FP;
421 }
422
423 template<typename F> DelegatePImpl(F functional)
424 {
425 kind = FP;
427 }
428
430 {
431 if (this == &del) return *this;
432 if (kind != del.kind)
433 {
434 if (FPA == kind)
435 {
436 obj = {};
437 }
438 kind = del.kind;
439 }
440 if (FPA == del.kind)
441 {
442 fnA = del.fnA;
443 obj = del.obj;
444 }
445 else
446 {
447 fn = del.fn;
448 }
449 return *this;
450 }
451
453 {
454 if (this == &del) return *this;
455 if (kind != del.kind)
456 {
457 if (FPA == kind)
458 {
459 obj = {};
460 }
461 kind = del.kind;
462 }
463 if (FPA == del.kind)
464 {
465 fnA = del.fnA;
466 obj = std::move(del.obj);
467 }
468 else
469 {
470 fn = del.fn;
471 }
472 return *this;
473 }
474
476 {
477 if (FPA == kind)
478 {
479 obj = {};
480 }
481 kind = FP;
482 this->fn = fn;
483 return *this;
484 }
485
487 {
488 if (FPA == kind)
489 {
490 obj = {};
491 }
492 kind = FP;
493 fn = nullptr;
494 return *this;
495 }
496
497 operator bool() const
498 {
499 if (FP == kind)
500 {
501 return fn;
502 }
503 else
504 {
505 return fnA;
506 }
507 }
508
509 static R IRAM_ATTR vPtrToFunAPtrExec(void* self, P... args)
510 {
511 return static_cast<DelegatePImpl*>(self)->fnA(
512 static_cast<DelegatePImpl*>(self)->obj,
513 std::forward<P...>(args...));
514 };
515
516 operator FunVPPtr() const
517 {
518 if (FP == kind)
519 {
520 return vPtrToFunPtrExec<R, P...>;
521 }
522 else
523 {
524 return vPtrToFunAPtrExec;
525 }
526 }
527
528 void* arg() const
529 {
530 if (FP == kind)
531 {
532 return reinterpret_cast<void*>(fn);
533 }
534 else
535 {
536 return const_cast<DelegatePImpl*>(this);
537 }
538 }
539
540 R IRAM_ATTR operator()(P... args) const
541 {
542 if (FP == kind)
543 {
544 return fn(std::forward<P...>(args...));
545 }
546 else
547 {
548 return fnA(obj, std::forward<P...>(args...));
549 }
550 }
551
552 protected:
553 union {
554 FunPtr fn;
555 FunAPtr fnA;
556 };
557 A obj;
558 enum { FP, FPA } kind;
559 };
560#endif
561
562#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
563 template<typename R, typename... P>
564 class DelegatePImpl<void, R, P...> {
565 public:
566 using target_type = R(P...);
567 protected:
570 using FunVPPtr = R(*)(void*, P...);
571 public:
573 {
574 kind = FP;
575 fn = nullptr;
576 }
577
579 {
580 kind = FP;
581 fn = nullptr;
582 }
583
585 {
586 if (FUNC == kind)
587 functional.~FunctionType();
588 }
589
591 {
592 kind = del.kind;
593 if (FUNC == del.kind)
594 {
595 new (&functional) FunctionType(del.functional);
596 }
597 else
598 {
599 fn = del.fn;
600 }
601 }
602
604 {
605 kind = del.kind;
606 if (FUNC == del.kind)
607 {
608 new (&functional) FunctionType(std::move(del.functional));
609 }
610 else
611 {
612 fn = del.fn;
613 }
614 }
615
617 {
618 kind = FP;
620 }
621
622 template<typename F> DelegatePImpl(F functional)
623 {
624 kind = FUNC;
625 new (&this->functional) FunctionType(std::forward<F>(functional));
626 }
627
629 {
630 if (this == &del) return *this;
631 if (FUNC == kind && FUNC != del.kind)
632 {
633 functional.~FunctionType();
634 }
635 else if (FUNC != kind && FUNC == del.kind)
636 {
637 new (&this->functional) FunctionType();
638 }
639 kind = del.kind;
640 if (FUNC == del.kind)
641 {
642 functional = del.functional;
643 }
644 else
645 {
646 fn = del.fn;
647 }
648 return *this;
649 }
650
652 {
653 if (this == &del) return *this;
654 if (FUNC == kind && FUNC != del.kind)
655 {
656 functional.~FunctionType();
657 }
658 else if (FUNC != kind && FUNC == del.kind)
659 {
660 new (&this->functional) FunctionType();
661 }
662 kind = del.kind;
663 if (FUNC == del.kind)
664 {
665 functional = std::move(del.functional);
666 }
667 else
668 {
669 fn = del.fn;
670 }
671 return *this;
672 }
673
675 {
676 if (FUNC == kind)
677 {
678 functional.~FunctionType();
679 kind = FP;
680 }
682 return *this;
683 }
684
686 {
687 if (FUNC == kind)
688 {
689 functional.~FunctionType();
690 }
691 kind = FP;
692 fn = nullptr;
693 return *this;
694 }
695
696 operator bool() const
697 {
698 if (FP == kind)
699 {
700 return fn;
701 }
702 else
703 {
704 return functional ? true : false;
705 }
706 }
707
708 operator FunVPPtr() const
709 {
710 if (FP == kind)
711 {
712 return vPtrToFunPtrExec<R, P...>;
713 }
714 else
715 {
716 return [](void* self, P... args) -> R
717 {
718 return static_cast<DelegatePImpl*>(self)->functional(std::forward<P...>(args...));
719 };
720 }
721 }
722
723 void* arg() const
724 {
725 if (FP == kind)
726 {
727 return reinterpret_cast<void*>(fn);
728 }
729 else
730 {
731 return const_cast<DelegatePImpl*>(this);
732 }
733 }
734
735 operator FunctionType() const
736 {
737 if (FP == kind)
738 {
739 return fn;
740 }
741 else
742 {
743 return functional;
744 }
745 }
746
747 R IRAM_ATTR operator()(P... args) const
748 {
749 if (FP == kind)
750 {
751 return fn(std::forward<P...>(args...));
752 }
753 else
754 {
755 return functional(std::forward<P...>(args...));
756 }
757 }
758
759 protected:
760 union {
763 };
764 enum { FUNC, FP } kind;
765 };
766#else
767 template<typename R, typename... P>
768 class DelegatePImpl<void, R, P...> {
769 public:
770 using target_type = R(P...);
771 protected:
772 using FunPtr = target_type*;
773 using FunVPPtr = R(*)(void*, P...);
774 public:
776 {
777 fn = nullptr;
778 }
779
781 {
782 fn = nullptr;
783 }
784
786 {
787 fn = del.fn;
788 }
789
791 {
792 fn = std::move(del.fn);
793 }
794
799
800 template<typename F> DelegatePImpl(F fn)
801 {
803 }
804
806 {
807 if (this == &del) return *this;
808 fn = del.fn;
809 return *this;
810 }
811
813 {
814 if (this == &del) return *this;
815 fn = std::move(del.fn);
816 return *this;
817 }
818
820 {
822 return *this;
823 }
824
826 {
827 fn = nullptr;
828 return *this;
829 }
830
831 operator bool() const
832 {
833 return fn;
834 }
835
836 operator FunVPPtr() const
837 {
838 return vPtrToFunPtrExec<R, P...>;
839 }
840
841 void* arg() const
842 {
843 return reinterpret_cast<void*>(fn);
844 }
845
846 R IRAM_ATTR operator()(P... args) const
847 {
848 return fn(std::forward<P...>(args...));
849 }
850
851 protected:
852 FunPtr fn;
853 };
854#endif
855
856#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
857 template<typename A, typename R>
858 class DelegateImpl {
859 public:
860 using target_type = R();
861 protected:
863 using FunAPtr = R(*)(A);
865 using FunVPPtr = R(*)(void*);
866 public:
868 {
869 kind = FP;
870 fn = nullptr;
871 }
872
874 {
875 kind = FP;
876 fn = nullptr;
877 }
878
880 {
881 if (FUNC == kind)
882 functional.~FunctionType();
883 else if (FPA == kind)
884 obj.~A();
885 }
886
888 {
889 kind = del.kind;
890 if (FUNC == del.kind)
891 {
892 new (&functional) FunctionType(del.functional);
893 }
894 else if (FPA == del.kind)
895 {
896 fnA = del.fnA;
897 new (&obj) A(del.obj);
898 }
899 else
900 {
901 fn = del.fn;
902 }
903 }
904
906 {
907 kind = del.kind;
908 if (FUNC == del.kind)
909 {
910 new (&functional) FunctionType(std::move(del.functional));
911 }
912 else if (FPA == del.kind)
913 {
914 fnA = del.fnA;
915 new (&obj) A(std::move(del.obj));
916 }
917 else
918 {
919 fn = del.fn;
920 }
921 }
922
924 {
925 kind = FPA;
927 new (&this->obj) A(obj);
928 }
929
931 {
932 kind = FPA;
934 new (&this->obj) A(std::move(obj));
935 }
936
938 {
939 kind = FP;
941 }
942
943 template<typename F> DelegateImpl(F functional)
944 {
945 kind = FUNC;
946 new (&this->functional) FunctionType(std::forward<F>(functional));
947 }
948
950 {
951 if (this == &del) return *this;
952 if (kind != del.kind)
953 {
954 if (FUNC == kind)
955 {
956 functional.~FunctionType();
957 }
958 else if (FPA == kind)
959 {
960 obj.~A();
961 }
962 if (FUNC == del.kind)
963 {
964 new (&this->functional) FunctionType();
965 }
966 else if (FPA == del.kind)
967 {
968 new (&obj) A;
969 }
970 kind = del.kind;
971 }
972 if (FUNC == del.kind)
973 {
974 functional = del.functional;
975 }
976 else if (FPA == del.kind)
977 {
978 fnA = del.fnA;
979 obj = del.obj;
980 }
981 else
982 {
983 fn = del.fn;
984 }
985 return *this;
986 }
987
989 {
990 if (this == &del) return *this;
991 if (kind != del.kind)
992 {
993 if (FUNC == kind)
994 {
995 functional.~FunctionType();
996 }
997 else if (FPA == kind)
998 {
999 obj.~A();
1000 }
1001 if (FUNC == del.kind)
1002 {
1003 new (&this->functional) FunctionType();
1004 }
1005 else if (FPA == del.kind)
1006 {
1007 new (&obj) A;
1008 }
1009 kind = del.kind;
1010 }
1011 if (FUNC == del.kind)
1012 {
1013 functional = std::move(del.functional);
1014 }
1015 else if (FPA == del.kind)
1016 {
1017 fnA = del.fnA;
1018 obj = std::move(del.obj);
1019 }
1020 else
1021 {
1022 fn = del.fn;
1023 }
1024 return *this;
1025 }
1026
1028 {
1029 if (FUNC == kind)
1030 {
1031 functional.~FunctionType();
1032 }
1033 else if (FPA == kind)
1034 {
1035 obj.~A();
1036 }
1037 kind = FP;
1038 this->fn = fn;
1039 return *this;
1040 }
1041
1043 {
1044 if (FUNC == kind)
1045 {
1046 functional.~FunctionType();
1047 }
1048 else if (FPA == kind)
1049 {
1050 obj.~A();
1051 }
1052 kind = FP;
1053 fn = nullptr;
1054 return *this;
1055 }
1056
1057 operator bool() const
1058 {
1059 if (FP == kind)
1060 {
1061 return fn;
1062 }
1063 else if (FPA == kind)
1064 {
1065 return fnA;
1066 }
1067 else
1068 {
1069 return functional ? true : false;
1070 }
1071 }
1072
1073 static R IRAM_ATTR vPtrToFunAPtrExec(void* self)
1074 {
1075 return static_cast<DelegateImpl*>(self)->fnA(
1076 static_cast<DelegateImpl*>(self)->obj);
1077 };
1078
1079 operator FunVPPtr() const
1080 {
1081 if (FP == kind)
1082 {
1083 return reinterpret_cast<FunVPPtr>(fn);
1084 }
1085 else if (FPA == kind)
1086 {
1087 return vPtrToFunAPtrExec;
1088 }
1089 else
1090 {
1091 return [](void* self) -> R
1092 {
1093 return static_cast<DelegateImpl*>(self)->functional();
1094 };
1095 }
1096 }
1097
1098 void* arg() const
1099 {
1100 if (FP == kind)
1101 {
1102 return nullptr;
1103 }
1104 else
1105 {
1106 return const_cast<DelegateImpl*>(this);
1107 }
1108 }
1109
1110 operator FunctionType() const
1111 {
1112 if (FP == kind)
1113 {
1114 return fn;
1115 }
1116 else if (FPA == kind)
1117 {
1118 return [this]() { return fnA(obj); };
1119 }
1120 else
1121 {
1122 return functional;
1123 }
1124 }
1125
1126 R IRAM_ATTR operator()() const
1127 {
1128 if (FP == kind)
1129 {
1130 return fn();
1131 }
1132 else if (FPA == kind)
1133 {
1134 return fnA(obj);
1135 }
1136 else
1137 {
1138 return functional();
1139 }
1140 }
1141
1142 protected:
1143 union {
1146 struct {
1149 };
1150 };
1151 enum { FUNC, FP, FPA } kind;
1152 };
1153#else
1154 template<typename A, typename R>
1156 public:
1157 using target_type = R();
1158 protected:
1159 using FunPtr = target_type*;
1160 using FunAPtr = R(*)(A);
1161 using FunVPPtr = R(*)(void*);
1162 public:
1164 {
1165 kind = FP;
1166 fn = nullptr;
1167 }
1168
1170 {
1171 kind = FP;
1172 fn = nullptr;
1173 }
1174
1176 {
1177 kind = del.kind;
1178 if (FPA == del.kind)
1179 {
1180 fnA = del.fnA;
1181 obj = del.obj;
1182 }
1183 else
1184 {
1185 fn = del.fn;
1186 }
1187 }
1188
1190 {
1191 kind = del.kind;
1192 if (FPA == del.kind)
1193 {
1194 fnA = del.fnA;
1195 obj = std::move(del.obj);
1196 }
1197 else
1198 {
1199 fn = del.fn;
1200 }
1201 }
1202
1204 {
1205 kind = FPA;
1207 this->obj = obj;
1208 }
1209
1211 {
1212 kind = FPA;
1214 this->obj = std::move(obj);
1215 }
1216
1218 {
1219 kind = FP;
1221 }
1222
1223 template<typename F> DelegateImpl(F fn)
1224 {
1225 kind = FP;
1227 }
1228
1230 {
1231 if (this == &del) return *this;
1232 if (kind != del.kind)
1233 {
1234 if (FPA == kind)
1235 {
1236 obj = {};
1237 }
1238 kind = del.kind;
1239 }
1240 if (FPA == del.kind)
1241 {
1242 fnA = del.fnA;
1243 obj = del.obj;
1244 }
1245 else
1246 {
1247 fn = del.fn;
1248 }
1249 return *this;
1250 }
1251
1253 {
1254 if (this == &del) return *this;
1255 if (kind != del.kind)
1256 {
1257 if (FPA == kind)
1258 {
1259 obj = {};
1260 }
1261 kind = del.kind;
1262 }
1263 if (FPA == del.kind)
1264 {
1265 fnA = del.fnA;
1266 obj = std::move(del.obj);
1267 }
1268 else
1269 {
1270 fn = del.fn;
1271 }
1272 return *this;
1273 }
1274
1276 {
1277 if (FPA == kind)
1278 {
1279 obj = {};
1280 }
1281 kind = FP;
1282 this->fn = fn;
1283 return *this;
1284 }
1285
1287 {
1288 if (FPA == kind)
1289 {
1290 obj = {};
1291 }
1292 kind = FP;
1293 fn = nullptr;
1294 return *this;
1295 }
1296
1297 operator bool() const
1298 {
1299 if (FP == kind)
1300 {
1301 return fn;
1302 }
1303 else
1304 {
1305 return fnA;
1306 }
1307 }
1308
1309 static R IRAM_ATTR vPtrToFunAPtrExec(void* self)
1310 {
1311 return static_cast<DelegateImpl*>(self)->fnA(
1312 static_cast<DelegateImpl*>(self)->obj);
1313 };
1314
1315 operator FunVPPtr() const
1316 {
1317 if (FP == kind)
1318 {
1319 return reinterpret_cast<FunVPPtr>(fn);
1320 }
1321 else
1322 {
1323 return vPtrToFunAPtrExec;
1324 }
1325 }
1326
1327 void* arg() const
1328 {
1329 if (FP == kind)
1330 {
1331 return nullptr;
1332 }
1333 else
1334 {
1335 return const_cast<DelegateImpl*>(this);
1336 }
1337 }
1338
1339 R IRAM_ATTR operator()() const
1340 {
1341 if (FP == kind)
1342 {
1343 return fn();
1344 }
1345 else
1346 {
1347 return fnA(obj);
1348 }
1349 }
1350
1351 protected:
1352 union {
1353 FunPtr fn;
1354 FunAPtr fnA;
1355 };
1356 A obj;
1357 enum { FP, FPA } kind;
1358 };
1359#endif
1360
1361#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
1362 template<typename R>
1363 class DelegateImpl<void, R> {
1364 public:
1365 using target_type = R();
1366 protected:
1369 using FunVPPtr = R(*)(void*);
1370 public:
1372 {
1373 kind = FP;
1374 fn = nullptr;
1375 }
1376
1378 {
1379 kind = FP;
1380 fn = nullptr;
1381 }
1382
1384 {
1385 if (FUNC == kind)
1386 functional.~FunctionType();
1387 }
1388
1390 {
1391 kind = del.kind;
1392 if (FUNC == del.kind)
1393 {
1394 new (&functional) FunctionType(del.functional);
1395 }
1396 else
1397 {
1398 fn = del.fn;
1399 }
1400 }
1401
1403 {
1404 kind = del.kind;
1405 if (FUNC == del.kind)
1406 {
1407 new (&functional) FunctionType(std::move(del.functional));
1408 }
1409 else
1410 {
1411 fn = del.fn;
1412 }
1413 }
1414
1416 {
1417 kind = FP;
1419 }
1420
1421 template<typename F> DelegateImpl(F functional)
1422 {
1423 kind = FUNC;
1424 new (&this->functional) FunctionType(std::forward<F>(functional));
1425 }
1426
1428 {
1429 if (this == &del) return *this;
1430 if (FUNC == kind && FUNC != del.kind)
1431 {
1432 functional.~FunctionType();
1433 }
1434 else if (FUNC != kind && FUNC == del.kind)
1435 {
1436 new (&this->functional) FunctionType();
1437 }
1438 kind = del.kind;
1439 if (FUNC == del.kind)
1440 {
1441 functional = del.functional;
1442 }
1443 else
1444 {
1445 fn = del.fn;
1446 }
1447 return *this;
1448 }
1449
1451 {
1452 if (this == &del) return *this;
1453 if (FUNC == kind && FUNC != del.kind)
1454 {
1455 functional.~FunctionType();
1456 }
1457 else if (FUNC != kind && FUNC == del.kind)
1458 {
1459 new (&this->functional) FunctionType();
1460 }
1461 kind = del.kind;
1462 if (FUNC == del.kind)
1463 {
1464 functional = std::move(del.functional);
1465 }
1466 else
1467 {
1468 fn = del.fn;
1469 }
1470 return *this;
1471 }
1472
1474 {
1475 if (FUNC == kind)
1476 {
1477 functional.~FunctionType();
1478 kind = FP;
1479 }
1481 return *this;
1482 }
1483
1485 {
1486 if (FUNC == kind)
1487 {
1488 functional.~FunctionType();
1489 }
1490 kind = FP;
1491 fn = nullptr;
1492 return *this;
1493 }
1494
1495 operator bool() const
1496 {
1497 if (FP == kind)
1498 {
1499 return fn;
1500 }
1501 else
1502 {
1503 return functional ? true : false;
1504 }
1505 }
1506
1507 operator FunVPPtr() const
1508 {
1509 if (FP == kind)
1510 {
1511 return reinterpret_cast<FunVPPtr>(fn);
1512 }
1513 else
1514 {
1515 return [](void* self) -> R
1516 {
1517 return static_cast<DelegateImpl*>(self)->functional();
1518 };
1519 }
1520 }
1521
1522 void* arg() const
1523 {
1524 if (FP == kind)
1525 {
1526 return nullptr;
1527 }
1528 else
1529 {
1530 return const_cast<DelegateImpl*>(this);
1531 }
1532 }
1533
1534 operator FunctionType() const
1535 {
1536 if (FP == kind)
1537 {
1538 return fn;
1539 }
1540 else
1541 {
1542 return functional;
1543 }
1544 }
1545
1546 R IRAM_ATTR operator()() const
1547 {
1548 if (FP == kind)
1549 {
1550 return fn();
1551 }
1552 else
1553 {
1554 return functional();
1555 }
1556 }
1557
1558 protected:
1559 union {
1562 };
1563 enum { FUNC, FP } kind;
1564 };
1565#else
1566 template<typename R>
1567 class DelegateImpl<void, R> {
1568 public:
1569 using target_type = R();
1570 protected:
1571 using FunPtr = target_type*;
1572 using FunVPPtr = R(*)(void*);
1573 public:
1575 {
1576 fn = nullptr;
1577 }
1578
1580 {
1581 fn = nullptr;
1582 }
1583
1585 {
1586 fn = del.fn;
1587 }
1588
1590 {
1591 fn = std::move(del.fn);
1592 }
1593
1595 {
1597 }
1598
1599 template<typename F> DelegateImpl(F fn)
1600 {
1602 }
1603
1605 {
1606 if (this == &del) return *this;
1607 fn = del.fn;
1608 return *this;
1609 }
1610
1612 {
1613 if (this == &del) return *this;
1614 fn = std::move(del.fn);
1615 return *this;
1616 }
1617
1619 {
1621 return *this;
1622 }
1623
1625 {
1626 fn = nullptr;
1627 return *this;
1628 }
1629
1630 operator bool() const
1631 {
1632 return fn;
1633 }
1634
1635 operator FunVPPtr() const
1636 {
1637 return reinterpret_cast<FunVPPtr>(fn);
1638 }
1639
1640 void* arg() const
1641 {
1642 return nullptr;
1643 }
1644
1645 R IRAM_ATTR operator()() const
1646 {
1647 return fn();
1648 }
1649
1650 protected:
1651 FunPtr fn;
1652 };
1653#endif
1654
1655 template<typename A = void, typename R = void, typename... P>
1656 class Delegate : private detail::DelegatePImpl<A, R, P...>
1657 {
1658 public:
1659 using target_type = R(P...);
1660 protected:
1662 using FunAPtr = R(*)(A, P...);
1663 using FunVPPtr = R(*)(void*, P...);
1664#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
1666#endif
1667 public:
1668 using detail::DelegatePImpl<A, R, P...>::operator bool;
1669 using detail::DelegatePImpl<A, R, P...>::arg;
1670 using detail::DelegatePImpl<A, R, P...>::operator();
1671
1672 operator FunVPPtr() { return detail::DelegatePImpl<A, R, P...>::operator FunVPPtr(); }
1673#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
1674 operator FunctionType() { return detail::DelegatePImpl<A, R, P...>::operator FunctionType(); }
1675#endif
1676
1677 Delegate() : detail::DelegatePImpl<A, R, P...>::DelegatePImpl() {}
1678
1679 Delegate(std::nullptr_t) : detail::DelegatePImpl<A, R, P...>::DelegatePImpl(nullptr) {}
1680
1681 Delegate(const Delegate& del) : detail::DelegatePImpl<A, R, P...>::DelegatePImpl(
1682 static_cast<const detail::DelegatePImpl<A, R, P...>&>(del)) {}
1683
1684 Delegate(Delegate&& del) : detail::DelegatePImpl<A, R, P...>::DelegatePImpl(
1685 std::move(static_cast<detail::DelegatePImpl<A, R, P...>&>(del))) {}
1686
1687 Delegate(FunAPtr fnA, const A& obj) : detail::DelegatePImpl<A, R, P...>::DelegatePImpl(fnA, obj) {}
1688
1689 Delegate(FunAPtr fnA, A&& obj) : detail::DelegatePImpl<A, R, P...>::DelegatePImpl(fnA, std::move(obj)) {}
1690
1691 Delegate(FunPtr fn) : detail::DelegatePImpl<A, R, P...>::DelegatePImpl(fn) {}
1692
1693 template<typename F> Delegate(F functional) : detail::DelegatePImpl<A, R, P...>::DelegatePImpl(std::forward<F>(functional)) {}
1694
1697 return *this;
1698 }
1699
1704
1709
1712 return *this;
1713 }
1714 };
1715
1716 template<typename A, typename R, typename... P>
1717 class Delegate<A*, R, P...> : private detail::DelegatePImpl<A*, R, P...>
1718 {
1719 public:
1720 using target_type = R(P...);
1721 protected:
1723 using FunAPtr = R(*)(A*, P...);
1724 using FunVPPtr = R(*)(void*, P...);
1725#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
1727#endif
1728 public:
1729 using detail::DelegatePImpl<A*, R, P...>::operator bool;
1730 using detail::DelegatePImpl<A*, R, P...>::operator();
1731
1732 operator FunVPPtr() const
1733 {
1735 {
1736 return reinterpret_cast<FunVPPtr>(detail::DelegatePImpl<A*, R, P...>::fnA);
1737 }
1738 else
1739 {
1740 return detail::DelegatePImpl<A*, R, P...>::operator FunVPPtr();
1741 }
1742 }
1743#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
1744 operator FunctionType() { return detail::DelegatePImpl<A*, R, P...>::operator FunctionType(); }
1745#endif
1746 void* arg() const
1747 {
1749 {
1750 return detail::DelegatePImpl<A*, R, P...>::obj;
1751 }
1752 else
1753 {
1755 }
1756 }
1757
1758 Delegate() : detail::DelegatePImpl<A*, R, P...>::DelegatePImpl() {}
1759
1760 Delegate(std::nullptr_t) : detail::DelegatePImpl<A*, R, P...>::DelegatePImpl(nullptr) {}
1761
1762 Delegate(const Delegate& del) : detail::DelegatePImpl<A*, R, P...>::DelegatePImpl(
1763 static_cast<const detail::DelegatePImpl<A*, R, P...>&>(del)) {}
1764
1765 Delegate(Delegate&& del) : detail::DelegatePImpl<A*, R, P...>::DelegatePImpl(
1766 std::move(static_cast<detail::DelegatePImpl<A*, R, P...>&>(del))) {}
1767
1768 Delegate(FunAPtr fnA, A* obj) : detail::DelegatePImpl<A*, R, P...>::DelegatePImpl(fnA, obj) {}
1769
1770 Delegate(FunPtr fn) : detail::DelegatePImpl<A*, R, P...>::DelegatePImpl(fn) {}
1771
1772 template<typename F> Delegate(F functional) : detail::DelegatePImpl<A*, R, P...>::DelegatePImpl(std::forward<F>(functional)) {}
1773
1776 return *this;
1777 }
1778
1783
1788
1791 return *this;
1792 }
1793 };
1794
1795 template<typename R, typename... P>
1796 class Delegate<void, R, P...> : private detail::DelegatePImpl<void, R, P...>
1797 {
1798 public:
1799 using target_type = R(P...);
1800 protected:
1802#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
1804#endif
1805 using FunVPPtr = R(*)(void*, P...);
1806 public:
1807 using detail::DelegatePImpl<void, R, P...>::operator bool;
1808 using detail::DelegatePImpl<void, R, P...>::arg;
1809 using detail::DelegatePImpl<void, R, P...>::operator();
1810
1811 operator FunVPPtr() const { return detail::DelegatePImpl<void, R, P...>::operator FunVPPtr(); }
1812#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
1813 operator FunctionType() { return detail::DelegatePImpl<void, R, P...>::operator FunctionType(); }
1814#endif
1815
1816 Delegate() : detail::DelegatePImpl<void, R, P...>::DelegatePImpl() {}
1817
1818 Delegate(std::nullptr_t) : detail::DelegatePImpl<void, R, P...>::DelegatePImpl(nullptr) {}
1819
1820 Delegate(const Delegate& del) : detail::DelegatePImpl<void, R, P...>::DelegatePImpl(
1821 static_cast<const detail::DelegatePImpl<void, R, P...>&>(del)) {}
1822
1823 Delegate(Delegate&& del) : detail::DelegatePImpl<void, R, P...>::DelegatePImpl(
1824 std::move(static_cast<detail::DelegatePImpl<void, R, P...>&>(del))) {}
1825
1826 Delegate(FunPtr fn) : detail::DelegatePImpl<void, R, P...>::DelegatePImpl(fn) {}
1827
1828 template<typename F> Delegate(F functional) : detail::DelegatePImpl<void, R, P...>::DelegatePImpl(std::forward<F>(functional)) {}
1829
1832 return *this;
1833 }
1834
1839
1844
1847 return *this;
1848 }
1849 };
1850
1851 template<typename A, typename R>
1852 class Delegate<A, R> : private detail::DelegateImpl<A, R>
1853 {
1854 public:
1855 using target_type = R();
1856 protected:
1858 using FunAPtr = R(*)(A);
1859 using FunVPPtr = R(*)(void*);
1860#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
1862#endif
1863 public:
1864 using detail::DelegateImpl<A, R>::operator bool;
1865 using detail::DelegateImpl<A, R>::arg;
1866 using detail::DelegateImpl<A, R>::operator();
1867
1869#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
1871#endif
1872
1873 Delegate() : detail::DelegateImpl<A, R>::DelegateImpl() {}
1874
1875 Delegate(std::nullptr_t) : detail::DelegateImpl<A, R>::DelegateImpl(nullptr) {}
1876
1877 Delegate(const Delegate& del) : detail::DelegateImpl<A, R>::DelegateImpl(
1878 static_cast<const detail::DelegateImpl<A, R>&>(del)) {}
1879
1881 std::move(static_cast<detail::DelegateImpl<A, R>&>(del))) {}
1882
1883 Delegate(FunAPtr fnA, const A& obj) : detail::DelegateImpl<A, R>::DelegateImpl(fnA, obj) {}
1884
1885 Delegate(FunAPtr fnA, A&& obj) : detail::DelegateImpl<A, R>::DelegateImpl(fnA, std::move(obj)) {}
1886
1888
1889 template<typename F> Delegate(F functional) : detail::DelegateImpl<A, R>::DelegateImpl(std::forward<F>(functional)) {}
1890
1893 return *this;
1894 }
1895
1898 return *this;
1899 }
1900
1905
1908 return *this;
1909 }
1910 };
1911
1912 template<typename A, typename R>
1914 {
1915 public:
1916 using target_type = R();
1917 protected:
1919 using FunAPtr = R(*)(A*);
1920 using FunVPPtr = R(*)(void*);
1921#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
1923#endif
1924 public:
1925 using detail::DelegateImpl<A*, R>::operator bool;
1926 using detail::DelegateImpl<A*, R>::operator();
1927
1928 operator FunVPPtr() const
1929 {
1931 {
1932 return reinterpret_cast<FunVPPtr>(detail::DelegateImpl<A*, R>::fnA);
1933 }
1934 else
1935 {
1937 }
1938 }
1939#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
1941#endif
1942 void* arg() const
1943 {
1945 {
1947 }
1948 else
1949 {
1951 }
1952 }
1953
1954 Delegate() : detail::DelegateImpl<A*, R>::DelegateImpl() {}
1955
1956 Delegate(std::nullptr_t) : detail::DelegateImpl<A*, R>::DelegateImpl(nullptr) {}
1957
1958 Delegate(const Delegate& del) : detail::DelegateImpl<A*, R>::DelegateImpl(
1959 static_cast<const detail::DelegateImpl<A*, R>&>(del)) {}
1960
1961 Delegate(Delegate&& del) : detail::DelegateImpl<A*, R>::DelegateImpl(
1962 std::move(static_cast<detail::DelegateImpl<A*, R>&>(del))) {}
1963
1964 Delegate(FunAPtr fnA, A* obj) : detail::DelegateImpl<A*, R>::DelegateImpl(fnA, obj) {}
1965
1966 Delegate(FunPtr fn) : detail::DelegateImpl<A*, R>::DelegateImpl(fn) {}
1967
1968 template<typename F> Delegate(F functional) : detail::DelegateImpl<A*, R>::DelegateImpl(std::forward<F>(functional)) {}
1969
1972 return *this;
1973 }
1974
1977 return *this;
1978 }
1979
1982 return *this;
1983 }
1984
1987 return *this;
1988 }
1989 };
1990
1991 template<typename R>
1992 class Delegate<void, R> : private detail::DelegateImpl<void, R>
1993 {
1994 public:
1995 using target_type = R();
1996 protected:
1998#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
2000#endif
2001 using FunVPPtr = R(*)(void*);
2002 public:
2003 using detail::DelegateImpl<void, R>::operator bool;
2004 using detail::DelegateImpl<void, R>::arg;
2005 using detail::DelegateImpl<void, R>::operator();
2006
2008#if !defined(ARDUINO) || defined(ESP8266) || defined(ESP32)
2010#endif
2011
2012 Delegate() : detail::DelegateImpl<void, R>::DelegateImpl() {}
2013
2014 Delegate(std::nullptr_t) : detail::DelegateImpl<void, R>::DelegateImpl(nullptr) {}
2015
2016 Delegate(const Delegate& del) : detail::DelegateImpl<void, R>::DelegateImpl(
2017 static_cast<const detail::DelegateImpl<void, R>&>(del)) {}
2018
2019 Delegate(Delegate&& del) : detail::DelegateImpl<void, R>::DelegateImpl(
2020 std::move(static_cast<detail::DelegateImpl<void, R>&>(del))) {}
2021
2023
2024 template<typename F> Delegate(F functional) : detail::DelegateImpl<void, R>::DelegateImpl(std::forward<F>(functional)) {}
2025
2028 return *this;
2029 }
2030
2033 return *this;
2034 }
2035
2040
2043 return *this;
2044 }
2045 };
2046 }
2047}
2048
2049template<typename A = void, typename R = void, typename... P> class Delegate;
2050template<typename A, typename R, typename... P> class Delegate<R(P...), A> : public delegate::detail::Delegate<A, R, P...>
2051{
2052public:
2053 Delegate() : delegate::detail::Delegate<A, R, P...>::Delegate() {}
2054
2055 Delegate(std::nullptr_t) : delegate::detail::Delegate<A, R, P...>::Delegate(nullptr) {}
2056
2057 Delegate(const Delegate& del) : delegate::detail::Delegate<A, R, P...>::Delegate(
2058 static_cast<const delegate::detail::Delegate<A, R, P...>&>(del)) {}
2059
2060 Delegate(Delegate&& del) : delegate::detail::Delegate<A, R, P...>::Delegate(
2061 std::move(static_cast<delegate::detail::Delegate<A, R, P...>&>(del))) {}
2062
2063 Delegate(typename delegate::detail::Delegate<A, R, P...>::FunAPtr fnA, const A& obj) : delegate::detail::Delegate<A, R, P...>::Delegate(fnA, obj) {}
2064
2065 Delegate(typename delegate::detail::Delegate<A, R, P...>::FunAPtr fnA, A&& obj) : delegate::detail::Delegate<A, R, P...>::Delegate(fnA, std::move(obj)) {}
2066
2068
2069 template<typename F> Delegate(F functional) : delegate::detail::Delegate<A, R, P...>::Delegate(std::forward<F>(functional)) {}
2070
2073 return *this;
2074 }
2075
2080
2085
2088 return *this;
2089 }
2090};
2091
2092template<typename R, typename... P> class Delegate<R(P...)> : public delegate::detail::Delegate<void, R, P...>
2093{
2094public:
2095 Delegate() : delegate::detail::Delegate<void, R, P...>::Delegate() {}
2096
2097 Delegate(std::nullptr_t) : delegate::detail::Delegate<void, R, P...>::Delegate(nullptr) {}
2098
2099 Delegate(const Delegate& del) : delegate::detail::Delegate<void, R, P...>::Delegate(
2100 static_cast<const delegate::detail::Delegate<void, R, P...>&>(del)) {}
2101
2102 Delegate(Delegate&& del) : delegate::detail::Delegate<void, R, P...>::Delegate(
2103 std::move(static_cast<delegate::detail::Delegate<void, R, P...>&>(del))) {}
2104
2106
2107 template<typename F> Delegate(F functional) : delegate::detail::Delegate<void, R, P...>::Delegate(std::forward<F>(functional)) {}
2108
2111 return *this;
2112 }
2113
2118
2123
2126 return *this;
2127 }
2128};
2129
2130#endif // __Delegate_h
Delegate(const Delegate &del)
Definition Delegate.h:2057
Delegate & operator=(typename delegate::detail::Delegate< A, R, P... >::FunPtr fn)
Definition Delegate.h:2081
Delegate & operator=(const Delegate &del)
Definition Delegate.h:2071
Delegate &IRAM_ATTR operator=(std::nullptr_t)
Definition Delegate.h:2086
Delegate(F functional)
Definition Delegate.h:2069
Delegate(typename delegate::detail::Delegate< A, R, P... >::FunAPtr fnA, const A &obj)
Definition Delegate.h:2063
Delegate(Delegate &&del)
Definition Delegate.h:2060
Delegate(typename delegate::detail::Delegate< A, R, P... >::FunAPtr fnA, A &&obj)
Definition Delegate.h:2065
Delegate(typename delegate::detail::Delegate< A, R, P... >::FunPtr fn)
Definition Delegate.h:2067
Delegate(std::nullptr_t)
Definition Delegate.h:2055
Delegate & operator=(Delegate &&del)
Definition Delegate.h:2076
Delegate()
Definition Delegate.h:2053
Delegate(Delegate &&del)
Definition Delegate.h:2102
Delegate(const Delegate &del)
Definition Delegate.h:2099
Delegate(typename delegate::detail::Delegate< void, R, P... >::FunPtr fn)
Definition Delegate.h:2105
Delegate & operator=(typename delegate::detail::Delegate< void, R, P... >::FunPtr fn)
Definition Delegate.h:2119
Delegate(F functional)
Definition Delegate.h:2107
Delegate & operator=(Delegate &&del)
Definition Delegate.h:2114
Delegate()
Definition Delegate.h:2095
Delegate(std::nullptr_t)
Definition Delegate.h:2097
Delegate & operator=(const Delegate &del)
Definition Delegate.h:2109
Delegate &IRAM_ATTR operator=(std::nullptr_t)
Definition Delegate.h:2124
Definition Delegate.h:2049
Delegate(const Delegate &del)
Definition Delegate.h:1877
target_type * FunPtr
Definition Delegate.h:1857
Delegate(FunAPtr fnA, A &&obj)
Definition Delegate.h:1885
R() target_type
Definition Delegate.h:1855
Delegate(Delegate &&del)
Definition Delegate.h:1880
Delegate & operator=(const Delegate &del)
Definition Delegate.h:1891
R(*)(void *) FunVPPtr
Definition Delegate.h:1859
Delegate & operator=(Delegate &&del)
Definition Delegate.h:1896
Delegate(std::nullptr_t)
Definition Delegate.h:1875
Delegate(FunPtr fn)
Definition Delegate.h:1887
Delegate(FunAPtr fnA, const A &obj)
Definition Delegate.h:1883
Delegate()
Definition Delegate.h:1873
Delegate(F functional)
Definition Delegate.h:1889
R(*)(A) FunAPtr
Definition Delegate.h:1858
std::function< target_type > FunctionType
Definition Delegate.h:1861
Delegate & operator=(FunPtr fn)
Definition Delegate.h:1901
Delegate &IRAM_ATTR operator=(std::nullptr_t)
Definition Delegate.h:1906
void * arg() const
Definition Delegate.h:1746
R(P...) target_type
Definition Delegate.h:1720
Delegate()
Definition Delegate.h:1758
R(*)(A *, P...) FunAPtr
Definition Delegate.h:1723
Delegate(const Delegate &del)
Definition Delegate.h:1762
Delegate & operator=(FunPtr fn)
Definition Delegate.h:1784
Delegate(std::nullptr_t)
Definition Delegate.h:1760
Delegate & operator=(const Delegate &del)
Definition Delegate.h:1774
Delegate &IRAM_ATTR operator=(std::nullptr_t)
Definition Delegate.h:1789
std::function< target_type > FunctionType
Definition Delegate.h:1726
Delegate(FunPtr fn)
Definition Delegate.h:1770
Delegate(F functional)
Definition Delegate.h:1772
R(*)(void *, P...) FunVPPtr
Definition Delegate.h:1724
Delegate(FunAPtr fnA, A *obj)
Definition Delegate.h:1768
Delegate & operator=(Delegate &&del)
Definition Delegate.h:1779
target_type * FunPtr
Definition Delegate.h:1722
Delegate(Delegate &&del)
Definition Delegate.h:1765
R() target_type
Definition Delegate.h:1916
Delegate(FunPtr fn)
Definition Delegate.h:1966
Delegate()
Definition Delegate.h:1954
R(*)(void *) FunVPPtr
Definition Delegate.h:1920
void * arg() const
Definition Delegate.h:1942
target_type * FunPtr
Definition Delegate.h:1918
std::function< target_type > FunctionType
Definition Delegate.h:1922
Delegate & operator=(const Delegate &del)
Definition Delegate.h:1970
Delegate(FunAPtr fnA, A *obj)
Definition Delegate.h:1964
R(*)(A *) FunAPtr
Definition Delegate.h:1919
Delegate &IRAM_ATTR operator=(std::nullptr_t)
Definition Delegate.h:1985
Delegate(const Delegate &del)
Definition Delegate.h:1958
Delegate & operator=(FunPtr fn)
Definition Delegate.h:1980
Delegate(Delegate &&del)
Definition Delegate.h:1961
Delegate(F functional)
Definition Delegate.h:1968
Delegate & operator=(Delegate &&del)
Definition Delegate.h:1975
Delegate(std::nullptr_t)
Definition Delegate.h:1956
Delegate & operator=(FunPtr fn)
Definition Delegate.h:1840
Delegate & operator=(const Delegate &del)
Definition Delegate.h:1830
Delegate(Delegate &&del)
Definition Delegate.h:1823
Delegate(std::nullptr_t)
Definition Delegate.h:1818
Delegate(const Delegate &del)
Definition Delegate.h:1820
Delegate(F functional)
Definition Delegate.h:1828
R(P...) target_type
Definition Delegate.h:1799
Delegate()
Definition Delegate.h:1816
Delegate(FunPtr fn)
Definition Delegate.h:1826
Delegate & operator=(Delegate &&del)
Definition Delegate.h:1835
std::function< target_type > FunctionType
Definition Delegate.h:1803
R(*)(void *, P...) FunVPPtr
Definition Delegate.h:1805
target_type * FunPtr
Definition Delegate.h:1801
Delegate &IRAM_ATTR operator=(std::nullptr_t)
Definition Delegate.h:1845
Delegate(std::nullptr_t)
Definition Delegate.h:2014
Delegate(Delegate &&del)
Definition Delegate.h:2019
R() target_type
Definition Delegate.h:1995
target_type * FunPtr
Definition Delegate.h:1997
Delegate()
Definition Delegate.h:2012
Delegate(FunPtr fn)
Definition Delegate.h:2022
Delegate &IRAM_ATTR operator=(std::nullptr_t)
Definition Delegate.h:2041
Delegate(F functional)
Definition Delegate.h:2024
Delegate & operator=(const Delegate &del)
Definition Delegate.h:2026
R(*)(void *) FunVPPtr
Definition Delegate.h:2001
Delegate & operator=(Delegate &&del)
Definition Delegate.h:2031
Delegate & operator=(FunPtr fn)
Definition Delegate.h:2036
Delegate(const Delegate &del)
Definition Delegate.h:2016
std::function< target_type > FunctionType
Definition Delegate.h:1999
Definition Delegate.h:1657
std::function< target_type > FunctionType
Definition Delegate.h:1665
Delegate & operator=(Delegate &&del)
Definition Delegate.h:1700
Delegate(FunAPtr fnA, const A &obj)
Definition Delegate.h:1687
Delegate(std::nullptr_t)
Definition Delegate.h:1679
R(P...) target_type
Definition Delegate.h:1659
R(*)(void *, P...) FunVPPtr
Definition Delegate.h:1663
Delegate(F functional)
Definition Delegate.h:1693
Delegate & operator=(FunPtr fn)
Definition Delegate.h:1705
Delegate(Delegate &&del)
Definition Delegate.h:1684
R(*)(A, P...) FunAPtr
Definition Delegate.h:1662
Delegate(FunAPtr fnA, A &&obj)
Definition Delegate.h:1689
Delegate &IRAM_ATTR operator=(std::nullptr_t)
Definition Delegate.h:1710
Delegate & operator=(const Delegate &del)
Definition Delegate.h:1695
Delegate(FunPtr fn)
Definition Delegate.h:1691
Delegate(const Delegate &del)
Definition Delegate.h:1681
Delegate()
Definition Delegate.h:1677
target_type * FunPtr
Definition Delegate.h:1661
DelegateImpl(FunPtr fn)
Definition Delegate.h:1415
DelegateImpl(std::nullptr_t)
Definition Delegate.h:1377
void * arg() const
Definition Delegate.h:1522
R IRAM_ATTR operator()() const
Definition Delegate.h:1546
DelegateImpl(F fn)
Definition Delegate.h:1599
R() target_type
Definition Delegate.h:1365
DelegateImpl &IRAM_ATTR operator=(std::nullptr_t)
Definition Delegate.h:1484
DelegateImpl & operator=(DelegateImpl &&del)
Definition Delegate.h:1450
DelegateImpl()
Definition Delegate.h:1371
DelegateImpl & operator=(FunPtr fn)
Definition Delegate.h:1473
DelegateImpl(F functional)
Definition Delegate.h:1421
DelegateImpl & operator=(const DelegateImpl &del)
Definition Delegate.h:1427
DelegateImpl(const DelegateImpl &del)
Definition Delegate.h:1389
std::function< target_type > FunctionType
Definition Delegate.h:1368
~DelegateImpl()
Definition Delegate.h:1383
R(*)(void *) FunVPPtr
Definition Delegate.h:1369
DelegateImpl(DelegateImpl &&del)
Definition Delegate.h:1402
target_type * FunPtr
Definition Delegate.h:1367
FunctionType functional
Definition Delegate.h:1560
FunPtr fn
Definition Delegate.h:1561
Definition Delegate.h:1155
DelegateImpl(FunAPtr fnA, const A &obj)
Definition Delegate.h:923
std::function< target_type > FunctionType
Definition Delegate.h:864
DelegateImpl & operator=(const DelegateImpl &del)
Definition Delegate.h:949
target_type * FunPtr
Definition Delegate.h:862
R() target_type
Definition Delegate.h:860
FunAPtr fnA
Definition Delegate.h:1147
DelegateImpl(const DelegateImpl &del)
Definition Delegate.h:887
@ FUNC
Definition Delegate.h:1151
R(*)(void *) FunVPPtr
Definition Delegate.h:865
@ FP
Definition Delegate.h:1151
@ FPA
Definition Delegate.h:1151
DelegateImpl & operator=(DelegateImpl &&del)
Definition Delegate.h:988
R IRAM_ATTR operator()() const
Definition Delegate.h:1126
enum delegate::detail::DelegateImpl::@13 kind
~DelegateImpl()
Definition Delegate.h:879
void * arg() const
Definition Delegate.h:1098
static R IRAM_ATTR vPtrToFunAPtrExec(void *self)
Definition Delegate.h:1073
DelegateImpl &IRAM_ATTR operator=(std::nullptr_t)
Definition Delegate.h:1042
DelegateImpl(F functional)
Definition Delegate.h:943
DelegateImpl & operator=(FunPtr fn)
Definition Delegate.h:1027
DelegateImpl(FunAPtr fnA, A &&obj)
Definition Delegate.h:930
DelegateImpl()
Definition Delegate.h:867
R(*)(A) FunAPtr
Definition Delegate.h:863
DelegateImpl(F fn)
Definition Delegate.h:1223
DelegateImpl(std::nullptr_t)
Definition Delegate.h:873
DelegateImpl(FunPtr fn)
Definition Delegate.h:937
DelegateImpl(DelegateImpl &&del)
Definition Delegate.h:905
A obj
Definition Delegate.h:1148
FunPtr fn
Definition Delegate.h:1145
FunctionType functional
Definition Delegate.h:1144
void * arg() const
Definition Delegate.h:723
DelegatePImpl(DelegatePImpl &&del)
Definition Delegate.h:603
R(*)(void *, P...) FunVPPtr
Definition Delegate.h:570
R IRAM_ATTR operator()(P... args) const
Definition Delegate.h:747
target_type * FunPtr
Definition Delegate.h:568
DelegatePImpl & operator=(DelegatePImpl &&del)
Definition Delegate.h:651
DelegatePImpl(const DelegatePImpl &del)
Definition Delegate.h:590
DelegatePImpl & operator=(const DelegatePImpl &del)
Definition Delegate.h:628
DelegatePImpl(FunPtr fn)
Definition Delegate.h:616
FunctionType functional
Definition Delegate.h:761
R(P...) target_type
Definition Delegate.h:566
DelegatePImpl(F functional)
Definition Delegate.h:622
DelegatePImpl(F fn)
Definition Delegate.h:800
DelegatePImpl(std::nullptr_t)
Definition Delegate.h:578
DelegatePImpl &IRAM_ATTR operator=(std::nullptr_t)
Definition Delegate.h:685
std::function< target_type > FunctionType
Definition Delegate.h:569
DelegatePImpl & operator=(FunPtr fn)
Definition Delegate.h:674
Definition Delegate.h:355
enum delegate::detail::DelegatePImpl::@2 kind
DelegatePImpl()
Definition Delegate.h:66
DelegatePImpl(std::nullptr_t)
Definition Delegate.h:72
DelegatePImpl &IRAM_ATTR operator=(std::nullptr_t)
Definition Delegate.h:241
DelegatePImpl(const DelegatePImpl &del)
Definition Delegate.h:86
~DelegatePImpl()
Definition Delegate.h:78
DelegatePImpl & operator=(DelegatePImpl &&del)
Definition Delegate.h:187
static R IRAM_ATTR vPtrToFunAPtrExec(void *self, P... args)
Definition Delegate.h:272
R(*)(A, P...) FunAPtr
Definition Delegate.h:62
DelegatePImpl(FunAPtr fnA, A &&obj)
Definition Delegate.h:129
A obj
Definition Delegate.h:348
FunctionType functional
Definition Delegate.h:344
DelegatePImpl(DelegatePImpl &&del)
Definition Delegate.h:104
@ FPA
Definition Delegate.h:351
@ FP
Definition Delegate.h:351
void * arg() const
Definition Delegate.h:298
target_type * FunPtr
Definition Delegate.h:61
DelegatePImpl(F functional)
Definition Delegate.h:142
R IRAM_ATTR operator()(P... args) const
Definition Delegate.h:326
DelegatePImpl & operator=(FunPtr fn)
Definition Delegate.h:226
@ FUNC
Definition Delegate.h:351
DelegatePImpl(FunAPtr fnA, const A &obj)
Definition Delegate.h:122
FunPtr fn
Definition Delegate.h:345
R(*)(void *, P...) FunVPPtr
Definition Delegate.h:63
DelegatePImpl(FunPtr fn)
Definition Delegate.h:136
DelegatePImpl & operator=(const DelegatePImpl &del)
Definition Delegate.h:148
R(P...) target_type
Definition Delegate.h:59
std::function< target_type > FunctionType
Definition Delegate.h:64
FunAPtr fnA
Definition Delegate.h:347
Definition Delegate.h:51
Definition ghostl.h:32
T && move(T &t) noexcept
Definition ghostl.h:50
decltype(nullptr) nullptr_t
Definition ghostl.h:80
T && forward(typename identity< T >::type &t) noexcept
Definition ghostl.h:88
T * function
Definition ghostl.h:79