A Discrete-Event Network Simulator
API
timer-impl.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 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  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #ifndef TIMER_IMPL_H
22 #define TIMER_IMPL_H
23 
24 #include "simulator.h"
25 #include "type-traits.h"
26 #include "fatal-error.h"
27 #include "int-to-type.h"
28 
36 namespace ns3 {
37 
42 class TimerImpl
43 {
44 public:
46  virtual ~TimerImpl ()
47  {
48  }
49 
58  template <typename T1>
59  void SetArgs (T1 a1);
66  template <typename T1, typename T2>
67  void SetArgs (T1 a1, T2 a2);
76  template <typename T1, typename T2, typename T3>
77  void SetArgs (T1 a1, T2 a2, T3 a3);
88  template <typename T1, typename T2, typename T3,
89  typename T4>
90  void SetArgs (T1 a1, T2 a2, T3 a3, T4 a4);
103  template <typename T1, typename T2, typename T3,
104  typename T4, typename T5>
105  void SetArgs (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
120  template <typename T1, typename T2, typename T3,
121  typename T4, typename T5, typename T6>
122  void SetArgs (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
131  virtual EventId Schedule (const Time &delay) = 0;
133  virtual void Invoke (void) = 0;
134 };
135 
136 } // namespace ns3
137 
138 
139 /********************************************************************
140  * Implementation of TimerImpl implementation functions.
141  ********************************************************************/
142 
143 namespace ns3 {
144 
152 template <typename T1>
153 struct TimerImplOne : public TimerImpl
154 {
160  virtual void SetArguments (T1 a1) = 0;
161 };
163 template <typename T1, typename T2>
164 struct TimerImplTwo : public TimerImpl
165 {
172  virtual void SetArguments (T1 a1,T2 a2) = 0;
173 };
175 template <typename T1, typename T2, typename T3>
176 struct TimerImplThree : public TimerImpl
177 {
185  virtual void SetArguments (T1 a1,T2 a2,T3 a3) = 0;
186 };
188 template <typename T1, typename T2, typename T3, typename T4>
189 struct TimerImplFour : public TimerImpl
190 {
199  virtual void SetArguments (T1 a1,T2 a2,T3 a3, T4 a4) = 0;
200 };
202 template <typename T1, typename T2, typename T3, typename T4, typename T5>
203 struct TimerImplFive : public TimerImpl
204 {
214  virtual void SetArguments (T1 a1,T2 a2,T3 a3, T4 a4, T5 a5) = 0;
215 };
217 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
218 struct TimerImplSix : public TimerImpl
219 {
230  virtual void SetArguments (T1 a1,T2 a2,T3 a3, T4 a4, T5 a5, T6 a6) = 0;
231 };
232 
233 
235 template <typename T>
237 {
241  typedef const StoredType &ParameterType;
242 };
243 
251 template <typename FN>
252 TimerImpl *
254 {
257 }
258 
263 template <typename FN>
264 TimerImpl *
266 {
267  struct FnTimerImplZero : public TimerImpl
268  {
269  FnTimerImplZero (FN fn)
270  : m_fn (fn)
271  {
272  }
273  virtual EventId Schedule (const Time &delay)
274  {
275  return Simulator::Schedule (delay, m_fn);
276  }
277  virtual void Invoke (void)
278  {
279  m_fn ();
280  }
281  FN m_fn;
282  } *function = new FnTimerImplZero (fn);
283  return function;
284 }
285 
290 template <typename FN>
291 TimerImpl *
293 {
295  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
296  typedef typename TimerTraits<T1>::StoredType T1Stored;
297 
298  struct FnTimerImplOne : public TimerImplOne<T1Parameter>
299  {
300  FnTimerImplOne (FN fn)
301  : m_fn (fn)
302  {
303  }
304  virtual void SetArguments (T1Parameter a1)
305  {
306  m_a1 = a1;
307  }
308  virtual EventId Schedule (const Time &delay)
309  {
310  return Simulator::Schedule (delay, m_fn, m_a1);
311  }
312  virtual void Invoke (void)
313  {
314  m_fn (m_a1);
315  }
316  FN m_fn;
317  T1Stored m_a1;
318  } *function = new FnTimerImplOne (fn);
319  return function;
320 }
321 
326 template <typename FN>
327 TimerImpl *
329 {
331  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
332  typedef typename TimerTraits<T1>::StoredType T1Stored;
334  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
335  typedef typename TimerTraits<T2>::StoredType T2Stored;
336 
337  struct FnTimerImplTwo : public TimerImplTwo<T1Parameter,T2Parameter>
338  {
339  FnTimerImplTwo (FN fn)
340  : m_fn (fn)
341  {
342  }
343  virtual void SetArguments (T1Parameter a1, T2Parameter a2)
344  {
345  m_a1 = a1;
346  m_a2 = a2;
347  }
348  virtual EventId Schedule (const Time &delay)
349  {
350  return Simulator::Schedule (delay, m_fn, m_a1, m_a2);
351  }
352  virtual void Invoke (void)
353  {
354  m_fn (m_a1, m_a2);
355  }
356  FN m_fn;
357  T1Stored m_a1;
358  T2Stored m_a2;
359  } *function = new FnTimerImplTwo (fn);
360  return function;
361 }
362 
367 template <typename FN>
368 TimerImpl *
370 {
372  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
373  typedef typename TimerTraits<T1>::StoredType T1Stored;
375  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
376  typedef typename TimerTraits<T2>::StoredType T2Stored;
378  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
379  typedef typename TimerTraits<T3>::StoredType T3Stored;
380 
381  struct FnTimerImplThree : public TimerImplThree<T1Parameter,T2Parameter,T3Parameter>
382  {
383  FnTimerImplThree (FN fn)
384  : m_fn (fn)
385  {
386  }
387  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3)
388  {
389  m_a1 = a1;
390  m_a2 = a2;
391  m_a3 = a3;
392  }
393  virtual EventId Schedule (const Time &delay)
394  {
395  return Simulator::Schedule (delay, m_fn, m_a1, m_a2, m_a3);
396  }
397  virtual void Invoke (void)
398  {
399  m_fn (m_a1, m_a2, m_a3);
400  }
401  FN m_fn;
402  T1Stored m_a1;
403  T2Stored m_a2;
404  T3Stored m_a3;
405  } *function = new FnTimerImplThree (fn);
406  return function;
407 }
408 
413 template <typename FN>
414 TimerImpl *
416 {
418  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
419  typedef typename TimerTraits<T1>::StoredType T1Stored;
421  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
422  typedef typename TimerTraits<T2>::StoredType T2Stored;
424  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
425  typedef typename TimerTraits<T3>::StoredType T3Stored;
427  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
428  typedef typename TimerTraits<T4>::StoredType T4Stored;
429 
430  struct FnTimerImplFour : public TimerImplFour<T1Parameter,T2Parameter,T3Parameter,T4Parameter>
431  {
432  FnTimerImplFour (FN fn)
433  : m_fn (fn)
434  {
435  }
436  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4)
437  {
438  m_a1 = a1;
439  m_a2 = a2;
440  m_a3 = a3;
441  m_a4 = a4;
442  }
443  virtual EventId Schedule (const Time &delay)
444  {
445  return Simulator::Schedule (delay, m_fn, m_a1, m_a2, m_a3, m_a4);
446  }
447  virtual void Invoke (void)
448  {
449  m_fn (m_a1, m_a2, m_a3, m_a4);
450  }
451  FN m_fn;
452  T1Stored m_a1;
453  T2Stored m_a2;
454  T3Stored m_a3;
455  T4Stored m_a4;
456  } *function = new FnTimerImplFour (fn);
457  return function;
458 }
459 
464 template <typename FN>
465 TimerImpl *
467 {
469  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
470  typedef typename TimerTraits<T1>::StoredType T1Stored;
472  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
473  typedef typename TimerTraits<T2>::StoredType T2Stored;
475  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
476  typedef typename TimerTraits<T3>::StoredType T3Stored;
478  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
479  typedef typename TimerTraits<T4>::StoredType T4Stored;
481  typedef typename TimerTraits<T5>::ParameterType T5Parameter;
482  typedef typename TimerTraits<T5>::StoredType T5Stored;
483 
484  struct FnTimerImplFive : public TimerImplFive<T1Parameter,T2Parameter,T3Parameter,T4Parameter,T5Parameter>
485  {
486  FnTimerImplFive (FN fn)
487  : m_fn (fn)
488  {
489  }
490  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4, T5Parameter a5)
491  {
492  m_a1 = a1;
493  m_a2 = a2;
494  m_a3 = a3;
495  m_a4 = a4;
496  m_a5 = a5;
497  }
498  virtual EventId Schedule (const Time &delay)
499  {
500  return Simulator::Schedule (delay, m_fn, m_a1, m_a2, m_a3, m_a4, m_a5);
501  }
502  virtual void Invoke (void)
503  {
504  m_fn (m_a1, m_a2, m_a3, m_a4, m_a5);
505  }
506  FN m_fn;
507  T1Stored m_a1;
508  T2Stored m_a2;
509  T3Stored m_a3;
510  T4Stored m_a4;
511  T5Stored m_a5;
512  } *function = new FnTimerImplFive (fn);
513  return function;
514 }
515 
520 template <typename FN>
521 TimerImpl *
523 {
525  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
526  typedef typename TimerTraits<T1>::StoredType T1Stored;
528  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
529  typedef typename TimerTraits<T2>::StoredType T2Stored;
531  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
532  typedef typename TimerTraits<T3>::StoredType T3Stored;
534  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
535  typedef typename TimerTraits<T4>::StoredType T4Stored;
537  typedef typename TimerTraits<T5>::ParameterType T5Parameter;
538  typedef typename TimerTraits<T5>::StoredType T5Stored;
540  typedef typename TimerTraits<T6>::ParameterType T6Parameter;
541  typedef typename TimerTraits<T6>::StoredType T6Stored;
542 
543  struct FnTimerImplSix : public TimerImplSix<T1Parameter,T2Parameter,T3Parameter,T4Parameter,T5Parameter,T6Parameter>
544  {
545  FnTimerImplSix (FN fn)
546  : m_fn (fn)
547  {
548  }
549  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4, T5Parameter a5, T6Parameter a6)
550  {
551  m_a1 = a1;
552  m_a2 = a2;
553  m_a3 = a3;
554  m_a4 = a4;
555  m_a5 = a5;
556  m_a6 = a6;
557  }
558  virtual EventId Schedule (const Time &delay)
559  {
560  return Simulator::Schedule (delay, m_fn, m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
561  }
562  virtual void Invoke (void)
563  {
564  m_fn (m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
565  }
566  FN m_fn;
567  T1Stored m_a1;
568  T2Stored m_a2;
569  T3Stored m_a3;
570  T4Stored m_a4;
571  T5Stored m_a5;
572  T6Stored m_a6;
573  } *function = new FnTimerImplSix (fn);
574  return function;
575 }
576 
577 
587 template <typename T>
589 
590 
600 template <typename T>
602 {
609  static T &GetReference (T *p)
610  {
611  return *p;
612  }
613 };
614 
625 template <typename MEM_PTR, typename OBJ_PTR>
626 TimerImpl *
627 MakeTimerImpl (MEM_PTR memPtr, OBJ_PTR objPtr)
628 {
631 }
632 
637 template <typename MEM_PTR, typename OBJ_PTR>
638 TimerImpl *
639 MakeTimerImpl (IntToType<0>, MEM_PTR memPtr, OBJ_PTR objPtr)
640 {
641  struct MemFnTimerImplZero : public TimerImpl
642  {
643  MemFnTimerImplZero (MEM_PTR memPtr, OBJ_PTR objPtr)
644  : m_memPtr (memPtr),
645  m_objPtr (objPtr)
646  {
647  }
648  virtual EventId Schedule (const Time &delay)
649  {
650  return Simulator::Schedule (delay, m_memPtr, m_objPtr);
651  }
652  virtual void Invoke (void)
653  {
654  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)();
655  }
656  MEM_PTR m_memPtr;
657  OBJ_PTR m_objPtr;
658  } *function = new MemFnTimerImplZero (memPtr, objPtr);
659  return function;
660 }
661 
666 template <typename MEM_PTR, typename OBJ_PTR>
667 TimerImpl *
668 MakeTimerImpl (IntToType<1>, MEM_PTR memPtr, OBJ_PTR objPtr)
669 {
671  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
672  typedef typename TimerTraits<T1>::StoredType T1Stored;
673 
674  struct MemFnTimerImplOne : public TimerImplOne<T1Parameter>
675  {
676  MemFnTimerImplOne (MEM_PTR memPtr, OBJ_PTR objPtr)
677  : m_memPtr (memPtr),
678  m_objPtr (objPtr)
679  {
680  }
681  virtual void SetArguments (T1Parameter a1)
682  {
683  m_a1 = a1;
684  }
685  virtual EventId Schedule (const Time &delay)
686  {
687  return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1);
688  }
689  virtual void Invoke (void)
690  {
691  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1);
692  }
693  MEM_PTR m_memPtr;
694  OBJ_PTR m_objPtr;
695  T1Stored m_a1;
696  } *function = new MemFnTimerImplOne (memPtr, objPtr);
697  return function;
698 }
699 
704 template <typename MEM_PTR, typename OBJ_PTR>
705 TimerImpl *
706 MakeTimerImpl (IntToType<2>, MEM_PTR memPtr, OBJ_PTR objPtr)
707 {
709  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
710  typedef typename TimerTraits<T1>::StoredType T1Stored;
712  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
713  typedef typename TimerTraits<T2>::StoredType T2Stored;
714 
715  struct MemFnTimerImplTwo : public TimerImplTwo<T1Parameter,T2Parameter>
716  {
717  MemFnTimerImplTwo (MEM_PTR memPtr, OBJ_PTR objPtr)
718  : m_memPtr (memPtr),
719  m_objPtr (objPtr)
720  {
721  }
722  virtual void SetArguments (T1Parameter a1, T2Parameter a2)
723  {
724  m_a1 = a1;
725  m_a2 = a2;
726  }
727  virtual EventId Schedule (const Time &delay)
728  {
729  return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2);
730  }
731  virtual void Invoke (void)
732  {
733  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2);
734  }
735  MEM_PTR m_memPtr;
736  OBJ_PTR m_objPtr;
737  T1Stored m_a1;
738  T2Stored m_a2;
739  } *function = new MemFnTimerImplTwo (memPtr, objPtr);
740  return function;
741 }
742 
747 template <typename MEM_PTR, typename OBJ_PTR>
748 TimerImpl *
749 MakeTimerImpl (IntToType<3>, MEM_PTR memPtr, OBJ_PTR objPtr)
750 {
752  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
753  typedef typename TimerTraits<T1>::StoredType T1Stored;
755  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
756  typedef typename TimerTraits<T2>::StoredType T2Stored;
758  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
759  typedef typename TimerTraits<T3>::StoredType T3Stored;
760 
761  struct MemFnTimerImplThree : public TimerImplThree<T1Parameter,T2Parameter,T3Parameter>
762  {
763  MemFnTimerImplThree (MEM_PTR memPtr, OBJ_PTR objPtr)
764  : m_memPtr (memPtr),
765  m_objPtr (objPtr)
766  {
767  }
768  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3)
769  {
770  m_a1 = a1;
771  m_a2 = a2;
772  m_a3 = a3;
773  }
774  virtual EventId Schedule (const Time &delay)
775  {
776  return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3);
777  }
778  virtual void Invoke (void)
779  {
780  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2, m_a3);
781  }
782  MEM_PTR m_memPtr;
783  OBJ_PTR m_objPtr;
784  T1Stored m_a1;
785  T2Stored m_a2;
786  T3Stored m_a3;
787  } *function = new MemFnTimerImplThree (memPtr, objPtr);
788  return function;
789 }
790 
795 template <typename MEM_PTR, typename OBJ_PTR>
796 TimerImpl *
797 MakeTimerImpl (IntToType<4>, MEM_PTR memPtr, OBJ_PTR objPtr)
798 {
800  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
801  typedef typename TimerTraits<T1>::StoredType T1Stored;
803  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
804  typedef typename TimerTraits<T2>::StoredType T2Stored;
806  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
807  typedef typename TimerTraits<T3>::StoredType T3Stored;
809  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
810  typedef typename TimerTraits<T4>::StoredType T4Stored;
811 
812  struct MemFnTimerImplFour : public TimerImplFour<T1Parameter,T2Parameter,T3Parameter,T4Parameter>
813  {
814  MemFnTimerImplFour (MEM_PTR memPtr, OBJ_PTR objPtr)
815  : m_memPtr (memPtr),
816  m_objPtr (objPtr)
817  {
818  }
819  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4)
820  {
821  m_a1 = a1;
822  m_a2 = a2;
823  m_a3 = a3;
824  m_a4 = a4;
825  }
826  virtual EventId Schedule (const Time &delay)
827  {
828  return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3, m_a4);
829  }
830  virtual void Invoke (void)
831  {
832  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2, m_a3, m_a4);
833  }
834  MEM_PTR m_memPtr;
835  OBJ_PTR m_objPtr;
836  T1Stored m_a1;
837  T2Stored m_a2;
838  T3Stored m_a3;
839  T4Stored m_a4;
840  } *function = new MemFnTimerImplFour (memPtr, objPtr);
841  return function;
842 }
843 
848 template <typename MEM_PTR, typename OBJ_PTR>
849 TimerImpl *
850 MakeTimerImpl (IntToType<5>, MEM_PTR memPtr, OBJ_PTR objPtr)
851 {
853  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
854  typedef typename TimerTraits<T1>::StoredType T1Stored;
856  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
857  typedef typename TimerTraits<T2>::StoredType T2Stored;
859  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
860  typedef typename TimerTraits<T3>::StoredType T3Stored;
862  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
863  typedef typename TimerTraits<T4>::StoredType T4Stored;
865  typedef typename TimerTraits<T5>::ParameterType T5Parameter;
866  typedef typename TimerTraits<T5>::StoredType T5Stored;
867 
868  struct MemFnTimerImplFive : public TimerImplFive<T1Parameter,T2Parameter,T3Parameter,T4Parameter,T5Parameter>
869  {
870  MemFnTimerImplFive (MEM_PTR memPtr, OBJ_PTR objPtr)
871  : m_memPtr (memPtr),
872  m_objPtr (objPtr)
873  {
874  }
875  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4,T5Parameter a5)
876  {
877  m_a1 = a1;
878  m_a2 = a2;
879  m_a3 = a3;
880  m_a4 = a4;
881  m_a5 = a5;
882  }
883  virtual EventId Schedule (const Time &delay)
884  {
885  return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3, m_a4, m_a5);
886  }
887  virtual void Invoke (void)
888  {
889  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2, m_a3, m_a4, m_a5);
890  }
891  MEM_PTR m_memPtr;
892  OBJ_PTR m_objPtr;
893  T1Stored m_a1;
894  T2Stored m_a2;
895  T3Stored m_a3;
896  T4Stored m_a4;
897  T5Stored m_a5;
898  } *function = new MemFnTimerImplFive (memPtr, objPtr);
899  return function;
900 }
901 
906 template <typename MEM_PTR, typename OBJ_PTR>
907 TimerImpl *
908 MakeTimerImpl (IntToType<6>, MEM_PTR memPtr, OBJ_PTR objPtr)
909 {
911  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
912  typedef typename TimerTraits<T1>::StoredType T1Stored;
914  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
915  typedef typename TimerTraits<T2>::StoredType T2Stored;
917  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
918  typedef typename TimerTraits<T3>::StoredType T3Stored;
920  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
921  typedef typename TimerTraits<T4>::StoredType T4Stored;
923  typedef typename TimerTraits<T5>::ParameterType T5Parameter;
924  typedef typename TimerTraits<T5>::StoredType T5Stored;
926  typedef typename TimerTraits<T6>::ParameterType T6Parameter;
927  typedef typename TimerTraits<T6>::StoredType T6Stored;
928 
929  struct MemFnTimerImplSix : public TimerImplSix<T1Parameter,T2Parameter,T3Parameter,T4Parameter,T5Parameter,T6Parameter>
930  {
931  MemFnTimerImplSix (MEM_PTR memPtr, OBJ_PTR objPtr)
932  : m_memPtr (memPtr),
933  m_objPtr (objPtr)
934  {
935  }
936  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4,T5Parameter a5,T6Parameter a6)
937  {
938  m_a1 = a1;
939  m_a2 = a2;
940  m_a3 = a3;
941  m_a4 = a4;
942  m_a5 = a5;
943  m_a6 = a6;
944  }
945  virtual EventId Schedule (const Time &delay)
946  {
947  return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
948  }
949  virtual void Invoke (void)
950  {
951  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
952  }
953  MEM_PTR m_memPtr;
954  OBJ_PTR m_objPtr;
955  T1Stored m_a1;
956  T2Stored m_a2;
957  T3Stored m_a3;
958  T4Stored m_a4;
959  T5Stored m_a5;
960  T6Stored m_a6;
961  } *function = new MemFnTimerImplSix (memPtr, objPtr);
962  return function;
963 }
964  // \ingroup timer
966 
967 
968 /********************************************************************
969  * Implementation of TimerImpl itself.
970  ********************************************************************/
971 
972 template <typename T1>
973 void
975 {
976  typedef struct TimerImplOne<
977  typename TimerTraits<T1>::ParameterType
978  > TimerImplBase;
979  TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
980  if (impl == 0)
981  {
982  NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
983  return;
984  }
985  impl->SetArguments (a1);
986 }
987 
988 template <typename T1, typename T2>
989 void
990 TimerImpl::SetArgs (T1 a1, T2 a2)
991 {
992  typedef struct TimerImplTwo<
993  typename TimerTraits<T1>::ParameterType,
994  typename TimerTraits<T2>::ParameterType
995  > TimerImplBase;
996  TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
997  if (impl == 0)
998  {
999  NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
1000  return;
1001  }
1002  impl->SetArguments (a1, a2);
1003 }
1004 
1005 template <typename T1, typename T2, typename T3>
1006 void
1007 TimerImpl::SetArgs (T1 a1, T2 a2, T3 a3)
1008 {
1009  typedef struct TimerImplThree<
1010  typename TimerTraits<T1>::ParameterType,
1011  typename TimerTraits<T2>::ParameterType,
1012  typename TimerTraits<T3>::ParameterType
1013  > TimerImplBase;
1014  TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
1015  if (impl == 0)
1016  {
1017  NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
1018  return;
1019  }
1020  impl->SetArguments (a1, a2, a3);
1021 }
1022 
1023 template <typename T1, typename T2, typename T3, typename T4>
1024 void
1025 TimerImpl::SetArgs (T1 a1, T2 a2, T3 a3, T4 a4)
1026 {
1027  typedef struct TimerImplFour<
1028  typename TimerTraits<T1>::ParameterType,
1029  typename TimerTraits<T2>::ParameterType,
1030  typename TimerTraits<T3>::ParameterType,
1031  typename TimerTraits<T4>::ParameterType
1032  > TimerImplBase;
1033  TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
1034  if (impl == 0)
1035  {
1036  NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
1037  return;
1038  }
1039  impl->SetArguments (a1, a2, a3, a4);
1040 }
1041 
1042 template <typename T1, typename T2, typename T3, typename T4, typename T5>
1043 void
1044 TimerImpl::SetArgs (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
1045 {
1046  typedef struct TimerImplFive<
1047  typename TimerTraits<T1>::ParameterType,
1048  typename TimerTraits<T2>::ParameterType,
1049  typename TimerTraits<T3>::ParameterType,
1050  typename TimerTraits<T4>::ParameterType,
1051  typename TimerTraits<T5>::ParameterType
1052  > TimerImplBase;
1053  TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
1054  if (impl == 0)
1055  {
1056  NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
1057  return;
1058  }
1059  impl->SetArguments (a1, a2, a3, a4, a5);
1060 }
1061 
1062 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
1063 void
1064 TimerImpl::SetArgs (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
1065 {
1066  typedef struct TimerImplSix<
1067  typename TimerTraits<T1>::ParameterType,
1068  typename TimerTraits<T2>::ParameterType,
1069  typename TimerTraits<T3>::ParameterType,
1070  typename TimerTraits<T4>::ParameterType,
1071  typename TimerTraits<T5>::ParameterType,
1072  typename TimerTraits<T6>::ParameterType
1073  > TimerImplBase;
1074  TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
1075  if (impl == 0)
1076  {
1077  NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
1078  return;
1079  }
1080  impl->SetArguments (a1, a2, a3, a4, a5, a6);
1081 }
1082 
1083 } // namespace ns3
1084 
1085 #endif /* TIMER_IMPL_H */
NS_FATAL_x macro definitions.
virtual void SetArguments(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)=0
Bind the arguments to be used when the callback function is invoked.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
TypeTraits< typename TypeTraits< T >::ReferencedType >::NonConstType StoredType
Storage type for an argument.
Definition: timer-impl.h:239
TimerImpl specialization class for varying numbers of arguments.
Definition: timer-impl.h:203
TimerImpl * MakeTimerImpl(FN fn)
Make a TimerImpl from a function pointer taking varying numbers of arguments.
Definition: timer-impl.h:253
TimerImpl specialization class for varying numbers of arguments.
Definition: timer-impl.h:218
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
TimerImpl specialization class for varying numbers of arguments.
Definition: timer-impl.h:176
virtual void SetArguments(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)=0
Bind the arguments to be used when the callback function is invoked.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
ns3::Simulator declaration.
virtual void SetArguments(T1 a1, T2 a2)=0
Bind the arguments to be used when the callback function is invoked.
const StoredType & ParameterType
Parameter type for an argument.
Definition: timer-impl.h:241
Convert an integer into a type.
Definition: int-to-type.h:43
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1381
virtual ~TimerImpl()
Destructor.
Definition: timer-impl.h:46
virtual void SetArguments(T1 a1, T2 a2, T3 a3)=0
Bind the arguments to be used when the callback function is invoked.
virtual EventId Schedule(const Time &delay)=0
Schedule the callback for a future time.
ns3::IntToType template class.
TimerImpl specialization class for varying numbers of arguments.
Definition: timer-impl.h:153
TimerImpl specialization class for varying numbers of arguments.
Definition: timer-impl.h:164
Every class exported by the ns3 library is enclosed in the ns3 namespace.
The timer implementation underlying Timer and Watchdog.
Definition: timer-impl.h:42
Helper for the MakeTimerImpl functions which take a class method.
Definition: timer-impl.h:588
Inspect a type to deduce its features.
Definition: type-traits.h:39
virtual void SetArguments(T1 a1)=0
Bind the arguments to be used when the callback function is invoked.
if(desigRtr==addrLocal)
TimerImpl specialization class for varying numbers of arguments.
Definition: timer-impl.h:189
An identifier for simulation events.
Definition: event-id.h:53
Type and reference traits for TimerImpl arguments.
Definition: timer-impl.h:236
virtual void SetArguments(T1 a1, T2 a2, T3 a3, T4 a4)=0
Bind the arguments to be used when the callback function is invoked.
virtual void Invoke(void)=0
Invoke the expire function.
void SetArgs(T1 a1)
Set the arguments to be used when invoking the expire function.
Definition: timer-impl.h:974
static T & GetReference(T *p)
Convert a pointer type to a reference.
Definition: timer-impl.h:609
ns3::TypeTraits introspection declaration and template implementation.