79template <
typename T,
typename... Descriptors>
142template <
typename T,
typename... Descriptors>
194 template <
typename U>
225template <
typename Value, auto Getter, auto Setter =
nullptr>
260template <auto Function>
274template <
typename Field>
277 typename Field::value_type;
278 typename Field::getter_type;
279 typename Field::setter_type;
280 } && ((std::is_member_object_pointer_v<typename Field::getter_type> &&
281 std::same_as<typename Field::setter_type, std::nullptr_t>) ||
282 (std::is_member_function_pointer_v<typename Field::getter_type> &&
283 (std::same_as<typename Field::setter_type, std::nullptr_t> ||
284 std::is_member_function_pointer_v<typename Field::setter_type>)));
287template <
typename Field,
typename T>
292template <
typename Field,
typename T,
typename Value>
295 std::invocable<typename Field::setter_type, T&, Value>);
307template <
typename T,
auto Constructor,
typename... Fields>
345 template <std::size_t... Is>
356 template <
typename Field>
366 template <std::size_t... Is>
377 template <std::size_t... Is>
390 template <
typename Field,
typename Value>
403template <
typename T,
typename... Fields>
418template <
typename T,
auto Constructor,
typename... Fields>
447template <
typename T,
typename... Ts>
448 requires(
sizeof...(Ts) == T::field_count)
464template <
typename T,
typename T1>
482template <
typename T,
typename T1,
typename T2>
497template <
typename T,
auto Constructor,
typename... Fields>
498 requires(StructFieldFor<Fields, T> && ...)
502 if constexpr ((std::is_member_object_pointer_v<typename Fields::getter_type> && ...))
506 return std::make_from_tuple<T>(std::move(values));
510 static_assert(std::is_default_constructible_v<T>,
511 "A structure requiring AttributeValue conversion must be default "
514 SetFields(
object, std::move(values), std::index_sequence_for<Fields...>{});
518 else if constexpr (!std::is_same_v<
decltype(Constructor), std::nullptr_t>)
521 "StructConstructor must accept the values returned by the field "
522 "AttributeValues and return the represented structure");
523 return std::apply(Constructor, std::move(values));
527 static_assert(std::is_default_constructible_v<T>,
528 "A structure accessed through getters and setters must be default "
530 static_assert(((std::is_member_object_pointer_v<typename Fields::getter_type> ||
531 std::is_member_function_pointer_v<typename Fields::setter_type>) &&
533 "Every getter requires either a StructConstructor or a setter");
535 SetFields(
object, std::move(values), std::index_sequence_for<Fields...>{});
540template <
typename T,
auto Constructor,
typename... Fields>
548template <
typename T,
auto Constructor,
typename... Fields>
550template <
std::
size_t... Is>
553 std::index_sequence<Is...>)
555 return std::is_constructible_v<T, std::tuple_element_t<Is, tuple_type>...>;
558template <
typename T,
auto Constructor,
typename... Fields>
560template <
typename Field>
564 typename Field::value_type attributeValue;
565 attributeValue.Set(std::invoke(Field::getter,
object));
566 return attributeValue.Get();
569template <
typename T,
auto Constructor,
typename... Fields>
571template <
std::
size_t... Is>
575 using constructor_type =
decltype(Constructor);
577 std::is_invocable_r<T, constructor_type, std::tuple_element_t<Is, tuple_type>&&...>;
578 return is_invocable::value;
581template <
typename T,
auto Constructor,
typename... Fields>
583template <std::size_t... Is>
587 std::index_sequence<Is...>)
592template <
typename T,
auto Constructor,
typename... Fields>
594template <typename Field, typename Value>
599 if constexpr (std::is_member_object_pointer_v<typename Field::getter_type>)
601 if constexpr (std::is_assignable_v<
decltype(std::invoke(Field::getter,
object)), Value>)
603 std::invoke(Field::getter,
object) = std::forward<Value>(value);
607 typename Field::value_type attributeValue(std::forward<Value>(value));
609 attributeValue.GetAccessor(std::invoke(Field::getter,
object)),
610 "The AttributeValue could not be converted to the structure field type");
615 std::invoke(Field::setter,
object, std::forward<Value>(value));
621template <
typename T,
typename... Fields>
627template <
typename T,
typename... Fields>
634template <
typename T,
typename... Fields>
641template <
typename T,
typename... Fields>
648template <
typename T,
typename... Fields>
681template <
typename T,
typename... Fields>
692 template <
typename... Ts>
698 const std::vector<Ptr<const AttributeChecker>>&
GetCheckers()
const override
705 const auto structValue =
dynamic_cast<const StructValue<T, Fields...
>*>(&value);
706 if (structValue ==
nullptr)
713 [
this, &n](
const auto&... values) {
return (
m_checkers[n++]->
Check(values) && ...); },
714 structValue->GetValue());
719 return "ns3::StructValue";
739 const auto src =
dynamic_cast<const StructValue<T, Fields...
>*>(&source);
740 auto dst =
dynamic_cast<StructValue<T, Fields...
>*>(&destination);
741 if (src ==
nullptr || dst ==
nullptr)
755template <
typename T,
typename... Ts>
756 requires(
sizeof...(Ts) == T::field_count)
763template <
typename T,
typename T1>
764Ptr<const AttributeAccessor>
770template <
typename T,
typename T1,
typename T2>
771Ptr<const AttributeAccessor>
NS_ABORT_x macro definitions.
Hold a value for an Attribute.
Smart pointer class similar to boost::intrusive_ptr.
Checker for attribute values representing structures.
AttributeValue implementation for structures.
StructValue(const result_type &value)
Construct a StructValue from a structure.
T result_type
The represented structure type.
internal::StructValueTraits< T, Descriptors... > Traits
Traits describing the constructor and fields.
result_type Get() const
Get the stored fields as a structure.
Ptr< AttributeValue > Copy() const override
StructValue()=default
Construct a StructValue containing default-initialized field values.
void Set(const result_type &value)
Set the stored fields from a structure.
typename Traits::base_type Base
TupleValue type used to store the structure fields.
static constexpr std::size_t field_count
typename internal::StructValueTraits< T, Descriptors... >::tuple_type tuple_type
Tuple of the values returned by the field AttributeValue objects.
typename internal::StructValueTraits< T, Descriptors... >::value_type value_type
Tuple of the field AttributeValue objects.
bool GetAccessor(U &value) const
Set the given variable to the structure represented by this object.
Checker for attribute values storing tuples.
AttributeValue implementation for Tuple.
std::tuple< Args... > value_type
std::tuple< std::invoke_result_t< decltype(&Args::Get), Args >... > result_type
bool Check(const AttributeValue &value) const override
bool HasUnderlyingTypeInformation() const override
std::string GetValueTypeName() const override
const std::vector< Ptr< const AttributeChecker > > & GetCheckers() const override
Get the checkers for all tuple elements.
bool Copy(const AttributeValue &source, AttributeValue &destination) const override
Copy the source to the destination.
StructChecker(Ts... checkers)
Construct a checker from the checkers for the individual fields.
Ptr< AttributeValue > Create() const override
std::vector< Ptr< const AttributeChecker > > m_checkers
Field checkers.
std::string GetUnderlyingTypeInformation() const override
Internal StructChecker implementation.
Concept matching a structure field that can be set from the given value type.
Concept matching a valid structure field descriptor.
Concept matching a structure field that can be read from the represented structure.
Ptr< const AttributeChecker > MakeStructChecker(Ts... checkers)
Create a StructChecker from the AttributeCheckers associated with the fields.
Ptr< const AttributeAccessor > MakeStructAccessor(T1 a1)
Create an AttributeAccessor for a structure data member, or for a lone class get functor or set metho...
Ptr< const AttributeAccessor > MakeAccessorHelper(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Namespace for implementation details.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Describe a function that constructs a structure from its field values.
decltype(Function) function_type
Type of the constructor function pointer.
static constexpr auto function
Pointer to the function that constructs the structure.
Describe a structure field and the AttributeValue used to represent it.
static constexpr auto setter
Pointer to the setter associated with a getter.
decltype(Getter) getter_type
Type of the data member pointer or getter.
static constexpr auto getter
Pointer to the represented data member or to its getter.
Value value_type
AttributeValue type used to represent the field.
decltype(Setter) setter_type
Type of the setter.
Provide the implementation details of StructValue for a set of fields.
static auto ReadField(const T &object)
Read a field through its AttributeValue type.
TupleValue< typename Fields::value_type... > base_type
static constexpr std::size_t field_count
Number of structure fields.
typename base_type::value_type value_type
Tuple of the field AttributeValue objects.
static T Construct(tuple_type values)
Construct the represented structure from field values.
static constexpr bool IsDirectlyConstructible(std::index_sequence< Is... >)
Check whether the structure can be constructed directly from field values.
static void SetField(T &object, Value &&value)
Set a structure field through its data member or setter.
static tuple_type Read(const T &value)
Read the field values from a structure.
static constexpr bool IsConstructorInvocable(std::index_sequence< Is... >)
Check whether the constructor function accepts all field values.
static void SetFields(T &object, tuple_type &&values, std::index_sequence< Is... >)
Set the fields of a structure from tuple elements.
typename base_type::result_type tuple_type
Tuple of the values returned by the field AttributeValue objects.
Select the StructValue implementation when no constructor function is provided.