/
callback.h
754 lines (706 loc) · 26.8 KB
/
callback.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
/*****************************************************************************
* GCL - callback.h *
* Copyright (C) F. Gausling *
* Version 0.9.0 for more information and the full license visit *
* http://www.gcl-ui.com *
*****************************************************************************/
using namespace std;
#ifndef CALLBACK_H
#define CALLBACK_H
#if _MSC_VER
#pragma once
#endif
#include "stdafx.h"
namespace gcl {
template <int i>
struct pl_holder {bool operator==(const pl_holder<i>&){return true;}};
namespace placeholder {
static const pl_holder<1> _1;
static const pl_holder<2> _2;
static const pl_holder<3> _3;
static const pl_holder<4> _4;
static const pl_holder<5> _5;
static const pl_holder<6> _6;
static const pl_holder<7> _7;
static const pl_holder<8> _8;
static const pl_holder<9> _9;
static const pl_holder<10> _10;
};
template <typename t>
struct gcl_list1
{
gcl_list1(const t& i) : itm(i) {}
t operator[](const pl_holder<1>&) const {return itm;}
template <typename it>
it operator[](const it& _it) const {return _it;}
template <typename fn>
void operator()(fn func)
{
func(itm);
}
template <typename func, typename lst>
void operator()(func fn, const lst& _lst)
{
fn(_lst[itm]);
}
bool operator==(const gcl_list1<t>& lst)
{
return itm == lst.itm;
}
private:
t itm;
};
template <typename t, typename t1>
struct gcl_list2
{
gcl_list2(const t& i, const t1& i1) : itm(i), itm1(i1) {}
t operator[](const pl_holder<1>&) const {return itm;}
t1 operator[](const pl_holder<2>&) const {return itm1;}
template <typename it>
it operator[](const it& _it) const {return _it;}
template <typename fn>
void operator()(fn func)
{
func(itm, itm1);
}
template <typename func, typename lst>
void operator()(func fn, const lst& _lst)
{
fn(_lst[itm], _lst[itm1]);
}
bool operator==(const gcl_list2<t, t1>& lst)
{
return (itm == lst.itm) && (itm1 == lst.itm1);
}
private:
t itm;
t1 itm1;
};
template <typename t, typename t1, typename t2>
struct gcl_list3
{
gcl_list3(const t& i, const t1& i1, const t2& i2) : itm(i), itm1(i1), itm2(i2) {}
t operator[](const pl_holder<1>&) const {return itm;}
t1 operator[](const pl_holder<2>&) const {return itm1;}
t2 operator[](const pl_holder<3>&) const {return itm2;}
template <typename it>
it operator[](const it& _it) const {return _it;}
template <typename fn>
void operator()(fn func)
{
func(itm, itm1, itm2);
}
template <typename func, typename lst>
void operator()(func fn, const lst& _lst)
{
fn(_lst[itm], _lst[itm1], _lst[itm2]);
}
bool operator==(const gcl_list3<t, t1, t2>& lst)
{
return (itm == lst.itm) && (itm1 == lst.itm1) && (itm2 == lst.itm2);
}
private:
t itm;
t1 itm1;
t2 itm2;
};
template <typename t, typename t1, typename t2, typename t3>
struct gcl_list4
{
gcl_list4(const t& i, const t1& i1, const t2& i2, const t3& i3) : itm(i), itm1(i1), itm2(i2), itm3(i3) {}
t operator[](const pl_holder<1>&) const {return itm;}
t1 operator[](const pl_holder<2>&) const {return itm1;}
t2 operator[](const pl_holder<3>&) const {return itm2;}
t3 operator[](const pl_holder<4>&) const {return itm3;}
template <typename it>
it operator[](const it& _it) const {return _it;}
template <typename fn>
void operator()(fn func)
{
func(itm, itm1, itm2, itm3);
}
template <typename func, typename lst>
void operator()(func fn, const lst& _lst)
{
fn(_lst[itm], _lst[itm1], _lst[itm2], _lst[itm3]);
}
bool operator==(const gcl_list4<t, t1, t2, t3>& lst)
{
return (itm == lst.itm) && (itm1 == lst.itm1) && (itm2 == lst.itm2) && (itm3 == lst.itm3);
}
private:
t itm;
t1 itm1;
t2 itm2;
t3 itm3;
};
template <typename t, typename t1, typename t2, typename t3, typename t4>
struct gcl_list5
{
gcl_list5(const t& i, const t1& i1, const t2& i2, const t3& i3, const t4& i4) : itm(i), itm1(i1), itm2(i2), itm3(i3), itm4(i4) {}
t operator[](const pl_holder<1>&) const {return itm;}
t1 operator[](const pl_holder<2>&) const {return itm1;}
t2 operator[](const pl_holder<3>&) const {return itm2;}
t3 operator[](const pl_holder<4>&) const {return itm3;}
t4 operator[](const pl_holder<5>&) const {return itm4;}
template <typename it>
it operator[](const it& _it) const {return _it;}
template <typename fn>
void operator()(fn func)
{
func(itm, itm1, itm2, itm3, itm4);
}
template <typename func, typename lst>
void operator()(func fn, const lst& _lst)
{
fn(_lst[itm], _lst[itm1], _lst[itm2], _lst[itm3], _lst[itm4]);
}
bool operator==(const gcl_list5<t, t1, t2, t3, t4>& lst)
{
return (itm == lst.itm) && (itm1 == lst.itm1) && (itm2 == lst.itm2) && (itm3 == lst.itm3) && (itm4 == lst.itm4);
}
private:
t itm;
t1 itm1;
t2 itm2;
t3 itm3;
t4 itm4;
};
template <typename t, typename t1, typename t2, typename t3, typename t4, typename t5>
struct gcl_list6
{
gcl_list6(const t& i, const t1& i1, const t2& i2, const t3& i3, const t4& i4, const t5& i5) : itm(i), itm1(i1), itm2(i2), itm3(i3), itm4(i4), itm5(i5) {}
t operator[](const pl_holder<1>&) const {return itm;}
t1 operator[](const pl_holder<2>&) const {return itm1;}
t2 operator[](const pl_holder<3>&) const {return itm2;}
t3 operator[](const pl_holder<4>&) const {return itm3;}
t4 operator[](const pl_holder<5>&) const {return itm4;}
t5 operator[](const pl_holder<6>&) const {return itm5;}
template <typename it>
it operator[](const it& _it) const {return _it;}
template <typename fn>
void operator()(fn func)
{
func(itm, itm1, itm2, itm3, itm4, itm5);
}
template <typename func, typename lst>
void operator()(func fn, const lst& _lst)
{
fn(_lst[itm], _lst[itm1], _lst[itm2], _lst[itm3], _lst[itm4], _lst[itm5]);
}
bool operator==(const gcl_list6<t, t1, t2, t3, t4, t5>& lst)
{
return (itm == lst.itm) && (itm1 == lst.itm1) && (itm2 == lst.itm2) && (itm3 == lst.itm3) && (itm4 == lst.itm4) && (itm5 == lst.itm5);
}
private:
t itm;
t1 itm1;
t2 itm2;
t3 itm3;
t4 itm4;
t5 itm5;
};
template <typename t, typename t1, typename t2, typename t3, typename t4, typename t5, typename t6>
struct gcl_list7
{
gcl_list7(const t& i, const t1& i1, const t2& i2, const t3& i3, const t4& i4, const t5& i5, const t6& i6) : itm(i), itm1(i1), itm2(i2), itm3(i3), itm4(i4), itm5(i5), itm6(i6) {}
t operator[](const pl_holder<1>&) const {return itm;}
t1 operator[](const pl_holder<2>&) const {return itm1;}
t2 operator[](const pl_holder<3>&) const {return itm2;}
t3 operator[](const pl_holder<4>&) const {return itm3;}
t4 operator[](const pl_holder<5>&) const {return itm4;}
t5 operator[](const pl_holder<6>&) const {return itm5;}
t6 operator[](const pl_holder<7>&) const {return itm6;}
template <typename it>
it operator[](const it& _it) const {return _it;}
template <typename fn>
void operator()(fn func)
{
func(itm, itm1, itm2, itm3, itm4, itm5, itm6);
}
template <typename func, typename lst>
void operator()(func fn, const lst& _lst)
{
fn(_lst[itm], _lst[itm1], _lst[itm2], _lst[itm3], _lst[itm4], _lst[itm5], _lst[itm6]);
}
bool operator==(const gcl_list7<t, t1, t2, t3, t4, t5, t6>& lst)
{
return (itm == lst.itm) && (itm1 == lst.itm1) && (itm2 == lst.itm2) && (itm3 == lst.itm3) && (itm4 == lst.itm4) && (itm5 == lst.itm5) && (itm6 == lst.itm6);
}
private:
t itm;
t1 itm1;
t2 itm2;
t3 itm3;
t4 itm4;
t5 itm5;
t6 itm6;
};
template <typename t, typename t1, typename t2, typename t3, typename t4, typename t5, typename t6, typename t7>
struct gcl_list8
{
gcl_list8(const t& i, const t1& i1, const t2& i2, const t3& i3, const t4& i4, const t5& i5, const t6& i6, const t7& i7) : itm(i), itm1(i1), itm2(i2), itm3(i3), itm4(i4), itm5(i5), itm6(i6), itm7(i7) {}
t operator[](const pl_holder<1>&) const {return itm;}
t1 operator[](const pl_holder<2>&) const {return itm1;}
t2 operator[](const pl_holder<3>&) const {return itm2;}
t3 operator[](const pl_holder<4>&) const {return itm3;}
t4 operator[](const pl_holder<5>&) const {return itm4;}
t5 operator[](const pl_holder<6>&) const {return itm5;}
t6 operator[](const pl_holder<7>&) const {return itm6;}
t7 operator[](const pl_holder<8>&) const {return itm7;}
template <typename it>
it operator[](const it& _it) const {return _it;}
template <typename fn>
void operator()(fn func)
{
func(itm, itm1, itm2, itm3, itm4, itm5, itm6, itm7);
}
template <typename func, typename lst>
void operator()(func fn, const lst& _lst)
{
fn(_lst[itm], _lst[itm1], _lst[itm2], _lst[itm3], _lst[itm4], _lst[itm5], _lst[itm6], _lst[itm7]);
}
bool operator==(const gcl_list8<t, t1, t2, t3, t4, t5, t6, t7>& lst)
{
return (itm == lst.itm) && (itm1 == lst.itm1) && (itm2 == lst.itm2) && (itm3 == lst.itm3) && (itm4 == lst.itm4) && (itm5 == lst.itm5) && (itm6 == lst.itm6) && (itm7 == lst.itm7);
}
private:
t itm;
t1 itm1;
t2 itm2;
t3 itm3;
t4 itm4;
t5 itm5;
t6 itm6;
t7 itm7;
};
template <typename t, typename t1, typename t2, typename t3, typename t4, typename t5, typename t6, typename t7, typename t8>
struct gcl_list9
{
gcl_list9(const t& i, const t1& i1, const t2& i2, const t3& i3, const t4& i4, const t5& i5, const t6& i6, const t7& i7, const t8& i8) : itm(i), itm1(i1), itm2(i2), itm3(i3), itm4(i4), itm5(i5), itm6(i6), itm7(i7), itm8(i8) {}
t operator[](const pl_holder<1>&) const {return itm;}
t1 operator[](const pl_holder<2>&) const {return itm1;}
t2 operator[](const pl_holder<3>&) const {return itm2;}
t3 operator[](const pl_holder<4>&) const {return itm3;}
t4 operator[](const pl_holder<5>&) const {return itm4;}
t5 operator[](const pl_holder<6>&) const {return itm5;}
t6 operator[](const pl_holder<7>&) const {return itm6;}
t7 operator[](const pl_holder<8>&) const {return itm7;}
t8 operator[](const pl_holder<9>&) const {return itm8;}
template <typename it>
it operator[](const it& _it) const {return _it;}
template <typename fn>
void operator()(fn func)
{
func(itm, itm1, itm2, itm3, itm4, itm5, itm6, itm7, itm8);
}
template <typename func, typename lst>
void operator()(func fn, const lst& _lst)
{
fn(_lst[itm], _lst[itm1], _lst[itm2], _lst[itm3], _lst[itm4], _lst[itm5], _lst[itm6], _lst[itm7], _lst[itm8]);
}
bool operator==(const gcl_list9<t, t1, t2, t3, t4, t5, t6, t7, t8>& lst)
{
return (itm == lst.itm) && (itm1 == lst.itm1) && (itm2 == lst.itm2) && (itm3 == lst.itm3) && (itm4 == lst.itm4) && (itm5 == lst.itm5) && (itm6 == lst.itm6) && (itm7 == lst.itm7) && (itm8 == lst.itm8);
}
private:
t itm;
t1 itm1;
t2 itm2;
t3 itm3;
t4 itm4;
t5 itm5;
t6 itm6;
t7 itm7;
t8 itm8;
};
template <typename t, typename t1, typename t2, typename t3, typename t4, typename t5, typename t6, typename t7, typename t8, typename t9>
struct gcl_list10
{
gcl_list10(const t& i, const t1& i1, const t2& i2, const t3& i3, const t4& i4, const t5& i5, const t6& i6, const t7& i7, const t8& i8, const t9& i9) : itm(i), itm1(i1), itm2(i2), itm3(i3), itm4(i4), itm5(i5), itm6(i6), itm7(i7), itm8(i8), itm9(i9) {}
t operator[](const pl_holder<1>&) const {return itm;}
t1 operator[](const pl_holder<2>&) const {return itm1;}
t2 operator[](const pl_holder<3>&) const {return itm2;}
t3 operator[](const pl_holder<4>&) const {return itm3;}
t4 operator[](const pl_holder<5>&) const {return itm4;}
t5 operator[](const pl_holder<6>&) const {return itm5;}
t6 operator[](const pl_holder<7>&) const {return itm6;}
t7 operator[](const pl_holder<8>&) const {return itm7;}
t8 operator[](const pl_holder<9>&) const {return itm8;}
t9 operator[](const pl_holder<10>&) const {return itm9;}
template <typename it>
it operator[](const it& _it) const {return _it;}
template <typename fn>
void operator()(fn func)
{
func(itm, itm1, itm2, itm3, itm4, itm5, itm6, itm7, itm8, itm9);
}
template <typename func, typename lst>
void operator()(func fn, const lst& _lst)
{
fn(_lst[itm], _lst[itm1], _lst[itm2], _lst[itm3], _lst[itm4], _lst[itm5], _lst[itm6], _lst[itm7], _lst[itm8], _lst[itm9]);
}
bool operator==(const gcl_list10<t, t1, t2, t3, t4, t5, t6, t7, t8, t9>& lst)
{
return (itm == lst.itm) && (itm1 == lst.itm1) && (itm2 == lst.itm2) && (itm3 == lst.itm3) && (itm4 == lst.itm4) && (itm5 == lst.itm5) && (itm6 == lst.itm6) && (itm7 == lst.itm7) && (itm8 == lst.itm8) && (itm9 == lst.itm9);
}
private:
t itm;
t1 itm1;
t2 itm2;
t3 itm3;
t4 itm4;
t5 itm5;
t6 itm6;
t7 itm7;
t8 itm8;
t9 itm9;
};
template <typename... args>
struct gcl_func
{
private:
struct bind_base
{
public:
virtual ~bind_base() {}
virtual void call(const args&... _args) = 0;
virtual bool operator==(bind_base* b) = 0;
};
template <typename func, typename lst>
struct gcl_binder :
public bind_base
{
public:
gcl_binder(func _fn, const lst& _lst) : fn(_fn), _list(move(_lst)) {}
void operator()()
{
_list(fn);
}
template <typename a0>
void operator()(const a0& _a0)
{
gcl_list1<a0> lst(_a0);
_list(fn, lst);
}
template <typename a0, typename a1>
void operator()(const a0& _a0, const a1& _a1)
{
gcl_list2<a0, a1> lst(_a0, _a1);
_list(fn, lst);
}
template <typename a0, typename a1, typename a2>
void operator()(const a0& _a0, const a1& _a1, const a2& _a2)
{
gcl_list3<a0, a1, a2> lst(_a0, _a1, _a2);
_list(fn, lst);
}
template <typename a0, typename a1, typename a2, typename a3>
void operator()(const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3)
{
gcl_list4<a0, a1, a2, a3> lst(_a0, _a1, _a2, _a3);
_list(fn, lst);
}
template <typename a0, typename a1, typename a2, typename a3, typename a4>
void operator()(const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4)
{
gcl_list5<a0, a1, a2, a3, a4> lst(_a0, _a1, _a2, _a3, _a4);
_list(fn, lst);
}
template <typename a0, typename a1, typename a2, typename a3, typename a4, typename a5>
void operator()(const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5)
{
gcl_list6<a0, a1, a2, a3, a4, a5> lst(_a0, _a1, _a2, _a3, _a4, _a5);
_list(fn, lst);
}
template <typename a0, typename a1, typename a2, typename a3, typename a4, typename a5, typename a6>
void operator()(const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5, const a6& _a6)
{
gcl_list7<a0, a1, a2, a3, a4, a5, a6> lst(_a0, _a1, _a2, _a3, _a4, _a5, _a6);
_list(fn, lst);
}
template <typename a0, typename a1, typename a2, typename a3, typename a4, typename a5, typename a6, typename a7>
void operator()(const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5, const a6& _a6, const a7& _a7)
{
gcl_list8<a0, a1, a2, a3, a4, a5, a6, a7> lst(_a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7);
_list(fn, lst);
}
template <typename a0, typename a1, typename a2, typename a3, typename a4, typename a5, typename a6, typename a7, typename a8>
void operator()(const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5, const a6& _a6, const a7& _a7, const a8& _a8)
{
gcl_list9<a0, a1, a2, a3, a4, a5, a6, a7, a8> lst(_a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7, _a8);
_list(fn, lst);
}
template <typename a0, typename a1, typename a2, typename a3, typename a4, typename a5, typename a6, typename a7, typename a8, typename a9>
void operator()(const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5, const a6& _a6, const a7& _a7, const a8& _a8, const a9& _a9)
{
gcl_list10<a0, a1, a2, a3, a4, a5, a6, a7, a8, a9> lst(_a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7, _a8, _a9);
_list(fn, lst);
}
bool operator==(bind_base* b)
{
auto ptr = dynamic_cast<gcl_binder<func, lst>*>(b);
if(!ptr)
return false;
return (fn == ptr->fn) && (_list == ptr->_list);
}
protected:
virtual void call(const args&... _args)
{
(*this)(_args...);
}
private:
func fn;
lst _list;
};
template <typename func, typename cl>
struct mem_func_ref :
public bind_base
{
public:
mem_func_ref(cl* _inst, func _fn) : inst(_inst), fn(_fn) {}
virtual void call(const args&... _args)
{
(*this)(_args...);
}
template <typename... args2>
void operator()(const args2&... _a0)
{
(inst->*fn)(_a0...);
}
bool operator==(bind_base* b)
{
auto ptr = dynamic_cast<mem_func_ref<func, cl>*>(b);
if(!ptr)
return false;
return (inst == ptr->inst) && (fn == ptr->fn);
}
private:
cl* inst;
func fn;
};
template <typename func>
struct func_ref :
public bind_base
{
public:
func_ref(func _fn) : fn(_fn) {}
virtual void call(const args&... _args)
{
(*this)(_args...);
}
template <typename... args2>
void operator()(const args2&... _a0)
{
fn(_a0...);
}
bool operator==(bind_base* b)
{
auto ptr = dynamic_cast<func_ref<func>*>(b);
if(!ptr)
return false;
return (fn == ptr->fn);
}
private:
func fn;
};
public:
template <typename func, typename lst>
explicit gcl_func(func fn, const lst& _lst)
{
cl_b = shared_ptr<bind_base>(new gcl_binder<func, lst>(fn, _lst));
}
template <typename func, typename cl>
explicit gcl_func(func fn, cl* inst)
{
cl_b = shared_ptr<bind_base>(new mem_func_ref<func, cl>(inst, fn));
}
template <typename func>
explicit gcl_func(func fn)
{
cl_b = shared_ptr<bind_base>(new func_ref<func>(fn));
}
void operator()(const args&... _args)
{
cl_b->call(_args...);
}
bool operator==(const gcl_func& fn)
{
return cl_b.get()->operator==(fn.cl_b.get());
}
private:
shared_ptr<bind_base> cl_b;
};
template <typename... args, typename func, typename a0>
gcl_func<args...> gcl_bind(func fn, const a0& _a0)
{
gcl_list1<a0> lst(_a0);
return gcl_func<args...>(fn, lst);
}
template <typename... args, typename ret, typename... args_fun, typename cl, typename a0>
gcl_func<args...> gcl_bind_mem(cl* inst, ret(cl::*fn)(args_fun...), const a0& _a0)
{
gcl_list1<a0> lst(_a0);
return gcl_func<args...>(gcl::make_func_ptr(inst, fn), lst);
}
template <typename... args, typename func, typename a0, typename a1>
gcl_func<args...> gcl_bind(func fn, const a0& _a0, const a1& _a1)
{
gcl_list2<a0, a1> lst(_a0, _a1);
return gcl_func<args...>(fn, lst);
}
template <typename... args, typename ret, typename... args_fun, typename cl, typename a0, typename a1>
gcl_func<args...> gcl_bind_mem(cl* inst, ret(cl::*fn)(args_fun...), const a0& _a0, const a1& _a1)
{
gcl_list2<a0, a1> lst(_a0, _a1);
return gcl_func<args...>(gcl::make_func_ptr(inst, fn), lst);
}
template <typename... args, typename func, typename a0, typename a1, typename a2>
gcl_func<args...> gcl_bind(func fn, const a0& _a0, const a1& _a1, const a2& _a2)
{
gcl_list3<a0, a1, a2> lst(_a0, _a1, _a2);
return gcl_func<args...>(fn, lst);
}
template <typename... args, typename ret, typename... args_fun, typename cl, typename a0, typename a1, typename a2>
gcl_func<args...> gcl_bind_mem(cl* inst, ret(cl::*fn)(args_fun...), const a0& _a0, const a1& _a1, const a2& _a2)
{
gcl_list3<a0, a1, a2> lst(_a0, _a1, _a2);
return gcl_func<args...>(gcl::make_func_ptr(inst, fn), lst);
}
template <typename... args, typename func, typename a0, typename a1, typename a2, typename a3>
gcl_func<args...> gcl_bind(func fn, const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3)
{
gcl_list4<a0, a1, a2, a3> lst(_a0, _a1, _a2, _a3);
return gcl_func<args...>(fn, lst);
}
template <typename... args, typename ret, typename... args_fun, typename cl, typename a0, typename a1, typename a2, typename a3>
gcl_func<args...> gcl_bind_mem(cl* inst, ret(cl::*fn)(args_fun...), const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3)
{
gcl_list4<a0, a1, a2, a3> lst(_a0, _a1, _a2, _a3);
return gcl_func<args...>(gcl::make_func_ptr(inst, fn), lst);
}
template <typename... args, typename func, typename a0, typename a1, typename a2, typename a3, typename a4>
gcl_func<args...> gcl_bind(func fn, const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4)
{
gcl_list5<a0, a1, a2, a3, a4> lst(_a0, _a1, _a2, _a3, _a4);
return gcl_func<args...>(fn, lst);
}
template <typename... args, typename ret, typename... args_fun, typename cl, typename a0, typename a1, typename a2, typename a3, typename a4>
gcl_func<args...> gcl_bind_mem(cl* inst, ret(cl::*fn)(args_fun...), const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4)
{
gcl_list5<a0, a1, a2, a3, a4> lst(_a0, _a1, _a2, _a3, _a4);
return gcl_func<args...>(gcl::make_func_ptr(inst, fn), lst);
}
template <typename... args, typename func, typename a0, typename a1, typename a2, typename a3, typename a4, typename a5>
gcl_func<args...> gcl_bind(func fn, const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5)
{
gcl_list6<a0, a1, a2, a3, a4, a5> lst(_a0, _a1, _a2, _a3, _a4, _a5);
return gcl_func<args...>(fn, lst);
}
template <typename... args, typename ret, typename... args_fun, typename cl, typename a0, typename a1, typename a2, typename a3, typename a4, typename a5>
gcl_func<args...> gcl_bind_mem(cl* inst, ret(cl::*fn)(args_fun...), const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5)
{
gcl_list6<a0, a1, a2, a3, a4, a5> lst(_a0, _a1, _a2, _a3, _a4, _a5);
return gcl_func<args...>(gcl::make_func_ptr(inst, fn), lst);
}
template <typename... args, typename func, typename a0, typename a1, typename a2, typename a3, typename a4, typename a5, typename a6>
gcl_func<args...> gcl_bind(func fn, const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5, const a6& _a6)
{
gcl_list7<a0, a1, a2, a3, a4, a5, a6> lst(_a0, _a1, _a2, _a3, _a4, _a5, _a6);
return gcl_func<args...>(fn, lst);
}
template <typename... args, typename ret, typename... args_fun, typename cl, typename a0, typename a1, typename a2, typename a3, typename a4, typename a5, typename a6>
gcl_func<args...> gcl_bind_mem(cl* inst, ret(cl::*fn)(args_fun...), const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5, const a6& _a6)
{
gcl_list7<a0, a1, a2, a3, a4, a5, a6> lst(_a0, _a1, _a2, _a3, _a4, _a5, _a6);
return gcl_func<args...>(gcl::make_func_ptr(inst, fn), lst);
}
template <typename... args, typename func, typename a0, typename a1, typename a2, typename a3, typename a4, typename a5, typename a6, typename a7>
gcl_func<args...> gcl_bind(func fn, const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5, const a6& _a6, const a7& _a7)
{
gcl_list8<a0, a1, a2, a3, a4, a5, a6, a7> lst(_a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7);
return gcl_func<args...>(fn, lst);
}
template <typename... args, typename ret, typename... args_fun, typename cl, typename a0, typename a1, typename a2, typename a3, typename a4, typename a5, typename a6, typename a7>
gcl_func<args...> gcl_bind_mem(cl* inst, ret(cl::*fn)(args_fun...), const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5, const a6& _a6, const a7& _a7)
{
gcl_list8<a0, a1, a2, a3, a4, a5, a6, a7> lst(_a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7);
return gcl_func<args...>(gcl::make_func_ptr(inst, fn), lst);
}
template <typename... args, typename func, typename a0, typename a1, typename a2, typename a3, typename a4, typename a5, typename a6, typename a7, typename a8>
gcl_func<args...> gcl_bind(func fn, const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5, const a6& _a6, const a7& _a7, const a8& _a8)
{
gcl_list9<a0, a1, a2, a3, a4, a5, a6, a7, a8> lst(_a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7, _a8);
return gcl_func<args...>(fn, lst);
}
template <typename... args, typename ret, typename... args_fun, typename cl, typename a0, typename a1, typename a2, typename a3, typename a4, typename a5, typename a6, typename a7, typename a8>
gcl_func<args...> gcl_bind_mem(cl* inst, ret(cl::*fn)(args_fun...), const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5, const a6& _a6, const a7& _a7, const a8& _a8)
{
gcl_list9<a0, a1, a2, a3, a4, a5, a6, a7, a8> lst(_a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7, _a8);
return gcl_func<args...>(gcl::make_func_ptr(inst, fn), lst);
}
template <typename... args, typename func, typename a0, typename a1, typename a2, typename a3, typename a4, typename a5, typename a6, typename a7, typename a8, typename a9>
gcl_func<args...> gcl_bind(func fn, const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5, const a6& _a6, const a7& _a7, const a8& _a8, const a9& _a9)
{
gcl_list10<a0, a1, a2, a3, a4, a5, a6, a7, a8, a9> lst(_a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7, _a8, _a9);
return gcl_func<args...>(fn, lst);
}
template <typename... args, typename ret, typename... args_fun, typename cl, typename a0, typename a1, typename a2, typename a3, typename a4, typename a5, typename a6, typename a7, typename a8, typename a9>
gcl_func<args...> gcl_bind_mem(cl* inst, ret(cl::*fn)(args_fun...), const a0& _a0, const a1& _a1, const a2& _a2, const a3& _a3, const a4& _a4, const a5& _a5, const a6& _a6, const a7& _a7, const a8& _a8, const a9& _a9)
{
gcl_list10<a0, a1, a2, a3, a4, a5, a6, a7, a8, a9> lst(_a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7, _a8, _a9);
return gcl_func<args...>(gcl::make_func_ptr(inst, fn), lst);
}
// Creates a storage for non static Memberfunctions
template <typename _class, typename ret, typename... _args>
const gcl_func<_args...>
make_func_ptr(_class* class_ptr, ret(_class::*func)(_args...)) {return gcl_func<_args...>(func, class_ptr);}
template <typename T>
class callback;
template <typename _ret_type, typename... _args>
class callback<_ret_type(_args...)>
{
typedef typename _ret_type return_type;
typedef return_type (*func_ptr) (_args...);
typedef typename callback<_ret_type(_args...)> type;
static const int arg_count = sizeof...(_args);
public:
// Adds a delegate to the callback
void operator+= (const gcl_func<_args...>& fn)
{
prv_coll.push_back(fn);
}
// Adds a delegate to the callback
void operator+= (func_ptr ptr)
{
prv_coll.push_back(gcl_func<_args...>(ptr));
}
// Removes a delegate to the callback
void operator-= (func_ptr ptr)
{
prv_coll.erase(std::remove(prv_coll.begin(), prv_coll.end(), gcl_func<_args...>(ptr)));
}
// Removes a delegate to the callback
void operator-= (const gcl_func<_args...>& fn)
{
prv_coll.erase(std::remove(prv_coll.begin(), prv_coll.end(), fn));
}
// Removes a delegate to the callback
void operator-= (unsigned idx)
{
prv_coll.erase(prv_coll.begin()+idx);
}
// Calls all bound delegates
void operator() (const _args&... args)
{
for(auto& itr = prv_coll.begin(); itr != prv_coll.end(); ++itr)
(*itr)(args...);
}
// Releases all bound delegates
void release_hooks() {prv_coll.clear()}
unsigned size() const {return prv_coll.size();}
private:
vector<gcl_func<_args...>> prv_coll;
};
};
#endif