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  }
370  virtual ~EventMemberImpl0 ()
371  {
372  }
373 private:
374  virtual void Notify (void)
375  {
376  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)();
377  }
378  OBJ m_obj;
379  MEM m_function;
380  } *ev = new EventMemberImpl0 (obj, mem_ptr);
381  return ev;
382 }
383 
384 
385 template <typename MEM, typename OBJ,
386  typename T1>
387 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1)
388 {
389  // one argument version
390  class EventMemberImpl1 : public EventImpl
391  {
392 public:
393  EventMemberImpl1 (OBJ obj, MEM function, T1 a1)
394  : m_obj (obj),
395  m_function (function),
396  m_a1 (a1)
397  {
398  }
399 protected:
400  virtual ~EventMemberImpl1 ()
401  {
402  }
403 private:
404  virtual void Notify (void)
405  {
406  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1);
407  }
408  OBJ m_obj;
409  MEM m_function;
410  typename TypeTraits<T1>::ReferencedType m_a1;
411  } *ev = new EventMemberImpl1 (obj, mem_ptr, a1);
412  return ev;
413 }
414 
415 template <typename MEM, typename OBJ,
416  typename T1, typename T2>
417 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2)
418 {
419  // two argument version
420  class EventMemberImpl2 : public EventImpl
421  {
422 public:
423  EventMemberImpl2 (OBJ obj, MEM function, T1 a1, T2 a2)
424  : m_obj (obj),
425  m_function (function),
426  m_a1 (a1),
427  m_a2 (a2)
428  {
429  }
430 protected:
431  virtual ~EventMemberImpl2 ()
432  {
433  }
434 private:
435  virtual void Notify (void)
436  {
437  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2);
438  }
439  OBJ m_obj;
440  MEM m_function;
441  typename TypeTraits<T1>::ReferencedType m_a1;
442  typename TypeTraits<T2>::ReferencedType m_a2;
443  } *ev = new EventMemberImpl2 (obj, mem_ptr, a1, a2);
444  return ev;
445 }
446 
447 template <typename MEM, typename OBJ,
448  typename T1, typename T2, typename T3>
449 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3)
450 {
451  // three argument version
452  class EventMemberImpl3 : public EventImpl
453  {
454 public:
455  EventMemberImpl3 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3)
456  : m_obj (obj),
457  m_function (function),
458  m_a1 (a1),
459  m_a2 (a2),
460  m_a3 (a3)
461  {
462  }
463 protected:
464  virtual ~EventMemberImpl3 ()
465  {
466  }
467 private:
468  virtual void Notify (void)
469  {
470  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3);
471  }
472  OBJ m_obj;
473  MEM m_function;
474  typename TypeTraits<T1>::ReferencedType m_a1;
475  typename TypeTraits<T2>::ReferencedType m_a2;
476  typename TypeTraits<T3>::ReferencedType m_a3;
477  } *ev = new EventMemberImpl3 (obj, mem_ptr, a1, a2, a3);
478  return ev;
479 }
480 
481 template <typename MEM, typename OBJ,
482  typename T1, typename T2, typename T3, typename T4>
483 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4)
484 {
485  // four argument version
486  class EventMemberImpl4 : public EventImpl
487  {
488 public:
489  EventMemberImpl4 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4)
490  : m_obj (obj),
491  m_function (function),
492  m_a1 (a1),
493  m_a2 (a2),
494  m_a3 (a3),
495  m_a4 (a4)
496  {
497  }
498 protected:
499  virtual ~EventMemberImpl4 ()
500  {
501  }
502 private:
503  virtual void Notify (void)
504  {
505  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3, m_a4);
506  }
507  OBJ m_obj;
508  MEM m_function;
509  typename TypeTraits<T1>::ReferencedType m_a1;
510  typename TypeTraits<T2>::ReferencedType m_a2;
511  typename TypeTraits<T3>::ReferencedType m_a3;
512  typename TypeTraits<T4>::ReferencedType m_a4;
513  } *ev = new EventMemberImpl4 (obj, mem_ptr, a1, a2, a3, a4);
514  return ev;
515 }
516 
517 template <typename MEM, typename OBJ,
518  typename T1, typename T2, typename T3, typename T4, typename T5>
519 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj,
520  T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
521 {
522  // five argument version
523  class EventMemberImpl5 : public EventImpl
524  {
525 public:
526  EventMemberImpl5 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
527  : m_obj (obj),
528  m_function (function),
529  m_a1 (a1),
530  m_a2 (a2),
531  m_a3 (a3),
532  m_a4 (a4),
533  m_a5 (a5)
534  {
535  }
536 protected:
537  virtual ~EventMemberImpl5 ()
538  {
539  }
540 private:
541  virtual void Notify (void)
542  {
543  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5);
544  }
545  OBJ m_obj;
546  MEM m_function;
547  typename TypeTraits<T1>::ReferencedType m_a1;
548  typename TypeTraits<T2>::ReferencedType m_a2;
549  typename TypeTraits<T3>::ReferencedType m_a3;
550  typename TypeTraits<T4>::ReferencedType m_a4;
551  typename TypeTraits<T5>::ReferencedType m_a5;
552  } *ev = new EventMemberImpl5 (obj, mem_ptr, a1, a2, a3, a4, a5);
553  return ev;
554 }
555 
556 template <typename MEM, typename OBJ,
557  typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
558 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj,
559  T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
560 {
561  // six argument version
562  class EventMemberImpl6 : public EventImpl
563  {
564 public:
565  EventMemberImpl6 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
566  : m_obj (obj),
567  m_function (function),
568  m_a1 (a1),
569  m_a2 (a2),
570  m_a3 (a3),
571  m_a4 (a4),
572  m_a5 (a5),
573  m_a6 (a6)
574  {
575  }
576 protected:
577  virtual ~EventMemberImpl6 ()
578  {
579  }
580 private:
581  virtual void Notify (void)
582  {
583  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
584  }
585  OBJ m_obj;
586  MEM m_function;
587  typename TypeTraits<T1>::ReferencedType m_a1;
588  typename TypeTraits<T2>::ReferencedType m_a2;
589  typename TypeTraits<T3>::ReferencedType m_a3;
590  typename TypeTraits<T4>::ReferencedType m_a4;
591  typename TypeTraits<T5>::ReferencedType m_a5;
592  typename TypeTraits<T6>::ReferencedType m_a6;
593  } *ev = new EventMemberImpl6 (obj, mem_ptr, a1, a2, a3, a4, a5, a6);
594  return ev;
595 }
596 
597 template <typename U1, typename T1>
598 EventImpl * MakeEvent (void (*f)(U1), T1 a1)
599 {
600  // one arg version
601  class EventFunctionImpl1 : public EventImpl
602  {
603 public:
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  typedef void (*F)(U1, U2);
634 
635  EventFunctionImpl2 (F function, T1 a1, T2 a2)
636  : m_function (function),
637  m_a1 (a1),
638  m_a2 (a2)
639  {
640  }
641 protected:
642  virtual ~EventFunctionImpl2 ()
643  {
644  }
645 private:
646  virtual void Notify (void)
647  {
648  (*m_function)(m_a1, m_a2);
649  }
650  F m_function;
651  typename TypeTraits<T1>::ReferencedType m_a1;
652  typename TypeTraits<T2>::ReferencedType m_a2;
653  } *ev = new EventFunctionImpl2 (f, a1, a2);
654  return ev;
655 }
656 
657 template <typename U1, typename U2, typename U3,
658  typename T1, typename T2, typename T3>
659 EventImpl * MakeEvent (void (*f)(U1,U2,U3), T1 a1, T2 a2, T3 a3)
660 {
661  // three arg version
662  class EventFunctionImpl3 : public EventImpl
663  {
664 public:
665  typedef void (*F)(U1, U2, U3);
666 
667  EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3)
668  : m_function (function),
669  m_a1 (a1),
670  m_a2 (a2),
671  m_a3 (a3)
672  {
673  }
674 protected:
675  virtual ~EventFunctionImpl3 ()
676  {
677  }
678 private:
679  virtual void Notify (void)
680  {
681  (*m_function)(m_a1, m_a2, m_a3);
682  }
683  F m_function;
684  typename TypeTraits<T1>::ReferencedType m_a1;
685  typename TypeTraits<T2>::ReferencedType m_a2;
686  typename TypeTraits<T3>::ReferencedType m_a3;
687  } *ev = new EventFunctionImpl3 (f, a1, a2, a3);
688  return ev;
689 }
690 
691 template <typename U1, typename U2, typename U3, typename U4,
692  typename T1, typename T2, typename T3, typename T4>
693 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4)
694 {
695  // four arg version
696  class EventFunctionImpl4 : public EventImpl
697  {
698 public:
699  typedef void (*F)(U1, U2, U3, U4);
700 
701  EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4)
702  : m_function (function),
703  m_a1 (a1),
704  m_a2 (a2),
705  m_a3 (a3),
706  m_a4 (a4)
707  {
708  }
709 protected:
710  virtual ~EventFunctionImpl4 ()
711  {
712  }
713 private:
714  virtual void Notify (void)
715  {
716  (*m_function)(m_a1, m_a2, m_a3, m_a4);
717  }
718  F m_function;
719  typename TypeTraits<T1>::ReferencedType m_a1;
720  typename TypeTraits<T2>::ReferencedType m_a2;
721  typename TypeTraits<T3>::ReferencedType m_a3;
722  typename TypeTraits<T4>::ReferencedType m_a4;
723  } *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4);
724  return ev;
725 }
726 
727 template <typename U1, typename U2, typename U3, typename U4, typename U5,
728  typename T1, typename T2, typename T3, typename T4, typename T5>
729 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
730 {
731  // five arg version
732  class EventFunctionImpl5 : public EventImpl
733  {
734 public:
735  typedef void (*F)(U1,U2,U3,U4,U5);
736 
737  EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
738  : m_function (function),
739  m_a1 (a1),
740  m_a2 (a2),
741  m_a3 (a3),
742  m_a4 (a4),
743  m_a5 (a5)
744  {
745  }
746 protected:
747  virtual ~EventFunctionImpl5 ()
748  {
749  }
750 private:
751  virtual void Notify (void)
752  {
753  (*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5);
754  }
755  F m_function;
756  typename TypeTraits<T1>::ReferencedType m_a1;
757  typename TypeTraits<T2>::ReferencedType m_a2;
758  typename TypeTraits<T3>::ReferencedType m_a3;
759  typename TypeTraits<T4>::ReferencedType m_a4;
760  typename TypeTraits<T5>::ReferencedType m_a5;
761  } *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5);
762  return ev;
763 }
764 
765 template <typename U1, typename U2, typename U3, typename U4, typename U5, typename U6,
766  typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
767 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4,U5,U6), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
768 {
769  // six arg version
770  class EventFunctionImpl6 : public EventImpl
771  {
772 public:
773  typedef void (*F)(U1,U2,U3,U4,U5,U6);
774 
775  EventFunctionImpl6 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
776  : m_function (function),
777  m_a1 (a1),
778  m_a2 (a2),
779  m_a3 (a3),
780  m_a4 (a4),
781  m_a5 (a5),
782  m_a6 (a6)
783  {
784  }
785 protected:
786  virtual ~EventFunctionImpl6 ()
787  {
788  }
789 private:
790  virtual void Notify (void)
791  {
792  (*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
793  }
794  F m_function;
795  typename TypeTraits<T1>::ReferencedType m_a1;
796  typename TypeTraits<T2>::ReferencedType m_a2;
797  typename TypeTraits<T3>::ReferencedType m_a3;
798  typename TypeTraits<T4>::ReferencedType m_a4;
799  typename TypeTraits<T5>::ReferencedType m_a5;
800  typename TypeTraits<T6>::ReferencedType m_a6;
801  } *ev = new EventFunctionImpl6 (f, a1, a2, a3, a4, a5, a6);
802  return ev;
803 }
804 
805 } // namespace ns3
806 
807 #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:576
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