59 template <
typename... Args>
83template <
typename... Args>
101template <
typename U,
typename... Ts>
105 struct FnTimerImpl :
public TimerImplX<const std::remove_cvref_t<Ts>&...>
107 FnTimerImpl(
void (*fn)(Ts...))
112 void SetArguments(
const std::remove_cvref_t<Ts>&... args)
override
114 m_arguments = std::tuple(args...);
120 [&,
this](Ts... args) { return Simulator::Schedule(delay, m_fn, args...); },
124 void Invoke()
override
126 std::apply([
this](Ts... args) { (m_fn)(args...); }, m_arguments);
130 std::tuple<std::remove_cvref_t<Ts>...> m_arguments;
131 }* function =
new FnTimerImpl(fn);
148template <
typename OBJ_PTR,
typename U,
typename V,
typename... Ts>
152 struct MemFnTimerImpl :
public TimerImplX<const std::remove_cvref_t<Ts>&...>
154 MemFnTimerImpl(
decltype(memPtr) memPtr, OBJ_PTR objPtr)
155 : m_memPtr(std::bind_front(memPtr, objPtr))
159 void SetArguments(
const std::remove_cvref_t<Ts>&... args)
override
161 m_arguments = std::tuple(args...);
167 [&,
this](Ts... args) {
168 return Simulator::Schedule(delay, std::bind(m_memPtr, args...));
173 void Invoke()
override
175 std::apply(m_memPtr, m_arguments);
178 std::function<U(Ts...)> m_memPtr;
179 std::tuple<std::remove_cvref_t<Ts>...> m_arguments;
180 }* function =
new MemFnTimerImpl(memPtr, objPtr);
191template <
typename... Args>
196 auto impl =
dynamic_cast<TimerImplBase*
>(
this);
199 NS_FATAL_ERROR(
"You tried to set Timer arguments incompatible with its function.");
202 impl->SetArguments(args...);
An identifier for simulation events.
Simulation virtual time values and global simulation resolution.
The timer implementation underlying Timer and Watchdog.
virtual void Invoke()=0
Invoke the expire function.
virtual EventId Schedule(const Time &delay)=0
Schedule the callback for a future time.
void SetArgs(Args... args)
Set the arguments to be used when invoking the expire function.
virtual ~TimerImpl()
Destructor.
NS_FATAL_x macro definitions.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
TimerImpl * MakeTimerImpl(U(fn)(Ts...))
Make a TimerImpl from a function pointer taking varying numbers of arguments.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Simulator declaration.
TimerImpl specialization class for varying numbers of arguments.
virtual void SetArguments(Args... args)=0
Bind the arguments to be used when the callback function is invoked.