A Discrete-Event Network Simulator
API
timer-impl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
20 #ifndef TIMER_IMPL_H
21 #define TIMER_IMPL_H
22 
23 #include "fatal-error.h"
24 #include "int-to-type.h"
25 #include "simulator.h"
26 #include "type-traits.h"
27 
35 namespace ns3
36 {
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, typename T4>
89  void SetArgs(T1 a1, T2 a2, T3 a3, T4 a4);
102  template <typename T1, typename T2, typename T3, typename T4, typename T5>
103  void SetArgs(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
118  template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
119  void SetArgs(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
128  virtual EventId Schedule(const Time& delay) = 0;
130  virtual void Invoke() = 0;
131 };
132 
133 } // namespace ns3
134 
135 /********************************************************************
136  * Implementation of TimerImpl implementation functions.
137  ********************************************************************/
138 
139 namespace ns3
140 {
141 
149 template <typename T1>
150 struct TimerImplOne : public TimerImpl
151 {
157  virtual void SetArguments(T1 a1) = 0;
158 };
159 
161 template <typename T1, typename T2>
162 struct TimerImplTwo : public TimerImpl
163 {
170  virtual void SetArguments(T1 a1, T2 a2) = 0;
171 };
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 };
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 };
201 
203 template <typename T1, typename T2, typename T3, typename T4, typename T5>
204 struct TimerImplFive : public TimerImpl
205 {
215  virtual void SetArguments(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) = 0;
216 };
217 
219 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
220 struct TimerImplSix : public TimerImpl
221 {
232  virtual void SetArguments(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) = 0;
233 };
234 
236 template <typename T>
238 {
242  typedef const StoredType& ParameterType;
243 };
244 
252 template <typename FN>
253 TimerImpl*
255 {
258 }
259 
264 template <typename FN>
265 TimerImpl*
267 {
268  struct FnTimerImplZero : public TimerImpl
269  {
270  FnTimerImplZero(FN fn)
271  : m_fn(fn)
272  {
273  }
274 
275  EventId Schedule(const Time& delay) override
276  {
277  return Simulator::Schedule(delay, m_fn);
278  }
279 
280  void Invoke() override
281  {
282  m_fn();
283  }
284 
285  FN m_fn;
286  }* function = new FnTimerImplZero(fn);
287 
288  return function;
289 }
290 
295 template <typename FN>
296 TimerImpl*
298 {
300  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
301  typedef typename TimerTraits<T1>::StoredType T1Stored;
302 
303  struct FnTimerImplOne : public TimerImplOne<T1Parameter>
304  {
305  FnTimerImplOne(FN fn)
306  : m_fn(fn)
307  {
308  }
309 
310  void SetArguments(T1Parameter a1) override
311  {
312  m_a1 = a1;
313  }
314 
315  EventId Schedule(const Time& delay) override
316  {
317  return Simulator::Schedule(delay, m_fn, m_a1);
318  }
319 
320  void Invoke() override
321  {
322  m_fn(m_a1);
323  }
324 
325  FN m_fn;
326  T1Stored m_a1;
327  }* function = new FnTimerImplOne(fn);
328 
329  return function;
330 }
331 
336 template <typename FN>
337 TimerImpl*
339 {
341  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
342  typedef typename TimerTraits<T1>::StoredType T1Stored;
344  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
345  typedef typename TimerTraits<T2>::StoredType T2Stored;
346 
347  struct FnTimerImplTwo : public TimerImplTwo<T1Parameter, T2Parameter>
348  {
349  FnTimerImplTwo(FN fn)
350  : m_fn(fn)
351  {
352  }
353 
354  void SetArguments(T1Parameter a1, T2Parameter a2) override
355  {
356  m_a1 = a1;
357  m_a2 = a2;
358  }
359 
360  EventId Schedule(const Time& delay) override
361  {
362  return Simulator::Schedule(delay, m_fn, m_a1, m_a2);
363  }
364 
365  void Invoke() override
366  {
367  m_fn(m_a1, m_a2);
368  }
369 
370  FN m_fn;
371  T1Stored m_a1;
372  T2Stored m_a2;
373  }* function = new FnTimerImplTwo(fn);
374 
375  return function;
376 }
377 
382 template <typename FN>
383 TimerImpl*
385 {
387  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
388  typedef typename TimerTraits<T1>::StoredType T1Stored;
390  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
391  typedef typename TimerTraits<T2>::StoredType T2Stored;
393  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
394  typedef typename TimerTraits<T3>::StoredType T3Stored;
395 
396  struct FnTimerImplThree : public TimerImplThree<T1Parameter, T2Parameter, T3Parameter>
397  {
398  FnTimerImplThree(FN fn)
399  : m_fn(fn)
400  {
401  }
402 
403  void SetArguments(T1Parameter a1, T2Parameter a2, T3Parameter a3) override
404  {
405  m_a1 = a1;
406  m_a2 = a2;
407  m_a3 = a3;
408  }
409 
410  EventId Schedule(const Time& delay) override
411  {
412  return Simulator::Schedule(delay, m_fn, m_a1, m_a2, m_a3);
413  }
414 
415  void Invoke() override
416  {
417  m_fn(m_a1, m_a2, m_a3);
418  }
419 
420  FN m_fn;
421  T1Stored m_a1;
422  T2Stored m_a2;
423  T3Stored m_a3;
424  }* function = new FnTimerImplThree(fn);
425 
426  return function;
427 }
428 
433 template <typename FN>
434 TimerImpl*
436 {
438  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
439  typedef typename TimerTraits<T1>::StoredType T1Stored;
441  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
442  typedef typename TimerTraits<T2>::StoredType T2Stored;
444  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
445  typedef typename TimerTraits<T3>::StoredType T3Stored;
447  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
448  typedef typename TimerTraits<T4>::StoredType T4Stored;
449 
450  struct FnTimerImplFour
451  : public TimerImplFour<T1Parameter, T2Parameter, T3Parameter, T4Parameter>
452  {
453  FnTimerImplFour(FN fn)
454  : m_fn(fn)
455  {
456  }
457 
458  void SetArguments(T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4) override
459  {
460  m_a1 = a1;
461  m_a2 = a2;
462  m_a3 = a3;
463  m_a4 = a4;
464  }
465 
466  EventId Schedule(const Time& delay) override
467  {
468  return Simulator::Schedule(delay, m_fn, m_a1, m_a2, m_a3, m_a4);
469  }
470 
471  void Invoke() override
472  {
473  m_fn(m_a1, m_a2, m_a3, m_a4);
474  }
475 
476  FN m_fn;
477  T1Stored m_a1;
478  T2Stored m_a2;
479  T3Stored m_a3;
480  T4Stored m_a4;
481  }* function = new FnTimerImplFour(fn);
482 
483  return function;
484 }
485 
490 template <typename FN>
491 TimerImpl*
493 {
495  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
496  typedef typename TimerTraits<T1>::StoredType T1Stored;
498  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
499  typedef typename TimerTraits<T2>::StoredType T2Stored;
501  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
502  typedef typename TimerTraits<T3>::StoredType T3Stored;
504  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
505  typedef typename TimerTraits<T4>::StoredType T4Stored;
507  typedef typename TimerTraits<T5>::ParameterType T5Parameter;
508  typedef typename TimerTraits<T5>::StoredType T5Stored;
509 
510  struct FnTimerImplFive
511  : public TimerImplFive<T1Parameter, T2Parameter, T3Parameter, T4Parameter, T5Parameter>
512  {
513  FnTimerImplFive(FN fn)
514  : m_fn(fn)
515  {
516  }
517 
518  void SetArguments(T1Parameter a1,
519  T2Parameter a2,
520  T3Parameter a3,
521  T4Parameter a4,
522  T5Parameter a5) override
523  {
524  m_a1 = a1;
525  m_a2 = a2;
526  m_a3 = a3;
527  m_a4 = a4;
528  m_a5 = a5;
529  }
530 
531  EventId Schedule(const Time& delay) override
532  {
533  return Simulator::Schedule(delay, m_fn, m_a1, m_a2, m_a3, m_a4, m_a5);
534  }
535 
536  void Invoke() override
537  {
538  m_fn(m_a1, m_a2, m_a3, m_a4, m_a5);
539  }
540 
541  FN m_fn;
542  T1Stored m_a1;
543  T2Stored m_a2;
544  T3Stored m_a3;
545  T4Stored m_a4;
546  T5Stored m_a5;
547  }* function = new FnTimerImplFive(fn);
548 
549  return function;
550 }
551 
556 template <typename FN>
557 TimerImpl*
559 {
561  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
562  typedef typename TimerTraits<T1>::StoredType T1Stored;
564  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
565  typedef typename TimerTraits<T2>::StoredType T2Stored;
567  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
568  typedef typename TimerTraits<T3>::StoredType T3Stored;
570  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
571  typedef typename TimerTraits<T4>::StoredType T4Stored;
573  typedef typename TimerTraits<T5>::ParameterType T5Parameter;
574  typedef typename TimerTraits<T5>::StoredType T5Stored;
576  typedef typename TimerTraits<T6>::ParameterType T6Parameter;
577  typedef typename TimerTraits<T6>::StoredType T6Stored;
578 
579  struct FnTimerImplSix : public TimerImplSix<T1Parameter,
580  T2Parameter,
581  T3Parameter,
582  T4Parameter,
583  T5Parameter,
584  T6Parameter>
585  {
586  FnTimerImplSix(FN fn)
587  : m_fn(fn)
588  {
589  }
590 
591  virtual void SetArguments(T1Parameter a1,
592  T2Parameter a2,
593  T3Parameter a3,
594  T4Parameter a4,
595  T5Parameter a5,
596  T6Parameter a6)
597  {
598  m_a1 = a1;
599  m_a2 = a2;
600  m_a3 = a3;
601  m_a4 = a4;
602  m_a5 = a5;
603  m_a6 = a6;
604  }
605 
606  virtual EventId Schedule(const Time& delay)
607  {
608  return Simulator::Schedule(delay, m_fn, m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
609  }
610 
611  virtual void Invoke()
612  {
613  m_fn(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
614  }
615 
616  FN m_fn;
617  T1Stored m_a1;
618  T2Stored m_a2;
619  T3Stored m_a3;
620  T4Stored m_a4;
621  T5Stored m_a5;
622  T6Stored m_a6;
623  }* function = new FnTimerImplSix(fn);
624 
625  return function;
626 }
627 
637 template <typename T>
639 
649 template <typename T>
651 {
658  static T& GetReference(T* p)
659  {
660  return *p;
661  }
662 };
663 
674 template <typename MEM_PTR, typename OBJ_PTR>
675 TimerImpl*
676 MakeTimerImpl(MEM_PTR memPtr, OBJ_PTR objPtr)
677 {
680  memPtr,
681  objPtr);
682 }
683 
688 template <typename MEM_PTR, typename OBJ_PTR>
689 TimerImpl*
690 MakeTimerImpl(IntToType<0>, MEM_PTR memPtr, OBJ_PTR objPtr)
691 {
692  struct MemFnTimerImplZero : public TimerImpl
693  {
694  MemFnTimerImplZero(MEM_PTR memPtr, OBJ_PTR objPtr)
695  : m_memPtr(memPtr),
696  m_objPtr(objPtr)
697  {
698  }
699 
700  EventId Schedule(const Time& delay) override
701  {
702  return Simulator::Schedule(delay, m_memPtr, m_objPtr);
703  }
704 
705  void Invoke() override
706  {
707  (TimerImplMemberTraits<OBJ_PTR>::GetReference(m_objPtr).*m_memPtr)();
708  }
709 
710  MEM_PTR m_memPtr;
711  OBJ_PTR m_objPtr;
712  }* function = new MemFnTimerImplZero(memPtr, objPtr);
713 
714  return function;
715 }
716 
721 template <typename MEM_PTR, typename OBJ_PTR>
722 TimerImpl*
723 MakeTimerImpl(IntToType<1>, MEM_PTR memPtr, OBJ_PTR objPtr)
724 {
726  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
727  typedef typename TimerTraits<T1>::StoredType T1Stored;
728 
729  struct MemFnTimerImplOne : public TimerImplOne<T1Parameter>
730  {
731  MemFnTimerImplOne(MEM_PTR memPtr, OBJ_PTR objPtr)
732  : m_memPtr(memPtr),
733  m_objPtr(objPtr)
734  {
735  }
736 
737  void SetArguments(T1Parameter a1) override
738  {
739  m_a1 = a1;
740  }
741 
742  EventId Schedule(const Time& delay) override
743  {
744  return Simulator::Schedule(delay, m_memPtr, m_objPtr, m_a1);
745  }
746 
747  void Invoke() override
748  {
749  (TimerImplMemberTraits<OBJ_PTR>::GetReference(m_objPtr).*m_memPtr)(m_a1);
750  }
751 
752  MEM_PTR m_memPtr;
753  OBJ_PTR m_objPtr;
754  T1Stored m_a1;
755  }* function = new MemFnTimerImplOne(memPtr, objPtr);
756 
757  return function;
758 }
759 
764 template <typename MEM_PTR, typename OBJ_PTR>
765 TimerImpl*
766 MakeTimerImpl(IntToType<2>, MEM_PTR memPtr, OBJ_PTR objPtr)
767 {
769  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
770  typedef typename TimerTraits<T1>::StoredType T1Stored;
772  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
773  typedef typename TimerTraits<T2>::StoredType T2Stored;
774 
775  struct MemFnTimerImplTwo : public TimerImplTwo<T1Parameter, T2Parameter>
776  {
777  MemFnTimerImplTwo(MEM_PTR memPtr, OBJ_PTR objPtr)
778  : m_memPtr(memPtr),
779  m_objPtr(objPtr)
780  {
781  }
782 
783  void SetArguments(T1Parameter a1, T2Parameter a2) override
784  {
785  m_a1 = a1;
786  m_a2 = a2;
787  }
788 
789  EventId Schedule(const Time& delay) override
790  {
791  return Simulator::Schedule(delay, m_memPtr, m_objPtr, m_a1, m_a2);
792  }
793 
794  void Invoke() override
795  {
796  (TimerImplMemberTraits<OBJ_PTR>::GetReference(m_objPtr).*m_memPtr)(m_a1, m_a2);
797  }
798 
799  MEM_PTR m_memPtr;
800  OBJ_PTR m_objPtr;
801  T1Stored m_a1;
802  T2Stored m_a2;
803  }* function = new MemFnTimerImplTwo(memPtr, objPtr);
804 
805  return function;
806 }
807 
812 template <typename MEM_PTR, typename OBJ_PTR>
813 TimerImpl*
814 MakeTimerImpl(IntToType<3>, MEM_PTR memPtr, OBJ_PTR objPtr)
815 {
817  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
818  typedef typename TimerTraits<T1>::StoredType T1Stored;
820  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
821  typedef typename TimerTraits<T2>::StoredType T2Stored;
823  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
824  typedef typename TimerTraits<T3>::StoredType T3Stored;
825 
826  struct MemFnTimerImplThree : public TimerImplThree<T1Parameter, T2Parameter, T3Parameter>
827  {
828  MemFnTimerImplThree(MEM_PTR memPtr, OBJ_PTR objPtr)
829  : m_memPtr(memPtr),
830  m_objPtr(objPtr)
831  {
832  }
833 
834  void SetArguments(T1Parameter a1, T2Parameter a2, T3Parameter a3) override
835  {
836  m_a1 = a1;
837  m_a2 = a2;
838  m_a3 = a3;
839  }
840 
841  EventId Schedule(const Time& delay) override
842  {
843  return Simulator::Schedule(delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3);
844  }
845 
846  void Invoke() override
847  {
848  (TimerImplMemberTraits<OBJ_PTR>::GetReference(m_objPtr).*m_memPtr)(m_a1, m_a2, m_a3);
849  }
850 
851  MEM_PTR m_memPtr;
852  OBJ_PTR m_objPtr;
853  T1Stored m_a1;
854  T2Stored m_a2;
855  T3Stored m_a3;
856  }* function = new MemFnTimerImplThree(memPtr, objPtr);
857 
858  return function;
859 }
860 
865 template <typename MEM_PTR, typename OBJ_PTR>
866 TimerImpl*
867 MakeTimerImpl(IntToType<4>, MEM_PTR memPtr, OBJ_PTR objPtr)
868 {
870  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
871  typedef typename TimerTraits<T1>::StoredType T1Stored;
873  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
874  typedef typename TimerTraits<T2>::StoredType T2Stored;
876  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
877  typedef typename TimerTraits<T3>::StoredType T3Stored;
879  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
880  typedef typename TimerTraits<T4>::StoredType T4Stored;
881 
882  struct MemFnTimerImplFour
883  : public TimerImplFour<T1Parameter, T2Parameter, T3Parameter, T4Parameter>
884  {
885  MemFnTimerImplFour(MEM_PTR memPtr, OBJ_PTR objPtr)
886  : m_memPtr(memPtr),
887  m_objPtr(objPtr)
888  {
889  }
890 
891  void SetArguments(T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4) override
892  {
893  m_a1 = a1;
894  m_a2 = a2;
895  m_a3 = a3;
896  m_a4 = a4;
897  }
898 
899  EventId Schedule(const Time& delay) override
900  {
901  return Simulator::Schedule(delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3, m_a4);
902  }
903 
904  void Invoke() override
905  {
907  m_memPtr)(m_a1, m_a2, m_a3, m_a4);
908  }
909 
910  MEM_PTR m_memPtr;
911  OBJ_PTR m_objPtr;
912  T1Stored m_a1;
913  T2Stored m_a2;
914  T3Stored m_a3;
915  T4Stored m_a4;
916  }* function = new MemFnTimerImplFour(memPtr, objPtr);
917 
918  return function;
919 }
920 
925 template <typename MEM_PTR, typename OBJ_PTR>
926 TimerImpl*
927 MakeTimerImpl(IntToType<5>, MEM_PTR memPtr, OBJ_PTR objPtr)
928 {
930  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
931  typedef typename TimerTraits<T1>::StoredType T1Stored;
933  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
934  typedef typename TimerTraits<T2>::StoredType T2Stored;
936  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
937  typedef typename TimerTraits<T3>::StoredType T3Stored;
939  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
940  typedef typename TimerTraits<T4>::StoredType T4Stored;
942  typedef typename TimerTraits<T5>::ParameterType T5Parameter;
943  typedef typename TimerTraits<T5>::StoredType T5Stored;
944 
945  struct MemFnTimerImplFive
946  : public TimerImplFive<T1Parameter, T2Parameter, T3Parameter, T4Parameter, T5Parameter>
947  {
948  MemFnTimerImplFive(MEM_PTR memPtr, OBJ_PTR objPtr)
949  : m_memPtr(memPtr),
950  m_objPtr(objPtr)
951  {
952  }
953 
954  void SetArguments(T1Parameter a1,
955  T2Parameter a2,
956  T3Parameter a3,
957  T4Parameter a4,
958  T5Parameter a5) override
959  {
960  m_a1 = a1;
961  m_a2 = a2;
962  m_a3 = a3;
963  m_a4 = a4;
964  m_a5 = a5;
965  }
966 
967  EventId Schedule(const Time& delay) override
968  {
969  return Simulator::Schedule(delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3, m_a4, m_a5);
970  }
971 
972  void Invoke() override
973  {
975  m_memPtr)(m_a1, m_a2, m_a3, m_a4, m_a5);
976  }
977 
978  MEM_PTR m_memPtr;
979  OBJ_PTR m_objPtr;
980  T1Stored m_a1;
981  T2Stored m_a2;
982  T3Stored m_a3;
983  T4Stored m_a4;
984  T5Stored m_a5;
985  }* function = new MemFnTimerImplFive(memPtr, objPtr);
986 
987  return function;
988 }
989 
994 template <typename MEM_PTR, typename OBJ_PTR>
995 TimerImpl*
996 MakeTimerImpl(IntToType<6>, MEM_PTR memPtr, OBJ_PTR objPtr)
997 {
999  typedef typename TimerTraits<T1>::ParameterType T1Parameter;
1000  typedef typename TimerTraits<T1>::StoredType T1Stored;
1002  typedef typename TimerTraits<T2>::ParameterType T2Parameter;
1003  typedef typename TimerTraits<T2>::StoredType T2Stored;
1005  typedef typename TimerTraits<T3>::ParameterType T3Parameter;
1006  typedef typename TimerTraits<T3>::StoredType T3Stored;
1008  typedef typename TimerTraits<T4>::ParameterType T4Parameter;
1009  typedef typename TimerTraits<T4>::StoredType T4Stored;
1011  typedef typename TimerTraits<T5>::ParameterType T5Parameter;
1012  typedef typename TimerTraits<T5>::StoredType T5Stored;
1014  typedef typename TimerTraits<T6>::ParameterType T6Parameter;
1015  typedef typename TimerTraits<T6>::StoredType T6Stored;
1016 
1017  struct MemFnTimerImplSix : public TimerImplSix<T1Parameter,
1018  T2Parameter,
1019  T3Parameter,
1020  T4Parameter,
1021  T5Parameter,
1022  T6Parameter>
1023  {
1024  MemFnTimerImplSix(MEM_PTR memPtr, OBJ_PTR objPtr)
1025  : m_memPtr(memPtr),
1026  m_objPtr(objPtr)
1027  {
1028  }
1029 
1030  virtual void SetArguments(T1Parameter a1,
1031  T2Parameter a2,
1032  T3Parameter a3,
1033  T4Parameter a4,
1034  T5Parameter a5,
1035  T6Parameter a6)
1036  {
1037  m_a1 = a1;
1038  m_a2 = a2;
1039  m_a3 = a3;
1040  m_a4 = a4;
1041  m_a5 = a5;
1042  m_a6 = a6;
1043  }
1044 
1045  virtual EventId Schedule(const Time& delay)
1046  {
1047  return Simulator::Schedule(delay,
1048  m_memPtr,
1049  m_objPtr,
1050  m_a1,
1051  m_a2,
1052  m_a3,
1053  m_a4,
1054  m_a5,
1055  m_a6);
1056  }
1057 
1058  virtual void Invoke()
1059  {
1061  m_memPtr)(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
1062  }
1063 
1064  MEM_PTR m_memPtr;
1065  OBJ_PTR m_objPtr;
1066  T1Stored m_a1;
1067  T2Stored m_a2;
1068  T3Stored m_a3;
1069  T4Stored m_a4;
1070  T5Stored m_a5;
1071  T6Stored m_a6;
1072  }* function = new MemFnTimerImplSix(memPtr, objPtr);
1073 
1074  return function;
1075 }
1076  // \ingroup timer
1078 
1079 /********************************************************************
1080  * Implementation of TimerImpl itself.
1081  ********************************************************************/
1082 
1083 template <typename T1>
1084 void
1086 {
1088  auto impl = dynamic_cast<TimerImplBase*>(this);
1089  if (impl == nullptr)
1090  {
1091  NS_FATAL_ERROR("You tried to set Timer arguments incompatible with its function.");
1092  return;
1093  }
1094  impl->SetArguments(a1);
1095 }
1096 
1097 template <typename T1, typename T2>
1098 void
1099 TimerImpl::SetArgs(T1 a1, T2 a2)
1100 {
1103  TimerImplBase;
1104  auto impl = dynamic_cast<TimerImplBase*>(this);
1105  if (impl == nullptr)
1106  {
1107  NS_FATAL_ERROR("You tried to set Timer arguments incompatible with its function.");
1108  return;
1109  }
1110  impl->SetArguments(a1, a2);
1111 }
1112 
1113 template <typename T1, typename T2, typename T3>
1114 void
1115 TimerImpl::SetArgs(T1 a1, T2 a2, T3 a3)
1116 {
1120  TimerImplBase;
1121  auto impl = dynamic_cast<TimerImplBase*>(this);
1122  if (impl == nullptr)
1123  {
1124  NS_FATAL_ERROR("You tried to set Timer arguments incompatible with its function.");
1125  return;
1126  }
1127  impl->SetArguments(a1, a2, a3);
1128 }
1129 
1130 template <typename T1, typename T2, typename T3, typename T4>
1131 void
1132 TimerImpl::SetArgs(T1 a1, T2 a2, T3 a3, T4 a4)
1133 {
1138  TimerImplBase;
1139  auto impl = dynamic_cast<TimerImplBase*>(this);
1140  if (impl == nullptr)
1141  {
1142  NS_FATAL_ERROR("You tried to set Timer arguments incompatible with its function.");
1143  return;
1144  }
1145  impl->SetArguments(a1, a2, a3, a4);
1146 }
1147 
1148 template <typename T1, typename T2, typename T3, typename T4, typename T5>
1149 void
1150 TimerImpl::SetArgs(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
1151 {
1157  TimerImplBase;
1158  auto impl = dynamic_cast<TimerImplBase*>(this);
1159  if (impl == nullptr)
1160  {
1161  NS_FATAL_ERROR("You tried to set Timer arguments incompatible with its function.");
1162  return;
1163  }
1164  impl->SetArguments(a1, a2, a3, a4, a5);
1165 }
1166 
1167 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
1168 void
1169 TimerImpl::SetArgs(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
1170 {
1177  TimerImplBase;
1178  auto impl = dynamic_cast<TimerImplBase*>(this);
1179  if (impl == 0)
1180  {
1181  NS_FATAL_ERROR("You tried to set Timer arguments incompatible with its function.");
1182  return;
1183  }
1184  impl->SetArguments(a1, a2, a3, a4, a5, a6);
1185 }
1186 
1187 } // namespace ns3
1188 
1189 #endif /* TIMER_IMPL_H */
An identifier for simulation events.
Definition: event-id.h:55
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
The timer implementation underlying Timer and Watchdog.
Definition: timer-impl.h:43
void SetArgs(T1 a1)
Set the arguments to be used when invoking the expire function.
Definition: timer-impl.h:1085
virtual ~TimerImpl()
Destructor.
Definition: timer-impl.h:46
virtual void Invoke()=0
Invoke the expire function.
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:66
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
TimerImpl * MakeTimerImpl(FN fn)
Make a TimerImpl from a function pointer taking varying numbers of arguments.
Definition: timer-impl.h:254
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:205
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:190
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:658
Helper for the MakeTimerImpl functions which take a class method.
Definition: timer-impl.h:638
TimerImpl specialization class for varying numbers of arguments.
Definition: timer-impl.h:151
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:221
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:163
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:238
TypeTraits< typename TypeTraits< T >::ReferencedType >::NonConstType StoredType
Storage type for an argument.
Definition: timer-impl.h:240
const StoredType & ParameterType
Parameter type for an argument.
Definition: timer-impl.h:242
Inspect a type to deduce its features.
Definition: type-traits.h:40
ns3::TypeTraits introspection declaration and template implementation.