101        std::string typeName;
 
  104            typeName = 
typeid(T).name();
 
  107        catch (
const std::bad_typeid& e)
 
 
 
  134    virtual bool IsEqual(std::shared_ptr<const CallbackComponentBase> other) 
const = 0;
 
 
  146template <
typename T, 
bool isComparable = true>
 
  166    bool IsEqual(std::shared_ptr<const CallbackComponentBase> other)
 const override 
  168        auto p = std::dynamic_pointer_cast<const CallbackComponent<T>>(other);
 
  171        return !(p == 
nullptr || p->m_comp != 
m_comp);
 
 
 
  208    bool IsEqual(std::shared_ptr<const CallbackComponentBase> other)
 const override 
 
 
  224template <
typename R, 
typename... UArgs>
 
  271        const auto otherDerived =
 
  274        if (otherDerived == 
nullptr)
 
  281        if (
m_components.size() != otherDerived->GetComponents().size())
 
  288        if (!
m_components.at(0)->IsEqual(otherDerived->GetComponents().at(0)) &&
 
  289            m_components.at(0) != otherDerived->GetComponents().at(0))
 
  297            if (!
m_components.at(i)->IsEqual(otherDerived->GetComponents().at(i)))
 
 
  316        static std::string id(
"CallbackImpl<");
 
  321        if (
id.back() == 
',')
 
 
 
  420template <
typename R, 
typename... UArgs>
 
  423    template <
typename ROther, 
typename... UArgsOther>
 
  448    template <
