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);
311 } // namespace ns3
312 
313 /********************************************************************
314  * Implementation of the templates declared above.
315  ********************************************************************/
316 
317 #include "event-impl.h"
318 #include "type-traits.h"
319 
320 namespace ns3 {
321 
332 template <typename T>
334 
345 template <typename T>
347 {
352  static T & GetReference (T *p)
353  {
354  return *p;
355  }
356 };
357 
358 template <typename MEM, typename OBJ>
359 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj)
360 {
361  // zero argument version
362  class EventMemberImpl0 : public EventImpl
363  {
364  public:
365  EventMemberImpl0 (OBJ obj, MEM function)
366  : m_obj (obj),
367  m_function (function)
368  {}
369  virtual ~EventMemberImpl0 ()
370  {}
371 
372  private:
373  virtual void Notify (void)
374  {
375  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)();
376  }
377  OBJ m_obj;
378  MEM m_function;
379  } *ev = new EventMemberImpl0 (obj, mem_ptr);
380  return ev;
381 }
382 
383 
384 template <typename MEM, typename OBJ,
385  typename T1>
386 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1)
387 {
388  // one argument version
389  class EventMemberImpl1 : public EventImpl
390  {
391  public:
392  EventMemberImpl1 (OBJ obj, MEM function, T1 a1)
393  : m_obj (obj),
394  m_function (function),
395  m_a1 (a1)
396  {}
397 
398  protected:
399  virtual ~EventMemberImpl1 ()
400  {}
401 
402  private:
403  virtual void Notify (void)
404  {
405  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1);
406  }
407  OBJ m_obj;
408  MEM m_function;
409  typename TypeTraits<T1>::ReferencedType m_a1;
410  } *ev = new EventMemberImpl1 (obj, mem_ptr, a1);
411  return ev;
412 }
413 
414 template <typename MEM, typename OBJ,
415  typename T1, typename T2>
416 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2)
417 {
418  // two argument version
419  class EventMemberImpl2 : public EventImpl
420  {
421  public:
422  EventMemberImpl2 (OBJ obj, MEM function, T1 a1, T2 a2)
423  : m_obj (obj),
424  m_function (function),
425  m_a1 (a1),
426  m_a2 (a2)
427  {}
428 
429  protected:
430  virtual ~EventMemberImpl2 ()
431  {}
432 
433  private:
434  virtual void Notify (void)
435  {
436  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2);
437  }
438  OBJ m_obj;
439  MEM m_function;
440  typename TypeTraits<T1>::ReferencedType m_a1;
441  typename TypeTraits<T2>::ReferencedType m_a2;
442  } *ev = new EventMemberImpl2 (obj, mem_ptr, a1, a2);
443  return ev;
444 }
445 
446 template <typename MEM, typename OBJ,
447  typename T1, typename T2, typename T3>
448 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3)
449 {
450  // three argument version
451  class EventMemberImpl3 : public EventImpl
452  {
453  public:
454  EventMemberImpl3 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3)
455  : m_obj (obj),
456  m_function (function),
457  m_a1 (a1),
458  m_a2 (a2),
459  m_a3 (a3)
460  {}
461 
462  protected:
463  virtual ~EventMemberImpl3 ()
464  {}
465 
466  private:
467  virtual void Notify (void)
468  {
469  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3);
470  }
471  OBJ m_obj;
472  MEM m_function;
473  typename TypeTraits<T1>::ReferencedType m_a1;
474  typename TypeTraits<T2>::ReferencedType m_a2;
475  typename TypeTraits<T3>::ReferencedType m_a3;
476  } *ev = new EventMemberImpl3 (obj, mem_ptr, a1, a2, a3);
477  return ev;
478 }
479 
480 template <typename MEM, typename OBJ,
481  typename T1, typename T2, typename T3, typename T4>
482 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4)
483 {
484  // four argument version
485  class EventMemberImpl4 : public EventImpl
486  {
487  public:
488  EventMemberImpl4 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4)
489  : m_obj (obj),
490  m_function (function),
491  m_a1 (a1),
492  m_a2 (a2),
493  m_a3 (a3),
494  m_a4 (a4)
495  {}
496 
497  protected:
498  virtual ~EventMemberImpl4 ()
499  {}
500 
501  private:
502  virtual void Notify (void)
503  {
504  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3, m_a4);
505  }
506  OBJ m_obj;
507  MEM m_function;
508  typename TypeTraits<T1>::ReferencedType m_a1;
509  typename TypeTraits<T2>::ReferencedType m_a2;
510  typename TypeTraits<T3>::ReferencedType m_a3;
511  typename TypeTraits<T4>::ReferencedType m_a4;
512  } *ev = new EventMemberImpl4 (obj, mem_ptr, a1, a2, a3, a4);
513  return ev;
514 }
515 
516 template <typename MEM, typename OBJ,
517  typename T1, typename T2, typename T3, typename T4, typename T5>
518 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj,
519  T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
520 {
521  // five argument version
522  class EventMemberImpl5 : public EventImpl
523  {
524  public:
525  EventMemberImpl5 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
526  : m_obj (obj),
527  m_function (function),
528  m_a1 (a1),
529  m_a2 (a2),
530  m_a3 (a3),
531  m_a4 (a4),
532  m_a5 (a5)
533  {}
534 
535  protected:
536  virtual ~EventMemberImpl5 ()
537  {}
538 
539  private:
540  virtual void Notify (void)
541  {
542  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5);
543  }
544  OBJ m_obj;
545  MEM m_function;
546  typename TypeTraits<T1>::ReferencedType m_a1;
547  typename TypeTraits<T2>::ReferencedType m_a2;
548  typename TypeTraits<T3>::ReferencedType m_a3;
549  typename TypeTraits<T4>::ReferencedType m_a4;
550  typename TypeTraits<T5>::ReferencedType m_a5;
551  } *ev = new EventMemberImpl5 (obj, mem_ptr, a1, a2, a3, a4, a5);
552  return ev;
553 }
554 
555 template <typename MEM, typename OBJ,
556  typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
557 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj,
558  T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
559 {
560  // six argument version
561  class EventMemberImpl6 : public EventImpl
562  {
563  public:
564  EventMemberImpl6 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
565  : m_obj (obj),
566  m_function (function),
567  m_a1 (a1),
568  m_a2 (a2),
569  m_a3 (a3),
570  m_a4 (a4),
571  m_a5 (a5),
572  m_a6 (a6)
573  {}
574 
575  protected:
576  virtual ~EventMemberImpl6 ()
577  {}
578 
579  private:
580  virtual void Notify (void)
581  {
582  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
583  }
584  OBJ m_obj;
585  MEM m_function;
586  typename TypeTraits<T1>::ReferencedType m_a1;
587  typename TypeTraits<T2>::ReferencedType m_a2;
588  typename TypeTraits<T3>::ReferencedType m_a3;
589  typename TypeTraits<T4>::ReferencedType m_a4;
590  typename TypeTraits<T5>::ReferencedType m_a5;
591  typename TypeTraits<T6>::ReferencedType m_a6;
592  } *ev = new EventMemberImpl6 (obj, mem_ptr, a1, a2, a3, a4, a5, a6);
593  return ev;
594 }
595 
596 template <typename U1, typename T1>
597 EventImpl * MakeEvent (void (*f)(U1), T1 a1)
598 {
599  // one arg version
600  class EventFunctionImpl1 : public EventImpl
601  {
602  public:
603  [[maybe_unused]]
604  typedef void (*F)(U1);
605 
606  EventFunctionImpl1 (F function, T1 a1)
607  : m_function (function),
608  m_a1 (a1)
609  {}
610 
611  protected:
612  virtual ~EventFunctionImpl1 ()
613  {}
614 
615  private:
616  virtual void Notify (void)
617  {
618  (*m_function)(m_a1);
619  }
620  F m_function;
621  typename TypeTraits<T1>::ReferencedType m_a1;
622  } *ev = new EventFunctionImpl1 (f, a1);
623  return ev;
624 }
625 
626 template <typename U1, typename U2, typename T1, typename T2>
627 EventImpl * MakeEvent (void (*f)(U1,U2), T1 a1, T2 a2)
628 {
629  // two arg version
630  class EventFunctionImpl2 : public EventImpl
631  {
632  public:
633  [[maybe_unused]]
634  typedef void (*F)(U1, U2);
635 
636  EventFunctionImpl2 (F function, T1 a1, T2 a2)
637  : m_function (function),
638  m_a1 (a1),
639  m_a2 (a2)
640  {}
641 
642  protected:
643  virtual ~EventFunctionImpl2 ()
644  {}
645 
646  private:
647  virtual void Notify (void)
648  {
649  (*m_function)(m_a1, m_a2);
650  }
651  F m_function;
652  typename TypeTraits<T1>::ReferencedType m_a1;
653  typename TypeTraits<T2>::ReferencedType m_a2;
654  } *ev = new EventFunctionImpl2 (f, a1, a2);
655  return ev;
656 }
657 
658 template <typename U1, typename U2, typename U3,
659  typename T1, typename T2, typename T3>
660 EventImpl * MakeEvent (void (*f)(U1,U2,U3), T1 a1, T2 a2, T3 a3)
661 {
662  // three arg version
663  class EventFunctionImpl3 : public EventImpl
664  {
665  public:
666  [[maybe_unused]]
667  typedef void (*F)(U1, U2, U3);
668 
669  EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3)
670  : m_function (function),
671  m_a1 (a1),
672  m_a2 (a2),
673  m_a3 (a3)
674  {}
675 
676  protected:
677  virtual ~EventFunctionImpl3 ()
678  {}
679 
680  private:
681  virtual void Notify (void)
682  {
683  (*m_function)(m_a1, m_a2, m_a3);
684  }
685  F m_function;
686  typename TypeTraits<T1>::ReferencedType m_a1;
687  typename TypeTraits<T2>::ReferencedType m_a2;
688  typename TypeTraits<T3>::ReferencedType m_a3;
689  } *ev = new EventFunctionImpl3 (f, a1, a2, a3);
690  return ev;
691 }
692 
693 template <typename U1, typename U2, typename U3, typename U4,
694  typename T1, typename T2, typename T3, typename T4>
695 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4)
696 {
697  // four arg version
698  class EventFunctionImpl4 : public EventImpl
699  {
700  public:
701  [[maybe_unused]]
702  typedef void (*F)(U1, U2, U3, U4);
703 
704  EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4)
705  : m_function (function),
706  m_a1 (a1),
707  m_a2 (a2),
708  m_a3 (a3),
709  m_a4 (a4)
710  {}
711 
712  protected:
713  virtual ~EventFunctionImpl4 ()
714  {}
715 
716  private:
717  virtual void Notify (void)
718  {
719  (*m_function)(m_a1, m_a2, m_a3, m_a4);
720  }
721  F m_function;
722  typename TypeTraits<T1>::ReferencedType m_a1;
723  typename TypeTraits<T2>::ReferencedType m_a2;
724  typename TypeTraits<T3>::ReferencedType m_a3;
725  typename TypeTraits<T4>::ReferencedType m_a4;
726  } *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4);
727  return ev;
728 }
729 
730 template <typename U1, typename U2, typename U3, typename U4, typename U5,
731  typename T1, typename T2, typename T3, typename T4, typename T5>
732 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
733 {
734  // five arg version
735  class EventFunctionImpl5 : public EventImpl
736  {
737  public:
738  [[maybe_unused]]
739  typedef void (*F)(U1,U2,U3,U4,U5);
740 
741  EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
742  : m_function (function),
743  m_a1 (a1),
744  m_a2 (a2),
745  m_a3 (a3),
746  m_a4 (a4),
747  m_a5 (a5)
748  {}
749 
750  protected:
751  virtual ~EventFunctionImpl5 ()
752  {}
753 
754  private:
755  virtual void Notify (void)
756  {
757  (*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5);
758  }
759  F m_function;
760  typename TypeTraits<T1>::ReferencedType m_a1;
761  typename TypeTraits<T2>::ReferencedType m_a2;
762  typename TypeTraits<T3>::ReferencedType m_a3;
763  typename TypeTraits<T4>::ReferencedType m_a4;
764  typename TypeTraits<T5>::ReferencedType m_a5;
765  } *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5);
766  return ev;
767 }
768 
769 template <typename U1, typename U2, typename U3, typename U4, typename U5, typename U6,
770  typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
771 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4,U5,U6), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
772 {
773  // six arg version
774  class EventFunctionImpl6 : public EventImpl
775  {
776  public:
777  [[maybe_unused]]
778  typedef void (*F)(U1,U2,U3,U4,U5,U6);
779 
780  EventFunctionImpl6 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
781  : m_function (function),
782  m_a1 (a1),
783  m_a2 (a2),
784  m_a3 (a3),
785  m_a4 (a4),
786  m_a5 (a5),
787  m_a6 (a6)
788  {}
789 
790  protected:
791  virtual ~EventFunctionImpl6 ()
792  {}
793 
794  private:
795  virtual void Notify (void)
796  {
797  (*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
798  }
799  F m_function;
800  typename TypeTraits<T1>::ReferencedType m_a1;
801  typename TypeTraits<T2>::ReferencedType m_a2;
802  typename TypeTraits<T3>::ReferencedType m_a3;
803  typename TypeTraits<T4>::ReferencedType m_a4;
804  typename TypeTraits<T5>::ReferencedType m_a5;
805  typename TypeTraits<T6>::ReferencedType m_a6;
806  } *ev = new EventFunctionImpl6 (f, a1, a2, a3, a4, a5, a6);
807  return ev;
808 }
809 
810 } // namespace ns3
811 
812 #endif /* MAKE_EVENT_H */
ns3::TypeTraits
Inspect a type to deduce its features.
Definition: type-traits.h:40
ns3::MakeEvent
EventImpl * MakeEvent(void(*f)(void))
Make an EventImpl from a function pointer taking varying numbers of arguments.
Definition: make-event.cc:34
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::EventMemberImplObjTraits< T * >::GetReference
static T & GetReference(T *p)
Definition: make-event.h:352
event-impl.h
ns3::EventImpl declarations.
ns3::TypeTraits::ReferencedType
ReferenceTraits< T >::ReferencedType ReferencedType
Referenced type.
Definition: type-traits.h:766
f
double f(double x, void *params)
Definition: 80211b.c:70
ns3::EventImpl
A simulation event.
Definition: event-impl.h:45
type-traits.h
ns3::TypeTraits introspection declaration and template implementation.
ns3::EventMemberImplObjTraits
Helper for the MakeEvent functions which take a class method.
Definition: make-event.h:333