A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
make-event.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  */
18 
19 #ifndef MAKE_EVENT_H
20 #define MAKE_EVENT_H
21 
28 namespace ns3
29 {
30 
31 class EventImpl;
32 
54 template <typename MEM, typename OBJ>
55 EventImpl* MakeEvent(MEM mem_ptr, OBJ obj);
56 
67 template <typename MEM, typename OBJ, typename T1>
68 EventImpl* MakeEvent(MEM mem_ptr, OBJ obj, T1 a1);
69 
82 template <typename MEM, typename OBJ, typename T1, typename T2>
83 EventImpl* MakeEvent(MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
84 
99 template <typename MEM, typename OBJ, typename T1, typename T2, typename T3>
100 EventImpl* MakeEvent(MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
101 
118 template <typename MEM, typename OBJ, typename T1, typename T2, typename T3, typename T4>
119 EventImpl* MakeEvent(MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4);
120 
139 template <typename MEM,
140  typename OBJ,
141  typename T1,
142  typename T2,
143  typename T3,
144  typename T4,
145  typename T5>
146 EventImpl* MakeEvent(MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
147 
168 template <typename MEM,
169  typename OBJ,
170  typename T1,
171  typename T2,
172  typename T3,
173  typename T4,
174  typename T5,
175  typename T6>
176 EventImpl* MakeEvent(MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
177 
196 EventImpl* MakeEvent(void (*f)());
197 
206 template <typename U1, typename T1>
207 EventImpl* MakeEvent(void (*f)(U1), T1 a1);
208 
220 template <typename U1, typename U2, typename T1, typename T2>
221 EventImpl* MakeEvent(void (*f)(U1, U2), T1 a1, T2 a2);
222 
237 template <typename U1, typename U2, typename U3, typename T1, typename T2, typename T3>
238 EventImpl* MakeEvent(void (*f)(U1, U2, U3), T1 a1, T2 a2, T3 a3);
239 
257 template <typename U1,
258  typename U2,
259  typename U3,
260  typename U4,
261  typename T1,
262  typename T2,
263  typename T3,
264  typename T4>
265 EventImpl* MakeEvent(void (*f)(U1, U2, U3, U4), T1 a1, T2 a2, T3 a3, T4 a4);
266 
287 template <typename U1,
288  typename U2,
289  typename U3,
290  typename U4,
291  typename U5,
292  typename T1,
293  typename T2,
294  typename T3,
295  typename T4,
296  typename T5>
297 EventImpl* MakeEvent(void (*f)(U1, U2, U3, U4, U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
298 
322 template <typename U1,
323  typename U2,
324  typename U3,
325  typename U4,
326  typename U5,
327  typename U6,
328  typename T1,
329  typename T2,
330  typename T3,
331  typename T4,
332  typename T5,
333  typename T6>
334 EventImpl* MakeEvent(void (*f)(U1, U2, U3, U4, U5, U6), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
335 
342 template <typename T>
343 EventImpl* MakeEvent(T function);
344 
347 } // namespace ns3
348 
349 /********************************************************************
350  * Implementation of the templates declared above.
351  ********************************************************************/
352 
353 #include "event-impl.h"
354 #include "type-traits.h"
355 
356 namespace ns3
357 {
358 
369 template <typename T>
371 
382 template <typename T>
384 {
389  static T& GetReference(T* p)
390  {
391  return *p;
392  }
393 };
394 
395 template <typename MEM, typename OBJ>
396 EventImpl*
397 MakeEvent(MEM mem_ptr, OBJ obj)
398 {
399  // zero argument version
400  class EventMemberImpl0 : public EventImpl
401  {
402  public:
403  EventMemberImpl0(OBJ obj, MEM function)
404  : m_obj(obj),
405  m_function(function)
406  {
407  }
408 
409  ~EventMemberImpl0() override
410  {
411  }
412 
413  private:
414  void Notify() override
415  {
416  (EventMemberImplObjTraits<OBJ>::GetReference(m_obj).*m_function)();
417  }
418 
419  OBJ m_obj;
420  MEM m_function;
421  }* ev = new EventMemberImpl0(obj, mem_ptr);
422 
423  return ev;
424 }
425 
426 template <typename MEM, typename OBJ, typename T1>
427 EventImpl*
428 MakeEvent(MEM mem_ptr, OBJ obj, T1 a1)
429 {
430  // one argument version
431  class EventMemberImpl1 : public EventImpl
432  {
433  public:
434  EventMemberImpl1(OBJ obj, MEM function, T1 a1)
435  : m_obj(obj),
436  m_function(function),
437  m_a1(a1)
438  {
439  }
440 
441  protected:
442  ~EventMemberImpl1() override
443  {
444  }
445 
446  private:
447  void Notify() override
448  {
449  (EventMemberImplObjTraits<OBJ>::GetReference(m_obj).*m_function)(m_a1);
450  }
451 
452  OBJ m_obj;
453  MEM m_function;
454  typename TypeTraits<T1>::ReferencedType m_a1;
455  }* ev = new EventMemberImpl1(obj, mem_ptr, a1);
456 
457  return ev;
458 }
459 
460 template <typename MEM, typename OBJ, typename T1, typename T2>
461 EventImpl*
462 MakeEvent(MEM mem_ptr, OBJ obj, T1 a1, T2 a2)
463 {
464  // two argument version
465  class EventMemberImpl2 : public EventImpl
466  {
467  public:
468  EventMemberImpl2(OBJ obj, MEM function, T1 a1, T2 a2)
469  : m_obj(obj),
470  m_function(function),
471  m_a1(a1),
472  m_a2(a2)
473  {
474  }
475 
476  protected:
477  ~EventMemberImpl2() override
478  {
479  }
480 
481  private:
482  void Notify() override
483  {
484  (EventMemberImplObjTraits<OBJ>::GetReference(m_obj).*m_function)(m_a1, m_a2);
485  }
486 
487  OBJ m_obj;
488  MEM m_function;
489  typename TypeTraits<T1>::ReferencedType m_a1;
490  typename TypeTraits<T2>::ReferencedType m_a2;
491  }* ev = new EventMemberImpl2(obj, mem_ptr, a1, a2);
492 
493  return ev;
494 }
495 
496 template <typename MEM, typename OBJ, typename T1, typename T2, typename T3>
497 EventImpl*
498 MakeEvent(MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3)
499 {
500  // three argument version
501  class EventMemberImpl3 : public EventImpl
502  {
503  public:
504  EventMemberImpl3(OBJ obj, MEM function, T1 a1, T2 a2, T3 a3)
505  : m_obj(obj),
506  m_function(function),
507  m_a1(a1),
508  m_a2(a2),
509  m_a3(a3)
510  {
511  }
512 
513  protected:
514  ~EventMemberImpl3() override
515  {
516  }
517 
518  private:
519  void Notify() override
520  {
521  (EventMemberImplObjTraits<OBJ>::GetReference(m_obj).*m_function)(m_a1, m_a2, m_a3);
522  }
523 
524  OBJ m_obj;
525  MEM m_function;
526  typename TypeTraits<T1>::ReferencedType m_a1;
527  typename TypeTraits<T2>::ReferencedType m_a2;
528  typename TypeTraits<T3>::ReferencedType m_a3;
529  }* ev = new EventMemberImpl3(obj, mem_ptr, a1, a2, a3);
530 
531  return ev;
532 }
533 
534 template <typename MEM, typename OBJ, typename T1, typename T2, typename T3, typename T4>
535 EventImpl*
536 MakeEvent(MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4)
537 {
538  // four argument version
539  class EventMemberImpl4 : public EventImpl
540  {
541  public:
542  EventMemberImpl4(OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4)
543  : m_obj(obj),
544  m_function(function),
545  m_a1(a1),
546  m_a2(a2),
547  m_a3(a3),
548  m_a4(a4)
549  {
550  }
551 
552  protected:
553  ~EventMemberImpl4() override
554  {
555  }
556 
557  private:
558  void Notify() override
559  {
561  m_function)(m_a1, m_a2, m_a3, m_a4);
562  }
563 
564  OBJ m_obj;
565  MEM m_function;
566  typename TypeTraits<T1>::ReferencedType m_a1;
567  typename TypeTraits<T2>::ReferencedType m_a2;
568  typename TypeTraits<T3>::ReferencedType m_a3;
569  typename TypeTraits<T4>::ReferencedType m_a4;
570  }* ev = new EventMemberImpl4(obj, mem_ptr, a1, a2, a3, a4);
571 
572  return ev;
573 }
574 
575 template <typename MEM,
576  typename OBJ,
577  typename T1,
578  typename T2,
579  typename T3,
580  typename T4,
581  typename T5>
582 EventImpl*
583 MakeEvent(MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
584 {
585  // five argument version
586  class EventMemberImpl5 : public EventImpl
587  {
588  public:
589  EventMemberImpl5(OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
590  : m_obj(obj),
591  m_function(function),
592  m_a1(a1),
593  m_a2(a2),
594  m_a3(a3),
595  m_a4(a4),
596  m_a5(a5)
597  {
598  }
599 
600  protected:
601  ~EventMemberImpl5() override
602  {
603  }
604 
605  private:
606  void Notify() override
607  {
609  m_function)(m_a1, m_a2, m_a3, m_a4, m_a5);
610  }
611 
612  OBJ m_obj;
613  MEM m_function;
614  typename TypeTraits<T1>::ReferencedType m_a1;
615  typename TypeTraits<T2>::ReferencedType m_a2;
616  typename TypeTraits<T3>::ReferencedType m_a3;
617  typename TypeTraits<T4>::ReferencedType m_a4;
618  typename TypeTraits<T5>::ReferencedType m_a5;
619  }* ev = new EventMemberImpl5(obj, mem_ptr, a1, a2, a3, a4, a5);
620 
621  return ev;
622 }
623 
624 template <typename MEM,
625  typename OBJ,
626  typename T1,
627  typename T2,
628  typename T3,
629  typename T4,
630  typename T5,
631  typename T6>
632 EventImpl*
633 MakeEvent(MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
634 {
635  // six argument version
636  class EventMemberImpl6 : public EventImpl
637  {
638  public:
639  EventMemberImpl6(OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
640  : m_obj(obj),
641  m_function(function),
642  m_a1(a1),
643  m_a2(a2),
644  m_a3(a3),
645  m_a4(a4),
646  m_a5(a5),
647  m_a6(a6)
648  {
649  }
650 
651  protected:
652  ~EventMemberImpl6() override
653  {
654  }
655 
656  private:
657  void Notify() override
658  {
660  m_function)(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
661  }
662 
663  OBJ m_obj;
664  MEM m_function;
665  typename TypeTraits<T1>::ReferencedType m_a1;
666  typename TypeTraits<T2>::ReferencedType m_a2;
667  typename TypeTraits<T3>::ReferencedType m_a3;
668  typename TypeTraits<T4>::ReferencedType m_a4;
669  typename TypeTraits<T5>::ReferencedType m_a5;
670  typename TypeTraits<T6>::ReferencedType m_a6;
671  }* ev = new EventMemberImpl6(obj, mem_ptr, a1, a2, a3, a4, a5, a6);
672 
673  return ev;
674 }
675 
676 template <typename U1, typename T1>
677 EventImpl*
678 MakeEvent(void (*f)(U1), T1 a1)
679 {
680  // one arg version
681  class EventFunctionImpl1 : public EventImpl
682  {
683  public:
684  [[maybe_unused]] typedef void (*F)(U1);
685 
686  EventFunctionImpl1(F function, T1 a1)
687  : m_function(function),
688  m_a1(a1)
689  {
690  }
691 
692  protected:
693  ~EventFunctionImpl1() override
694  {
695  }
696 
697  private:
698  void Notify() override
699  {
700  (*m_function)(m_a1);
701  }
702 
703  F m_function;
704  typename TypeTraits<T1>::ReferencedType m_a1;
705  }* ev = new EventFunctionImpl1(f, a1);
706 
707  return ev;
708 }
709 
710 template <typename U1, typename U2, typename T1, typename T2>
711 EventImpl*
712 MakeEvent(void (*f)(U1, U2), T1 a1, T2 a2)
713 {
714  // two arg version
715  class EventFunctionImpl2 : public EventImpl
716  {
717  public:
718  [[maybe_unused]] typedef void (*F)(U1, U2);
719 
720  EventFunctionImpl2(F function, T1 a1, T2 a2)
721  : m_function(function),
722  m_a1(a1),
723  m_a2(a2)
724  {
725  }
726 
727  protected:
728  ~EventFunctionImpl2() override
729  {
730  }
731 
732  private:
733  void Notify() override
734  {
735  (*m_function)(m_a1, m_a2);
736  }
737 
738  F m_function;
739  typename TypeTraits<T1>::ReferencedType m_a1;
740  typename TypeTraits<T2>::ReferencedType m_a2;
741  }* ev = new EventFunctionImpl2(f, a1, a2);
742 
743  return ev;
744 }
745 
746 template <typename U1, typename U2, typename U3, typename T1, typename T2, typename T3>
747 EventImpl*
748 MakeEvent(void (*f)(U1, U2, U3), T1 a1, T2 a2, T3 a3)
749 {
750  // three arg version
751  class EventFunctionImpl3 : public EventImpl
752  {
753  public:
754  [[maybe_unused]] typedef void (*F)(U1, U2, U3);
755 
756  EventFunctionImpl3(F function, T1 a1, T2 a2, T3 a3)
757  : m_function(function),
758  m_a1(a1),
759  m_a2(a2),
760  m_a3(a3)
761  {
762  }
763 
764  protected:
765  ~EventFunctionImpl3() override
766  {
767  }
768 
769  private:
770  void Notify() override
771  {
772  (*m_function)(m_a1, m_a2, m_a3);
773  }
774 
775  F m_function;
776  typename TypeTraits<T1>::ReferencedType m_a1;
777  typename TypeTraits<T2>::ReferencedType m_a2;
778  typename TypeTraits<T3>::ReferencedType m_a3;
779  }* ev = new EventFunctionImpl3(f, a1, a2, a3);
780 
781  return ev;
782 }
783 
784 template <typename U1,
785  typename U2,
786  typename U3,
787  typename U4,
788  typename T1,
789  typename T2,
790  typename T3,
791  typename T4>
792 EventImpl*
793 MakeEvent(void (*f)(U1, U2, U3, U4), T1 a1, T2 a2, T3 a3, T4 a4)
794 {
795  // four arg version
796  class EventFunctionImpl4 : public EventImpl
797  {
798  public:
799  [[maybe_unused]] typedef void (*F)(U1, U2, U3, U4);
800 
801  EventFunctionImpl4(F function, T1 a1, T2 a2, T3 a3, T4 a4)
802  : m_function(function),
803  m_a1(a1),
804  m_a2(a2),
805  m_a3(a3),
806  m_a4(a4)
807  {
808  }
809 
810  protected:
811  ~EventFunctionImpl4() override
812  {
813  }
814 
815  private:
816  void Notify() override
817  {
818  (*m_function)(m_a1, m_a2, m_a3, m_a4);
819  }
820 
821  F m_function;
822  typename TypeTraits<T1>::ReferencedType m_a1;
823  typename TypeTraits<T2>::ReferencedType m_a2;
824  typename TypeTraits<T3>::ReferencedType m_a3;
825  typename TypeTraits<T4>::ReferencedType m_a4;
826  }* ev = new EventFunctionImpl4(f, a1, a2, a3, a4);
827 
828  return ev;
829 }
830 
831 template <typename U1,
832  typename U2,
833  typename U3,
834  typename U4,
835  typename U5,
836  typename T1,
837  typename T2,
838  typename T3,
839  typename T4,
840  typename T5>
841 EventImpl*
842 MakeEvent(void (*f)(U1, U2, U3, U4, U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
843 {
844  // five arg version
845  class EventFunctionImpl5 : public EventImpl
846  {
847  public:
848  [[maybe_unused]] typedef void (*F)(U1, U2, U3, U4, U5);
849 
850  EventFunctionImpl5(F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
851  : m_function(function),
852  m_a1(a1),
853  m_a2(a2),
854  m_a3(a3),
855  m_a4(a4),
856  m_a5(a5)
857  {
858  }
859 
860  protected:
861  ~EventFunctionImpl5() override
862  {
863  }
864 
865  private:
866  void Notify() override
867  {
868  (*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5);
869  }
870 
871  F m_function;
872  typename TypeTraits<T1>::ReferencedType m_a1;
873  typename TypeTraits<T2>::ReferencedType m_a2;
874  typename TypeTraits<T3>::ReferencedType m_a3;
875  typename TypeTraits<T4>::ReferencedType m_a4;
876  typename TypeTraits<T5>::ReferencedType m_a5;
877  }* ev = new EventFunctionImpl5(f, a1, a2, a3, a4, a5);
878 
879  return ev;
880 }
881 
882 template <typename U1,
883  typename U2,
884  typename U3,
885  typename U4,
886  typename U5,
887  typename U6,
888  typename T1,
889  typename T2,
890  typename T3,
891  typename T4,
892  typename T5,
893  typename T6>
894 EventImpl*
895 MakeEvent(void (*f)(U1, U2, U3, U4, U5, U6), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
896 {
897  // six arg version
898  class EventFunctionImpl6 : public EventImpl
899  {
900  public:
901  [[maybe_unused]] typedef void (*F)(U1, U2, U3, U4, U5, U6);
902 
903  EventFunctionImpl6(F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
904  : m_function(function),
905  m_a1(a1),
906  m_a2(a2),
907  m_a3(a3),
908  m_a4(a4),
909  m_a5(a5),
910  m_a6(a6)
911  {
912  }
913 
914  protected:
915  ~EventFunctionImpl6() override
916  {
917  }
918 
919  private:
920  void Notify() override
921  {
922  (*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
923  }
924 
925  F m_function;
926  typename TypeTraits<T1>::ReferencedType m_a1;
927  typename TypeTraits<T2>::ReferencedType m_a2;
928  typename TypeTraits<T3>::ReferencedType m_a3;
929  typename TypeTraits<T4>::ReferencedType m_a4;
930  typename TypeTraits<T5>::ReferencedType m_a5;
931  typename TypeTraits<T6>::ReferencedType m_a6;
932  }* ev = new EventFunctionImpl6(f, a1, a2, a3, a4, a5, a6);
933 
934  return ev;
935 }
936 
937 template <typename T>
938 EventImpl*
939 MakeEvent(T function)
940 {
941  class EventImplFunctional : public EventImpl
942  {
943  public:
944  EventImplFunctional(T function)
945  : m_function(function)
946  {
947  }
948 
949  ~EventImplFunctional() override
950  {
951  }
952 
953  private:
954  void Notify() override
955  {
956  m_function();
957  }
958 
959  T m_function;
960  }* ev = new EventImplFunctional(function);
961 
962  return ev;
963 }
964 
965 } // namespace ns3
966 
967 #endif /* MAKE_EVENT_H */
double f(double x, void *params)
Definition: 80211b.c:70
A simulation event.
Definition: event-impl.h:46
ns3::EventImpl declarations.
EventImpl * MakeEvent(void(*f)())
Make an EventImpl from a function pointer taking varying numbers of arguments.
Definition: make-event.cc:36
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Helper for the MakeEvent functions which take a class method.
Definition: make-event.h:370
ReferenceTraits< T >::ReferencedType ReferencedType
Referenced type.
Definition: type-traits.h:857
ns3::TypeTraits introspection declaration and template implementation.