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>
316 static std::string id(
"CallbackImpl<");
321 if (
id.back() ==
',')
420template <
typename R,
typename...
UArgs>
448 template <
typename...
BArgs>
451 auto f =
cb.DoPeekImpl()->GetFunction();
455 {std::make_shared<CallbackComponent<std::decay_t<BArgs>>>(bargs)...});
476 template <
typename T,
478 std::enable_if_t<!std::is_base_of_v<CallbackBase, T> &&
489 std::is_function_v<std::remove_pointer_t<T>> || std::is_member_pointer_v<T>;
492 {std::make_shared<CallbackComponent<T, isComp>>(func),
517 Callback<
R, std::tuple_element_t<
sizeof...(bargs) +
INDEX, std::tuple<UArgs...>>...>
cb;
523 {std::make_shared<CallbackComponent<std::decay_t<BoundArgs>>>(bargs)...});
525 cb.m_impl =
Create<std::remove_pointer_t<
decltype(
cb.DoPeekImpl())>>(
545 static_assert(
sizeof...(UArgs) > 0);
547 std::forward<BoundArgs>(
bargs)...);
614 <<
"got=" <<
othTid << std::endl
615 <<
"expected=" <<
myTid);
656template <
typename R,
typename...
Args>
660 return !
a.IsEqual(b);
682template <
typename T,
typename OBJ,
typename R,
typename...
Args>
689template <
typename T,
typename OBJ,
typename R,
typename...
Args>
708template <
typename R,
typename...
Args>
725template <
typename R,
typename...
Args>
743template <
typename R,
typename...
Args,
typename...
BArgs>
764template <
typename T,
typename OBJ,
typename R,
typename...
Args,
typename...
BArgs>
771template <
typename T,
typename OBJ,
typename R,
typename...
Args,
typename...
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)
static unsigned int value(char c)
std::vector< std::shared_ptr< CallbackComponentBase > > CallbackComponentVector
Vector of callback components.
ns3::Ptr smart pointer declaration and implementation.
ns3::SimpleRefCount declaration and template implementation.