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 
57  template <typename T1>
58  void SetArgs (T1 a1);
65  template <typename T1, typename T2>
66  void SetArgs (T1 a1, T2 a2);
75  template <typename T1, typename T2, typename T3>
76  void SetArgs (T1 a1, T2 a2, T3 a3);
87  template <typename T1, typename T2, typename T3,
88  typename T4>
89  void SetArgs (T1 a1, T2 a2, T3 a3, T4 a4);
102  template <typename T1, typename T2, typename T3,
103  typename T4, typename T5>
104  void SetArgs (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
119  template <typename T1, typename T2, typename T3,
120  typename T4, typename T5, typename T6>
121  void SetArgs (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
130  virtual EventId Schedule (const Time &delay) = 0;
132  virtual void Invoke (void) = 0;
133 };
134 
135 } // namespace ns3
136 
137 
138 /********************************************************************
139  * Implementation of TimerImpl implementation functions.
140  ********************************************************************/
141 
142 namespace ns3 {
143 
151 template <typename T1>
152 struct TimerImplOne : public TimerImpl
153 {
159  virtual void SetArguments (T1 a1) = 0;
160 };
162 template <typename T1, typename T2>
163 struct TimerImplTwo : public TimerImpl
164 {
171  virtual void SetArguments (T1 a1,T2 a2) = 0;
172 };
174 template <typename T1, typename T2, typename T3>
175 struct TimerImplThree : public TimerImpl
176 {
184  virtual void SetArguments (T1 a1,T2 a2,T3 a3) = 0;
185 };
187 template <typename T1, typename T2, typename T3, typename T4>
188 struct TimerImplFour : public TimerImpl
189 {
198  virtual void SetArguments (T1 a1,T2 a2,T3 a3, T4 a4) = 0;
199 };
201 template <typename T1, typename T2, typename T3, typename T4, typename T5>
202 struct TimerImplFive : public TimerImpl
203 {
213  virtual void SetArguments (T1 a1,T2 a2,T3 a3, T4 a4, T5 a5) = 0;
214 };
216 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
217 struct TimerImplSix : public TimerImpl
218 {
229  virtual void SetArguments (T1 a1,T2 a2,T3 a3, T4 a4, T5 a5, T6 a6) = 0;
230 };
231 
232 
234 template <typename T>
236 {
240  typedef const StoredType &ParameterType;
241 };
242 
250 template <typename FN>
251 TimerImpl *
253 {
256 }
257 
262 template <typename FN>
263 TimerImpl *
265 {
266  struct FnTimerImplZero : public TimerImpl
267  {
268  FnTimerImplZero (FN fn)
269  : m_fn (fn)
270  {}
271  virtual EventId Schedule (const Time &delay)
272  {
273  return Simulator::Schedule (delay, m_fn);
274  }
275  virtual void Invoke (void)
276  {
277  m_fn ();
278  }
279  FN m_fn;
280  } *function = new FnTimerImplZero (fn);
281  return function;
282 }
283 
288 template <typename FN>
289 TimerImpl *
291 {
293  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
294  typedef typename TimerTraits<T1>::StoredType T1Stored;
295 
296  struct FnTimerImplOne : public TimerImplOne<T1Parameter>
297  {
298  FnTimerImplOne (FN fn)
299  : m_fn (fn)
300  {}
301  virtual void SetArguments (T1Parameter a1)
302  {
303  m_a1 = a1;
304  }
305  virtual EventId Schedule (const Time &delay)
306  {
307  return Simulator::Schedule (delay, m_fn, m_a1);
308  }
309  virtual void Invoke (void)
310  {
311  m_fn (m_a1);
312  }
313  FN m_fn;
314  T1Stored m_a1;
315  } *function = new FnTimerImplOne (fn);
316  return function;
317 }
318 
323 template <typename FN>
324 TimerImpl *
326 {
328  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
329  typedef typename TimerTraits<T1>::StoredType T1Stored;
331  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
332  typedef typename TimerTraits<T2>::StoredType T2Stored;
333 
334  struct FnTimerImplTwo : public TimerImplTwo<T1Parameter,T2Parameter>
335  {
336  FnTimerImplTwo (FN fn)
337  : m_fn (fn)
338  {}
339  virtual void SetArguments (T1Parameter a1, T2Parameter a2)
340  {
341  m_a1 = a1;
342  m_a2 = a2;
343  }
344  virtual EventId Schedule (const Time &delay)
345  {
346  return Simulator::Schedule (delay, m_fn, m_a1, m_a2);
347  }
348  virtual void Invoke (void)
349  {
350  m_fn (m_a1, m_a2);
351  }
352  FN m_fn;
353  T1Stored m_a1;
354  T2Stored m_a2;
355  } *function = new FnTimerImplTwo (fn);
356  return function;
357 }
358 
363 template <typename FN>
364 TimerImpl *
366 {
368  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
369  typedef typename TimerTraits<T1>::StoredType T1Stored;
371  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
372  typedef typename TimerTraits<T2>::StoredType T2Stored;
374  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
375  typedef typename TimerTraits<T3>::StoredType T3Stored;
376 
377  struct FnTimerImplThree : public TimerImplThree<T1Parameter,T2Parameter,T3Parameter>
378  {
379  FnTimerImplThree (FN fn)
380  : m_fn (fn)
381  {}
382  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3)
383  {
384  m_a1 = a1;
385  m_a2 = a2;
386  m_a3 = a3;
387  }
388  virtual EventId Schedule (const Time &delay)
389  {
390  return Simulator::Schedule (delay, m_fn, m_a1, m_a2, m_a3);
391  }
392  virtual void Invoke (void)
393  {
394  m_fn (m_a1, m_a2, m_a3);
395  }
396  FN m_fn;
397  T1Stored m_a1;
398  T2Stored m_a2;
399  T3Stored m_a3;
400  } *function = new FnTimerImplThree (fn);
401  return function;
402 }
403 
408 template <typename FN>
409 TimerImpl *
411 {
413  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
414  typedef typename TimerTraits<T1>::StoredType T1Stored;
416  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
417  typedef typename TimerTraits<T2>::StoredType T2Stored;
419  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
420  typedef typename TimerTraits<T3>::StoredType T3Stored;
422  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
423  typedef typename TimerTraits<T4>::StoredType T4Stored;
424 
425  struct FnTimerImplFour : public TimerImplFour<T1Parameter,T2Parameter,T3Parameter,T4Parameter>
426  {
427  FnTimerImplFour (FN fn)
428  : m_fn (fn)
429  {}
430  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4)
431  {
432  m_a1 = a1;
433  m_a2 = a2;
434  m_a3 = a3;
435  m_a4 = a4;
436  }
437  virtual EventId Schedule (const Time &delay)
438  {
439  return Simulator::Schedule (delay, m_fn, m_a1, m_a2, m_a3, m_a4);
440  }
441  virtual void Invoke (void)
442  {
443  m_fn (m_a1, m_a2, m_a3, m_a4);
444  }
445  FN m_fn;
446  T1Stored m_a1;
447  T2Stored m_a2;
448  T3Stored m_a3;
449  T4Stored m_a4;
450  } *function = new FnTimerImplFour (fn);
451  return function;
452 }
453 
458 template <typename FN>
459 TimerImpl *
461 {
463  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
464  typedef typename TimerTraits<T1>::StoredType T1Stored;
466  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
467  typedef typename TimerTraits<T2>::StoredType T2Stored;
469  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
470  typedef typename TimerTraits<T3>::StoredType T3Stored;
472  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
473  typedef typename TimerTraits<T4>::StoredType T4Stored;
475  typedef typename TimerTraits<T5>::ParameterType T5Parameter;
476  typedef typename TimerTraits<T5>::StoredType T5Stored;
477 
478  struct FnTimerImplFive : public TimerImplFive<T1Parameter,T2Parameter,T3Parameter,T4Parameter,T5Parameter>
479  {
480  FnTimerImplFive (FN fn)
481  : m_fn (fn)
482  {}
483  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4, T5Parameter a5)
484  {
485  m_a1 = a1;
486  m_a2 = a2;
487  m_a3 = a3;
488  m_a4 = a4;
489  m_a5 = a5;
490  }
491  virtual EventId Schedule (const Time &delay)
492  {
493  return Simulator::Schedule (delay, m_fn, m_a1, m_a2, m_a3, m_a4, m_a5);
494  }
495  virtual void Invoke (void)
496  {
497  m_fn (m_a1, m_a2, m_a3, m_a4, m_a5);
498  }
499  FN m_fn;
500  T1Stored m_a1;
501  T2Stored m_a2;
502  T3Stored m_a3;
503  T4Stored m_a4;
504  T5Stored m_a5;
505  } *function = new FnTimerImplFive (fn);
506  return function;
507 }
508 
513 template <typename FN>
514 TimerImpl *
516 {
518  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
519  typedef typename TimerTraits<T1>::StoredType T1Stored;
521  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
522  typedef typename TimerTraits<T2>::StoredType T2Stored;
524  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
525  typedef typename TimerTraits<T3>::StoredType T3Stored;
527  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
528  typedef typename TimerTraits<T4>::StoredType T4Stored;
530  typedef typename TimerTraits<T5>::ParameterType T5Parameter;
531  typedef typename TimerTraits<T5>::StoredType T5Stored;
533  typedef typename TimerTraits<T6>::ParameterType T6Parameter;
534  typedef typename TimerTraits<T6>::StoredType T6Stored;
535 
536  struct FnTimerImplSix : public TimerImplSix<T1Parameter,T2Parameter,T3Parameter,T4Parameter,T5Parameter,T6Parameter>
537  {
538  FnTimerImplSix (FN fn)
539  : m_fn (fn)
540  {}
541  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4, T5Parameter a5, T6Parameter a6)
542  {
543  m_a1 = a1;
544  m_a2 = a2;
545  m_a3 = a3;
546  m_a4 = a4;
547  m_a5 = a5;
548  m_a6 = a6;
549  }
550  virtual EventId Schedule (const Time &delay)
551  {
552  return Simulator::Schedule (delay, m_fn, m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
553  }
554  virtual void Invoke (void)
555  {
556  m_fn (m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
557  }
558  FN m_fn;
559  T1Stored m_a1;
560  T2Stored m_a2;
561  T3Stored m_a3;
562  T4Stored m_a4;
563  T5Stored m_a5;
564  T6Stored m_a6;
565  } *function = new FnTimerImplSix (fn);
566  return function;
567 }
568 
569 
579 template <typename T>
581 
582 
592 template <typename T>
594 {
601  static T & GetReference (T *p)
602  {
603  return *p;
604  }
605 };
606 
617 template <typename MEM_PTR, typename OBJ_PTR>
618 TimerImpl *
619 MakeTimerImpl (MEM_PTR memPtr, OBJ_PTR objPtr)
620 {
623 }
624 
629 template <typename MEM_PTR, typename OBJ_PTR>
630 TimerImpl *
631 MakeTimerImpl (IntToType<0>, MEM_PTR memPtr, OBJ_PTR objPtr)
632 {
633  struct MemFnTimerImplZero : public TimerImpl
634  {
635  MemFnTimerImplZero (MEM_PTR memPtr, OBJ_PTR objPtr)
636  : m_memPtr (memPtr),
637  m_objPtr (objPtr)
638  {}
639  virtual EventId Schedule (const Time &delay)
640  {
641  return Simulator::Schedule (delay, m_memPtr, m_objPtr);
642  }
643  virtual void Invoke (void)
644  {
645  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)();
646  }
647  MEM_PTR m_memPtr;
648  OBJ_PTR m_objPtr;
649  } *function = new MemFnTimerImplZero (memPtr, objPtr);
650  return function;
651 }
652 
657 template <typename MEM_PTR, typename OBJ_PTR>
658 TimerImpl *
659 MakeTimerImpl (IntToType<1>, MEM_PTR memPtr, OBJ_PTR objPtr)
660 {
662  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
663  typedef typename TimerTraits<T1>::StoredType T1Stored;
664 
665  struct MemFnTimerImplOne : public TimerImplOne<T1Parameter>
666  {
667  MemFnTimerImplOne (MEM_PTR memPtr, OBJ_PTR objPtr)
668  : m_memPtr (memPtr),
669  m_objPtr (objPtr)
670  {}
671  virtual void SetArguments (T1Parameter a1)
672  {
673  m_a1 = a1;
674  }
675  virtual EventId Schedule (const Time &delay)
676  {
677  return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1);
678  }
679  virtual void Invoke (void)
680  {
681  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1);
682  }
683  MEM_PTR m_memPtr;
684  OBJ_PTR m_objPtr;
685  T1Stored m_a1;
686  } *function = new MemFnTimerImplOne (memPtr, objPtr);
687  return function;
688 }
689 
694 template <typename MEM_PTR, typename OBJ_PTR>
695 TimerImpl *
696 MakeTimerImpl (IntToType<2>, MEM_PTR memPtr, OBJ_PTR objPtr)
697 {
699  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
700  typedef typename TimerTraits<T1>::StoredType T1Stored;
702  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
703  typedef typename TimerTraits<T2>::StoredType T2Stored;
704 
705  struct MemFnTimerImplTwo : public TimerImplTwo<T1Parameter,T2Parameter>
706  {
707  MemFnTimerImplTwo (MEM_PTR memPtr, OBJ_PTR objPtr)
708  : m_memPtr (memPtr),
709  m_objPtr (objPtr)
710  {}
711  virtual void SetArguments (T1Parameter a1, T2Parameter a2)
712  {
713  m_a1 = a1;
714  m_a2 = a2;
715  }
716  virtual EventId Schedule (const Time &delay)
717  {
718  return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2);
719  }
720  virtual void Invoke (void)
721  {
722  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2);
723  }
724  MEM_PTR m_memPtr;
725  OBJ_PTR m_objPtr;
726  T1Stored m_a1;
727  T2Stored m_a2;
728  } *function = new MemFnTimerImplTwo (memPtr, objPtr);
729  return function;
730 }
731 
736 template <typename MEM_PTR, typename OBJ_PTR>
737 TimerImpl *
738 MakeTimerImpl (IntToType<3>, MEM_PTR memPtr, OBJ_PTR objPtr)
739 {
741  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
742  typedef typename TimerTraits<T1>::StoredType T1Stored;
744  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
745  typedef typename TimerTraits<T2>::StoredType T2Stored;
747  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
748  typedef typename TimerTraits<T3>::StoredType T3Stored;
749 
750  struct MemFnTimerImplThree : public TimerImplThree<T1Parameter,T2Parameter,T3Parameter>
751  {
752  MemFnTimerImplThree (MEM_PTR memPtr, OBJ_PTR objPtr)
753  : m_memPtr (memPtr),
754  m_objPtr (objPtr)
755  {}
756  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3)
757  {
758  m_a1 = a1;
759  m_a2 = a2;
760  m_a3 = a3;
761  }
762  virtual EventId Schedule (const Time &delay)
763  {
764  return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3);
765  }
766  virtual void Invoke (void)
767  {
768  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2, m_a3);
769  }
770  MEM_PTR m_memPtr;
771  OBJ_PTR m_objPtr;
772  T1Stored m_a1;
773  T2Stored m_a2;
774  T3Stored m_a3;
775  } *function = new MemFnTimerImplThree (memPtr, objPtr);
776  return function;
777 }
778 
783 template <typename MEM_PTR, typename OBJ_PTR>
784 TimerImpl *
785 MakeTimerImpl (IntToType<4>, MEM_PTR memPtr, OBJ_PTR objPtr)
786 {
788  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
789  typedef typename TimerTraits<T1>::StoredType T1Stored;
791  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
792  typedef typename TimerTraits<T2>::StoredType T2Stored;
794  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
795  typedef typename TimerTraits<T3>::StoredType T3Stored;
797  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
798  typedef typename TimerTraits<T4>::StoredType T4Stored;
799 
800  struct MemFnTimerImplFour : public TimerImplFour<T1Parameter,T2Parameter,T3Parameter,T4Parameter>
801  {
802  MemFnTimerImplFour (MEM_PTR memPtr, OBJ_PTR objPtr)
803  : m_memPtr (memPtr),
804  m_objPtr (objPtr)
805  {}
806  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4)
807  {
808  m_a1 = a1;
809  m_a2 = a2;
810  m_a3 = a3;
811  m_a4 = a4;
812  }
813  virtual EventId Schedule (const Time &delay)
814  {
815  return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3, m_a4);
816  }
817  virtual void Invoke (void)
818  {
819  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2, m_a3, m_a4);
820  }
821  MEM_PTR m_memPtr;
822  OBJ_PTR m_objPtr;
823  T1Stored m_a1;
824  T2Stored m_a2;
825  T3Stored m_a3;
826  T4Stored m_a4;
827  } *function = new MemFnTimerImplFour (memPtr, objPtr);
828  return function;
829 }
830 
835 template <typename MEM_PTR, typename OBJ_PTR>
836 TimerImpl *
837 MakeTimerImpl (IntToType<5>, MEM_PTR memPtr, OBJ_PTR objPtr)
838 {
840  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
841  typedef typename TimerTraits<T1>::StoredType T1Stored;
843  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
844  typedef typename TimerTraits<T2>::StoredType T2Stored;
846  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
847  typedef typename TimerTraits<T3>::StoredType T3Stored;
849  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
850  typedef typename TimerTraits<T4>::StoredType T4Stored;
852  typedef typename TimerTraits<T5>::ParameterType T5Parameter;
853  typedef typename TimerTraits<T5>::StoredType T5Stored;
854 
855  struct MemFnTimerImplFive : public TimerImplFive<T1Parameter,T2Parameter,T3Parameter,T4Parameter,T5Parameter>
856  {
857  MemFnTimerImplFive (MEM_PTR memPtr, OBJ_PTR objPtr)
858  : m_memPtr (memPtr),
859  m_objPtr (objPtr)
860  {}
861  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4,T5Parameter a5)
862  {
863  m_a1 = a1;
864  m_a2 = a2;
865  m_a3 = a3;
866  m_a4 = a4;
867  m_a5 = a5;
868  }
869  virtual EventId Schedule (const Time &delay)
870  {
871  return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3, m_a4, m_a5);
872  }
873  virtual void Invoke (void)
874  {
875  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2, m_a3, m_a4, m_a5);
876  }
877  MEM_PTR m_memPtr;
878  OBJ_PTR m_objPtr;
879  T1Stored m_a1;
880  T2Stored m_a2;
881  T3Stored m_a3;
882  T4Stored m_a4;
883  T5Stored m_a5;
884  } *function = new MemFnTimerImplFive (memPtr, objPtr);
885  return function;
886 }
887 
892 template <typename MEM_PTR, typename OBJ_PTR>
893 TimerImpl *
894 MakeTimerImpl (IntToType<6>, MEM_PTR memPtr, OBJ_PTR objPtr)
895 {
897  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
898  typedef typename TimerTraits<T1>::StoredType T1Stored;
900  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
901  typedef typename TimerTraits<T2>::StoredType T2Stored;
903  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
904  typedef typename TimerTraits<T3>::StoredType T3Stored;
906  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
907  typedef typename TimerTraits<T4>::StoredType T4Stored;
909  typedef typename TimerTraits<T5>::ParameterType T5Parameter;
910  typedef typename TimerTraits<T5>::StoredType T5Stored;
912  typedef typename TimerTraits<T6>::ParameterType T6Parameter;
913  typedef typename TimerTraits<T6>::StoredType T6Stored;
914 
915  struct MemFnTimerImplSix : public TimerImplSix<T1Parameter,T2Parameter,T3Parameter,T4Parameter,T5Parameter,T6Parameter>
916  {
917  MemFnTimerImplSix (MEM_PTR memPtr, OBJ_PTR objPtr)
918  : m_memPtr (memPtr),
919  m_objPtr (objPtr)
920  {}
921  virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4,T5Parameter a5,T6Parameter a6)
922  {
923  m_a1 = a1;
924  m_a2 = a2;
925  m_a3 = a3;
926  m_a4 = a4;
927  m_a5 = a5;
928  m_a6 = a6;
929  }
930  virtual EventId Schedule (const Time &delay)
931  {
932  return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
933  }
934  virtual void Invoke (void)
935  {
936  (TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
937  }
938  MEM_PTR m_memPtr;
939  OBJ_PTR m_objPtr;
940  T1Stored m_a1;
941  T2Stored m_a2;
942  T3Stored m_a3;
943  T4Stored m_a4;
944  T5Stored m_a5;
945  T6Stored m_a6;
946  } *function = new MemFnTimerImplSix (memPtr, objPtr);
947  return function;
948 }
949  // \ingroup timer
951 
952 
953 /********************************************************************
954  * Implementation of TimerImpl itself.
955  ********************************************************************/
956 
957 template <typename T1>
958 void
960 {
961  typedef struct TimerImplOne<
962  typename TimerTraits<T1>::ParameterType
963  > TimerImplBase;
964  TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
965  if (impl == 0)
966  {
967  NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
968  return;
969  }
970  impl->SetArguments (a1);
971 }
972 
973 template <typename T1, typename T2>
974 void
975 TimerImpl::SetArgs (T1 a1, T2 a2)
976 {
977  typedef struct TimerImplTwo<
978  typename TimerTraits<T1>::ParameterType,
979  typename TimerTraits<T2>::ParameterType
980  > TimerImplBase;
981  TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
982  if (impl == 0)
983  {
984  NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
985  return;
986  }
987  impl->SetArguments (a1, a2);
988 }
989 
990 template <typename T1, typename T2, typename T3>
991 void
992 TimerImpl::SetArgs (T1 a1, T2 a2, T3 a3)
993 {
994  typedef struct TimerImplThree<
995  typename TimerTraits<T1>::ParameterType,
996  typename TimerTraits<T2>::ParameterType,
997  typename TimerTraits<T3>::ParameterType
998  > TimerImplBase;
999  TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
1000  if (impl == 0)
1001  {
1002  NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
1003  return;
1004  }
1005  impl->SetArguments (a1, a2, a3);
1006 }
1007 
1008 template <typename T1, typename T2, typename T3, typename T4>
1009 void
1010 TimerImpl::SetArgs (T1 a1, T2 a2, T3 a3, T4 a4)
1011 {
1012  typedef struct TimerImplFour<
1013  typename TimerTraits<T1>::ParameterType,
1014  typename TimerTraits<T2>::ParameterType,
1015  typename TimerTraits<T3>::ParameterType,
1016  typename TimerTraits<T4>::ParameterType
1017  > TimerImplBase;
1018  TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
1019  if (impl == 0)
1020  {
1021  NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
1022  return;
1023  }
1024  impl->SetArguments (a1, a2, a3, a4);
1025 }
1026 
1027 template <typename T1, typename T2, typename T3, typename T4, typename T5>
1028 void
1029 TimerImpl::SetArgs (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
1030 {
1031  typedef struct TimerImplFive<
1032  typename TimerTraits<T1>::ParameterType,
1033  typename TimerTraits<T2>::ParameterType,
1034  typename TimerTraits<T3>::ParameterType,
1035  typename TimerTraits<T4>::ParameterType,
1036  typename TimerTraits<T5>::ParameterType
1037  > TimerImplBase;
1038  TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
1039  if (impl == 0)
1040  {
1041  NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
1042  return;
1043  }
1044  impl->SetArguments (a1, a2, a3, a4, a5);
1045 }
1046 
1047 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
1048 void
1049 TimerImpl::SetArgs (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
1050 {
1051  typedef struct TimerImplSix<
1052  typename TimerTraits<T1>::ParameterType,
1053  typename TimerTraits<T2>::ParameterType,
1054  typename TimerTraits<T3>::ParameterType,
1055  typename TimerTraits<T4>::ParameterType,
1056  typename TimerTraits<T5>::ParameterType,
1057  typename TimerTraits<T6>::ParameterType
1058  > TimerImplBase;
1059  TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
1060  if (impl == 0)
1061  {
1062  NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
1063  return;
1064  }
1065  impl->SetArguments (a1, a2, a3, a4, a5, a6);
1066 }
1067 
1068 } // namespace ns3
1069 
1070 #endif /* TIMER_IMPL_H */
An identifier for simulation events.
Definition: event-id.h:54
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
The timer implementation underlying Timer and Watchdog.
Definition: timer-impl.h:43
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:959
virtual ~TimerImpl()
Destructor.
Definition: timer-impl.h:46
virtual EventId Schedule(const Time &delay)=0
Schedule the callback for a future time.
NS_FATAL_x macro definitions.
#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
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
TimerImpl * MakeTimerImpl(FN fn)
Make a TimerImpl from a function pointer taking varying numbers of arguments.
Definition: timer-impl.h:252
ns3::IntToType template class.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Simulator declaration.
Convert an integer into a type.
Definition: int-to-type.h:44
TimerImpl specialization class for varying numbers of arguments.
Definition: timer-impl.h:203
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.
TimerImpl specialization class for varying numbers of arguments.
Definition: timer-impl.h:189
virtual void SetArguments(T1 a1, T2 a2, T3 a3, T4 a4)=0
Bind the arguments to be used when the callback function is invoked.
static T & GetReference(T *p)
Convert a pointer type to a reference.
Definition: timer-impl.h:601
Helper for the MakeTimerImpl functions which take a class method.
Definition: timer-impl.h:580
TimerImpl specialization class for varying numbers of arguments.
Definition: timer-impl.h:153
virtual void SetArguments(T1 a1)=0
Bind the arguments to be used when the callback function is invoked.
TimerImpl specialization class for varying numbers of arguments.
Definition: timer-impl.h:218
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.
TimerImpl specialization class for varying numbers of arguments.
Definition: timer-impl.h:176
virtual void SetArguments(T1 a1, T2 a2, T3 a3)=0
Bind the arguments to be used when the callback function is invoked.
TimerImpl specialization class for varying numbers of arguments.
Definition: timer-impl.h:164
virtual void SetArguments(T1 a1, T2 a2)=0
Bind the arguments to be used when the callback function is invoked.
Type and reference traits for TimerImpl arguments.
Definition: timer-impl.h:236
TypeTraits< typename TypeTraits< T >::ReferencedType >::NonConstType StoredType
Storage type for an argument.
Definition: timer-impl.h:238
const StoredType & ParameterType
Parameter type for an argument.
Definition: timer-impl.h:240
Inspect a type to deduce its features.
Definition: type-traits.h:40
ns3::TypeTraits introspection declaration and template implementation.