A Discrete-Event Network Simulator
API
make-event.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19 
20 #ifndef MAKE_EVENT_H
21 #define MAKE_EVENT_H
22 
29 namespace ns3 {
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,
68  typename T1>
69 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1);
70 
83 template <typename MEM, typename OBJ,
84  typename T1, typename T2>
85 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
86 
101 template <typename MEM, typename OBJ,
102  typename T1, typename T2, typename T3>
103 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
104 
121 template <typename MEM, typename OBJ,
122  typename T1, typename T2, typename T3, typename T4>
123 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4);
124 
143 template <typename MEM, typename OBJ,
144  typename T1, typename T2, typename T3, typename T4, typename T5>
145 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj,
146  T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
147 
168 template <typename MEM, typename OBJ,
169  typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
170 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj,
171  T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
172 
191 EventImpl * MakeEvent (void (*f)(void));
192 
201 template <typename U1,
202  typename T1>
203 EventImpl * MakeEvent (void (*f)(U1), T1 a1);
204 
216 template <typename U1, typename U2,
217  typename T1, typename T2>
218 EventImpl * MakeEvent (void (*f)(U1,U2), T1 a1, T2 a2);
219 
234 template <typename U1, typename U2, typename U3,
235  typename T1, typename T2, typename T3>
236 EventImpl * MakeEvent (void (*f)(U1,U2,U3), T1 a1, T2 a2, T3 a3);
237 
255 template <typename U1, typename U2, typename U3, typename U4,
256  typename T1, typename T2, typename T3, typename T4>
257 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
258 
279 template <typename U1, typename U2, typename U3, typename U4, typename U5,
280  typename T1, typename T2, typename T3, typename T4, typename T5>
281 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
282 
306 template <typename U1, typename U2, typename U3, typename U4, typename U5, typename U6,
307  typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
308 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4,U5,U6), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
309 
316 template <typename T>
317 EventImpl * MakeEvent (T function);
318 
319 
322 } // namespace ns3
323 
324 /********************************************************************
325  * Implementation of the templates declared above.
326  ********************************************************************/
327 
328 #include "event-impl.h"
329 #include "type-traits.h"
330 
331 namespace ns3 {
332 
343 template <typename T>
345 
356 template <typename T>
358 {
363  static T & GetReference (T *p)
364  {
365  return *p;
366  }
367 };
368 
369 template <typename MEM, typename OBJ>
370 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj)
371 {
372  // zero argument version
373  class EventMemberImpl0 : public EventImpl
374  {
375  public:
376  EventMemberImpl0 (OBJ obj, MEM function)
377  : m_obj (obj),
378  m_function (function)
379  {}
380  virtual ~EventMemberImpl0 ()
381  {}
382 
383  private:
384  virtual void Notify (void)
385  {
386  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)();
387  }
388  OBJ m_obj;
389  MEM m_function;
390  } *ev = new EventMemberImpl0 (obj, mem_ptr);
391  return ev;
392 }
393 
394 
395 template <typename MEM, typename OBJ,
396  typename T1>
397 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1)
398 {
399  // one argument version
400  class EventMemberImpl1 : public EventImpl
401  {
402  public:
403  EventMemberImpl1 (OBJ obj, MEM function, T1 a1)
404  : m_obj (obj),
405  m_function (function),
406  m_a1 (a1)
407  {}
408 
409  protected:
410  virtual ~EventMemberImpl1 ()
411  {}
412 
413  private:
414  virtual void Notify (void)
415  {
416  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1);
417  }
418  OBJ m_obj;
419  MEM m_function;
420  typename TypeTraits<T1>::ReferencedType m_a1;
421  } *ev = new EventMemberImpl1 (obj, mem_ptr, a1);
422  return ev;
423 }
424 
425 template <typename MEM, typename OBJ,
426  typename T1, typename T2>
427 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2)
428 {
429  // two argument version
430  class EventMemberImpl2 : public EventImpl
431  {
432  public:
433  EventMemberImpl2 (OBJ obj, MEM function, T1 a1, T2 a2)
434  : m_obj (obj),
435  m_function (function),
436  m_a1 (a1),
437  m_a2 (a2)
438  {}
439 
440  protected:
441  virtual ~EventMemberImpl2 ()
442  {}
443 
444  private:
445  virtual void Notify (void)
446  {
447  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2);
448  }
449  OBJ m_obj;
450  MEM m_function;
451  typename TypeTraits<T1>::ReferencedType m_a1;
452  typename TypeTraits<T2>::ReferencedType m_a2;
453  } *ev = new EventMemberImpl2 (obj, mem_ptr, a1, a2);
454  return ev;
455 }
456 
457 template <typename MEM, typename OBJ,
458  typename T1, typename T2, typename T3>
459 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3)
460 {
461  // three argument version
462  class EventMemberImpl3 : public EventImpl
463  {
464  public:
465  EventMemberImpl3 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3)
466  : m_obj (obj),
467  m_function (function),
468  m_a1 (a1),
469  m_a2 (a2),
470  m_a3 (a3)
471  {}
472 
473  protected:
474  virtual ~EventMemberImpl3 ()
475  {}
476 
477  private:
478  virtual void Notify (void)
479  {
480  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3);
481  }
482  OBJ m_obj;
483  MEM m_function;
484  typename TypeTraits<T1>::ReferencedType m_a1;
485  typename TypeTraits<T2>::ReferencedType m_a2;
486  typename TypeTraits<T3>::ReferencedType m_a3;
487  } *ev = new EventMemberImpl3 (obj, mem_ptr, a1, a2, a3);
488  return ev;
489 }
490 
491 template <typename MEM, typename OBJ,
492  typename T1, typename T2, typename T3, typename T4>
493 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4)
494 {
495  // four argument version
496  class EventMemberImpl4 : public EventImpl
497  {
498  public:
499  EventMemberImpl4 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4)
500  : m_obj (obj),
501  m_function (function),
502  m_a1 (a1),
503  m_a2 (a2),
504  m_a3 (a3),
505  m_a4 (a4)
506  {}
507 
508  protected:
509  virtual ~EventMemberImpl4 ()
510  {}
511 
512  private:
513  virtual void Notify (void)
514  {
515  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3, m_a4);
516  }
517  OBJ m_obj;
518  MEM m_function;
519  typename TypeTraits<T1>::ReferencedType m_a1;
520  typename TypeTraits<T2>::ReferencedType m_a2;
521  typename TypeTraits<T3>::ReferencedType m_a3;
522  typename TypeTraits<T4>::ReferencedType m_a4;
523  } *ev = new EventMemberImpl4 (obj, mem_ptr, a1, a2, a3, a4);
524  return ev;
525 }
526 
527 template <typename MEM, typename OBJ,
528  typename T1, typename T2, typename T3, typename T4, typename T5>
529 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj,
530  T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
531 {
532  // five argument version
533  class EventMemberImpl5 : public EventImpl
534  {
535  public:
536  EventMemberImpl5 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
537  : m_obj (obj),
538  m_function (function),
539  m_a1 (a1),
540  m_a2 (a2),
541  m_a3 (a3),
542  m_a4 (a4),
543  m_a5 (a5)
544  {}
545 
546  protected:
547  virtual ~EventMemberImpl5 ()
548  {}
549 
550  private:
551  virtual void Notify (void)
552  {
553  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5);
554  }
555  OBJ m_obj;
556  MEM m_function;
557  typename TypeTraits<T1>::ReferencedType m_a1;
558  typename TypeTraits<T2>::ReferencedType m_a2;
559  typename TypeTraits<T3>::ReferencedType m_a3;
560  typename TypeTraits<T4>::ReferencedType m_a4;
561  typename TypeTraits<T5>::ReferencedType m_a5;
562  } *ev = new EventMemberImpl5 (obj, mem_ptr, a1, a2, a3, a4, a5);
563  return ev;
564 }
565 
566 template <typename MEM, typename OBJ,
567  typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
568 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj,
569  T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
570 {
571  // six argument version
572  class EventMemberImpl6 : public EventImpl
573  {
574  public:
575  EventMemberImpl6 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
576  : m_obj (obj),
577  m_function (function),
578  m_a1 (a1),
579  m_a2 (a2),
580  m_a3 (a3),
581  m_a4 (a4),
582  m_a5 (a5),
583  m_a6 (a6)
584  {}
585 
586  protected:
587  virtual ~EventMemberImpl6 ()
588  {}
589 
590  private:
591  virtual void Notify (void)
592  {
593  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
594  }
595  OBJ m_obj;
596  MEM m_function;
597  typename TypeTraits<T1>::ReferencedType m_a1;
598  typename TypeTraits<T2>::ReferencedType m_a2;
599  typename TypeTraits<T3>::ReferencedType m_a3;
600  typename TypeTraits<T4>::ReferencedType m_a4;
601  typename TypeTraits<T5>::ReferencedType m_a5;
602  typename TypeTraits<T6>::ReferencedType m_a6;
603  } *ev = new EventMemberImpl6 (obj, mem_ptr, a1, a2, a3, a4, a5, a6);
604  return ev;
605 }
606 
607 template <typename U1, typename T1>
608 EventImpl * MakeEvent (void (*f)(U1), T1 a1)
609 {
610  // one arg version
611  class EventFunctionImpl1 : public EventImpl
612  {
613  public:
614  [[maybe_unused]]
615  typedef void (*F)(U1);
616 
617  EventFunctionImpl1 (F function, T1 a1)
618  : m_function (function),
619  m_a1 (a1)
620  {}
621 
622  protected:
623  virtual ~EventFunctionImpl1 ()
624  {}
625 
626  private:
627  virtual void Notify (void)
628  {
629  (*m_function)(m_a1);
630  }
631  F m_function;
632  typename TypeTraits<T1>::ReferencedType m_a1;
633  } *ev = new EventFunctionImpl1 (f, a1);
634  return ev;
635 }
636 
637 template <typename U1, typename U2, typename T1, typename T2>
638 EventImpl * MakeEvent (void (*f)(U1,U2), T1 a1, T2 a2)
639 {
640  // two arg version
641  class EventFunctionImpl2 : public EventImpl
642  {
643  public:
644  [[maybe_unused]]
645  typedef void (*F)(U1, U2);
646 
647  EventFunctionImpl2 (F function, T1 a1, T2 a2)
648  : m_function (function),
649  m_a1 (a1),
650  m_a2 (a2)
651  {}
652 
653  protected:
654  virtual ~EventFunctionImpl2 ()
655  {}
656 
657  private:
658  virtual void Notify (void)
659  {
660  (*m_function)(m_a1, m_a2);
661  }
662  F m_function;
663  typename TypeTraits<T1>::ReferencedType m_a1;
664  typename TypeTraits<T2>::ReferencedType m_a2;
665  } *ev = new EventFunctionImpl2 (f, a1, a2);
666  return ev;
667 }
668 
669 template <typename U1, typename U2, typename U3,
670  typename T1, typename T2, typename T3>
671 EventImpl * MakeEvent (void (*f)(U1,U2,U3), T1 a1, T2 a2, T3 a3)
672 {
673  // three arg version
674  class EventFunctionImpl3 : public EventImpl
675  {
676  public:
677  [[maybe_unused]]
678  typedef void (*F)(U1, U2, U3);
679 
680  EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3)
681  : m_function (function),
682  m_a1 (a1),
683  m_a2 (a2),
684  m_a3 (a3)
685  {}
686 
687  protected:
688  virtual ~EventFunctionImpl3 ()
689  {}
690 
691  private:
692  virtual void Notify (void)
693  {
694  (*m_function)(m_a1, m_a2, m_a3);
695  }
696  F m_function;
697  typename TypeTraits<T1>::ReferencedType m_a1;
698  typename TypeTraits<T2>::ReferencedType m_a2;
699  typename TypeTraits<T3>::ReferencedType m_a3;
700  } *ev = new EventFunctionImpl3 (f, a1, a2, a3);
701  return ev;
702 }
703 
704 template <typename U1, typename U2, typename U3, typename U4,
705  typename T1, typename T2, typename T3, typename T4>
706 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4)
707 {
708  // four arg version
709  class EventFunctionImpl4 : public EventImpl
710  {
711  public:
712  [[maybe_unused]]
713  typedef void (*F)(U1, U2, U3, U4);
714 
715  EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4)
716  : m_function (function),
717  m_a1 (a1),
718  m_a2 (a2),
719  m_a3 (a3),
720  m_a4 (a4)
721  {}
722 
723  protected:
724  virtual ~EventFunctionImpl4 ()
725  {}
726 
727  private:
728  virtual void Notify (void)
729  {
730  (*m_function)(m_a1, m_a2, m_a3, m_a4);
731  }
732  F m_function;
733  typename TypeTraits<T1>::ReferencedType m_a1;
734  typename TypeTraits<T2>::ReferencedType m_a2;
735  typename TypeTraits<T3>::ReferencedType m_a3;
736  typename TypeTraits<T4>::ReferencedType m_a4;
737  } *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4);
738  return ev;
739 }
740 
741 template <typename U1, typename U2, typename U3, typename U4, typename U5,
742  typename T1, typename T2, typename T3, typename T4, typename T5>
743 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
744 {
745  // five arg version
746  class EventFunctionImpl5 : public EventImpl
747  {
748  public:
749  [[maybe_unused]]
750  typedef void (*F)(U1,U2,U3,U4,U5);
751 
752  EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
753  : m_function (function),
754  m_a1 (a1),
755  m_a2 (a2),
756  m_a3 (a3),
757  m_a4 (a4),
758  m_a5 (a5)
759  {}
760 
761  protected:
762  virtual ~EventFunctionImpl5 ()
763  {}
764 
765  private:
766  virtual void Notify (void)
767  {
768  (*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5);
769  }
770  F m_function;
771  typename TypeTraits<T1>::ReferencedType m_a1;
772  typename TypeTraits<T2>::ReferencedType m_a2;
773  typename TypeTraits<T3>::ReferencedType m_a3;
774  typename TypeTraits<T4>::ReferencedType m_a4;
775  typename TypeTraits<T5>::ReferencedType m_a5;
776  } *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5);
777  return ev;
778 }
779 
780 template <typename U1, typename U2, typename U3, typename U4, typename U5, typename U6,
781  typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
782 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4,U5,U6), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
783 {
784  // six arg version
785  class EventFunctionImpl6 : public EventImpl
786  {
787  public:
788  [[maybe_unused]]
789  typedef void (*F)(U1,U2,U3,U4,U5,U6);
790 
791  EventFunctionImpl6 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
792  : m_function (function),
793  m_a1 (a1),
794  m_a2 (a2),
795  m_a3 (a3),
796  m_a4 (a4),
797  m_a5 (a5),
798  m_a6 (a6)
799  {}
800 
801  protected:
802  virtual ~EventFunctionImpl6 ()
803  {}
804 
805  private:
806  virtual void Notify (void)
807  {
808  (*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
809  }
810  F m_function;
811  typename TypeTraits<T1>::ReferencedType m_a1;
812  typename TypeTraits<T2>::ReferencedType m_a2;
813  typename TypeTraits<T3>::ReferencedType m_a3;
814  typename TypeTraits<T4>::ReferencedType m_a4;
815  typename TypeTraits<T5>::ReferencedType m_a5;
816  typename TypeTraits<T6>::ReferencedType m_a6;
817  } *ev = new EventFunctionImpl6 (f, a1, a2, a3, a4, a5, a6);
818  return ev;
819 }
820 
821 template <typename T>
822 EventImpl * MakeEvent (T function)
823 {
824  class EventImplFunctional : public EventImpl
825  {
826 public:
827  EventImplFunctional (T function)
828  : m_function (function)
829  {
830  }
831  virtual ~EventImplFunctional ()
832  {
833  }
834 private:
835  virtual void Notify (void)
836  {
837  m_function();
838  }
839  T m_function;
840  } *ev = new EventImplFunctional (function);
841  return ev;
842 }
843 
844 
845 } // namespace ns3
846 
847 #endif /* MAKE_EVENT_H */
double f(double x, void *params)
Definition: 80211b.c:70
A simulation event.
Definition: event-impl.h:45
ns3::EventImpl declarations.
EventImpl * MakeEvent(void(*f)(void))
Make an EventImpl from a function pointer taking varying numbers of arguments.
Definition: make-event.cc:34
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:344
ReferenceTraits< T >::ReferencedType ReferencedType
Referenced type.
Definition: type-traits.h:766
ns3::TypeTraits introspection declaration and template implementation.