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 if (p ==
nullptr || p->m_comp !=
m_comp)
210 template <
typename T>
229 bool IsEqual(std::shared_ptr<const CallbackComponentBase> other)
const override
245 template <
typename R,
typename... UArgs>
295 if (otherDerived ==
nullptr)
302 if (
m_components.size() != otherDerived->GetComponents().size())
309 if (!
m_components.at(0)->IsEqual(otherDerived->GetComponents().at(0)) &&
310 m_components.at(0) != otherDerived->GetComponents().at(0))
318 if (!
m_components.at(i)->IsEqual(otherDerived->GetComponents().at(i)))
335 static std::vector<std::string> vec = {GetCppTypeid<R>(), GetCppTypeid<UArgs>()...};
337 static std::string id(
"CallbackImpl<");
342 if (
id.back() ==
',')
441 template <
typename R,
typename... UArgs>
444 template <
typename ROther,
typename... UArgsOther>
469 template <
typename... BArgs>
475 components.insert(components.end(), {std::make_shared<CallbackComponent<BArgs>>(bargs)...});
478 [
f, bargs...](
auto&&... uargs) -> R {
479 return f(bargs..., std::forward<decltype(uargs)>(uargs)...);
496 template <
typename T,
497 std::enable_if_t<!std::is_base_of_v<CallbackBase, T>,
int> = 0,
502 std::function<R(BArgs..., UArgs...)>
f(func);
506 constexpr
bool isComp =
507 std::is_function_v<std::remove_pointer_t<T>> || std::is_member_pointer_v<T>;
513 [
f, bargs...](
auto&&... uargs) -> R {
514 return f(bargs..., std::forward<decltype(uargs)>(uargs)...);
531 template <std::size_t... INDEX,
typename... BoundArgs>
532 auto BindImpl(std::index_sequence<INDEX...> seq, BoundArgs&&... bargs)
534 Callback<R, std::tuple_element_t<
sizeof...(bargs) + INDEX, std::tuple<UArgs...>>...> cb;
539 components.insert(components.end(),
540 {std::make_shared<CallbackComponent<BoundArgs>>(bargs)...});
542 cb.m_impl =
Create<std::remove_pointer_t<decltype(cb.DoPeekImpl())>>(
543 [
f, bargs...](
auto&&... uargs)
mutable {
544 return f(bargs..., std::forward<decltype(uargs)>(uargs)...);
559 template <
typename... BoundArgs>
560 auto Bind(BoundArgs&&... bargs)
562 static_assert(
sizeof...(UArgs) > 0);
563 return BindImpl(std::make_index_sequence<
sizeof...(UArgs) -
sizeof...(BoundArgs)>{},
564 std::forward<BoundArgs>(bargs)...);
624 auto otherImpl = other.
GetImpl();
627 std::string othTid = otherImpl->GetTypeid();
631 <<
"got=" << othTid << std::endl
632 <<
"expected=" << myTid);
679 template <
typename R,
typename... Args>
705 template <
typename T,
typename OBJ,
typename R,
typename... Args>
709 return Callback<R, Args...>(memPtr, objPtr);
712 template <
typename T,
typename OBJ,
typename R,
typename... Args>
716 return Callback<R, Args...>(memPtr, objPtr);
731 template <
typename R,
typename... Args>
748 template <
typename R,
typename... Args>
766 template <
typename R,
typename... Args,
typename... BArgs>
770 return Callback<R, Args...>(fnPtr).Bind(std::forward<BArgs>(bargs)...);
787 template <
typename T,
typename OBJ,
typename R,
typename... Args,
typename... BArgs>
791 return Callback<R, Args...>(memPtr, objPtr).Bind(bargs...);
794 template <
typename T,
typename OBJ,
typename R,
typename... Args,
typename... BArgs>
796 MakeCallback(R (T::*memPtr)(Args...)
const, OBJ objPtr, BArgs... bargs)
798 return Callback<R, Args...>(memPtr, objPtr).Bind(bargs...);
823 template <
typename T>
855 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()
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.
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(CallbackBase base)
CallbackValue()
Constructor.
bool GetAccessor(T &value) const
Access the Callback value as type T.
Ptr< AttributeValue > Copy() const override
~CallbackValue() override
Destructor.
CallbackBase m_value
The stored Callback instance.
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.