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  typedef void (*F)(U1);
604 
605  EventFunctionImpl1 (F function, T1 a1)
606  : m_function (function),
607  m_a1 (a1)
608  {}
609 
610  protected:
611  virtual ~EventFunctionImpl1 ()
612  {}
613 
614  private:
615  virtual void Notify (void)
616  {
617  (*m_function)(m_a1);
618  }
619  F m_function;
620  typename TypeTraits<T1>::ReferencedType m_a1;
621  } *ev = new EventFunctionImpl1 (f, a1);
622  return ev;
623 }
624 
625 template <typename U1, typename U2, typename T1, typename T2>
626 EventImpl * MakeEvent (void (*f)(U1,U2), T1 a1, T2 a2)
627 {
628  // two arg version
629  class EventFunctionImpl2 : public EventImpl
630  {
631  public:
632  typedef void (*F)(U1, U2);
633 
634  EventFunctionImpl2 (F function, T1 a1, T2 a2)
635  : m_function (function),
636  m_a1 (a1),
637  m_a2 (a2)
638  {}
639 
640  protected:
641  virtual ~EventFunctionImpl2 ()
642  {}
643 
644  private:
645  virtual void Notify (void)
646  {
647  (*m_function)(m_a1, m_a2);
648  }
649  F m_function;
650  typename TypeTraits<T1>::ReferencedType m_a1;
651  typename TypeTraits<T2>::ReferencedType m_a2;
652  } *ev = new EventFunctionImpl2 (f, a1, a2);
653  return ev;
654 }
655 
656 template <typename U1, typename U2, typename U3,
657  typename T1, typename T2, typename T3>
658 EventImpl * MakeEvent (void (*f)(U1,U2,U3), T1 a1, T2 a2, T3 a3)
659 {
660  // three arg version
661  class EventFunctionImpl3 : public EventImpl
662  {
663  public:
664  typedef void (*F)(U1, U2, U3);
665 
666  EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3)
667  : m_function (function),
668  m_a1 (a1),
669  m_a2 (a2),
670  m_a3 (a3)
671  {}
672 
673  protected:
674  virtual ~EventFunctionImpl3 ()
675  {}
676 
677  private:
678  virtual void Notify (void)
679  {
680  (*m_function)(m_a1, m_a2, m_a3);
681  }
682  F m_function;
683  typename TypeTraits<T1>::ReferencedType m_a1;
684  typename TypeTraits<T2>::ReferencedType m_a2;
685  typename TypeTraits<T3>::ReferencedType m_a3;
686  } *ev = new EventFunctionImpl3 (f, a1, a2, a3);
687  return ev;
688 }
689 
690 template <typename U1, typename U2, typename U3, typename U4,
691  typename T1, typename T2, typename T3, typename T4>
692 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4)
693 {
694  // four arg version
695  class EventFunctionImpl4 : public EventImpl
696  {
697  public:
698  typedef void (*F)(U1, U2, U3, U4);
699 
700  EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4)
701  : m_function (function),
702  m_a1 (a1),
703  m_a2 (a2),
704  m_a3 (a3),
705  m_a4 (a4)
706  {}
707 
708  protected:
709  virtual ~EventFunctionImpl4 ()
710  {}
711 
712  private:
713  virtual void Notify (void)
714  {
715  (*m_function)(m_a1, m_a2, m_a3, m_a4);
716  }
717  F m_function;
718  typename TypeTraits<T1>::ReferencedType m_a1;
719  typename TypeTraits<T2>::ReferencedType m_a2;
720  typename TypeTraits<T3>::ReferencedType m_a3;
721  typename TypeTraits<T4>::ReferencedType m_a4;
722  } *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4);
723  return ev;
724 }
725 
726 template <typename U1, typename U2, typename U3, typename U4, typename U5,
727  typename T1, typename T2, typename T3, typename T4, typename T5>
728 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
729 {
730  // five arg version
731  class EventFunctionImpl5 : public EventImpl
732  {
733  public:
734  typedef void (*F)(U1,U2,U3,U4,U5);
735 
736  EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
737  : m_function (function),
738  m_a1 (a1),
739  m_a2 (a2),
740  m_a3 (a3),
741  m_a4 (a4),
742  m_a5 (a5)
743  {}
744 
745  protected:
746  virtual ~EventFunctionImpl5 ()
747  {}
748 
749  private:
750  virtual void Notify (void)
751  {
752  (*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5);
753  }
754  F m_function;
755  typename TypeTraits<T1>::ReferencedType m_a1;
756  typename TypeTraits<T2>::ReferencedType m_a2;
757  typename TypeTraits<T3>::ReferencedType m_a3;
758  typename TypeTraits<T4>::ReferencedType m_a4;
759  typename TypeTraits<T5>::ReferencedType m_a5;
760  } *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5);
761  return ev;
762 }
763 
764 template <typename U1, typename U2, typename U3, typename U4, typename U5, typename U6,
765  typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
766 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4,U5,U6), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
767 {
768  // six arg version
769  class EventFunctionImpl6 : public EventImpl
770  {
771  public:
772  typedef void (*F)(U1,U2,U3,U4,U5,U6);
773 
774  EventFunctionImpl6 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
775  : m_function (function),
776  m_a1 (a1),
777  m_a2 (a2),
778  m_a3 (a3),
779  m_a4 (a4),
780  m_a5 (a5),
781  m_a6 (a6)
782  {}
783 
784  protected:
785  virtual ~EventFunctionImpl6 ()
786  {}
787 
788  private:
789  virtual void Notify (void)
790  {
791  (*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
792  }
793  F m_function;
794  typename TypeTraits<T1>::ReferencedType m_a1;
795  typename TypeTraits<T2>::ReferencedType m_a2;
796  typename TypeTraits<T3>::ReferencedType m_a3;
797  typename TypeTraits<T4>::ReferencedType m_a4;
798  typename TypeTraits<T5>::ReferencedType m_a5;
799  typename TypeTraits<T6>::ReferencedType m_a6;
800  } *ev = new EventFunctionImpl6 (f, a1, a2, a3, a4, a5, a6);
801  return ev;
802 }
803 
804 } // namespace ns3
805 
806 #endif /* MAKE_EVENT_H */
ns3::EventImpl declarations.
Helper for the MakeEvent functions which take a class method.
Definition: make-event.h:333
ReferenceTraits< T >::ReferencedType ReferencedType
Referenced type.
Definition: type-traits.h:766
double f(double x, void *params)
Definition: 80211b.c:70
Every class exported by the ns3 library is enclosed in the ns3 namespace.
A simulation event.
Definition: event-impl.h:44
Inspect a type to deduce its features.
Definition: type-traits.h:39
ns3::TypeTraits introspection declaration and template implementation.
EventImpl * MakeEvent(void(*f)(void))
Make an EventImpl from a function pointer taking varying numbers of arguments.
Definition: make-event.cc:34