typename... BArgs>
 
  454        components.insert(components.end(),
 
  455                          {std::make_shared<CallbackComponent<std::decay_t<BArgs>>>(bargs)...});
 
  458            [f, bargs...](
auto&&... uargs) -> R {
 
  459                return f(bargs..., std::forward<
decltype(uargs)>(uargs)...);
 
 
  476    template <
typename T,
 
  478              std::enable_if_t<!std::is_base_of_v<CallbackBase, T> &&
 
  479                                   std::is_invocable_r_v<R, T, BArgs..., UArgs...>,
 
  484        std::function<R(BArgs..., UArgs...)> f(func);
 
  488        constexpr bool isComp =
 
  489            std::is_function_v<std::remove_pointer_t<T>> || std::is_member_pointer_v<T>;
 
  492            {std::make_shared<CallbackComponent<T, isComp>>(func),
 
  496            [f, bargs...](
auto&&... uargs) -> R {
 
  497                return f(bargs..., std::forward<
decltype(uargs)>(uargs)...);
 
 
  514    template <std::size_t... INDEX, 
typename... BoundArgs>
 
  515    auto BindImpl(std::index_sequence<INDEX...> seq, BoundArgs&&... bargs)
 
  517        Callback<R, std::tuple_element_t<
sizeof...(bargs) + INDEX, std::tuple<UArgs...>>...> cb;
 
  522        components.insert(components.end(),
 
  523                          {std::make_shared<CallbackComponent<std::decay_t<BoundArgs>>>(bargs)...});
 
  525        cb.m_impl = 
Create<std::remove_pointer_t<
decltype(cb.DoPeekImpl())>>(
 
  526            [f, bargs...](
auto&&... uargs) 
mutable {
 
  527                return f(bargs..., std::forward<
decltype(uargs)>(uargs)...);
 
 
  542    template <
typename... BoundArgs>
 
  543    auto Bind(BoundArgs&&... bargs)
 
  545        static_assert(
sizeof...(UArgs) > 0);
 
  546        return BindImpl(std::make_index_sequence<
sizeof...(UArgs) - 
sizeof...(BoundArgs)>{},
 
  547                        std::forward<BoundArgs>(bargs)...);
 
 
  607        auto otherImpl = other.
GetImpl();
 
  610            std::string othTid = otherImpl->GetTypeid();
 
  614                                << 
"got=" << othTid << std::endl
 
  615                                << 
"expected=" << myTid);
 
 
 
  656template <
typename R, 
typename... Args>
 
  682template <
typename T, 
typename OBJ, 
typename R, 
typename... Args>
 
  686    return Callback<R, Args...>(memPtr, objPtr);
 
 
  689template <
typename T, 
typename OBJ, 
typename R, 
typename... Args>
 
  693    return Callback<R, Args...>(memPtr, objPtr);
 
  708template <
typename R, 
typename... Args>
 
  725template <
typename R, 
typename... Args>
 
  743template <
typename R, 
typename... Args, 
typename... BArgs>
 
  747    return Callback<R, Args...>(fnPtr).Bind(std::forward<BArgs>(bargs)...);
 
 
  764template <
typename T, 
typename OBJ, 
typename R, 
typename... Args, 
typename... BArgs>
 
  768    return Callback<R, Args...>(memPtr, objPtr).Bind(bargs...);
 
 
  771template <
typename T, 
typename OBJ, 
typename R, 
typename... Args, 
typename... BArgs>
 
  773MakeCallback(R (T::*memPtr)(Args...) const, OBJ objPtr, BArgs... bargs)
 
  775    return Callback<R, Args...>(memPtr, objPtr).Bind(bargs...);
 
  794    template <
typename T>
 
 
Attribute helper (ATTRIBUTE_ )macros definition.
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Hold a value for an Attribute.
Base class for Callback class.
CallbackBase(Ptr< CallbackImplBase > impl)
Construct from a pimpl.
Ptr< CallbackImplBase > m_impl
the pimpl
Ptr< CallbackImplBase > GetImpl() const
bool IsEqual(std::shared_ptr< const CallbackComponentBase > other) const override
Equality test between functions.
CallbackComponent(const T &t)
Constructor.
Abstract base class for CallbackComponent.
virtual bool IsEqual(std::shared_ptr< const CallbackComponentBase > other) const =0
Equality test.
virtual ~CallbackComponentBase()
Virtual destructor.
Stores a component of a callback, i.e., the callable object or a bound argument.
CallbackComponent(const T &t)
Constructor.
T m_comp
the value of the callback component
bool IsEqual(std::shared_ptr< const CallbackComponentBase > other) const override
Equality test between the values of two components.
bool IsEqual(const CallbackBase &other) const
Equality test.
bool DoCheckType(Ptr< const CallbackImplBase > other) const
Check for compatible types.
void Nullify()
Discard the implementation, set it to null.
Callback(const Ptr< CallbackImpl< R, UArgs... > > &impl)
Construct from a CallbackImpl pointer.
bool IsNull() const
Check for null implementation.
CallbackImpl< R, UArgs... > * DoPeekImpl() const
R operator()(UArgs... uargs) const
Functor with varying numbers of arguments.
auto Bind(BoundArgs &&... bargs)
Bind a variable number of arguments.
auto BindImpl(std::index_sequence< INDEX... > seq, BoundArgs &&... bargs)
Implementation of the Bind method.
Callback(T func, BArgs... bargs)
Construct from a function and bind some arguments (if any)
Callback(const Callback< R, BArgs..., UArgs... > &cb, BArgs... bargs)
Construct from another callback and bind some arguments (if any)
bool CheckType(const CallbackBase &other) const
Check for compatible types.
bool Assign(const CallbackBase &other)
Adopt the other's implementation, if type compatible.
Abstract base class for CallbackImpl Provides reference counting and equality test.
virtual bool IsEqual(Ptr< const CallbackImplBase > other) const =0
Equality test.
static std::string GetCppTypeid()
Helper to get the C++ typeid as a string.
virtual ~CallbackImplBase()
Virtual destructor.
virtual std::string GetTypeid() const =0
Get the name of this object type.
CallbackImpl class with varying numbers of argument types.
std::vector< std::shared_ptr< CallbackComponentBase > > m_components
Stores the original callable object and the bound arguments, if any.
std::function< R(UArgs...)> m_func
Stores the callable object associated with this callback (as a lambda)
R operator()(UArgs... uargs) const
Function call operator.
const std::function< R(UArgs...)> & GetFunction() const
Get the stored function.
static std::string DoGetTypeid()
Get the name of this object type.
CallbackImpl(std::function< R(UArgs...)> func, const CallbackComponentVector &components)
Constructor.
const CallbackComponentVector & GetComponents() const
Get the vector of callback components.
std::string GetTypeid() const override
Get the name of this object type.
bool IsEqual(Ptr< const CallbackImplBase > other) const override
Equality test.
AttributeValue implementation for Callback.
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
Deserialize from string (not implemented)
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
Serialize to string.
void Set(const CallbackBase &value)
Set the value.
bool GetAccessor(T &value) const
Access the Callback value as type T.
CallbackBase m_value
The stored Callback instance.
Ptr< AttributeValue > Copy() const override
~CallbackValue() override
Smart pointer class similar to boost::intrusive_ptr.
A template-based reference counting class.
NS_FATAL_x macro definitions.
#define ATTRIBUTE_ACCESSOR_DEFINE(type)
Define the attribute accessor functions MakeTypeAccessor for class type .
#define ATTRIBUTE_CHECKER_DEFINE(type)
Declare the AttributeChecker class typeChecker and the MaketypeChecker function for class type .
Callback< R, Args... > MakeNullCallback()
#define NS_FATAL_ERROR_CONT(msg)
Report a fatal error with a message, deferring termination.
#define NS_FATAL_ERROR_NO_MSG()
Report a fatal error and terminate.
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
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...
std::string Demangle(const std::string &mangled)
std::vector< std::shared_ptr< CallbackComponentBase > > CallbackComponentVector
Vector of callback components.
ns3::Ptr smart pointer declaration and implementation.
ns3::SimpleRefCount declaration and template implementation.