106 static std::string
Demangle(
const std::string& mangled);
114 template <
typename T>
117 std::string typeName;
120 typeName =
typeid(T).name();
123 catch (
const std::bad_typeid& e)
150 virtual bool IsEqual(std::shared_ptr<const CallbackComponentBase> other)
const = 0;
162 template <
typename T,
bool isComparable = true>
182 bool IsEqual(std::shared_ptr<const CallbackComponentBase> other)
const override
184 auto p = std::dynamic_pointer_cast<const CallbackComponent<T>>(other);
187 return !(p ==
nullptr || p->m_comp !=
m_comp);
205 template <
typename T>
224 bool IsEqual(std::shared_ptr<const CallbackComponentBase> other)
const override
240 template <
typename R,
typename... UArgs>
287 const auto otherDerived =
290 if (otherDerived ==
nullptr)
297 if (
m_components.size() != otherDerived->GetComponents().size())
304 if (!
m_components.at(0)->IsEqual(otherDerived->GetComponents().at(0)) &&
305 m_components.at(0) != otherDerived->GetComponents().at(0))
313 if (!
m_components.at(i)->IsEqual(otherDerived->GetComponents().at(i)))
330 static std::vector<std::string> vec = {GetCppTypeid<R>(), GetCppTypeid<UArgs>()...};
332 static std::string id(
"CallbackImpl<");
337 if (
id.back() ==
',')
436 template <
typename R,
typename... UArgs>
439 template <
typename ROther,
typename... UArgsOther>
464 template <
typename... BArgs>
470 components.insert(components.end(),
471 {std::make_shared<CallbackComponent<std::decay_t<BArgs>>>(bargs)...});
474 [
f, bargs...](
auto&&... uargs) -> R {
475 return f(bargs..., std::forward<decltype(uargs)>(uargs)...);
492 template <
typename T,
493 std::enable_if_t<!std::is_base_of_v<CallbackBase, T>,
int> = 0,
498 std::function<R(BArgs..., UArgs...)>
f(func);
502 constexpr
bool isComp =
503 std::is_function_v<std::remove_pointer_t<T>> || std::is_member_pointer_v<T>;
506 {std::make_shared<CallbackComponent<T, isComp>>(func),
510 [
f, bargs...](
auto&&... uargs) -> R {
511 return f(bargs..., std::forward<decltype(uargs)>(uargs)...);
528 template <std::size_t... INDEX,
typename... BoundArgs>
529 auto BindImpl(std::index_sequence<INDEX...> seq, BoundArgs&&... bargs)
531 Callback<R, std::tuple_element_t<
sizeof...(bargs) + INDEX, std::tuple<UArgs...>>...> cb;
536 components.insert(components.end(),
537 {std::make_shared<CallbackComponent<std::decay_t<BoundArgs>>>(bargs)...});
539 cb.m_impl =
Create<std::remove_pointer_t<decltype(cb.DoPeekImpl())>>(
540 [
f, bargs...](
auto&&... uargs)
mutable {
541 return f(bargs..., std::forward<decltype(uargs)>(uargs)...);
556 template <
typename... BoundArgs>
557 auto Bind(BoundArgs&&... bargs)
559 static_assert(
sizeof...(UArgs) > 0);
560 return BindImpl(std::make_index_sequence<
sizeof...(UArgs) -
sizeof...(BoundArgs)>{},
561 std::forward<BoundArgs>(bargs)...);
621 auto otherImpl = other.
GetImpl();
624 std::string othTid = otherImpl->GetTypeid();
628 <<
"got=" << othTid << std::endl
629 <<
"expected=" << myTid);
676 template <
typename R,
typename... Args>
702 template <
typename T,
typename OBJ,
typename R,
typename... Args>
706 return Callback<R, Args...>(memPtr, objPtr);
709 template <
typename T,
typename OBJ,
typename R,
typename... Args>
713 return Callback<R, Args...>(memPtr, objPtr);
728 template <
typename R,
typename... Args>
745 template <
typename R,
typename... Args>
763 template <
typename R,
typename... Args,
typename... BArgs>
767 return Callback<R, Args...>(fnPtr).Bind(std::forward<BArgs>(bargs)...);
784 template <
typename T,
typename OBJ,
typename R,
typename... Args,
typename... BArgs>
788 return Callback<R, Args...>(memPtr, objPtr).Bind(bargs...);
791 template <
typename T,
typename OBJ,
typename R,
typename... Args,
typename... BArgs>
793 MakeCallback(R (T::*memPtr)(Args...)
const, OBJ objPtr, BArgs... bargs)
795 return Callback<R, Args...>(memPtr, objPtr).Bind(bargs...);
820 template <
typename T>
852 template <
typename T>
double f(double x, void *params)
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 > GetImpl() const
Ptr< CallbackImplBase > m_impl
the pimpl
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.
Callback(const Ptr< CallbackImpl< R, UArgs... >> &impl)
Construct from a CallbackImpl pointer.
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.
bool IsNull() const
Check for null implementation.
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)
CallbackImpl< R, UArgs... > * DoPeekImpl() const
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.
static std::string Demangle(const std::string &mangled)
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.
static std::string DoGetTypeid()
Get the name of this object type.
const CallbackComponentVector & GetComponents() const
Get the vector of callback components.
const std::function< R(UArgs...)> & GetFunction() const
Get the stored function.
CallbackImpl(std::function< R(UArgs...)> func, const CallbackComponentVector &components)
Constructor.
std::string GetTypeid() const override
Get the name of this object type.
bool IsEqual(Ptr< const CallbackImplBase > other) const override
Equality test.
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(CallbackBase base)
CallbackValue()
Constructor.
bool GetAccessor(T &value) const
Ptr< AttributeValue > Copy() const override
~CallbackValue() override
Destructor.
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.
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::vector< std::shared_ptr< CallbackComponentBase > > CallbackComponentVector
Vector of callback components.
U * PeekPointer(const Ptr< U > &p)
ns3::Ptr smart pointer declaration and implementation.
ns3::SimpleRefCount declaration and template implementation.