|
| Callback () |
|
template<typename... BArgs> |
| Callback (const Callback< R, BArgs..., UArgs... > &cb, BArgs... bargs) |
| Construct from another callback and bind some arguments (if any)
|
|
| Callback (const Ptr< CallbackImpl< R, UArgs... > > &impl) |
| Construct from a CallbackImpl pointer.
|
|
template<typename T, typename... BArgs, std::enable_if_t<!std::is_base_of_v< CallbackBase, T > &&std::is_invocable_r_v< R, T, BArgs..., UArgs... >, int > = 0> |
| Callback (T func, BArgs... bargs) |
| Construct from a function and bind some arguments (if any)
|
|
bool | Assign (const CallbackBase &other) |
| Adopt the other's implementation, if type compatible.
|
|
template<typename... BoundArgs> |
auto | Bind (BoundArgs &&... bargs) |
| Bind a variable number of arguments.
|
|
bool | CheckType (const CallbackBase &other) const |
| Check for compatible types.
|
|
bool | IsEqual (const CallbackBase &other) const |
| Equality test.
|
|
bool | IsNull () const |
| Check for null implementation.
|
|
void | Nullify () |
| Discard the implementation, set it to null.
|
|
R | operator() (UArgs... uargs) const |
| Functor with varying numbers of arguments.
|
|
| CallbackBase () |
|
Ptr< CallbackImplBase > | GetImpl () const |
|
template<typename R, typename... UArgs>
class ns3::Callback< R, UArgs >
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.
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/assert.h"
#include "ns3/callback.h"
#include "ns3/command-line.h"
#include <iostream>
namespace
{
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[])
{
double retOne;
retOne = one(10.0, 20.0);
MyCb cb;
int retTwo;
#if 0
#endif
#if 0
#endif
return 0;
}
bool IsNull() const
Check for null implementation.
bool Assign(const CallbackBase &other)
Adopt the other's implementation, if type compatible.
Parse command-line arguments.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Callback< R, Args... > MakeNullCallback()
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
-ray-to-three-gpp-ch-calibration
- 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.
- 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
- attribute_Callback
- Template Parameters
-
R | [explicit] The return type of the Callback. |
UArgs | [explicit] The types of any arguments to the Callback. |
Definition at line 421 of file callback.h.
template<typename R, typename... UArgs>
template<std::size_t... INDEX, typename... BoundArgs>
auto ns3::Callback< R, UArgs >::BindImpl |
( |
std::index_sequence< INDEX... > | seq, |
|
|
BoundArgs &&... | bargs ) |
|
inlineprivate |
Implementation of the Bind method.
- Template Parameters
-
BoundArgs | The types of the arguments to bind |
- Parameters
-
[in] | seq | A compile-time integer sequence |
[in] | bargs | The values of the arguments to bind |
- Returns
- The bound callback
- Internal:
- The integer sequence is 0..N-1, where N is the number of arguments left unbound.
Definition at line 515 of file callback.h.
Referenced by ns3::Callback< void, int >::Bind().