|
| Callback () |
|
template<typename FUNCTOR > |
| Callback (FUNCTOR const &functor, bool, bool) |
| Construct a functor call back, supporting operator() calls. More...
|
|
template<typename OBJ_PTR , typename MEM_PTR > |
| Callback (OBJ_PTR const &objPtr, MEM_PTR memPtr) |
| Construct a member function pointer call back. More...
|
|
| Callback (Ptr< CallbackImpl< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > > const &impl) |
| Construct from a CallbackImpl pointer. More...
|
|
bool | Assign (const CallbackBase &other) |
| Adopt the other's implementation, if type compatible. More...
|
|
template<typename T > |
Callback< R, T2, T3, T4, T5, T6, T7, T8, T9 > | Bind (T a) |
| Bind the first arguments. More...
|
|
bool | CheckType (const CallbackBase &other) const |
| Check for compatible types. More...
|
|
bool | IsEqual (const CallbackBase &other) const |
| Equality test. More...
|
|
bool | IsNull (void) const |
| Check for null implementation. More...
|
|
void | Nullify (void) |
| Discard the implementation, set it to null. More...
|
|
template<typename TX1 , typename TX2 , typename TX3 > |
Callback< R, T4, T5, T6, T7, T8, T9 > | ThreeBind (TX1 a1, TX2 a2, TX3 a3) |
| Bind the first three arguments. More...
|
|
template<typename TX1 , typename TX2 > |
Callback< R, T3, T4, T5, T6, T7, T8, T9 > | TwoBind (TX1 a1, TX2 a2) |
| Bind the first two arguments. More...
|
|
|
R | operator() (void) const |
| Functor with varying numbers of arguments. More...
|
|
R | operator() (T1 a1) const |
|
R | operator() (T1 a1, T2 a2) const |
|
R | operator() (T1 a1, T2 a2, T3 a3) const |
|
R | operator() (T1 a1, T2 a2, T3 a3, T4 a4) const |
|
R | operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) const |
|
R | operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) const |
|
R | operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) const |
|
R | operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8) const |
|
R | operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9) const |
|
| CallbackBase () |
|
Ptr< CallbackImplBase > | GetImpl (void) const |
|
template<typename R, typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
class ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >
Callback template class.
This class template implements the Functor Design Pattern. It is used to declare the type of a Callback:
- the first non-optional template argument represents the return type of the callback.
- the remaining (optional) template arguments represent the type of the subsequent arguments to the callback.
- up to nine arguments are supported.
Callback instances are built with the MakeCallback template functions. Callback instances have POD semantics: the memory they allocate is managed automatically, without user intervention which allows you to pass around Callback instances by value.
Sample code which shows how to use this class template as well as the function templates MakeCallback :
#include "ns3/callback.h"
#include "ns3/assert.h"
#include "ns3/command-line.h"
#include <iostream>
namespace {
static double
CbOne (double a, double b)
{
std::cout << "invoke cbOne a=" << a << ", b=" << b << std::endl;
return a;
}
class MyCb
{
public:
int CbTwo (double a)
{
std::cout << "invoke cbTwo a=" << a << std::endl;
return -5;
}
};
}
int main (int argc, char *argv[])
{
CommandLine
cmd (__FILE__);
Callback<double, double, double> one;
double retOne;
retOne = one (10.0, 20.0);
Callback<int, double> two;
MyCb cb;
int retTwo;
retTwo = two (10.0);
two = MakeNullCallback<int, double> ();
#if 0
#endif
#if 0
Callback<void, float> three;
#endif
return 0;
}
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
- Internal:
- This code was originally written based on the techniques described in http://www.codeproject.com/cpp/TTLFunction.asp It was subsequently rewritten to follow the architecture outlined in "Modern C++ Design" by Andrei Alexandrescu in chapter 5, "Generalized Functors".
This code uses:
- default template parameters to saves users from having to specify empty parameters when the number of parameters is smaller than the maximum supported number
- the pimpl idiom: the Callback class is passed around by value and delegates the crux of the work to its pimpl pointer.
- two pimpl implementations which derive from CallbackImpl FunctorCallbackImpl can be used with any functor-type while MemPtrCallbackImpl can be used with pointers to member functions.
- a reference list implementation to implement the Callback's value semantics.
This code most notably departs from the alexandrescu implementation in that it does not use type lists to specify and pass around the types of the callback arguments. Of course, it also does not use copy-destruction semantics and relies on a reference list rather than autoPtr to hold the pointer.
- See also
- Callback Attribute
- Template Parameters
-
R | [explicit] The return type of the Callback. The remaining template arguments are the types of any arguments to the Callback. |
Definition at line 1278 of file callback.h.
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
template<typename FUNCTOR >
ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::Callback |
( |
FUNCTOR const & |
functor, |
|
|
bool |
, |
|
|
bool |
|
|
) |
| |
|
inline |
Construct a functor call back, supporting operator() calls.
- Parameters
-
[in] | functor | The functor to run on this callback |
- Internal:
- There are two dummy args below to ensure that this constructor is always properly disambiguated by the c++ compiler.
- Template Parameters
-
FUNCTOR | [deduced] The actual type of the functor. |
Definition at line 1295 of file callback.h.
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
template<typename OBJ_PTR , typename MEM_PTR >
ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::Callback |
( |
OBJ_PTR const & |
objPtr, |
|
|
MEM_PTR |
memPtr |
|
) |
| |
|
inline |
Construct a member function pointer call back.
- Template Parameters
-
OBJ_PTR | [deduced] Type of the target object, as a pointer. |
MEM_PTR | [deduced] Type of the class member function. |
- Parameters
-
[in] | objPtr | Pointer to the object |
[in] | memPtr | Pointer to the member function |
Definition at line 1308 of file callback.h.
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
Adopt the other's implementation, if type compatible.
- Parameters
-
- Returns
true
if other was type-compatible and could be adopted.
Definition at line 1542 of file callback.h.
References ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::DoAssign(), and ns3::CallbackBase::GetImpl().
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
template<typename T >
Callback<R,T2,T3,T4,T5,T6,T7,T8,T9> ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::Bind |
( |
T |
a | ) |
|
|
inline |
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
Check for compatible types.
- Parameters
-
- Returns
true
if other can be dynamic_cast to my type
Definition at line 1532 of file callback.h.
References ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::DoCheckType(), and ns3::CallbackBase::GetImpl().
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
Adopt the other's implementation, if type compatible.
- Parameters
-
- Returns
true
if other was type-compatible and could be adopted.
Definition at line 1582 of file callback.h.
References ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::DoCheckType(), ns3::CallbackImpl< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::DoGetTypeid(), ns3::CallbackBase::m_impl, NS_FATAL_ERROR_CONT, and ns3::PeekPointer().
Referenced by ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::Assign().
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
Check for compatible types.
- Parameters
-
- Returns
true
if other can be dynamic_cast to my type
Definition at line 1559 of file callback.h.
References ns3::PeekPointer().
Referenced by ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::CheckType(), and ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::DoAssign().
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
CallbackImpl<R,T1,T2,T3,T4,T5,T6,T7,T8,T9>* ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::DoPeekImpl |
( |
void |
| ) |
const |
|
inlineprivate |
- Returns
- The pimpl pointer
Definition at line 1549 of file callback.h.
References ns3::CallbackBase::m_impl, and ns3::PeekPointer().
Referenced by ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::IsNull(), and ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::operator()().
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
R ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::operator() |
( |
T1 |
a1 | ) |
const |
|
inline |
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
R ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::operator() |
( |
T1 |
a1, |
|
|
T2 |
a2 |
|
) |
| const |
|
inline |
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
R ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::operator() |
( |
T1 |
a1, |
|
|
T2 |
a2, |
|
|
T3 |
a3 |
|
) |
| const |
|
inline |
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
R ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::operator() |
( |
T1 |
a1, |
|
|
T2 |
a2, |
|
|
T3 |
a3, |
|
|
T4 |
a4 |
|
) |
| const |
|
inline |
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
R ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::operator() |
( |
T1 |
a1, |
|
|
T2 |
a2, |
|
|
T3 |
a3, |
|
|
T4 |
a4, |
|
|
T5 |
a5 |
|
) |
| const |
|
inline |
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
R ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::operator() |
( |
T1 |
a1, |
|
|
T2 |
a2, |
|
|
T3 |
a3, |
|
|
T4 |
a4, |
|
|
T5 |
a5, |
|
|
T6 |
a6 |
|
) |
| const |
|
inline |
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
R ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::operator() |
( |
T1 |
a1, |
|
|
T2 |
a2, |
|
|
T3 |
a3, |
|
|
T4 |
a4, |
|
|
T5 |
a5, |
|
|
T6 |
a6, |
|
|
T7 |
a7 |
|
) |
| const |
|
inline |
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
R ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::operator() |
( |
T1 |
a1, |
|
|
T2 |
a2, |
|
|
T3 |
a3, |
|
|
T4 |
a4, |
|
|
T5 |
a5, |
|
|
T6 |
a6, |
|
|
T7 |
a7, |
|
|
T8 |
a8 |
|
) |
| const |
|
inline |
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
R ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::operator() |
( |
T1 |
a1, |
|
|
T2 |
a2, |
|
|
T3 |
a3, |
|
|
T4 |
a4, |
|
|
T5 |
a5, |
|
|
T6 |
a6, |
|
|
T7 |
a7, |
|
|
T8 |
a8, |
|
|
T9 |
a9 |
|
) |
| const |
|
inline |
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
R ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::operator() |
( |
void |
| ) |
const |
|
inline |
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
template<typename TX1 , typename TX2 , typename TX3 >
Callback<R,T4,T5,T6,T7,T8,T9> ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::ThreeBind |
( |
TX1 |
a1, |
|
|
TX2 |
a2, |
|
|
TX3 |
a3 |
|
) |
| |
|
inline |
Bind the first three arguments.
- Template Parameters
-
TX1 | [deduced] The actual type of the first bound argument. |
TX2 | [deduced] The actual type of the second bound argument. |
TX3 | [deduced] The actual type of the third bound argument. |
- Parameters
-
[in] | a1 | First argument to bind |
[in] | a2 | Second argument to bind |
[in] | a3 | Third argument to bind |
- Returns
- The bound callback
Definition at line 1371 of file callback.h.
template<typename R , typename T1 = empty, typename T2 = empty, typename T3 = empty, typename T4 = empty, typename T5 = empty, typename T6 = empty, typename T7 = empty, typename T8 = empty, typename T9 = empty>
template<typename TX1 , typename TX2 >
Callback<R,T3,T4,T5,T6,T7,T8,T9> ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::TwoBind |
( |
TX1 |
a1, |
|
|
TX2 |
a2 |
|
) |
| |
|
inline |
Bind the first two arguments.
- Template Parameters
-
TX1 | [deduced] Type of the first bound argument. |
TX2 | [deduced] Type of the second bound argument. |
- Parameters
-
[in] | a1 | First argument to bind |
[in] | a2 | Second argument to bind |
- Returns
- The bound callback
Definition at line 1349 of file callback.h.