/usr/include/ns3.26/ns3/timer-impl.h is in libns3-dev 3.26+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef TIMER_IMPL_H
#define TIMER_IMPL_H
#include "simulator.h"
#include "type-traits.h"
#include "fatal-error.h"
#include "int-to-type.h"
/**
* \file
* \ingroup timer
* \ingroup timerimpl
* ns3::TimerImpl declaration and implementation.
*/
namespace ns3 {
/**
* \ingroup timer
* The timer implementation underlying Timer and Watchdog.
*/
class TimerImpl
{
public:
/** Destructor. */
virtual ~TimerImpl ()
{
}
/**
* Set the arguments to be used when invoking the expire function.
*/
/**@{*/
/**
* \tparam T1 \deduced Type of the first argument.
* \param [in] a1 The first argument
*/
template <typename T1>
void SetArgs (T1 a1);
/**
* \tparam T1 \deduced Type of the first argument.
* \tparam T2 \deduced Type of the second argument.
* \param [in] a1 the first argument
* \param [in] a2 the second argument
*/
template <typename T1, typename T2>
void SetArgs (T1 a1, T2 a2);
/**
* \tparam T1 \deduced Type of the first argument.
* \tparam T2 \deduced Type of the second argument.
* \tparam T3 \deduced Type of the third argument.
* \param [in] a1 the first argument
* \param [in] a2 the second argument
* \param [in] a3 the third argument
*/
template <typename T1, typename T2, typename T3>
void SetArgs (T1 a1, T2 a2, T3 a3);
/**
* \tparam T1 \deduced Type of the first argument.
* \tparam T2 \deduced Type of the second argument.
* \tparam T3 \deduced Type of the third argument.
* \tparam T4 \deduced Type of the fourth argument.
* \param [in] a1 the first argument
* \param [in] a2 the second argument
* \param [in] a3 the third argument
* \param [in] a4 the fourth argument
*/
template <typename T1, typename T2, typename T3,
typename T4>
void SetArgs (T1 a1, T2 a2, T3 a3, T4 a4);
/**
* \tparam T1 \deduced Type of the first argument.
* \tparam T2 \deduced Type of the second argument.
* \tparam T3 \deduced Type of the third argument.
* \tparam T4 \deduced Type of the fourth argument.
* \tparam T5 \deduced Type of the fifth argument.
* \param [in] a1 the first argument
* \param [in] a2 the second argument
* \param [in] a3 the third argument
* \param [in] a4 the fourth argument
* \param [in] a5 the fifth argument
*/
template <typename T1, typename T2, typename T3,
typename T4, typename T5>
void SetArgs (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
/**
* \tparam T1 \deduced Type of the first argument.
* \tparam T2 \deduced Type of the second argument.
* \tparam T3 \deduced Type of the third argument.
* \tparam T4 \deduced Type of the fourth argument.
* \tparam T5 \deduced Type of the fifth argument.
* \tparam T6 \deduced Type of the sixth argument.
* \param [in] a1 the first argument
* \param [in] a2 the second argument
* \param [in] a3 the third argument
* \param [in] a4 the fourth argument
* \param [in] a5 the fifth argument
* \param [in] a6 the sixth argument
*/
template <typename T1, typename T2, typename T3,
typename T4, typename T5, typename T6>
void SetArgs (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
/**@}*/
/**
* Schedule the callback for a future time.
*
* \param [in] delay The amount of time until the timer expires.
* \returns The scheduled EventId.
*/
virtual EventId Schedule (const Time &delay) = 0;
/** Invoke the expire function. */
virtual void Invoke (void) = 0;
};
} // namespace ns3
/********************************************************************
* Implementation of TimerImpl implementation functions.
********************************************************************/
namespace ns3 {
/**
* \ingroup timer
* \defgroup timerimpl TimerImpl Implementation
* @{
*/
/** TimerImpl specialization class for varying numbers of arguments. */
template <typename T1>
struct TimerImplOne : public TimerImpl
{
/**
* Bind the arguments to be used when the callback function is invoked.
*
* \param [in] a1 The first argument.
*/
virtual void SetArguments (T1 a1) = 0;
};
/** TimerImpl specialization class for varying numbers of arguments. */
template <typename T1, typename T2>
struct TimerImplTwo : public TimerImpl
{
/**
* Bind the arguments to be used when the callback function is invoked.
*
* \param [in] a1 The first argument.
* \param [in] a2 The second argument.
*/
virtual void SetArguments (T1 a1,T2 a2) = 0;
};
/** TimerImpl specialization class for varying numbers of arguments. */
template <typename T1, typename T2, typename T3>
struct TimerImplThree : public TimerImpl
{
/**
* Bind the arguments to be used when the callback function is invoked.
*
* \param [in] a1 The first argument.
* \param [in] a2 The second argument.
* \param [in] a3 The third argument.
*/
virtual void SetArguments (T1 a1,T2 a2,T3 a3) = 0;
};
/** TimerImpl specialization class for varying numbers of arguments. */
template <typename T1, typename T2, typename T3, typename T4>
struct TimerImplFour : public TimerImpl
{
/**
* Bind the arguments to be used when the callback function is invoked.
*
* \param [in] a1 The first argument.
* \param [in] a2 The second argument.
* \param [in] a3 The third argument.
* \param [in] a4 The fourth argument.
*/
virtual void SetArguments (T1 a1,T2 a2,T3 a3, T4 a4) = 0;
};
/** TimerImpl specialization class for varying numbers of arguments. */
template <typename T1, typename T2, typename T3, typename T4, typename T5>
struct TimerImplFive : public TimerImpl
{
/**
* Bind the arguments to be used when the callback function is invoked.
*
* \param [in] a1 The first argument.
* \param [in] a2 The second argument.
* \param [in] a3 The third argument.
* \param [in] a4 The fourth argument.
* \param [in] a5 The fifth argument.
*/
virtual void SetArguments (T1 a1,T2 a2,T3 a3, T4 a4, T5 a5) = 0;
};
/** TimerImpl specialization class for varying numbers of arguments. */
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct TimerImplSix : public TimerImpl
{
/**
* Bind the arguments to be used when the callback function is invoked.
*
* \param [in] a1 The first argument.
* \param [in] a2 The second argument.
* \param [in] a3 The third argument.
* \param [in] a4 The fourth argument.
* \param [in] a5 The fifth argument.
* \param [in] a6 The sixth argument.
*/
virtual void SetArguments (T1 a1,T2 a2,T3 a3, T4 a4, T5 a5, T6 a6) = 0;
};
/** Type and reference traits for TimerImpl arguments. */
template <typename T>
struct TimerTraits
{
/** Storage type for an argument. */
typedef typename TypeTraits<typename TypeTraits<T>::ReferencedType>::NonConstType StoredType;
/** Parameter type for an argument. */
typedef const StoredType &ParameterType;
};
/**
* Make a TimerImpl from a function pointer taking varying numbers of arguments.
*
* \tparam FN \deduced Function signature type of the callback function.
* \param [in] fn The function pointer to invoke when the timer expires.
* \returns The TimerImpl.
*/
template <typename FN>
TimerImpl *
MakeTimerImpl (FN fn)
{
NS_ASSERT (TypeTraits<FN>::IsFunctionPointer);
return MakeTimerImpl (IntToType<TypeTraits<FN>::FunctionPointerTraits::nArgs> (), fn);
}
/**
* Make a TimerImpl from a function pointer taking zero arguments.
* \copydetails MakeTimerImpl(FN)
*/
template <typename FN>
TimerImpl *
MakeTimerImpl (IntToType<0>, FN fn)
{
struct FnTimerImplZero : public TimerImpl
{
FnTimerImplZero (FN fn)
: m_fn (fn)
{
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_fn);
}
virtual void Invoke (void)
{
m_fn ();
}
FN m_fn;
} *function = new FnTimerImplZero (fn);
return function;
}
/**
* Make a TimerImpl from a function pointer taking one argument.
* \copydetails MakeTimerImpl(FN)
*/
template <typename FN>
TimerImpl *
MakeTimerImpl (IntToType<1>, FN fn)
{
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg1Type T1;
typedef typename TimerTraits<T1>::ParameterType T1Parameter;
typedef typename TimerTraits<T1>::StoredType T1Stored;
struct FnTimerImplOne : public TimerImplOne<T1Parameter>
{
FnTimerImplOne (FN fn)
: m_fn (fn)
{
}
virtual void SetArguments (T1Parameter a1)
{
m_a1 = a1;
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_fn, m_a1);
}
virtual void Invoke (void)
{
m_fn (m_a1);
}
FN m_fn;
T1Stored m_a1;
} *function = new FnTimerImplOne (fn);
return function;
}
/**
* Make a TimerImpl from a function pointer taking two arguments.
* \copydetails MakeTimerImpl(FN)
*/
template <typename FN>
TimerImpl *
MakeTimerImpl (IntToType<2>, FN fn)
{
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg1Type T1;
typedef typename TimerTraits<T1>::ParameterType T1Parameter;
typedef typename TimerTraits<T1>::StoredType T1Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg2Type T2;
typedef typename TimerTraits<T2>::ParameterType T2Parameter;
typedef typename TimerTraits<T2>::StoredType T2Stored;
struct FnTimerImplTwo : public TimerImplTwo<T1Parameter,T2Parameter>
{
FnTimerImplTwo (FN fn)
: m_fn (fn)
{
}
virtual void SetArguments (T1Parameter a1, T2Parameter a2)
{
m_a1 = a1;
m_a2 = a2;
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_fn, m_a1, m_a2);
}
virtual void Invoke (void)
{
m_fn (m_a1, m_a2);
}
FN m_fn;
T1Stored m_a1;
T2Stored m_a2;
} *function = new FnTimerImplTwo (fn);
return function;
}
/**
* Make a TimerImpl from a function pointer taking three arguments.
* \copydetails MakeTimerImpl(FN)
*/
template <typename FN>
TimerImpl *
MakeTimerImpl (IntToType<3>, FN fn)
{
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg1Type T1;
typedef typename TimerTraits<T1>::ParameterType T1Parameter;
typedef typename TimerTraits<T1>::StoredType T1Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg2Type T2;
typedef typename TimerTraits<T2>::ParameterType T2Parameter;
typedef typename TimerTraits<T2>::StoredType T2Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg3Type T3;
typedef typename TimerTraits<T3>::ParameterType T3Parameter;
typedef typename TimerTraits<T3>::StoredType T3Stored;
struct FnTimerImplThree : public TimerImplThree<T1Parameter,T2Parameter,T3Parameter>
{
FnTimerImplThree (FN fn)
: m_fn (fn)
{
}
virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3)
{
m_a1 = a1;
m_a2 = a2;
m_a3 = a3;
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_fn, m_a1, m_a2, m_a3);
}
virtual void Invoke (void)
{
m_fn (m_a1, m_a2, m_a3);
}
FN m_fn;
T1Stored m_a1;
T2Stored m_a2;
T3Stored m_a3;
} *function = new FnTimerImplThree (fn);
return function;
}
/**
* Make a TimerImpl from a function pointer taking four arguments.
* \copydetails MakeTimerImpl(FN)
*/
template <typename FN>
TimerImpl *
MakeTimerImpl (IntToType<4>, FN fn)
{
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg1Type T1;
typedef typename TimerTraits<T1>::ParameterType T1Parameter;
typedef typename TimerTraits<T1>::StoredType T1Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg2Type T2;
typedef typename TimerTraits<T2>::ParameterType T2Parameter;
typedef typename TimerTraits<T2>::StoredType T2Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg3Type T3;
typedef typename TimerTraits<T3>::ParameterType T3Parameter;
typedef typename TimerTraits<T3>::StoredType T3Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg4Type T4;
typedef typename TimerTraits<T4>::ParameterType T4Parameter;
typedef typename TimerTraits<T4>::StoredType T4Stored;
struct FnTimerImplFour : public TimerImplFour<T1Parameter,T2Parameter,T3Parameter,T4Parameter>
{
FnTimerImplFour (FN fn)
: m_fn (fn)
{
}
virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4)
{
m_a1 = a1;
m_a2 = a2;
m_a3 = a3;
m_a4 = a4;
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_fn, m_a1, m_a2, m_a3, m_a4);
}
virtual void Invoke (void)
{
m_fn (m_a1, m_a2, m_a3, m_a4);
}
FN m_fn;
T1Stored m_a1;
T2Stored m_a2;
T3Stored m_a3;
T4Stored m_a4;
} *function = new FnTimerImplFour (fn);
return function;
}
/**
* Make a TimerImpl from a function pointer taking five arguments.
* \copydetails MakeTimerImpl(FN)
*/
template <typename FN>
TimerImpl *
MakeTimerImpl (IntToType<5>, FN fn)
{
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg1Type T1;
typedef typename TimerTraits<T1>::ParameterType T1Parameter;
typedef typename TimerTraits<T1>::StoredType T1Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg2Type T2;
typedef typename TimerTraits<T2>::ParameterType T2Parameter;
typedef typename TimerTraits<T2>::StoredType T2Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg3Type T3;
typedef typename TimerTraits<T3>::ParameterType T3Parameter;
typedef typename TimerTraits<T3>::StoredType T3Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg4Type T4;
typedef typename TimerTraits<T4>::ParameterType T4Parameter;
typedef typename TimerTraits<T4>::StoredType T4Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg5Type T5;
typedef typename TimerTraits<T5>::ParameterType T5Parameter;
typedef typename TimerTraits<T5>::StoredType T5Stored;
struct FnTimerImplFive : public TimerImplFive<T1Parameter,T2Parameter,T3Parameter,T4Parameter,T5Parameter>
{
FnTimerImplFive (FN fn)
: m_fn (fn)
{
}
virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4, T5Parameter a5)
{
m_a1 = a1;
m_a2 = a2;
m_a3 = a3;
m_a4 = a4;
m_a5 = a5;
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_fn, m_a1, m_a2, m_a3, m_a4, m_a5);
}
virtual void Invoke (void)
{
m_fn (m_a1, m_a2, m_a3, m_a4, m_a5);
}
FN m_fn;
T1Stored m_a1;
T2Stored m_a2;
T3Stored m_a3;
T4Stored m_a4;
T5Stored m_a5;
} *function = new FnTimerImplFive (fn);
return function;
}
/**
* Make a TimerImpl from a function pointer taking six arguments.
* \copydetails MakeTimerImpl(FN)
*/
template <typename FN>
TimerImpl *
MakeTimerImpl (IntToType<6>, FN fn)
{
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg1Type T1;
typedef typename TimerTraits<T1>::ParameterType T1Parameter;
typedef typename TimerTraits<T1>::StoredType T1Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg2Type T2;
typedef typename TimerTraits<T2>::ParameterType T2Parameter;
typedef typename TimerTraits<T2>::StoredType T2Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg3Type T3;
typedef typename TimerTraits<T3>::ParameterType T3Parameter;
typedef typename TimerTraits<T3>::StoredType T3Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg4Type T4;
typedef typename TimerTraits<T4>::ParameterType T4Parameter;
typedef typename TimerTraits<T4>::StoredType T4Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg5Type T5;
typedef typename TimerTraits<T5>::ParameterType T5Parameter;
typedef typename TimerTraits<T5>::StoredType T5Stored;
typedef typename TypeTraits<FN>::FunctionPointerTraits::Arg6Type T6;
typedef typename TimerTraits<T6>::ParameterType T6Parameter;
typedef typename TimerTraits<T6>::StoredType T6Stored;
struct FnTimerImplSix : public TimerImplSix<T1Parameter,T2Parameter,T3Parameter,T4Parameter,T5Parameter,T6Parameter>
{
FnTimerImplSix (FN fn)
: m_fn (fn)
{
}
virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4, T5Parameter a5, T6Parameter a6)
{
m_a1 = a1;
m_a2 = a2;
m_a3 = a3;
m_a4 = a4;
m_a5 = a5;
m_a6 = a6;
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_fn, m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
}
virtual void Invoke (void)
{
m_fn (m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
}
FN m_fn;
T1Stored m_a1;
T2Stored m_a2;
T3Stored m_a3;
T4Stored m_a4;
T5Stored m_a5;
T6Stored m_a6;
} *function = new FnTimerImplSix (fn);
return function;
}
/**
* Helper for the MakeTimerImpl functions which take a class method.
*
* This helper converts a pointer to a reference.
*
* This is the generic template declaration (with empty body).
*
* \tparam T \explicit The object type.
*/
template <typename T>
struct TimerImplMemberTraits;
/**
* Helper for the MakeTimerImpl functions which take a class method.
*
* This helper converts a pointer to a reference.
*
* This is the specialization for pointer to \c T.
*
* \tparam T \explicit The object type.
*/
template <typename T>
struct TimerImplMemberTraits<T *>
{
/**
* Convert a pointer type to a reference.
*
* \param [in] p The pointer.
* \returns A reference to the object pointed to by \c p.
*/
static T &GetReference (T *p)
{
return *p;
}
};
/**
* Make a TimerImpl from a class method pointer taking
* a varying number of arguments.
*
* \tparam MEM_PTR \deduced Class method function signature type.
* \tparam OBJ_PTR \deduced Class type.
* \param [in] memPtr Class method to invoke when the timer expires.
* \param [in] objPtr Object instance pointer.
* \returns The TimerImpl.
*/
template <typename MEM_PTR, typename OBJ_PTR>
TimerImpl *
MakeTimerImpl (MEM_PTR memPtr, OBJ_PTR objPtr)
{
NS_ASSERT (TypeTraits<MEM_PTR>::IsPointerToMember);
return MakeTimerImpl (IntToType<TypeTraits<MEM_PTR>::PointerToMemberTraits::nArgs> (), memPtr, objPtr);
}
/**
* Make a TimerImpl from a function pointer taking zero arguments.
* \copydetails MakeTimerImpl(MEM_PTR,OBJ_PTR)
*/
template <typename MEM_PTR, typename OBJ_PTR>
TimerImpl *
MakeTimerImpl (IntToType<0>, MEM_PTR memPtr, OBJ_PTR objPtr)
{
struct MemFnTimerImplZero : public TimerImpl
{
MemFnTimerImplZero (MEM_PTR memPtr, OBJ_PTR objPtr)
: m_memPtr (memPtr),
m_objPtr (objPtr)
{
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_memPtr, m_objPtr);
}
virtual void Invoke (void)
{
(TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)();
}
MEM_PTR m_memPtr;
OBJ_PTR m_objPtr;
} *function = new MemFnTimerImplZero (memPtr, objPtr);
return function;
}
/**
* Make a TimerImpl from a function pointer taking one argument.
* \copydetails MakeTimerImpl(MEM_PTR,OBJ_PTR)
*/
template <typename MEM_PTR, typename OBJ_PTR>
TimerImpl *
MakeTimerImpl (IntToType<1>, MEM_PTR memPtr, OBJ_PTR objPtr)
{
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg1Type T1;
typedef typename TimerTraits<T1>::ParameterType T1Parameter;
typedef typename TimerTraits<T1>::StoredType T1Stored;
struct MemFnTimerImplOne : public TimerImplOne<T1Parameter>
{
MemFnTimerImplOne (MEM_PTR memPtr, OBJ_PTR objPtr)
: m_memPtr (memPtr),
m_objPtr (objPtr)
{
}
virtual void SetArguments (T1Parameter a1)
{
m_a1 = a1;
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1);
}
virtual void Invoke (void)
{
(TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1);
}
MEM_PTR m_memPtr;
OBJ_PTR m_objPtr;
T1Stored m_a1;
} *function = new MemFnTimerImplOne (memPtr, objPtr);
return function;
}
/**
* Make a TimerImpl from a function pointer taking two arguments.
* \copydetails MakeTimerImpl(MEM_PTR,OBJ_PTR)
*/
template <typename MEM_PTR, typename OBJ_PTR>
TimerImpl *
MakeTimerImpl (IntToType<2>, MEM_PTR memPtr, OBJ_PTR objPtr)
{
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg1Type T1;
typedef typename TimerTraits<T1>::ParameterType T1Parameter;
typedef typename TimerTraits<T1>::StoredType T1Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg2Type T2;
typedef typename TimerTraits<T2>::ParameterType T2Parameter;
typedef typename TimerTraits<T2>::StoredType T2Stored;
struct MemFnTimerImplTwo : public TimerImplTwo<T1Parameter,T2Parameter>
{
MemFnTimerImplTwo (MEM_PTR memPtr, OBJ_PTR objPtr)
: m_memPtr (memPtr),
m_objPtr (objPtr)
{
}
virtual void SetArguments (T1Parameter a1, T2Parameter a2)
{
m_a1 = a1;
m_a2 = a2;
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2);
}
virtual void Invoke (void)
{
(TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2);
}
MEM_PTR m_memPtr;
OBJ_PTR m_objPtr;
T1Stored m_a1;
T2Stored m_a2;
} *function = new MemFnTimerImplTwo (memPtr, objPtr);
return function;
}
/**
* Make a TimerImpl from a function pointer taking three arguments.
* \copydetails MakeTimerImpl(MEM_PTR,OBJ_PTR)
*/
template <typename MEM_PTR, typename OBJ_PTR>
TimerImpl *
MakeTimerImpl (IntToType<3>, MEM_PTR memPtr, OBJ_PTR objPtr)
{
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg1Type T1;
typedef typename TimerTraits<T1>::ParameterType T1Parameter;
typedef typename TimerTraits<T1>::StoredType T1Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg2Type T2;
typedef typename TimerTraits<T2>::ParameterType T2Parameter;
typedef typename TimerTraits<T2>::StoredType T2Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg3Type T3;
typedef typename TimerTraits<T3>::ParameterType T3Parameter;
typedef typename TimerTraits<T3>::StoredType T3Stored;
struct MemFnTimerImplThree : public TimerImplThree<T1Parameter,T2Parameter,T3Parameter>
{
MemFnTimerImplThree (MEM_PTR memPtr, OBJ_PTR objPtr)
: m_memPtr (memPtr),
m_objPtr (objPtr)
{
}
virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3)
{
m_a1 = a1;
m_a2 = a2;
m_a3 = a3;
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3);
}
virtual void Invoke (void)
{
(TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2, m_a3);
}
MEM_PTR m_memPtr;
OBJ_PTR m_objPtr;
T1Stored m_a1;
T2Stored m_a2;
T3Stored m_a3;
} *function = new MemFnTimerImplThree (memPtr, objPtr);
return function;
}
/**
* Make a TimerImpl from a function pointer taking four arguments.
* \copydetails MakeTimerImpl(MEM_PTR,OBJ_PTR)
*/
template <typename MEM_PTR, typename OBJ_PTR>
TimerImpl *
MakeTimerImpl (IntToType<4>, MEM_PTR memPtr, OBJ_PTR objPtr)
{
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg1Type T1;
typedef typename TimerTraits<T1>::ParameterType T1Parameter;
typedef typename TimerTraits<T1>::StoredType T1Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg2Type T2;
typedef typename TimerTraits<T2>::ParameterType T2Parameter;
typedef typename TimerTraits<T2>::StoredType T2Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg3Type T3;
typedef typename TimerTraits<T3>::ParameterType T3Parameter;
typedef typename TimerTraits<T3>::StoredType T3Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg4Type T4;
typedef typename TimerTraits<T4>::ParameterType T4Parameter;
typedef typename TimerTraits<T4>::StoredType T4Stored;
struct MemFnTimerImplFour : public TimerImplFour<T1Parameter,T2Parameter,T3Parameter,T4Parameter>
{
MemFnTimerImplFour (MEM_PTR memPtr, OBJ_PTR objPtr)
: m_memPtr (memPtr),
m_objPtr (objPtr)
{
}
virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4)
{
m_a1 = a1;
m_a2 = a2;
m_a3 = a3;
m_a4 = a4;
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3, m_a4);
}
virtual void Invoke (void)
{
(TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2, m_a3, m_a4);
}
MEM_PTR m_memPtr;
OBJ_PTR m_objPtr;
T1Stored m_a1;
T2Stored m_a2;
T3Stored m_a3;
T4Stored m_a4;
} *function = new MemFnTimerImplFour (memPtr, objPtr);
return function;
}
/**
* Make a TimerImpl from a function pointer taking five arguments.
* \copydetails MakeTimerImpl(MEM_PTR,OBJ_PTR)
*/
template <typename MEM_PTR, typename OBJ_PTR>
TimerImpl *
MakeTimerImpl (IntToType<5>, MEM_PTR memPtr, OBJ_PTR objPtr)
{
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg1Type T1;
typedef typename TimerTraits<T1>::ParameterType T1Parameter;
typedef typename TimerTraits<T1>::StoredType T1Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg2Type T2;
typedef typename TimerTraits<T2>::ParameterType T2Parameter;
typedef typename TimerTraits<T2>::StoredType T2Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg3Type T3;
typedef typename TimerTraits<T3>::ParameterType T3Parameter;
typedef typename TimerTraits<T3>::StoredType T3Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg4Type T4;
typedef typename TimerTraits<T4>::ParameterType T4Parameter;
typedef typename TimerTraits<T4>::StoredType T4Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg5Type T5;
typedef typename TimerTraits<T5>::ParameterType T5Parameter;
typedef typename TimerTraits<T5>::StoredType T5Stored;
struct MemFnTimerImplFive : public TimerImplFive<T1Parameter,T2Parameter,T3Parameter,T4Parameter,T5Parameter>
{
MemFnTimerImplFive (MEM_PTR memPtr, OBJ_PTR objPtr)
: m_memPtr (memPtr),
m_objPtr (objPtr)
{
}
virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4,T5Parameter a5)
{
m_a1 = a1;
m_a2 = a2;
m_a3 = a3;
m_a4 = a4;
m_a5 = a5;
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3, m_a4, m_a5);
}
virtual void Invoke (void)
{
(TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2, m_a3, m_a4, m_a5);
}
MEM_PTR m_memPtr;
OBJ_PTR m_objPtr;
T1Stored m_a1;
T2Stored m_a2;
T3Stored m_a3;
T4Stored m_a4;
T5Stored m_a5;
} *function = new MemFnTimerImplFive (memPtr, objPtr);
return function;
}
/**
* Make a TimerImpl from a function pointer taking six arguments.
* \copydetails MakeTimerImpl(MEM_PTR,OBJ_PTR)
*/
template <typename MEM_PTR, typename OBJ_PTR>
TimerImpl *
MakeTimerImpl (IntToType<6>, MEM_PTR memPtr, OBJ_PTR objPtr)
{
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg1Type T1;
typedef typename TimerTraits<T1>::ParameterType T1Parameter;
typedef typename TimerTraits<T1>::StoredType T1Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg2Type T2;
typedef typename TimerTraits<T2>::ParameterType T2Parameter;
typedef typename TimerTraits<T2>::StoredType T2Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg3Type T3;
typedef typename TimerTraits<T3>::ParameterType T3Parameter;
typedef typename TimerTraits<T3>::StoredType T3Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg4Type T4;
typedef typename TimerTraits<T4>::ParameterType T4Parameter;
typedef typename TimerTraits<T4>::StoredType T4Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg5Type T5;
typedef typename TimerTraits<T5>::ParameterType T5Parameter;
typedef typename TimerTraits<T5>::StoredType T5Stored;
typedef typename TypeTraits<MEM_PTR>::PointerToMemberTraits::Arg6Type T6;
typedef typename TimerTraits<T6>::ParameterType T6Parameter;
typedef typename TimerTraits<T6>::StoredType T6Stored;
struct MemFnTimerImplSix : public TimerImplSix<T1Parameter,T2Parameter,T3Parameter,T4Parameter,T5Parameter,T6Parameter>
{
MemFnTimerImplSix (MEM_PTR memPtr, OBJ_PTR objPtr)
: m_memPtr (memPtr),
m_objPtr (objPtr)
{
}
virtual void SetArguments (T1Parameter a1, T2Parameter a2, T3Parameter a3, T4Parameter a4,T5Parameter a5,T6Parameter a6)
{
m_a1 = a1;
m_a2 = a2;
m_a3 = a3;
m_a4 = a4;
m_a5 = a5;
m_a6 = a6;
}
virtual EventId Schedule (const Time &delay)
{
return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
}
virtual void Invoke (void)
{
(TimerImplMemberTraits<OBJ_PTR>::GetReference (m_objPtr).*m_memPtr)(m_a1, m_a2, m_a3, m_a4, m_a5, m_a6);
}
MEM_PTR m_memPtr;
OBJ_PTR m_objPtr;
T1Stored m_a1;
T2Stored m_a2;
T3Stored m_a3;
T4Stored m_a4;
T5Stored m_a5;
T6Stored m_a6;
} *function = new MemFnTimerImplSix (memPtr, objPtr);
return function;
}
/**@}*/ // \ingroup timer
/********************************************************************
* Implementation of TimerImpl itself.
********************************************************************/
template <typename T1>
void
TimerImpl::SetArgs (T1 a1)
{
typedef struct TimerImplOne<
typename TimerTraits<T1>::ParameterType
> TimerImplBase;
TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
if (impl == 0)
{
NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
return;
}
impl->SetArguments (a1);
}
template <typename T1, typename T2>
void
TimerImpl::SetArgs (T1 a1, T2 a2)
{
typedef struct TimerImplTwo<
typename TimerTraits<T1>::ParameterType,
typename TimerTraits<T2>::ParameterType
> TimerImplBase;
TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
if (impl == 0)
{
NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
return;
}
impl->SetArguments (a1, a2);
}
template <typename T1, typename T2, typename T3>
void
TimerImpl::SetArgs (T1 a1, T2 a2, T3 a3)
{
typedef struct TimerImplThree<
typename TimerTraits<T1>::ParameterType,
typename TimerTraits<T2>::ParameterType,
typename TimerTraits<T3>::ParameterType
> TimerImplBase;
TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
if (impl == 0)
{
NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
return;
}
impl->SetArguments (a1, a2, a3);
}
template <typename T1, typename T2, typename T3, typename T4>
void
TimerImpl::SetArgs (T1 a1, T2 a2, T3 a3, T4 a4)
{
typedef struct TimerImplFour<
typename TimerTraits<T1>::ParameterType,
typename TimerTraits<T2>::ParameterType,
typename TimerTraits<T3>::ParameterType,
typename TimerTraits<T4>::ParameterType
> TimerImplBase;
TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
if (impl == 0)
{
NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
return;
}
impl->SetArguments (a1, a2, a3, a4);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void
TimerImpl::SetArgs (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
typedef struct TimerImplFive<
typename TimerTraits<T1>::ParameterType,
typename TimerTraits<T2>::ParameterType,
typename TimerTraits<T3>::ParameterType,
typename TimerTraits<T4>::ParameterType,
typename TimerTraits<T5>::ParameterType
> TimerImplBase;
TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
if (impl == 0)
{
NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
return;
}
impl->SetArguments (a1, a2, a3, a4, a5);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
void
TimerImpl::SetArgs (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
{
typedef struct TimerImplSix<
typename TimerTraits<T1>::ParameterType,
typename TimerTraits<T2>::ParameterType,
typename TimerTraits<T3>::ParameterType,
typename TimerTraits<T4>::ParameterType,
typename TimerTraits<T5>::ParameterType,
typename TimerTraits<T6>::ParameterType
> TimerImplBase;
TimerImplBase *impl = dynamic_cast<TimerImplBase *> (this);
if (impl == 0)
{
NS_FATAL_ERROR ("You tried to set Timer arguments incompatible with its function.");
return;
}
impl->SetArguments (a1, a2, a3, a4, a5, a6);
}
} // namespace ns3
#endif /* TIMER_IMPL_H */
|