yasmine
behavior_caller.hpp
Go to the documentation of this file.
1 // //
3 // This file is part of the Seadex yasmine ecosystem (http://yasmine.seadex.de). //
4 // Copyright (C) 2016-2017 Seadex GmbH //
5 // //
6 // Licensing information is available in the folder "license" which is part of this distribution. //
7 // The same information is available on the www @ http://yasmine.seadex.de/Licenses.html. //
8 // //
10 
11 
12 #ifndef BEHAVIOR_CALLER_B33A4070_B042_4171_8DC5_9E5AE0B2DDD5
13 #define BEHAVIOR_CALLER_B33A4070_B042_4171_8DC5_9E5AE0B2DDD5
14 
15 
16 #include "essentials/base.hpp"
17 #include "essentials/exception.hpp"
18 
19 #include "event.hpp"
20 #include "adapter.hpp"
21 #include "caller_helper.hpp"
22 #include "event_adjuster.hpp"
23 #include "event_collector.hpp"
24 
25 
26 namespace sxy
27 {
28 
29 
30 void behavior_caller( const sxy::event& _event, sxy::event_collector& _event_collector,
31  const sxe::function<void()>& _function );
32 
33 
34 void behavior_caller( const sxy::event& _event, sxy::event_collector& _event_collector,
35  const sxe::function<void( event_collector& )>& _function );
36 
37 
38 template< typename _event_type >
39 void behavior_caller( const sxy::event& _event, sxy::event_collector& _event_collector,
40  const sxe::function<void( const _event_type& )>& _function )
41 {
42  SX_UNUSED_PARAMETER( _event_collector );
43 
44 #if defined( SX_CPP03_BOOST ) || ( defined(_MSC_VER) && _MSC_VER <=1800 )
45 
46 
47  const _event_type* specialized_event = dynamic_cast< const _event_type* >( &_event );
48  if( specialized_event )
49  {
50  _function( *specialized_event );
51  }
52  else
53  {
54  throw sxe::exception( "Invalid event type!" );
55  }
56 
57 
58 #else
59 
60 
61  auto& specialized_event = sxy::adjust_event_type< _event_type >( _event );
62  _function( specialized_event );
63 
64 
65 #endif
66 }
67 
68 
69 template< typename _event_type >
70 void behavior_caller( const sxy::event& _event, sxy::event_collector& _event_collector,
71  const sxe::function<void( const _event_type&, sxy::event_collector& _event_collector )>& _function )
72 {
73 #if defined( SX_CPP03_BOOST ) || ( defined(_MSC_VER) && _MSC_VER <=1800 )
74 
75 
76  const _event_type* specialized_event = dynamic_cast< const _event_type* >( &_event );
77  if( specialized_event )
78  {
79  _function( *specialized_event, _event_collector );
80  }
81  else
82  {
83  throw sxe::exception( "Invalid event type!" );
84  }
85 
86 
87 #else
88 
89 
90  auto& specialized_event = sxy::adjust_event_type< _event_type >( _event );
91  _function( specialized_event, _event_collector );
92 
93 
94 #endif
95 }
96 
97 
98 template< typename _event_type1, typename _event_type2 >
99 void behavior_caller( const sxy::event& _event, sxy::event_collector& _event_collector,
100  const sxe::function<void( const _event_type1&, sxy::event_collector& )>& _function1,
101  const sxe::function<void( const _event_type2&, sxy::event_collector& )>& _function2 )
102 {
103 
104 #if defined( SX_CPP03_BOOST ) || ( defined(_MSC_VER) && _MSC_VER <=1800 )
105 
106 
107  const _event_type1* specialized_event = dynamic_cast< const _event_type1* >( &_event );
108  if( specialized_event )
109  {
110  _function1( *specialized_event, _event_collector );
111  }
112  else
113  {
114  const _event_type2* specialized_event2 = dynamic_cast< const _event_type2* >( &_event );
115  if( specialized_event2 )
116  {
117  _function2( *specialized_event2, _event_collector );
118  }
119  else
120  {
121  throw sxe::exception( "Invalid event type!" );
122  }
123  }
124 
125 
126 #else
127 
128 
130  "Event type 1 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
132  "Event type 2 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
133 
134  switch( _event.get_id() )
135  {
136  case _event_type1::get_event_id():
137  {
138  auto& specialized_event = sxy::adjust_event_type< _event_type1 >( _event );
139  _function1( specialized_event, _event_collector );
140  break;
141  }
142 
143  case _event_type2::get_event_id():
144  {
145  const auto& specialized_event = sxy::adjust_event_type< _event_type2 >( _event );
146  _function2( specialized_event, _event_collector );
147  break;
148  }
149 
150  default:
151  SX_ASSERT( false, "Invalid event type!" );
152  }
153 
154 
155 #endif
156 }
157 
158 
159 template< typename _event_type1, typename _event_type2, typename _event_type3 >
160 void behavior_caller( const sxy::event& _event, sxy::event_collector& _event_collector,
161  const sxe::function<void( const _event_type1&, sxy::event_collector& )>& _function1,
162  const sxe::function<void( const _event_type2&, sxy::event_collector& )>& _function2,
163  const sxe::function<void( const _event_type3&, sxy::event_collector& )>& _function3 )
164 {
165 #if defined( SX_CPP03_BOOST ) || ( defined(_MSC_VER) && _MSC_VER <=1800 )
166 
167 
168  const _event_type1* specialized_event = dynamic_cast< const _event_type1* >( &_event );
169  if( specialized_event )
170  {
171  _function1( *specialized_event, _event_collector );
172  }
173  else
174  {
175  const _event_type2* specialized_event2 = dynamic_cast< const _event_type2* >( &_event );
176  if( specialized_event2 )
177  {
178  _function2( *specialized_event2, _event_collector );
179  }
180  else
181  {
182  const _event_type3* specialized_event3 = dynamic_cast< const _event_type3* >( &_event );
183  if( specialized_event3 )
184  {
185  _function3( *specialized_event3, _event_collector );
186  }
187  else
188  {
189  throw sxe::exception( "Invalid event type!" );
190  }
191  }
192  }
193 
194 
195 #else
196 
197 
199  "Event type 1 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
201  "Event type 2 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
203  "Event type 3 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
204 
205  switch( _event.get_id() )
206  {
207  case _event_type1::get_event_id():
208  {
209  auto& specialized_event = sxy::adjust_event_type< _event_type1 >( _event );
210  _function1( specialized_event, _event_collector );
211  break;
212  }
213 
214  case _event_type2::get_event_id():
215  {
216  auto& specialized_event = sxy::adjust_event_type< _event_type2 >( _event );
217  _function2( specialized_event, _event_collector );
218  break;
219  }
220 
221  case _event_type3::get_event_id():
222  {
223  auto& specialized_event = sxy::adjust_event_type< _event_type3 >( _event );
224  _function3( specialized_event, _event_collector );
225  break;
226  }
227 
228  default:
229  SX_ASSERT( false, "Invalid event type!" );
230  }
231 
232 
233 #endif
234 }
235 
236 
237 template< typename _event_type1, typename _event_type2, typename _event_type3, typename _event_type4 >
238 void behavior_caller( const sxy::event& _event, sxy::event_collector& _event_collector,
239  const sxe::function<void( const _event_type1&, sxy::event_collector& )>& _function1,
240  const sxe::function<void( const _event_type2&, sxy::event_collector& )>& _function2,
241  const sxe::function<void( const _event_type3&, sxy::event_collector& )>& _function3,
242  const sxe::function<void( const _event_type4&, sxy::event_collector& )>& _function4 )
243 {
244 #if defined( SX_CPP03_BOOST ) || ( defined(_MSC_VER) && _MSC_VER <=1800 )
245 
246 
247  const _event_type1* specialized_event = dynamic_cast< const _event_type1* >( &_event );
248  if( specialized_event )
249  {
250  _function1( *specialized_event, _event_collector );
251  }
252  else
253  {
254  const _event_type2* specialized_event2 = dynamic_cast< const _event_type2* >( &_event );
255  if( specialized_event2 )
256  {
257  _function2( *specialized_event2, _event_collector );
258  }
259  else
260  {
261  const _event_type3* specialized_event3 = dynamic_cast< const _event_type3* >( &_event );
262  if( specialized_event3 )
263  {
264  _function3( *specialized_event3, _event_collector );
265  }
266  else
267  {
268  const _event_type4* specialized_event4 = dynamic_cast< const _event_type4* >( &_event );
269  if( specialized_event4 )
270  {
271  _function4( *specialized_event4, _event_collector );
272  }
273  else
274  {
275  throw sxe::exception( "Invalid event type!" );
276  }
277  }
278  }
279  }
280 
281 
282 #else
283 
284 
286  "Event type 1 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
288  "Event type 2 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
290  "Event type 3 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
292  "Event type 4 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
293 
294  switch( _event.get_id() )
295  {
296  case _event_type1::get_event_id():
297  {
298  auto& specialized_event = sxy::adjust_event_type< _event_type1 >( _event );
299  _function1( specialized_event, _event_collector );
300  break;
301  }
302 
303  case _event_type2::get_event_id():
304  {
305  auto& specialized_event = sxy::adjust_event_type< _event_type2 >( _event );
306  _function2( specialized_event, _event_collector );
307  break;
308  }
309 
310  case _event_type3::get_event_id():
311  {
312  auto& specialized_event = sxy::adjust_event_type< _event_type3 >( _event );
313  _function3( specialized_event, _event_collector );
314  break;
315  }
316 
317  case _event_type4::get_event_id():
318  {
319  auto& specialized_event = sxy::adjust_event_type< _event_type4 >( _event );
320  _function4( specialized_event, _event_collector );
321  break;
322  }
323 
324  default:
325  SX_ASSERT( false, "Invalid event type!" );
326  }
327 
328 
329 #endif
330 }
331 
332 
333 template< typename _event_type1, typename _event_type2, typename _event_type3, typename _event_type4,
334  typename _event_type5 >
335 void behavior_caller( const sxy::event& _event, sxy::event_collector& _event_collector,
336  const sxe::function<void( const _event_type1&, sxy::event_collector& )>& _function1,
337  const sxe::function<void( const _event_type2&, sxy::event_collector& )>& _function2,
338  const sxe::function<void( const _event_type3&, sxy::event_collector& )>& _function3,
339  const sxe::function<void( const _event_type4&, sxy::event_collector& )>& _function4,
340  const sxe::function<void( const _event_type5&, sxy::event_collector& )>& _function5 )
341 {
342 #if defined( SX_CPP03_BOOST ) || ( defined(_MSC_VER) && _MSC_VER <=1800 )
343 
344 
345  const _event_type1* specialized_event = dynamic_cast< const _event_type1* >( &_event );
346  if( specialized_event )
347  {
348  _function1( *specialized_event, _event_collector );
349  }
350  else
351  {
352  const _event_type2* specialized_event2 = dynamic_cast< const _event_type2* >( &_event );
353  if( specialized_event2 )
354  {
355  _function2( *specialized_event2, _event_collector );
356  }
357  else
358  {
359  const _event_type3* specialized_event3 = dynamic_cast< const _event_type3* >( &_event );
360  if( specialized_event3 )
361  {
362  _function3( *specialized_event3, _event_collector );
363  }
364  else
365  {
366  const _event_type4* specialized_event4 = dynamic_cast< const _event_type4* >( &_event );
367  if( specialized_event4 )
368  {
369  _function4( *specialized_event4, _event_collector );
370  }
371  else
372  {
373  const _event_type5* specialized_event5 = dynamic_cast< const _event_type5* >( &_event );
374  if( specialized_event5 )
375  {
376  _function5( *specialized_event5, _event_collector );
377  }
378  else
379  {
380  throw sxe::exception( "Invalid event type!" );
381  }
382  }
383  }
384  }
385  }
386 
387 
388 #else
389 
390 
392  "Event type 1 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
394  "Event type 2 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
396  "Event type 3 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
398  "Event type 4 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
400  "Event type 5 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
401 
402  switch( _event.get_id() )
403  {
404  case _event_type1::get_event_id():
405  {
406  auto& specialized_event = sxy::adjust_event_type< _event_type1 >( _event );
407  _function1( specialized_event, _event_collector );
408  break;
409  }
410 
411  case _event_type2::get_event_id():
412  {
413  auto& specialized_event = sxy::adjust_event_type< _event_type2 >( _event );
414  _function2( specialized_event, _event_collector );
415  break;
416  }
417 
418  case _event_type3::get_event_id():
419  {
420  auto& specialized_event = sxy::adjust_event_type< _event_type3 >( _event );
421  _function3( specialized_event, _event_collector );
422  break;
423  }
424 
425  case _event_type4::get_event_id():
426  {
427  auto& specialized_event = sxy::adjust_event_type< _event_type4 >( _event );
428  _function4( specialized_event, _event_collector );
429  break;
430  }
431 
432  case _event_type5::get_event_id():
433  {
434  auto& specialized_event = sxy::adjust_event_type< _event_type5 >( _event );
435  _function5( specialized_event, _event_collector );
436  break;
437  }
438 
439  default:
440  SX_ASSERT( false, "Invalid event type!" );
441  }
442 
443 
444 #endif
445 }
446 
447 
448 template< typename _event_type1, typename _event_type2, typename _event_type3, typename _event_type4,
449  typename _event_type5, typename _event_type6 >
450  void behavior_caller( const sxy::event& _event, sxy::event_collector& _event_collector,
451  const sxe::function<void( const _event_type1&, sxy::event_collector& )>& _function1,
452  const sxe::function<void( const _event_type2&, sxy::event_collector& )>& _function2,
453  const sxe::function<void( const _event_type3&, sxy::event_collector& )>& _function3,
454  const sxe::function<void( const _event_type4&, sxy::event_collector& )>& _function4,
455  const sxe::function<void( const _event_type5&, sxy::event_collector& )>& _function5,
456  const sxe::function<void( const _event_type6&, sxy::event_collector& )>& _function6 )
457 {
458 #if defined( SX_CPP03_BOOST ) || ( defined(_MSC_VER) && _MSC_VER <=1800 )
459 
460 
461  const _event_type1* specialized_event = dynamic_cast< const _event_type1* >( &_event );
462  if( specialized_event )
463  {
464  _function1( *specialized_event, _event_collector );
465  }
466  else
467  {
468  const _event_type2* specialized_event2 = dynamic_cast< const _event_type2* >( &_event );
469  if( specialized_event2 )
470  {
471  _function2( *specialized_event2, _event_collector );
472  }
473  else
474  {
475  const _event_type3* specialized_event3 = dynamic_cast< const _event_type3* >( &_event );
476  if( specialized_event3 )
477  {
478  _function3( *specialized_event3, _event_collector );
479  }
480  else
481  {
482  const _event_type4* specialized_event4 = dynamic_cast< const _event_type4* >( &_event );
483  if( specialized_event4 )
484  {
485  _function4( *specialized_event4, _event_collector );
486  }
487  else
488  {
489  const _event_type5* specialized_event5 = dynamic_cast< const _event_type5* >( &_event );
490  if( specialized_event5 )
491  {
492  _function5( *specialized_event5, _event_collector );
493  }
494  else
495  {
496  const _event_type6* specialized_event6 = dynamic_cast< const _event_type6* >( &_event );
497  if( specialized_event6 )
498  {
499  _function6( *specialized_event6, _event_collector );
500  }
501  else
502  {
503  throw sxe::exception( "Invalid event type!" );
504  }
505  }
506  }
507  }
508  }
509  }
510 
511 
512 #else
513 
514 
516  "Event type 1 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
518  "Event type 2 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
520  "Event type 3 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
522  "Event type 4 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
524  "Event type 5 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
526  "Event type 6 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
527 
528  switch( _event.get_id() )
529  {
530  case _event_type1::get_event_id():
531  {
532  auto& specialized_event = sxy::adjust_event_type< _event_type1 >( _event );
533  _function1( specialized_event, _event_collector );
534  break;
535  }
536 
537  case _event_type2::get_event_id():
538  {
539  auto& specialized_event = sxy::adjust_event_type< _event_type2 >( _event );
540  _function2( specialized_event, _event_collector );
541  break;
542  }
543 
544  case _event_type3::get_event_id():
545  {
546  auto& specialized_event = sxy::adjust_event_type< _event_type3 >( _event );
547  _function3( specialized_event, _event_collector );
548  break;
549  }
550 
551  case _event_type4::get_event_id():
552  {
553  auto& specialized_event = sxy::adjust_event_type< _event_type4 >( _event );
554  _function4( specialized_event, _event_collector );
555  break;
556  }
557 
558  case _event_type5::get_event_id():
559  {
560  auto& specialized_event = sxy::adjust_event_type< _event_type5 >( _event );
561  _function5( specialized_event, _event_collector );
562  break;
563  }
564 
565  case _event_type6::get_event_id():
566  {
567  auto& specialized_event = sxy::adjust_event_type< _event_type6 >( _event );
568  _function6( specialized_event, _event_collector );
569  break;
570  }
571 
572  default:
573  SX_ASSERT( false, "Invalid event type!" );
574  }
575 
576 
577 #endif
578 }
579 
580 
581 template< typename _event_type1, typename _event_type2, typename _event_type3, typename _event_type4,
582  typename _event_type5, typename _event_type6, typename _event_type7 >
583  void behavior_caller( const sxy::event& _event, sxy::event_collector& _event_collector,
584  const sxe::function<void( const _event_type1&, sxy::event_collector& )>& _function1,
585  const sxe::function<void( const _event_type2&, sxy::event_collector& )>& _function2,
586  const sxe::function<void( const _event_type3&, sxy::event_collector& )>& _function3,
587  const sxe::function<void( const _event_type4&, sxy::event_collector& )>& _function4,
588  const sxe::function<void( const _event_type5&, sxy::event_collector& )>& _function5,
589  const sxe::function<void( const _event_type6&, sxy::event_collector& )>& _function6,
590  const sxe::function<void( const _event_type7&, sxy::event_collector& )>& _function7 )
591 {
592 #if defined( SX_CPP03_BOOST ) || ( defined(_MSC_VER) && _MSC_VER <=1800 )
593 
594 
595  const _event_type1* specialized_event = dynamic_cast< const _event_type1* >( &_event );
596  if( specialized_event )
597  {
598  _function1( *specialized_event, _event_collector );
599  }
600  else
601  {
602  const _event_type2* specialized_event2 = dynamic_cast< const _event_type2* >( &_event );
603  if( specialized_event2 )
604  {
605  _function2( *specialized_event2, _event_collector );
606  }
607  else
608  {
609  const _event_type3* specialized_event3 = dynamic_cast< const _event_type3* >( &_event );
610  if( specialized_event3 )
611  {
612  _function3( *specialized_event3, _event_collector );
613  }
614  else
615  {
616  const _event_type4* specialized_event4 = dynamic_cast< const _event_type4* >( &_event );
617  if( specialized_event4 )
618  {
619  _function4( *specialized_event4, _event_collector );
620  }
621  else
622  {
623  const _event_type5* specialized_event5 = dynamic_cast< const _event_type5* >( &_event );
624  if( specialized_event5 )
625  {
626  _function5( *specialized_event5, _event_collector );
627  }
628  else
629  {
630  const _event_type6* specialized_event6 = dynamic_cast< const _event_type6* >( &_event );
631  if( specialized_event6 )
632  {
633  _function6( *specialized_event6, _event_collector );
634  }
635  else
636  {
637  const _event_type7* specialized_event7 = dynamic_cast< const _event_type7* >( &_event );
638  if( specialized_event7 )
639  {
640  _function7( *specialized_event7, _event_collector );
641  }
642  else
643  {
644  throw sxe::exception( "Invalid event type!" );
645  }
646  }
647  }
648  }
649  }
650  }
651  }
652 
653 
654 #else
655 
656 
658  "Event type 1 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
660  "Event type 2 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
662  "Event type 3 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
664  "Event type 4 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
666  "Event type 5 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
668  "Event type 6 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
670  "Event type 7 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
671 
672  switch( _event.get_id() )
673  {
674  case _event_type1::get_event_id():
675  {
676  auto& specialized_event = sxy::adjust_event_type< _event_type1 >( _event );
677  _function1( specialized_event, _event_collector );
678  break;
679  }
680 
681  case _event_type2::get_event_id():
682  {
683  auto& specialized_event = sxy::adjust_event_type< _event_type2 >( _event );
684  _function2( specialized_event, _event_collector );
685  break;
686  }
687 
688  case _event_type3::get_event_id():
689  {
690  auto& specialized_event = sxy::adjust_event_type< _event_type3 >( _event );
691  _function3( specialized_event, _event_collector );
692  break;
693  }
694 
695  case _event_type4::get_event_id():
696  {
697  auto& specialized_event = sxy::adjust_event_type< _event_type4 >( _event );
698  _function4( specialized_event, _event_collector );
699  break;
700  }
701 
702  case _event_type5::get_event_id():
703  {
704  auto& specialized_event = sxy::adjust_event_type< _event_type5 >( _event );
705  _function5( specialized_event, _event_collector );
706  break;
707  }
708 
709  case _event_type6::get_event_id():
710  {
711  auto& specialized_event = sxy::adjust_event_type< _event_type6 >( _event );
712  _function6( specialized_event, _event_collector );
713  break;
714  }
715 
716  case _event_type7::get_event_id():
717  {
718  auto& specialized_event = sxy::adjust_event_type< _event_type7 >( _event );
719  _function7( specialized_event, _event_collector );
720  break;
721  }
722 
723  default:
724  SX_ASSERT( false, "Invalid event type!" );
725  }
726 
727 
728 #endif
729 }
730 
731 
732 template< typename _event_type1, typename _event_type2, typename _event_type3, typename _event_type4,
733  typename _event_type5, typename _event_type6, typename _event_type7, typename _event_type8 >
734  void behavior_caller( const sxy::event& _event, sxy::event_collector& _event_collector,
735  const sxe::function<void( const _event_type1&, sxy::event_collector& )>& _function1,
736  const sxe::function<void( const _event_type2&, sxy::event_collector& )>& _function2,
737  const sxe::function<void( const _event_type3&, sxy::event_collector& )>& _function3,
738  const sxe::function<void( const _event_type4&, sxy::event_collector& )>& _function4,
739  const sxe::function<void( const _event_type5&, sxy::event_collector& )>& _function5,
740  const sxe::function<void( const _event_type6&, sxy::event_collector& )>& _function6,
741  const sxe::function<void( const _event_type7&, sxy::event_collector& )>& _function7,
742  const sxe::function<void( const _event_type8&, sxy::event_collector& )>& _function8 )
743 {
744 #if defined( SX_CPP03_BOOST ) || ( defined(_MSC_VER) && _MSC_VER <=1800 )
745 
746 
747  const _event_type1* specialized_event = dynamic_cast< const _event_type1* >( &_event );
748  if( specialized_event )
749  {
750  _function1( *specialized_event, _event_collector );
751  }
752  else
753  {
754  const _event_type2* specialized_event2 = dynamic_cast< const _event_type2* >( &_event );
755  if( specialized_event2 )
756  {
757  _function2( *specialized_event2, _event_collector );
758  }
759  else
760  {
761  const _event_type3* specialized_event3 = dynamic_cast< const _event_type3* >( &_event );
762  if( specialized_event3 )
763  {
764  _function3( *specialized_event3, _event_collector );
765  }
766  else
767  {
768  const _event_type4* specialized_event4 = dynamic_cast< const _event_type4* >( &_event );
769  if( specialized_event4 )
770  {
771  _function4( *specialized_event4, _event_collector );
772  }
773  else
774  {
775  const _event_type5* specialized_event5 = dynamic_cast< const _event_type5* >( &_event );
776  if( specialized_event5 )
777  {
778  _function5( *specialized_event5, _event_collector );
779  }
780  else
781  {
782  const _event_type6* specialized_event6 = dynamic_cast< const _event_type6* >( &_event );
783  if( specialized_event6 )
784  {
785  _function6( *specialized_event6, _event_collector );
786  }
787  else
788  {
789  const _event_type7* specialized_event7 = dynamic_cast< const _event_type7* >( &_event );
790  if( specialized_event7 )
791  {
792  _function7( *specialized_event7, _event_collector );
793  }
794  else
795  {
796  const _event_type8* specialized_event8 = dynamic_cast< const _event_type8* >( &_event );
797  if( specialized_event8 )
798  {
799  _function8( *specialized_event8, _event_collector );
800  }
801  else
802  {
803  throw sxe::exception( "Invalid event type!" );
804  }
805  }
806  }
807  }
808  }
809  }
810  }
811  }
812 
813 
814 #else
815 
816 
818  "Event type 1 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
820  "Event type 2 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
822  "Event type 3 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
824  "Event type 4 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
826  "Event type 5 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
828  "Event type 6 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
830  "Event type 7 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
832  "Event type 8 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
833 
834  switch( _event.get_id() )
835  {
836  case _event_type1::get_event_id():
837  {
838  auto& specialized_event = sxy::adjust_event_type< _event_type1 >( _event );
839  _function1( specialized_event, _event_collector );
840  break;
841  }
842 
843  case _event_type2::get_event_id():
844  {
845  auto& specialized_event = sxy::adjust_event_type< _event_type2 >( _event );
846  _function2( specialized_event, _event_collector );
847  break;
848  }
849 
850  case _event_type3::get_event_id():
851  {
852  auto& specialized_event = sxy::adjust_event_type< _event_type3 >( _event );
853  _function3( specialized_event, _event_collector );
854  break;
855  }
856 
857  case _event_type4::get_event_id():
858  {
859  auto& specialized_event = sxy::adjust_event_type< _event_type4 >( _event );
860  _function4( specialized_event, _event_collector );
861  break;
862  }
863 
864  case _event_type5::get_event_id():
865  {
866  auto& specialized_event = sxy::adjust_event_type< _event_type5 >( _event );
867  _function5( specialized_event, _event_collector );
868  break;
869  }
870 
871  case _event_type6::get_event_id():
872  {
873  auto& specialized_event = sxy::adjust_event_type< _event_type6 >( _event );
874  _function6( specialized_event, _event_collector );
875  break;
876  }
877 
878  case _event_type7::get_event_id():
879  {
880  auto& specialized_event = sxy::adjust_event_type< _event_type7 >( _event );
881  _function7( specialized_event, _event_collector );
882  break;
883  }
884 
885  case _event_type8::get_event_id():
886  {
887  auto& specialized_event = sxy::adjust_event_type< _event_type8 >( _event );
888  _function8( specialized_event, _event_collector );
889  break;
890  }
891 
892  default:
893  SX_ASSERT( false, "Invalid event type!" );
894  }
895 
896 
897 #endif
898 }
899 
900 
901 template< typename _event_type1, typename _event_type2, typename _event_type3, typename _event_type4,
902  typename _event_type5, typename _event_type6, typename _event_type7, typename _event_type8, typename _event_type9 >
903  void behavior_caller( const sxy::event& _event, sxy::event_collector& _event_collector,
904  const sxe::function<void( const _event_type1&, sxy::event_collector& )>& _function1,
905  const sxe::function<void( const _event_type2&, sxy::event_collector& )>& _function2,
906  const sxe::function<void( const _event_type3&, sxy::event_collector& )>& _function3,
907  const sxe::function<void( const _event_type4&, sxy::event_collector& )>& _function4,
908  const sxe::function<void( const _event_type5&, sxy::event_collector& )>& _function5,
909  const sxe::function<void( const _event_type6&, sxy::event_collector& )>& _function6,
910  const sxe::function<void( const _event_type7&, sxy::event_collector& )>& _function7,
911  const sxe::function<void( const _event_type8&, sxy::event_collector& )>& _function8,
912  const sxe::function<void( const _event_type9&, sxy::event_collector& )>& _function9 )
913 {
914 #if defined( SX_CPP03_BOOST ) || ( defined(_MSC_VER) && _MSC_VER <=1800 )
915 
916 
917  const _event_type1* specialized_event = dynamic_cast< const _event_type1* >( &_event );
918  if( specialized_event )
919  {
920  _function1( *specialized_event, _event_collector );
921  }
922  else
923  {
924  const _event_type2* specialized_event2 = dynamic_cast< const _event_type2* >( &_event );
925  if( specialized_event2 )
926  {
927  _function2( *specialized_event2, _event_collector );
928  }
929  else
930  {
931  const _event_type3* specialized_event3 = dynamic_cast< const _event_type3* >( &_event );
932  if( specialized_event3 )
933  {
934  _function3( *specialized_event3, _event_collector );
935  }
936  else
937  {
938  const _event_type4* specialized_event4 = dynamic_cast< const _event_type4* >( &_event );
939  if( specialized_event4 )
940  {
941  _function4( *specialized_event4, _event_collector );
942  }
943  else
944  {
945  const _event_type5* specialized_event5 = dynamic_cast< const _event_type5* >( &_event );
946  if( specialized_event5 )
947  {
948  _function5( *specialized_event5, _event_collector );
949  }
950  else
951  {
952  const _event_type6* specialized_event6 = dynamic_cast< const _event_type6* >( &_event );
953  if( specialized_event6 )
954  {
955  _function6( *specialized_event6, _event_collector );
956  }
957  else
958  {
959  const _event_type7* specialized_event7 = dynamic_cast< const _event_type7* >( &_event );
960  if( specialized_event7 )
961  {
962  _function7( *specialized_event7, _event_collector );
963  }
964  else
965  {
966  const _event_type8* specialized_event8 = dynamic_cast< const _event_type8* >( &_event );
967  if( specialized_event8 )
968  {
969  _function8( *specialized_event8, _event_collector );
970  }
971  else
972  {
973  const _event_type9* specialized_event9 = dynamic_cast< const _event_type9* >( &_event );
974  if( specialized_event9 )
975  {
976  _function9( *specialized_event9, _event_collector );
977  }
978  else
979  {
980  throw sxe::exception( "Invalid event type!" );
981  }
982  }
983  }
984  }
985  }
986  }
987  }
988  }
989  }
990 
991 
992 #else
993 
994 
996  "Event type 1 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
998  "Event type 2 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1000  "Event type 3 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1002  "Event type 4 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1004  "Event type 5 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1006  "Event type 6 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1008  "Event type 7 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1010  "Event type 8 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1012  "Event type 9 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1013 
1014  switch( _event.get_id() )
1015  {
1016  case _event_type1::get_event_id():
1017  {
1018  auto& specialized_event = sxy::adjust_event_type< _event_type1 >( _event );
1019  _function1( specialized_event, _event_collector );
1020  break;
1021  }
1022 
1023  case _event_type2::get_event_id():
1024  {
1025  auto& specialized_event = sxy::adjust_event_type< _event_type2 >( _event );
1026  _function2( specialized_event, _event_collector );
1027  break;
1028  }
1029 
1030  case _event_type3::get_event_id():
1031  {
1032  auto& specialized_event = sxy::adjust_event_type< _event_type3 >( _event );
1033  _function3( specialized_event, _event_collector );
1034  break;
1035  }
1036 
1037  case _event_type4::get_event_id():
1038  {
1039  auto& specialized_event = sxy::adjust_event_type< _event_type4 >( _event );
1040  _function4( specialized_event, _event_collector );
1041  break;
1042  }
1043 
1044  case _event_type5::get_event_id():
1045  {
1046  auto& specialized_event = sxy::adjust_event_type< _event_type5 >( _event );
1047  _function5( specialized_event, _event_collector );
1048  break;
1049  }
1050 
1051  case _event_type6::get_event_id():
1052  {
1053  auto& specialized_event = sxy::adjust_event_type< _event_type6 >( _event );
1054  _function6( specialized_event, _event_collector );
1055  break;
1056  }
1057 
1058  case _event_type7::get_event_id():
1059  {
1060  auto& specialized_event = sxy::adjust_event_type< _event_type7 >( _event );
1061  _function7( specialized_event, _event_collector );
1062  break;
1063  }
1064 
1065  case _event_type8::get_event_id():
1066  {
1067  auto& specialized_event = sxy::adjust_event_type< _event_type8 >( _event );
1068  _function8( specialized_event, _event_collector );
1069  break;
1070  }
1071 
1072  case _event_type9::get_event_id():
1073  {
1074  auto& specialized_event = sxy::adjust_event_type< _event_type9 >( _event );
1075  _function9( specialized_event, _event_collector );
1076  break;
1077  }
1078 
1079  default:
1080  SX_ASSERT( false, "Invalid event type!" );
1081  }
1082 
1083 
1084 #endif
1085 }
1086 
1087 
1088 template< typename _event_type1, typename _event_type2, typename _event_type3, typename _event_type4,
1089  typename _event_type5, typename _event_type6, typename _event_type7, typename _event_type8, typename _event_type9,
1090  typename _event_type10 >
1091  void behavior_caller( const sxy::event& _event, sxy::event_collector& _event_collector,
1092  const sxe::function<void( const _event_type1&, sxy::event_collector& )>& _function1,
1093  const sxe::function<void( const _event_type2&, sxy::event_collector& )>& _function2,
1094  const sxe::function<void( const _event_type3&, sxy::event_collector& )>& _function3,
1095  const sxe::function<void( const _event_type4&, sxy::event_collector& )>& _function4,
1096  const sxe::function<void( const _event_type5&, sxy::event_collector& )>& _function5,
1097  const sxe::function<void( const _event_type6&, sxy::event_collector& )>& _function6,
1098  const sxe::function<void( const _event_type7&, sxy::event_collector& )>& _function7,
1099  const sxe::function<void( const _event_type8&, sxy::event_collector& )>& _function8,
1100  const sxe::function<void( const _event_type9&, sxy::event_collector& )>& _function9,
1101  const sxe::function<void( const _event_type10&, sxy::event_collector& )>& _function10 )
1102 {
1103 #if defined( SX_CPP03_BOOST ) || ( defined(_MSC_VER) && _MSC_VER <=1800 )
1104 
1105 
1106  const _event_type1* specialized_event = dynamic_cast< const _event_type1* >( &_event );
1107  if( specialized_event )
1108  {
1109  _function1( *specialized_event, _event_collector );
1110  }
1111  else
1112  {
1113  const _event_type2* specialized_event2 = dynamic_cast< const _event_type2* >( &_event );
1114  if( specialized_event2 )
1115  {
1116  _function2( *specialized_event2, _event_collector );
1117  }
1118  else
1119  {
1120  const _event_type3* specialized_event3 = dynamic_cast< const _event_type3* >( &_event );
1121  if( specialized_event3 )
1122  {
1123  _function3( *specialized_event3, _event_collector );
1124  }
1125  else
1126  {
1127  const _event_type4* specialized_event4 = dynamic_cast< const _event_type4* >( &_event );
1128  if( specialized_event4 )
1129  {
1130  _function4( *specialized_event4, _event_collector );
1131  }
1132  else
1133  {
1134  const _event_type5* specialized_event5 = dynamic_cast< const _event_type5* >( &_event );
1135  if( specialized_event5 )
1136  {
1137  _function5( *specialized_event5, _event_collector );
1138  }
1139  else
1140  {
1141  const _event_type6* specialized_event6 = dynamic_cast< const _event_type6* >( &_event );
1142  if( specialized_event6 )
1143  {
1144  _function6( *specialized_event6, _event_collector );
1145  }
1146  else
1147  {
1148  const _event_type7* specialized_event7 = dynamic_cast< const _event_type7* >( &_event );
1149  if( specialized_event7 )
1150  {
1151  _function7( *specialized_event7, _event_collector );
1152  }
1153  else
1154  {
1155  const _event_type8* specialized_event8 = dynamic_cast< const _event_type8* >( &_event );
1156  if( specialized_event8 )
1157  {
1158  _function8( *specialized_event8, _event_collector );
1159  }
1160  else
1161  {
1162  const _event_type9* specialized_event9 = dynamic_cast< const _event_type9* >( &_event );
1163  if( specialized_event9 )
1164  {
1165  _function9( *specialized_event9, _event_collector );
1166  }
1167  else
1168  {
1169  const _event_type10* specialized_event10 = dynamic_cast< const _event_type10* >( &_event );
1170  if( specialized_event10 )
1171  {
1172  _function10( *specialized_event10, _event_collector );
1173  }
1174  else
1175  {
1176  throw sxe::exception( "Invalid event type!" );
1177  }
1178  }
1179  }
1180  }
1181  }
1182  }
1183  }
1184  }
1185  }
1186  }
1187 
1188 
1189 #else
1190 
1191 
1193  "Event type 1 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1195  "Event type 2 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1197  "Event type 3 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1199  "Event type 4 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1201  "Event type 5 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1203  "Event type 6 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1205  "Event type 7 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1207  "Event type 8 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1209  "Event type 9 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1211  "Event type 10 does not have the method 'get_event_id'. This is mandatory for using the behavior_caller!" );
1212 
1213 
1214  switch( _event.get_id() )
1215  {
1216  case _event_type1::get_event_id():
1217  {
1218  auto& specialized_event = sxy::adjust_event_type< _event_type1 >( _event );
1219  _function1( specialized_event, _event_collector );
1220  break;
1221  }
1222 
1223  case _event_type2::get_event_id():
1224  {
1225  auto& specialized_event = sxy::adjust_event_type< _event_type2 >( _event );
1226  _function2( specialized_event, _event_collector );
1227  break;
1228  }
1229 
1230  case _event_type3::get_event_id():
1231  {
1232  auto& specialized_event = sxy::adjust_event_type< _event_type3 >( _event );
1233  _function3( specialized_event, _event_collector );
1234  break;
1235  }
1236 
1237  case _event_type4::get_event_id():
1238  {
1239  auto& specialized_event = sxy::adjust_event_type< _event_type4 >( _event );
1240  _function4( specialized_event, _event_collector );
1241  break;
1242  }
1243 
1244  case _event_type5::get_event_id():
1245  {
1246  auto& specialized_event = sxy::adjust_event_type< _event_type5 >( _event );
1247  _function5( specialized_event, _event_collector );
1248  break;
1249  }
1250 
1251  case _event_type6::get_event_id():
1252  {
1253  auto& specialized_event = sxy::adjust_event_type< _event_type6 >( _event );
1254  _function6( specialized_event, _event_collector );
1255  break;
1256  }
1257 
1258  case _event_type7::get_event_id():
1259  {
1260  auto& specialized_event = sxy::adjust_event_type< _event_type7 >( _event );
1261  _function7( specialized_event, _event_collector );
1262  break;
1263  }
1264 
1265  case _event_type8::get_event_id():
1266  {
1267  auto& specialized_event = sxy::adjust_event_type< _event_type8 >( _event );
1268  _function8( specialized_event, _event_collector );
1269  break;
1270  }
1271 
1272  case _event_type9::get_event_id():
1273  {
1274  auto& specialized_event = sxy::adjust_event_type< _event_type9 >( _event );
1275  _function9( specialized_event, _event_collector );
1276  break;
1277  }
1278 
1279  case _event_type10::get_event_id():
1280  {
1281  auto& specialized_event = sxy::adjust_event_type< _event_type10 >( _event );
1282  _function10( specialized_event, _event_collector );
1283  break;
1284  }
1285 
1286  default:
1287  SX_ASSERT( false, "Invalid event type!" );
1288  }
1289 
1290 
1291 #endif
1292 }
1293 
1294 
1295 }
1296 
1297 #endif
Definition: event_collector.hpp:25
virtual event_id get_id() const =0
Getter of event&#39;s ID.
Interface of an event. An event has an ID, a name and a priority (for processing by the async state m...
Definition: event.hpp:28
Definition: adapter_cpp11.hpp:21
void behavior_caller(const sxy::event &_event, sxy::event_collector &_event_collector, const sxe::function< void()> &_function)
Definition: behavior_caller.cpp:18
Class that inherits event_impl and provides a fixed event ID and priority as well as create methods f...
Definition: specialized_event.hpp:26
Definition: caller_helper.hpp:25