core: use variadic template for CreateObject

This commit is contained in:
Vivek Jain
2020-05-28 22:18:55 +00:00
committed by Peter Barnes
parent 5128a68dc6
commit 97dd10ea59
8 changed files with 272 additions and 2391 deletions

View File

@@ -55,41 +55,7 @@ namespace ns3 {
* Callback implementation classes
*/
/**
* \ingroup callback
* \defgroup makecallbackmemptr MakeCallback from member function pointer
*
* Build Callbacks for class method members which take varying numbers
* of arguments and potentially returning a value.
*
* Generally the \c MakeCallback functions are invoked with the
* method function address first, followed by the \c this pointer:
* \code
* MakeCallback ( & MyClass::Handler, this);
* \endcode
*
* There is not a version with bound arguments. You may be able to
* get the same result by using \c MakeBoundCallback with a \c static
* member function, as in:
* \code
* MakeBoundCallback ( & MyClass::StaticHandler, this);
* \endcode
* This still leaves two argument slots available for binding.
*/
/**
* \ingroup callback
* \defgroup makecallbackfnptr MakeCallback from function pointers
*
* Build Callbacks for functions which take varying numbers of arguments
* and potentially returning a value.
*/
/**
* \ingroup callback
* \defgroup makenullcallback MakeCallback with no arguments
*
* Define empty (Null) callbacks as placeholders for unset callback variables.
*/
/**
* \ingroup callback
* \ingroup callbackimpl
* \defgroup makeboundcallback MakeBoundCallback from functions bound with up to three arguments.
*
* Build bound Callbacks which take varying numbers of arguments,
@@ -104,19 +70,21 @@ namespace ns3 {
/**
* \ingroup makecallbackmemptr
* \ingroup callbackimpl
*
* Trait class to convert a pointer into a reference,
* used by MemPtrCallBackImpl
* \tparam T \deduced The type being converted.
*/
template <typename T>
struct CallbackTraits;
/**
* \ingroup makecallbackmemptr
* \ingroup callbackimpl
*
* Trait class to convert a pointer into a reference,
* used by MemPtrCallBackImpl
* \tparam T \deduced The type being converted.
*/
template <typename T>
struct CallbackTraits<T *>
@@ -164,7 +132,7 @@ protected:
/**
* Helper to get the C++ typeid as a string.
*
* \tparam T The type of the argument.
* \tparam T \explicit The type of the argument.
* \returns The result of applying typeid to the template type \pname{T}.
*/
template <typename T>
@@ -187,6 +155,9 @@ protected:
/**
* \ingroup callbackimpl
* The unqualified CallbackImpl class
* \tparam R \explicit The return type of the Callback.
* The remaining template arguments are the types of any arguments
* to the Callback.
*/
template <typename R, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
class CallbackImpl;
@@ -458,6 +429,7 @@ public:
/**
* \ingroup callbackimpl
* CallbackImpl with functors
* \tparam T \deduced Function pointer type.
*/
template <typename T, typename R, typename T1, typename T2, typename T3, typename T4,typename T5, typename T6, typename T7, typename T8, typename T9>
class FunctorCallbackImpl : public CallbackImpl<R,T1,T2,T3,T4,T5,T6,T7,T8,T9>
@@ -617,8 +589,10 @@ private:
};
/**
* \ingroup makecallbackmemptr
* \ingroup callbackimpl
* CallbackImpl for pointer to member functions
* \tparam OBJ_PTR \deduced Type of the target object, as a pointer.
* \tparam MEM_PTR \deduced Type of the class member function.
*/
template <typename OBJ_PTR, typename MEM_PTR, typename R, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
class MemPtrCallbackImpl : public CallbackImpl<R,T1,T2,T3,T4,T5,T6,T7,T8,T9>
@@ -783,6 +757,8 @@ private:
/**
* \ingroup callbackimpl
* CallbackImpl for functors with first argument bound at construction
* \tparam T \explicit Type of the functor.
* \tparam TX \explicit Type of the bound argument.
*/
template <typename T, typename R, typename TX, typename T1, typename T2, typename T3, typename T4,typename T5, typename T6, typename T7, typename T8>
class BoundFunctorCallbackImpl : public CallbackImpl<R,T1,T2,T3,T4,T5,T6,T7,T8,empty>
@@ -790,6 +766,10 @@ class BoundFunctorCallbackImpl : public CallbackImpl<R,T1,T2,T3,T4,T5,T6,T7,T8,e
public:
/**
* Construct from functor and a bound argument
* \tparam FUNCTOR \deduced The actual type of the functor.
* This must be convertible to \pname{T}.
* \tparam ARG \deduced The actual type of the bound argument.
* This must be convertible to type \pname{TX}.
* \param [in] functor The functor
* \param [in] a The argument to bind
*/
@@ -931,6 +911,9 @@ private:
/**
* \ingroup callbackimpl
* CallbackImpl for functors with first two arguments bound at construction
* \tparam T \explicit Type of the functor.
* \tparam TX1 \explicit Type of the first bound argument.
* \tparam TX2 \explicit Type of the second bound argument.
*/
template <typename T, typename R, typename TX1, typename TX2, typename T1, typename T2, typename T3, typename T4,typename T5, typename T6, typename T7>
class TwoBoundFunctorCallbackImpl : public CallbackImpl<R,T1,T2,T3,T4,T5,T6,T7,empty,empty>
@@ -938,6 +921,12 @@ class TwoBoundFunctorCallbackImpl : public CallbackImpl<R,T1,T2,T3,T4,T5,T6,T7,e
public:
/**
* Construct from functor and two arguments
* \tparam FUNCTOR \deduced The actual type of the functor.
* This must be convertible to \pname{T}.
* \tparam ARG1 \deduced The actual type of the first bound argument.
* This must be convertible to type \pname{TX1}.
* \tparam ARG2 \deduced The actual type of the second bound argument.
* This must be convertible to type \pname{TX2}.
* \param [in] functor The functor
* \param [in] arg1 The first argument to bind
* \param [in] arg2 The second argument to bind
@@ -1066,6 +1055,10 @@ private:
/**
* \ingroup callbackimpl
* CallbackImpl for functors with first three arguments bound at construction
* \tparam T \explicit Type of the functor.
* \tparam TX1 \explicit Type of the first bound argument.
* \tparam TX2 \explicit Type of the second bound argument.
* \tparam TX3 \explicit Type of the third bound argument.
*/
template <typename T, typename R, typename TX1, typename TX2, typename TX3, typename T1, typename T2, typename T3, typename T4,typename T5, typename T6>
class ThreeBoundFunctorCallbackImpl : public CallbackImpl<R,T1,T2,T3,T4,T5,T6,empty,empty,empty>
@@ -1073,6 +1066,14 @@ class ThreeBoundFunctorCallbackImpl : public CallbackImpl<R,T1,T2,T3,T4,T5,T6,em
public:
/**
* Construct from functor and three arguments
* \tparam FUNCTOR \deduced The actual type of the functor.
* This must be convertible to \pname{T}.
* \tparam ARG1 \deduced The actual type of the first bound argument.
* This must be convertible to type \pname{TX1}.
* \tparam ARG2 \deduced The actual type of the second bound argument.
* This must be convertible to type \pname{TX2}.
* \tparam ARG3 \deduced The actual type of the third bound argument.
* This must be convertible to type \pname{TX3}.
* \param [in] functor The functor
* \param [in] arg1 The first argument to bind
* \param [in] arg2 The second argument to bind
@@ -1263,6 +1264,10 @@ protected:
* the pointer.
*
* \see attribute_Callback
*
* \tparam R \explicit The return type of the Callback.
* The remaining template arguments are the types of any arguments
* to the Callback.
*/
template<typename R,
typename T1 = empty, typename T2 = empty,
@@ -1284,6 +1289,7 @@ public:
* \internal
* There are two dummy args below to ensure that this constructor is
* always properly disambiguated by the c++ compiler.
* \tparam FUNCTOR \deduced The actual type of the functor.
*/
template <typename FUNCTOR>
Callback (FUNCTOR const &functor, bool, bool)
@@ -1293,6 +1299,8 @@ public:
/**
* Construct a member function pointer call back.
*
* \tparam OBJ_PTR \deduced Type of the target object, as a pointer.
* \tparam MEM_PTR \deduced Type of the class member function.
* \param [in] objPtr Pointer to the object
* \param [in] memPtr Pointer to the member function
*/
@@ -1313,6 +1321,7 @@ public:
/**
* Bind the first arguments
*
* \tparam T \deduced The type of the bound argument.
* \param [in] a Argument to bind
* \return The bound callback
*/
@@ -1330,6 +1339,8 @@ public:
/**
* Bind the first two arguments
*
* \tparam TX1 \deduced Type of the first bound argument.
* \tparam TX2 \deduced Type of the second bound argument.
* \param [in] a1 First argument to bind
* \param [in] a2 Second argument to bind
* \return The bound callback
@@ -1348,6 +1359,9 @@ public:
/**
* Bind the first three arguments
*
* \tparam TX1 \deduced The actual type of the first bound argument.
* \tparam TX2 \deduced The actual type of the second bound argument.
* \tparam TX3 \deduced The actual type of the third bound argument.
* \param [in] a1 First argument to bind
* \param [in] a2 Second argument to bind
* \param [in] a3 Third argument to bind
@@ -1595,250 +1609,92 @@ bool operator != (Callback<R,T1,T2,T3,T4,T5,T6,T7,T8,T9> a, Callback<R,T1,T2,T3,
}
/**
* \ingroup makecallbackmemptr
* @{
*/
/**
* Build Callbacks for class method members which take varying numbers
* of arguments and potentially returning a value.
*
* \tparam T \deduced Type of the class having the member function.
* \tparam OBJ \deduced Type of the class instance.
* \tparam R \deduced Return type of the callback.
* \tparam Ts \deduced Type list of any arguments to the member function.
*
* \param [in] memPtr Class method member pointer
* \param [in] objPtr Class instance
* \return A wrapper Callback
*
* Build Callbacks for class method members which take varying numbers of arguments
* and potentially returning a value.
* This \c MakeCallback is invoked with the
* method function address first, followed by the \c this pointer:
* \code
* MakeCallback ( & MyClass::Handler, this);
* \endcode
*
* There is not a version with bound arguments. You may be able to
* get the same result by using \c MakeBoundCallback with a \c static
* member function, as in:
* \code
* MakeBoundCallback ( & MyClass::StaticHandler, this);
* \endcode
* This still leaves two argument slots available for binding.
*/
template <typename T, typename OBJ, typename R>
Callback<R> MakeCallback (R (T::*memPtr)(void), OBJ objPtr)
template <typename T, typename OBJ, typename R, typename... Ts>
Callback<R,Ts...> MakeCallback (R (T::*memPtr)(Ts...), OBJ objPtr)
{
return Callback<R> (objPtr, memPtr);
return Callback<R,Ts...> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R>
Callback<R> MakeCallback (R (T::*memPtr)() const, OBJ objPtr)
template <typename T, typename OBJ, typename R, typename... Ts>
Callback<R,Ts...> MakeCallback (R (T::*memPtr)(Ts...) const, OBJ objPtr)
{
return Callback<R> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1>
Callback<R,T1> MakeCallback (R (T::*memPtr)(T1), OBJ objPtr)
{
return Callback<R,T1> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1>
Callback<R,T1> MakeCallback (R (T::*memPtr)(T1) const, OBJ objPtr)
{
return Callback<R,T1> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2>
Callback<R,T1,T2> MakeCallback (R (T::*memPtr)(T1,T2), OBJ objPtr)
{
return Callback<R,T1,T2> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2>
Callback<R,T1,T2> MakeCallback (R (T::*memPtr)(T1,T2) const, OBJ objPtr)
{
return Callback<R,T1,T2> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1,typename T2, typename T3>
Callback<R,T1,T2,T3> MakeCallback (R (T::*memPtr)(T1,T2,T3), OBJ objPtr)
{
return Callback<R,T1,T2,T3> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1,typename T2, typename T3>
Callback<R,T1,T2,T3> MakeCallback (R (T::*memPtr)(T1,T2,T3) const, OBJ objPtr)
{
return Callback<R,T1,T2,T3> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4>
Callback<R,T1,T2,T3,T4> MakeCallback (R (T::*memPtr)(T1,T2,T3,T4), OBJ objPtr)
{
return Callback<R,T1,T2,T3,T4> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4>
Callback<R,T1,T2,T3,T4> MakeCallback (R (T::*memPtr)(T1,T2,T3,T4) const, OBJ objPtr)
{
return Callback<R,T1,T2,T3,T4> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4,typename T5>
Callback<R,T1,T2,T3,T4,T5> MakeCallback (R (T::*memPtr)(T1,T2,T3,T4,T5), OBJ objPtr)
{
return Callback<R,T1,T2,T3,T4,T5> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4,typename T5>
Callback<R,T1,T2,T3,T4,T5> MakeCallback (R (T::*memPtr)(T1,T2,T3,T4,T5) const, OBJ objPtr)
{
return Callback<R,T1,T2,T3,T4,T5> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4,typename T5,typename T6>
Callback<R,T1,T2,T3,T4,T5,T6> MakeCallback (R (T::*memPtr)(T1,T2,T3,T4,T5,T6), OBJ objPtr)
{
return Callback<R,T1,T2,T3,T4,T5,T6> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4,typename T5, typename T6>
Callback<R,T1,T2,T3,T4,T5,T6> MakeCallback (R (T::*memPtr)(T1,T2,T3,T4,T5,T6) const, OBJ objPtr)
{
return Callback<R,T1,T2,T3,T4,T5,T6> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4,typename T5,typename T6, typename T7>
Callback<R,T1,T2,T3,T4,T5,T6,T7> MakeCallback (R (T::*memPtr)(T1,T2,T3,T4,T5,T6,T7), OBJ objPtr)
{
return Callback<R,T1,T2,T3,T4,T5,T6,T7> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4,typename T5, typename T6, typename T7>
Callback<R,T1,T2,T3,T4,T5,T6,T7> MakeCallback (R (T::*memPtr)(T1,T2,T3,T4,T5,T6,T7) const, OBJ objPtr)
{
return Callback<R,T1,T2,T3,T4,T5,T6,T7> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4,typename T5,typename T6, typename T7, typename T8>
Callback<R,T1,T2,T3,T4,T5,T6,T7,T8> MakeCallback (R (T::*memPtr)(T1,T2,T3,T4,T5,T6,T7,T8), OBJ objPtr)
{
return Callback<R,T1,T2,T3,T4,T5,T6,T7,T8> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4,typename T5, typename T6, typename T7, typename T8>
Callback<R,T1,T2,T3,T4,T5,T6,T7,T8> MakeCallback (R (T::*memPtr)(T1,T2,T3,T4,T5,T6,T7,T8) const, OBJ objPtr)
{
return Callback<R,T1,T2,T3,T4,T5,T6,T7,T8> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4,typename T5,typename T6, typename T7, typename T8, typename T9>
Callback<R,T1,T2,T3,T4,T5,T6,T7,T8,T9> MakeCallback (R (T::*memPtr)(T1,T2,T3,T4,T5,T6,T7,T8,T9), OBJ objPtr)
{
return Callback<R,T1,T2,T3,T4,T5,T6,T7,T8,T9> (objPtr, memPtr);
}
template <typename T, typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4,typename T5, typename T6, typename T7, typename T8, typename T9>
Callback<R,T1,T2,T3,T4,T5,T6,T7,T8,T9> MakeCallback (R (T::*memPtr)(T1,T2,T3,T4,T5,T6,T7,T8,T9) const, OBJ objPtr)
{
return Callback<R,T1,T2,T3,T4,T5,T6,T7,T8,T9> (objPtr, memPtr);
return Callback<R,Ts...> (objPtr, memPtr);
}
/**@}*/
/**
* \ingroup makecallbackfnptr
* @{
*/
/**
* \ingroup callback
* \param [in] fnPtr Function pointer
* \return A wrapper Callback
*
* Build Callbacks for functions which take varying numbers of arguments
* and potentially returning a value.
*
* \tparam R \deduced Return type of the callback function..
* \tparam Ts \deduced Type list of any arguments to the member function.
*/
template <typename R>
Callback<R> MakeCallback (R (*fnPtr)())
template <typename R, typename... Ts>
Callback<R,Ts...> MakeCallback (R (*fnPtr)(Ts...))
{
return Callback<R> (fnPtr, true, true);
return Callback<R,Ts...> (fnPtr, true, true);
}
template <typename R, typename T1>
Callback<R,T1> MakeCallback (R (*fnPtr)(T1))
{
return Callback<R,T1> (fnPtr, true, true);
}
template <typename R, typename T1, typename T2>
Callback<R,T1,T2> MakeCallback (R (*fnPtr)(T1,T2))
{
return Callback<R,T1,T2> (fnPtr, true, true);
}
template <typename R, typename T1, typename T2,typename T3>
Callback<R,T1,T2,T3> MakeCallback (R (*fnPtr)(T1,T2,T3))
{
return Callback<R,T1,T2,T3> (fnPtr, true, true);
}
template <typename R, typename T1, typename T2,typename T3,typename T4>
Callback<R,T1,T2,T3,T4> MakeCallback (R (*fnPtr)(T1,T2,T3,T4))
{
return Callback<R,T1,T2,T3,T4> (fnPtr, true, true);
}
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5>
Callback<R,T1,T2,T3,T4,T5> MakeCallback (R (*fnPtr)(T1,T2,T3,T4,T5))
{
return Callback<R,T1,T2,T3,T4,T5> (fnPtr, true, true);
}
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5,typename T6>
Callback<R,T1,T2,T3,T4,T5,T6> MakeCallback (R (*fnPtr)(T1,T2,T3,T4,T5,T6))
{
return Callback<R,T1,T2,T3,T4,T5,T6> (fnPtr, true, true);
}
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5,typename T6, typename T7>
Callback<R,T1,T2,T3,T4,T5,T6,T7> MakeCallback (R (*fnPtr)(T1,T2,T3,T4,T5,T6,T7))
{
return Callback<R,T1,T2,T3,T4,T5,T6,T7> (fnPtr, true, true);
}
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5,typename T6, typename T7, typename T8>
Callback<R,T1,T2,T3,T4,T5,T6,T7,T8> MakeCallback (R (*fnPtr)(T1,T2,T3,T4,T5,T6,T7,T8))
{
return Callback<R,T1,T2,T3,T4,T5,T6,T7,T8> (fnPtr, true, true);
}
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5,typename T6, typename T7, typename T8, typename T9>
Callback<R,T1,T2,T3,T4,T5,T6,T7,T8,T9> MakeCallback (R (*fnPtr)(T1,T2,T3,T4,T5,T6,T7,T8,T9))
{
return Callback<R,T1,T2,T3,T4,T5,T6,T7,T8,T9> (fnPtr, true, true);
}
/**@}*/
/**
* \ingroup makenullcallback
* @{
*/
/**
* \ingroup callback
* \return A wrapper Callback
*
* Build null Callbacks which take no arguments,
* for varying number of template arguments,
* and potentially returning a value.
*
* \tparam R \deduced Return type of the callback function..
* \tparam Ts \deduced Type list of any arguments to the member function.
*/
template <typename R>
Callback<R> MakeNullCallback (void)
template <typename R, typename... Ts>
Callback<R,Ts...> MakeNullCallback (void)
{
return Callback<R> ();
return Callback<R,Ts...> ();
}
template <typename R, typename T1>
Callback<R,T1> MakeNullCallback (void)
{
return Callback<R,T1> ();
}
template <typename R, typename T1, typename T2>
Callback<R,T1,T2> MakeNullCallback (void)
{
return Callback<R,T1,T2> ();
}
template <typename R, typename T1, typename T2,typename T3>
Callback<R,T1,T2,T3> MakeNullCallback (void)
{
return Callback<R,T1,T2,T3> ();
}
template <typename R, typename T1, typename T2,typename T3,typename T4>
Callback<R,T1,T2,T3,T4> MakeNullCallback (void)
{
return Callback<R,T1,T2,T3,T4> ();
}
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5>
Callback<R,T1,T2,T3,T4,T5> MakeNullCallback (void)
{
return Callback<R,T1,T2,T3,T4,T5> ();
}
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5,typename T6>
Callback<R,T1,T2,T3,T4,T5,T6> MakeNullCallback (void)
{
return Callback<R,T1,T2,T3,T4,T5,T6> ();
}
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5,typename T6, typename T7>
Callback<R,T1,T2,T3,T4,T5,T6,T7> MakeNullCallback (void)
{
return Callback<R,T1,T2,T3,T4,T5,T6,T7> ();
}
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5,typename T6, typename T7, typename T8>
Callback<R,T1,T2,T3,T4,T5,T6,T7,T8> MakeNullCallback (void)
{
return Callback<R,T1,T2,T3,T4,T5,T6,T7,T8> ();
}
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5,typename T6, typename T7, typename T8, typename T9>
Callback<R,T1,T2,T3,T4,T5,T6,T7,T8,T9> MakeNullCallback (void)
{
return Callback<R,T1,T2,T3,T4,T5,T6,T7,T8,T9> ();
}
/**@}*/
/**
* \ingroup makeboundcallback
* @{
* Make Callbacks with one bound argument.
*
* \tparam R \deduced Return type of the callback
* \tparam TX \deduced Formal type of the first argument to the callback.
* \tparam ARG \deduced Actual type of the bound argument.
* Remaining template parameters are the types of remaining arguments
* to the callback.
* \param [in] fnPtr Function pointer
* \param [in] a1 First bound argument
* \return A bound Callback
@@ -1920,6 +1776,13 @@ Callback<R,T1,T2,T3,T4,T5,T6,T7,T8> MakeBoundCallback (R (*fnPtr)(TX,T1,T2,T3,T4
* \ingroup makeboundcallback
* @{
* Make Callbacks with two bound arguments.
* \tparam R \deduced Return type of the callback
* \tparam TX1 \deduced Formal type of the first argument to the callback.
* \tparam TX2 \deduced Formal type of the second argument to the callback.
* \tparam ARG1 \deduced Actual type of the first bound argument.
* \tparam ARG2 \deduced Actual type of the second bound argument.
* Remaining template parameters are the types of remaining arguments
* to the callback.
* \param [in] fnPtr Function pointer
* \param [in] a1 First bound argument
* \param [in] a2 Second bound argument
@@ -1994,6 +1857,15 @@ Callback<R,T1,T2,T3,T4,T5,T6,T7> MakeBoundCallback (R (*fnPtr)(TX1,TX2,T1,T2,T3,
* \ingroup makeboundcallback
* @{
* Make Callbacks with three bound arguments.
* \tparam R \deduced Return type of the callback
* \tparam TX1 \deduced Formal type of the first argument to the callback.
* \tparam TX2 \deduced Formal type of the second argument to the callback.
* \tparam TX3 \deduced Formal type of the third argument to the callback.
* \tparam ARG1 \deduced Actual type of the first bound argument.
* \tparam ARG2 \deduced Actual type of the second bound argument.
* \tparam ARG3 \deduced Actual type of the third bound argument.
* Remaining template parameters are the types of remaining arguments
* to the callback.
* \param [in] a1 First bound argument
* \param [in] a2 Second bound argument
* \param [in] a3 Third bound argument
@@ -2079,6 +1951,7 @@ public:
/**
* Give value my callback, if type compatible
*
* \tparam T \deduced The type in which to retrieve the value.
* \param [out] value Destination callback
* \returns \c true if successful
*/

View File

@@ -149,8 +149,9 @@ public:
* Get a pointer to the requested aggregated Object. If the type of object
* requested is ns3::Object, a Ptr to the calling object is returned.
*
* \returns A pointer to the requested aggregated Object matching the
* type requested, or zero if it could not be found.
* \tparam T \explicit The type of the aggregated Object to retrieve.
* \returns A pointer to the requested Object, or zero
* if it could not be found.
*/
template <typename T>
inline Ptr<T> GetObject (void) const;
@@ -158,6 +159,7 @@ public:
* Get a pointer to the requested aggregated Object by TypeId. If the
* TypeId argument is ns3::Object, a Ptr to the calling object is returned.
*
* \tparam T \explicit The type of the aggregated Object to retrieve.
* \param [in] tid The TypeId of the requested Object.
* \returns A pointer to the requested Object with the specified TypeId,
* or zero if it could not be found.
@@ -223,7 +225,8 @@ public:
/**
* Check if the object has been initialized.
*
* \returns true if the object has been initialized.
* \brief Check if the object has been initialized.
* \returns \c true if the object has been initialized.
*/
bool IsInitialized (void) const;
@@ -297,6 +300,7 @@ private:
/**
* Copy an Object.
*
* \tparam T \deduced The type of the Object being copied.
* \param [in] object A pointer to the object to copy.
* \returns A copy of the input object.
*
@@ -313,7 +317,7 @@ private:
/**
* Set the TypeId and construct all Attributes of an Object.
*
* \tparam T \explicit The type of the derived object we are constructing.
* \tparam T \deduced The type of the Object to complete.
* \param [in] object The uninitialized object pointer.
* \return The derived object.
*/
@@ -552,144 +556,13 @@ Ptr<T> CompleteConstruct (T *object)
* Create an object by type, with varying number of constructor parameters.
*
* \tparam T \explicit The type of the derived object to construct.
* \param [in] args Arguments to pass to the constructor.
* \return The derived object.
*/
template <typename T>
Ptr<T> CreateObject (void)
template <typename T, typename... Args>
Ptr<T> CreateObject (Args&&... args)
{
return CompleteConstruct (new T ());
}
/**
* \copybrief CreateObject()
* \tparam T \explicit The type of the derived object to construct.
* \tparam T1 \deduced The type of the constructor argument.
* \param [in] a1 The constructor argument
* \return The derived object.
*/
template <typename T, typename T1>
Ptr<T> CreateObject (T1 a1)
{
return CompleteConstruct (new T (a1));
}
/**
* \copybrief CreateObject()
* \tparam T \explicit The type of the derived object to construct.
* \tparam T1 \deduced The type of the first constructor argument.
* \tparam T2 \deduced The type of the second constructor argument.
* \param [in] a1 The constructor first argument
* \param [in] a2 The constructor second argument
* \return The derived object.
*/
template <typename T, typename T1, typename T2>
Ptr<T> CreateObject (T1 a1, T2 a2)
{
return CompleteConstruct (new T (a1,a2));
}
/**
* \copybrief CreateObject()
* \tparam T \explicit The type of the derived object to construct.
* \tparam T1 \deduced The type of the first constructor argument.
* \tparam T2 \deduced The type of the second constructor argument.
* \tparam T3 \deduced The type of the third constructor argument.
* \param [in] a1 The constructor first argument
* \param [in] a2 The constructor second argument
* \param [in] a3 The constructor third argument
* \return The derived object.
*/
template <typename T, typename T1, typename T2, typename T3>
Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3)
{
return CompleteConstruct (new T (a1,a2,a3));
}
/**
* \copybrief CreateObject()
* \tparam T \explicit The type of the derived object to construct.
* \tparam T1 \deduced The type of the first constructor argument.
* \tparam T2 \deduced The type of the second constructor argument.
* \tparam T3 \deduced The type of the third constructor argument.
* \tparam T4 \deduced The type of the fourth constructor argument.
* \param [in] a1 The constructor first argument
* \param [in] a2 The constructor second argument
* \param [in] a3 The constructor third argument
* \param [in] a4 The constructor fourth argument
* \return The derived object.
*/
template <typename T, typename T1, typename T2, typename T3, typename T4>
Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4)
{
return CompleteConstruct (new T (a1,a2,a3,a4));
}
/**
* \copybrief CreateObject()
* \tparam T \explicit The type of the derived object to construct.
* \tparam T1 \deduced The type of the first constructor argument.
* \tparam T2 \deduced The type of the second constructor argument.
* \tparam T3 \deduced The type of the third constructor argument.
* \tparam T4 \deduced The type of the fourth constructor argument.
* \tparam T5 \deduced The type of the fifth constructor argument.
* \param [in] a1 The constructor first argument
* \param [in] a2 The constructor second argument
* \param [in] a3 The constructor third argument
* \param [in] a4 The constructor fourth argument
* \param [in] a5 The constructor fifth argument
* \return The derived object.
*/
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
return CompleteConstruct (new T (a1,a2,a3,a4,a5));
}
/**
* \copybrief CreateObject()
* \tparam T \explicit The type of the derived object to construct.
* \tparam T1 \deduced The type of the first constructor argument.
* \tparam T2 \deduced The type of the second constructor argument.
* \tparam T3 \deduced The type of the third constructor argument.
* \tparam T4 \deduced The type of the fourth constructor argument.
* \tparam T5 \deduced The type of the fifth constructor argument.
* \tparam T6 \deduced The type of the sixth constructor argument.
* \param [in] a1 The constructor first argument
* \param [in] a2 The constructor second argument
* \param [in] a3 The constructor third argument
* \param [in] a4 The constructor fourth argument
* \param [in] a5 The constructor fifth argument
* \param [in] a6 The constructor sixth argument
* \return The derived object.
*/
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
{
return CompleteConstruct (new T (a1,a2,a3,a4,a5,a6));
}
/**
* \copybrief CreateObject()
* \tparam T \explicit The type of the derived object to construct.
* \tparam T1 \deduced The type of the first constructor argument.
* \tparam T2 \deduced The type of the second constructor argument.
* \tparam T3 \deduced The type of the third constructor argument.
* \tparam T4 \deduced The type of the fourth constructor argument.
* \tparam T5 \deduced The type of the fifth constructor argument.
* \tparam T6 \deduced The type of the sixth constructor argument.
* \tparam T7 \deduced The type of the seventh constructor argument.
* \param [in] a1 The constructor first argument
* \param [in] a2 The constructor second argument
* \param [in] a3 The constructor third argument
* \param [in] a4 The constructor fourth argument
* \param [in] a5 The constructor fifth argument
* \param [in] a6 The constructor sixth argument
* \param [in] a7 The constructor seventh argument
* \return The derived object.
*/
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
{
return CompleteConstruct (new T (a1,a2,a3,a4,a5,a6,a7));
return CompleteConstruct (new T (std::forward<Args> (args)...));
}
/**@}*/

View File

@@ -67,7 +67,7 @@ namespace ns3 {
* functions and their goal is just is save you a small
* bit of typing.
*
* \tparam T \explicit The underlying type.
* \tparam T \explicit The type of the underlying object.
*/
template <typename T>
class Ptr
@@ -95,6 +95,7 @@ private:
* to returning to the caller so the caller is
* responsible for calling Unref himself.
*
* \tparam U \deduced The actual type of the argument and return pointer.
* \param [in] p Smart pointer
* \return The pointer managed by this smart pointer.
*/
@@ -107,6 +108,7 @@ private:
* to returning to the caller so the caller is not
* responsible for calling Unref himself.
*
* \tparam U \deduced The actual type of the argument and return pointer.
* \param [in] p Smart pointer
* \return The pointer managed by this smart pointer.
*/
@@ -148,7 +150,7 @@ public:
/**
* Copy, removing \c const qualifier.
*
* \tparam U \deduced The underlying type of the \c const object.
* \tparam U \deduced The type underlying the Ptr being copied.
* \param [in] o The Ptr to copy.
*/
template <typename U>
@@ -211,143 +213,27 @@ public:
* Create class instances by constructors with varying numbers
* of arguments and return them by Ptr.
*
* These methods work for any class \c T.
* This template work for any class \c T derived from ns3::SimpleRefCount
*
* \see CreateObject for methods to create derivatives of ns3::Object
*/
/** @{ */
/**
* \tparam T \explicit The type of class object to create.
* \return A Ptr to the newly created \c T.
*/
template <typename T>
Ptr<T> Create (void);
/**
* \tparam T \explicit The type of class object to create.
* \tparam T1 \deduced The type of the first constructor argument.
* \param [in] a1 The first constructor argument.
* \tparam Ts \deduced Types of the constructor arguments.
* \param [in] args Constructor arguments.
* \return A Ptr to the newly created \c T.
*/
template <typename T,
typename T1>
Ptr<T> Create (T1 a1);
typename... Ts>
Ptr<T> Create (Ts... args);
/**
* \tparam T \explicit The type of class object to create.
* \tparam T1 \deduced The type of the first constructor argument.
* \tparam T2 \deduced The type of the second constructor argument.
* \param [in] a1 The first constructor argument.
* \param [in] a2 The second constructor argument.
* \return A Ptr to the newly created \c T.
*/
template <typename T,
typename T1, typename T2>
Ptr<T> Create (T1 a1, T2 a2);
/**
* \tparam T \explicit The type of class object to create.
* \tparam T1 \deduced The type of the first constructor argument.
* \tparam T2 \deduced The type of the second constructor argument.
* \tparam T3 \deduced The type of the third constructor argument.
* \param [in] a1 The first constructor argument.
* \param [in] a2 The second constructor argument.
* \param [in] a3 The third constructor argument.
* \return A Ptr to the newly created \c T.
*/
template <typename T,
typename T1, typename T2,
typename T3>
Ptr<T> Create (T1 a1, T2 a2, T3 a3);
/**
* \tparam T \explicit The type of class object to create.
* \tparam T1 \deduced The type of the first constructor argument.
* \tparam T2 \deduced The type of the second constructor argument.
* \tparam T3 \deduced The type of the third constructor argument.
* \tparam T4 \deduced The type of the fourth constructor argument.
* \param [in] a1 The first constructor argument.
* \param [in] a2 The second constructor argument.
* \param [in] a3 The third constructor argument.
* \param [in] a4 The fourth constructor argument.
* \return A Ptr to the newly created \c T.
*/
template <typename T,
typename T1, typename T2,
typename T3, typename T4>
Ptr<T> Create (T1 a1, T2 a2, T3 a3, T4 a4);
/**
* \tparam T \explicit The type of class object to create.
* \tparam T1 \deduced The type of the first constructor argument.
* \tparam T2 \deduced The type of the second constructor argument.
* \tparam T3 \deduced The type of the third constructor argument.
* \tparam T4 \deduced The type of the fourth constructor argument.
* \tparam T5 \deduced The type of the fifth constructor argument.
* \param [in] a1 The first constructor argument.
* \param [in] a2 The second constructor argument.
* \param [in] a3 The third constructor argument.
* \param [in] a4 The fourth constructor argument.
* \param [in] a5 The fifth constructor argument.
* \return A Ptr to the newly created \c T.
*/
template <typename T,
typename T1, typename T2,
typename T3, typename T4,
typename T5>
Ptr<T> Create (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
/**
* \tparam T \explicit The type of class object to create.
* \tparam T1 \deduced The type of the first constructor argument.
* \tparam T2 \deduced The type of the second constructor argument.
* \tparam T3 \deduced The type of the third constructor argument.
* \tparam T4 \deduced The type of the fourth constructor argument.
* \tparam T5 \deduced The type of the fifth constructor argument.
* \tparam T6 \deduced The type of the sixth constructor argument.
* \param [in] a1 The first constructor argument.
* \param [in] a2 The second constructor argument.
* \param [in] a3 The third constructor argument.
* \param [in] a4 The fourth constructor argument.
* \param [in] a5 The fifth constructor argument.
* \param [in] a6 The sixth constructor argument.
* \return A Ptr to the newly created \c T.
*/
template <typename T,
typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6>
Ptr<T> Create (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
/**
* \tparam T \explicit The type of class object to create.
* \tparam T1 \deduced The type of the first constructor argument.
* \tparam T2 \deduced The type of the second constructor argument.
* \tparam T3 \deduced The type of the third constructor argument.
* \tparam T4 \deduced The type of the fourth constructor argument.
* \tparam T5 \deduced The type of the fifth constructor argument.
* \tparam T6 \deduced The type of the sixth constructor argument.
* \tparam T7 \deduced The type of the seventh constructor argument.
* \param [in] a1 The first constructor argument.
* \param [in] a2 The second constructor argument.
* \param [in] a3 The third constructor argument.
* \param [in] a4 The fourth constructor argument.
* \param [in] a5 The fifth constructor argument.
* \param [in] a6 The sixth constructor argument.
* \param [in] a7 The seventh constructor argument.
* \return A Ptr to the newly created \c T.
*/
template <typename T,
typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7>
Ptr<T> Create (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7);
/** @}*/
/**
* \ingroup ptr
* Output streamer.
* \tparam T \deduced The type of the underlying Object.
* \param [in,out] os The output stream.
* \param [in] p The Ptr.
* \returns The stream.
@@ -422,6 +308,7 @@ bool operator != (Ptr<T1> const &lhs, Ptr<T2> const &rhs);
* \ingroup ptr
* Comparison operator applied to the underlying pointers.
*
* \tparam T \deduced The type of the operands.
* \param [in] lhs The left operand.
* \param [in] rhs The right operand.
* \return The comparison on the underlying pointers.
@@ -461,7 +348,7 @@ struct CallbackTraits;
*
* This is the specialization for Ptr types.
*
* \tparam T \deduced The base object type.
* \tparam T \deduced The type of the underlying object.
*/
template <typename T>
struct CallbackTraits<Ptr<T> >
@@ -488,7 +375,7 @@ struct EventMemberImplObjTraits;
*
* This is the specialization for Ptr types.
*
* \tparam T \explicit The class type.
* \tparam T \deduced The type of the underlying object.
*/
template <typename T>
struct EventMemberImplObjTraits<Ptr<T> >
@@ -514,52 +401,10 @@ namespace ns3 {
* friend non-member function implementations
************************************************/
template <typename T>
Ptr<T> Create (void)
template <typename T, typename... Ts>
Ptr<T> Create (Ts... args)
{
return Ptr<T> (new T (), false);
}
template <typename T, typename T1>
Ptr<T> Create (T1 a1)
{
return Ptr<T> (new T (a1), false);
}
template <typename T, typename T1, typename T2>
Ptr<T> Create (T1 a1, T2 a2)
{
return Ptr<T> (new T (a1, a2), false);
}
template <typename T, typename T1, typename T2, typename T3>
Ptr<T> Create (T1 a1, T2 a2, T3 a3)
{
return Ptr<T> (new T (a1, a2, a3), false);
}
template <typename T, typename T1, typename T2, typename T3, typename T4>
Ptr<T> Create (T1 a1, T2 a2, T3 a3, T4 a4)
{
return Ptr<T> (new T (a1, a2, a3, a4), false);
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
Ptr<T> Create (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
return Ptr<T> (new T (a1, a2, a3, a4, a5), false);
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
Ptr<T> Create (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
{
return Ptr<T> (new T (a1, a2, a3, a4, a5, a6), false);
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
Ptr<T> Create (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
{
return Ptr<T> (new T (a1, a2, a3, a4, a5, a6, a7), false);
return Ptr<T> (new T (args...), false);
}
template <typename U>
@@ -682,6 +527,7 @@ StaticCast (Ptr<T2> const&p)
/**
* Return a deep copy of a Ptr.
*
* \tparam T \deduced The type of the underlying object.
* \param [in] object The object Ptr to copy.
* \returns The copy.
*/

View File

@@ -254,30 +254,6 @@ Simulator::DoScheduleDestroy (EventImpl *impl)
}
EventId
Simulator::Schedule (Time const &delay, void (*f)(void))
{
return DoSchedule (delay, MakeEvent (f));
}
void
Simulator::ScheduleWithContext (uint32_t context, Time const &delay, void (*f)(void))
{
return ScheduleWithContext (context, delay, MakeEvent (f));
}
EventId
Simulator::ScheduleNow (void (*f)(void))
{
return DoScheduleNow (MakeEvent (f));
}
EventId
Simulator::ScheduleDestroy (void (*f)(void))
{
return DoScheduleDestroy (MakeEvent (f));
}
void
Simulator::Remove (const EventId &id)
{

File diff suppressed because it is too large Load Diff

View File

@@ -54,15 +54,15 @@ class TimerImpl;
/**
* \ingroup timer
* \brief A simple Timer class
* \brief A simple virtual Timer class
*
* A timer is used to hold together a delay, a function to invoke
* A (virtual time) timer is used to hold together a delay, a function to invoke
* when the delay expires, and a set of arguments to pass to the function
* when the delay expires.
*
* A Timer can be suspended, resumed, cancelled and queried for the
* time left, but it can't be extended (except by suspending and
* resuming.)
* resuming).
*
* A timer can also be used to enforce a set of predefined event lifetime
* management policies. These policies are specified at construction time
@@ -123,6 +123,7 @@ public:
~Timer ();
/**
* \tparam FN \deduced The type of the function.
* \param [in] fn the function
*
* Store this function in this Timer for later use by Timer::Schedule.
@@ -131,6 +132,8 @@ public:
void SetFunction (FN fn);
/**
* \tparam MEM_PTR \deduced The type of the class member function.
* \tparam OBJ_PTR \deduced The type of the class instance pointer.
* \param [in] memPtr the member function pointer
* \param [in] objPtr the pointer to object
*
@@ -142,62 +145,13 @@ public:
/**
* \param [in] a1 the first argument
*
* Store this argument in this Timer for later use by Timer::Schedule.
*/
template <typename T1>
void SetArguments (T1 a1);
/**
* \param [in] a1 the first argument
* \param [in] a2 the second argument
* \tparam Ts \deduced Argument types
* \param [in] args arguments
*
* Store these arguments in this Timer for later use by Timer::Schedule.
*/
template <typename T1, typename T2>
void SetArguments (T1 a1, T2 a2);
/**
* \param [in] a1 the first argument
* \param [in] a2 the second argument
* \param [in] a3 the third argument
*
* Store these arguments in this Timer for later use by Timer::Schedule.
*/
template <typename T1, typename T2, typename T3>
void SetArguments (T1 a1, T2 a2, T3 a3);
/**
* \param [in] a1 the first argument
* \param [in] a2 the second argument
* \param [in] a3 the third argument
* \param [in] a4 the fourth argument
*
* Store these arguments in this Timer for later use by Timer::Schedule.
*/
template <typename T1, typename T2, typename T3, typename T4>
void SetArguments (T1 a1, T2 a2, T3 a3, T4 a4);
/**
* \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
*
* Store these arguments in this Timer for later use by Timer::Schedule.
*/
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
/**
* \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
*
* Store these arguments in this Timer for later use by Timer::Schedule.
*/
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
void SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
template <typename... Ts>
void SetArguments (Ts... args);
/**
* \param [in] delay The delay
@@ -334,75 +288,16 @@ Timer::SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr)
m_impl = MakeTimerImpl (memPtr, objPtr);
}
template <typename T1>
template <typename... Ts>
void
Timer::SetArguments (T1 a1)
Timer::SetArguments (Ts... args)
{
if (m_impl == 0)
{
NS_FATAL_ERROR ("You cannot set the arguments of a Timer before setting its function.");
return;
}
m_impl->SetArgs (a1);
}
template <typename T1, typename T2>
void
Timer::SetArguments (T1 a1, T2 a2)
{
if (m_impl == 0)
{
NS_FATAL_ERROR ("You cannot set the arguments of a Timer before setting its function.");
return;
}
m_impl->SetArgs (a1, a2);
}
template <typename T1, typename T2, typename T3>
void
Timer::SetArguments (T1 a1, T2 a2, T3 a3)
{
if (m_impl == 0)
{
NS_FATAL_ERROR ("You cannot set the arguments of a Timer before setting its function.");
return;
}
m_impl->SetArgs (a1, a2, a3);
}
template <typename T1, typename T2, typename T3, typename T4>
void
Timer::SetArguments (T1 a1, T2 a2, T3 a3, T4 a4)
{
if (m_impl == 0)
{
NS_FATAL_ERROR ("You cannot set the arguments of a Timer before setting its function.");
return;
}
m_impl->SetArgs (a1, a2, a3, a4);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void
Timer::SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
if (m_impl == 0)
{
NS_FATAL_ERROR ("You cannot set the arguments of a Timer before setting its function.");
return;
}
m_impl->SetArgs (a1, a2, a3, a4, a5);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
void
Timer::SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
{
if (m_impl == 0)
{
NS_FATAL_ERROR ("You cannot set the arguments of a Timer before setting its function.");
return;
}
m_impl->SetArgs (a1, a2, a3, a4, a5, a6);
m_impl->SetArgs (args...);
}
} // namespace ns3

View File

@@ -36,29 +36,19 @@ namespace ns3 {
* \ingroup tracing
* \brief Forward calls to a chain of Callback
*
* An TracedCallback has almost exactly the same API as a normal
* A TracedCallback has almost exactly the same API as a normal
* Callback but instead of forwarding calls to a single function
* (as a Callback normally does), it forwards calls to a chain
* of Callback. Connect adds a Callback at the end of the chain
* of callbacks. Disconnect removes a Callback from the chain of callbacks.
*
* This is a functor: the chain of Callbacks is invoked by
* calling one of the \c operator() forms with the appropriate
* calling the \c operator() form with the appropriate
* number of arguments.
*
* \tparam T1 \explicit Type of the first argument to the functor.
* \tparam T2 \explicit Type of the second argument to the functor.
* \tparam T3 \explicit Type of the third argument to the functor.
* \tparam T4 \explicit Type of the fourth argument to the functor.
* \tparam T5 \explicit Type of the fifth argument to the functor.
* \tparam T6 \explicit Type of the sixth argument to the functor.
* \tparam T7 \explicit Type of the seventh argument to the functor.
* \tparam T8 \explicit Type of the eighth argument to the functor.
* \tparam Ts \explicit Types of the functor arguments.
*/
template<typename T1 = empty, typename T2 = empty,
typename T3 = empty, typename T4 = empty,
typename T5 = empty, typename T6 = empty,
typename T7 = empty, typename T8 = empty>
template<typename... Ts>
class TracedCallback
{
public:
@@ -94,120 +84,11 @@ public:
*/
void Disconnect (const CallbackBase & callback, std::string path);
/**
* \name Functors taking various numbers of arguments.
*
* The version selected is determined by the number of arguments
* at the point where the Callback is invoked in the class
* which fires the Callback.
* \brief Functor which invokes the chain of Callbacks.
* \tparam Ts \deduced Types of the functor arguments.
* \param [in] args The arguments to the functor
*/
/**@{*/
/** Functor which invokes the chain of Callbacks. */
void operator() (void) const;
/**
* \copybrief operator()()
* \tparam T1 \deduced Type of the first argument to the functor.
* \param [in] a1 The first argument to the functor.
*/
void operator() (T1 a1) const;
/**
* \copybrief operator()()
* \tparam T1 \deduced Type of the first argument to the functor.
* \tparam T2 \deduced Type of the second argument to the functor.
* \param [in] a1 The first argument to the functor.
* \param [in] a2 The second argument to the functor.
*/
void operator() (T1 a1, T2 a2) const;
/**
* \copybrief operator()()
* \tparam T1 \deduced Type of the first argument to the functor.
* \tparam T2 \deduced Type of the second argument to the functor.
* \tparam T3 \deduced Type of the third argument to the functor.
* \param [in] a1 The first argument to the functor.
* \param [in] a2 The second argument to the functor.
* \param [in] a3 The third argument to the functor.
*/
void operator() (T1 a1, T2 a2, T3 a3) const;
/**
* \copybrief operator()()
* \tparam T1 \deduced Type of the first argument to the functor.
* \tparam T2 \deduced Type of the second argument to the functor.
* \tparam T3 \deduced Type of the third argument to the functor.
* \tparam T4 \deduced Type of the fourth argument to the functor.
* \param [in] a1 The first argument to the functor.
* \param [in] a2 The second argument to the functor.
* \param [in] a3 The third argument to the functor.
* \param [in] a4 The fourth argument to the functor.
*/
void operator() (T1 a1, T2 a2, T3 a3, T4 a4) const;
/**
* \copybrief operator()()
* \tparam T1 \deduced Type of the first argument to the functor.
* \tparam T2 \deduced Type of the second argument to the functor.
* \tparam T3 \deduced Type of the third argument to the functor.
* \tparam T4 \deduced Type of the fourth argument to the functor.
* \tparam T5 \deduced Type of the fifth argument to the functor.
* \param [in] a1 The first argument to the functor.
* \param [in] a2 The second argument to the functor.
* \param [in] a3 The third argument to the functor.
* \param [in] a4 The fourth argument to the functor.
* \param [in] a5 The fifth argument to the functor.
*/
void operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) const;
/**
* \copybrief operator()()
* \tparam T1 \deduced Type of the first argument to the functor.
* \tparam T2 \deduced Type of the second argument to the functor.
* \tparam T3 \deduced Type of the third argument to the functor.
* \tparam T4 \deduced Type of the fourth argument to the functor.
* \tparam T5 \deduced Type of the fifth argument to the functor.
* \tparam T6 \deduced Type of the sixth argument to the functor.
* \param [in] a1 The first argument to the functor.
* \param [in] a2 The second argument to the functor.
* \param [in] a3 The third argument to the functor.
* \param [in] a4 The fourth argument to the functor.
* \param [in] a5 The fifth argument to the functor.
* \param [in] a6 The sixth argument to the functor.
*/
void operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) const;
/**
* \copybrief operator()()
* \tparam T1 \deduced Type of the first argument to the functor.
* \tparam T2 \deduced Type of the second argument to the functor.
* \tparam T3 \deduced Type of the third argument to the functor.
* \tparam T4 \deduced Type of the fourth argument to the functor.
* \tparam T5 \deduced Type of the fifth argument to the functor.
* \tparam T6 \deduced Type of the sixth argument to the functor.
* \tparam T7 \deduced Type of the seventh argument to the functor.
* \param [in] a1 The first argument to the functor.
* \param [in] a2 The second argument to the functor.
* \param [in] a3 The third argument to the functor.
* \param [in] a4 The fourth argument to the functor.
* \param [in] a5 The fifth argument to the functor.
* \param [in] a6 The sixth argument to the functor.
* \param [in] a7 The seventh argument to the functor.
*/
void operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) const;
/**
* \copybrief operator()()
* \tparam T1 \deduced Type of the first argument to the functor.
* \tparam T2 \deduced Type of the second argument to the functor.
* \tparam T3 \deduced Type of the third argument to the functor.
* \tparam T4 \deduced Type of the fourth argument to the functor.
* \tparam T5 \deduced Type of the fifth argument to the functor.
* \tparam T6 \deduced Type of the sixth argument to the functor.
* \tparam T7 \deduced Type of the seventh argument to the functor.
* \tparam T8 \deduced Type of the eighth argument to the functor.
* \param [in] a1 The first argument to the functor.
* \param [in] a2 The second argument to the functor.
* \param [in] a3 The third argument to the functor.
* \param [in] a4 The fourth argument to the functor.
* \param [in] a5 The fifth argument to the functor.
* \param [in] a6 The sixth argument to the functor.
* \param [in] a7 The seventh argument to the functor.
* \param [in] a8 The eighth argument to the functor.
*/
void operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8) const;
/**@}*/
void operator() (Ts... args) const;
/**
* TracedCallback signature for POD.
@@ -224,16 +105,9 @@ private:
/**
* Container type for holding the chain of Callbacks.
*
* \tparam T1 \deduced Type of the first argument to the functor.
* \tparam T2 \deduced Type of the second argument to the functor.
* \tparam T3 \deduced Type of the third argument to the functor.
* \tparam T4 \deduced Type of the fourth argument to the functor.
* \tparam T5 \deduced Type of the fifth argument to the functor.
* \tparam T6 \deduced Type of the sixth argument to the functor.
* \tparam T7 \deduced Type of the seventh argument to the functor.
* \tparam T8 \deduced Type of the eighth argument to the functor.
* \tparam Ts \deduced Types of the functor arguments.
*/
typedef std::list<Callback<void,T1,T2,T3,T4,T5,T6,T7,T8> > CallbackList;
typedef std::list<Callback<void,Ts...> > CallbackList;
/** The chain of Callbacks. */
CallbackList m_callbackList;
};
@@ -247,48 +121,36 @@ private:
namespace ns3 {
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::TracedCallback ()
template<typename... Ts>
TracedCallback<Ts...>::TracedCallback ()
: m_callbackList ()
{}
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
template<typename... Ts>
void
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::ConnectWithoutContext (const CallbackBase & callback)
TracedCallback<Ts...>::ConnectWithoutContext (const CallbackBase & callback)
{
Callback<void,T1,T2,T3,T4,T5,T6,T7,T8> cb;
Callback<void,Ts...> cb;
if (!cb.Assign (callback))
{
NS_FATAL_ERROR_NO_MSG ();
}
m_callbackList.push_back (cb);
}
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
template<typename... Ts>
void
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::Connect (const CallbackBase & callback, std::string path)
TracedCallback<Ts...>::Connect (const CallbackBase & callback, std::string path)
{
Callback<void,std::string,T1,T2,T3,T4,T5,T6,T7,T8> cb;
Callback<void,std::string,Ts...> cb;
if (!cb.Assign (callback))
{
NS_FATAL_ERROR ("when connecting to " << path);
}
Callback<void,T1,T2,T3,T4,T5,T6,T7,T8> realCb = cb.Bind (path);
Callback<void,Ts...> realCb = cb.Bind (path);
m_callbackList.push_back (realCb);
}
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
template<typename... Ts>
void
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::DisconnectWithoutContext (const CallbackBase & callback)
TracedCallback<Ts...>::DisconnectWithoutContext (const CallbackBase & callback)
{
for (typename CallbackList::iterator i = m_callbackList.begin ();
i != m_callbackList.end (); /* empty */)
@@ -303,136 +165,26 @@ TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::DisconnectWithoutContext (const Callbac
}
}
}
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
template<typename... Ts>
void
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::Disconnect (const CallbackBase & callback, std::string path)
TracedCallback<Ts...>::Disconnect (const CallbackBase & callback, std::string path)
{
Callback<void,std::string,T1,T2,T3,T4,T5,T6,T7,T8> cb;
Callback<void,std::string,Ts...> cb;
if (!cb.Assign (callback))
{
NS_FATAL_ERROR ("when disconnecting from " << path);
}
Callback<void,T1,T2,T3,T4,T5,T6,T7,T8> realCb = cb.Bind (path);
Callback<void,Ts...> realCb = cb.Bind (path);
DisconnectWithoutContext (realCb);
}
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
template<typename... Ts>
void
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (void) const
TracedCallback<Ts...>::operator() (Ts... args) const
{
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
i != m_callbackList.end (); i++)
{
(*i)();
}
}
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
void
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1) const
{
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
i != m_callbackList.end (); i++)
{
(*i)(a1);
}
}
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
void
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2) const
{
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
i != m_callbackList.end (); i++)
{
(*i)(a1, a2);
}
}
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
void
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3) const
{
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
i != m_callbackList.end (); i++)
{
(*i)(a1, a2, a3);
}
}
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
void
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3, T4 a4) const
{
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
i != m_callbackList.end (); i++)
{
(*i)(a1, a2, a3, a4);
}
}
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
void
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) const
{
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
i != m_callbackList.end (); i++)
{
(*i)(a1, a2, a3, a4, a5);
}
}
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
void
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) const
{
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
i != m_callbackList.end (); i++)
{
(*i)(a1, a2, a3, a4, a5, a6);
}
}
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
void
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) const
{
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
i != m_callbackList.end (); i++)
{
(*i)(a1, a2, a3, a4, a5, a6, a7);
}
}
template<typename T1, typename T2,
typename T3, typename T4,
typename T5, typename T6,
typename T7, typename T8>
void
TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8) const
{
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
i != m_callbackList.end (); i++)
{
(*i)(a1, a2, a3, a4, a5, a6, a7, a8);
(*i)(args...);
}
}

View File

@@ -75,6 +75,7 @@ public:
/**
* Set the function to execute when the timer expires.
*
* \tparam FN \deduced The type of the function.
* \param [in] fn The function
*
* Store this function in this Timer for later use by Timer::Schedule.
@@ -101,71 +102,11 @@ public:
*/
/**@{*/
/**
* \tparam T1 \deduced Type of the first argument.
* \param [in] a1 The first argument
* \tparam Ts \deduced Argument types.
* \param [in] args arguments
*/
template <typename T1>
void SetArguments (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 SetArguments (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 SetArguments (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 SetArguments (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 SetArguments (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 SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
template <typename... Ts>
void SetArguments (Ts&&... args);
/**@}*/
private:
@@ -209,75 +150,16 @@ Watchdog::SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr)
m_impl = MakeTimerImpl (memPtr, objPtr);
}
template <typename T1>
template <typename... Ts>
void
Watchdog::SetArguments (T1 a1)
Watchdog::SetArguments (Ts&&... args)
{
if (m_impl == 0)
{
NS_FATAL_ERROR ("You cannot set the arguments of a Watchdog before setting its function.");
return;
}
m_impl->SetArgs (a1);
}
template <typename T1, typename T2>
void
Watchdog::SetArguments (T1 a1, T2 a2)
{
if (m_impl == 0)
{
NS_FATAL_ERROR ("You cannot set the arguments of a Watchdog before setting its function.");
return;
}
m_impl->SetArgs (a1, a2);
}
template <typename T1, typename T2, typename T3>
void
Watchdog::SetArguments (T1 a1, T2 a2, T3 a3)
{
if (m_impl == 0)
{
NS_FATAL_ERROR ("You cannot set the arguments of a Watchdog before setting its function.");
return;
}
m_impl->SetArgs (a1, a2, a3);
}
template <typename T1, typename T2, typename T3, typename T4>
void
Watchdog::SetArguments (T1 a1, T2 a2, T3 a3, T4 a4)
{
if (m_impl == 0)
{
NS_FATAL_ERROR ("You cannot set the arguments of a Watchdog before setting its function.");
return;
}
m_impl->SetArgs (a1, a2, a3, a4);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void
Watchdog::SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
if (m_impl == 0)
{
NS_FATAL_ERROR ("You cannot set the arguments of a Watchdog before setting its function.");
return;
}
m_impl->SetArgs (a1, a2, a3, a4, a5);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
void
Watchdog::SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
{
if (m_impl == 0)
{
NS_FATAL_ERROR ("You cannot set the arguments of a Watchdog before setting its function.");
return;
}
m_impl->SetArgs (a1, a2, a3, a4, a5, a6);
m_impl->SetArgs (std::forward<Ts>(args)...);
}
} // namespace ns3