A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
struct.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Universita' degli Studi di Napoli Federico II
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8
9#ifndef STRUCT_H
10#define STRUCT_H
11
12#include "abort.h"
13#include "tuple.h"
14
15#include <concepts>
16#include <functional>
17#include <tuple>
18#include <type_traits>
19#include <utility>
20#include <vector>
21
22/**
23 * @file
24 * @ingroup attribute_Struct
25 * Guidelines for defining attributes represented by structures.
26 *
27 * StructValue allows a structure to use the attribute system's accessors,
28 * checkers, serialization, and deserialization facilities. To define a
29 * StructValue, provide one StructField descriptor for every field, in the same
30 * order in which the field values are serialized. Choose one of the following
31 * forms according to how the structure exposes and initializes its fields
32 * ( @see StructValue for more information):
33 *
34 * 1. **Public data members.** If all fields are publicly accessible, each
35 * StructField specifies the field's AttributeValue type and a pointer to the
36 * data member, for example
37 * `StructField<UintegerValue, &Data::count>`. StructValue reconstructs the
38 * structure directly from the field values. If an AttributeValue returns a
39 * different type, its GetAccessor() method converts the value to the data
40 * member type.
41 * 2. **Private data members with getters and a factory.** Each private field
42 * must have a getter, and its StructField specifies the AttributeValue type
43 * and a pointer to that getter, for example
44 * `StructField<UintegerValue, &Data::GetCount>`. For any public data member, a
45 * getter is not required, as its StructField descriptor can specify the field's
46 * AttributeValue type and a pointer to the data member. A StructConstructor
47 * descriptor must precede the StructField descriptors and identify a static member
48 * or free factory function that accepts all field values in order and returns
49 * the structure, for example `StructConstructor<&Data::Create>`.
50 * 3. **Private data members with getters and setters.** Each private field must
51 * have both a getter and a setter, and its StructField specifies the
52 * AttributeValue type and pointers to both methods, for example
53 * `StructField<UintegerValue, &Data::GetCount, &Data::SetCount>`. For any public
54 * data member, getter and setter are not required, as its StructField descriptor
55 * can specify the field's AttributeValue type and a pointer to the data member.
56 * The structure must be default constructible; StructValue reconstructs it by
57 * default-constructing an instance and invoking the setter, for private data
58 * members, or accessing the pointer, for public data members.
59 *
60 * StructValue stores the fields internally as a TupleValue. MakeStructAccessor()
61 * and MakeStructChecker() can then be used to register the structure as an
62 * attribute and validate its individual fields.
63 *
64 * @see StructValueTestSuite for examples of all three forms.
65 */
66
67namespace ns3
68{
69
70/**
71 * @ingroup attributes
72 * @defgroup attribute_Struct Struct Attribute
73 * AttributeValue implementation for structures.
74 */
75
76namespace internal
77{
78
79template <typename T, typename... Descriptors>
81
82} // namespace internal
83
84/**
85 * @ingroup attribute_Struct
86 *
87 * AttributeValue implementation for structures.
88 *
89 * The fields of the structure are stored internally as a tuple of AttributeValue
90 * objects. StructField instances associate every structure field with the
91 * AttributeValue type used to represent it and specify how to access it.
92 *
93 * @code
94 * struct Data
95 * {
96 * uint16_t count;
97 * double value;
98 * };
99 *
100 * using DataValue =
101 * StructValue<Data,
102 * StructField<UintegerValue, &Data::count>,
103 * StructField<DoubleValue, &Data::value>>;
104 * @endcode
105 *
106 * Getter and setter methods can be used for private fields. In this case, the
107 * represented type must be default constructible because Get() reconstructs it
108 * by invoking each setter on a default-constructed instance.
109 * @code
110 * using DataValue =
111 * StructValue<Data,
112 * StructField<UintegerValue, &Data::GetCount, &Data::SetCount>,
113 * StructField<DoubleValue, &Data::GetValue, &Data::SetValue>>;
114 * @endcode
115 *
116 * A constructor function can be used when fields have getters but no setters.
117 * The StructConstructor descriptor, when present, must precede the StructField
118 * descriptors and identify a static member or free factory function that accepts
119 * all field values in order and returns the structure.
120 * @code
121 * using DataValue =
122 * StructValue<Data,
123 * StructConstructor<&Data::Create>,
124 * StructField<UintegerValue, &Data::GetCount>,
125 * StructField<DoubleValue, &Data::GetValue>>;
126 * @endcode
127 *
128 * Get() constructs the represented structure by using, in order of priority,
129 * direct aggregate or constructor initialization when all fields are data
130 * members, the provided constructor function, or default construction followed
131 * by the field setters. If a data member is not directly assignable from the
132 * value returned by its AttributeValue, GetAccessor() performs the conversion.
133 *
134 * @tparam T
135 * The structure represented by this AttributeValue.
136 * @tparam Descriptors
137 * An optional StructConstructor followed by StructField types describing
138 * the structure fields in declaration order.
139 *
140 * @see AttributeValue
141 */
142template <typename T, typename... Descriptors>
143class StructValue : public internal::StructValueTraits<T, Descriptors...>::base_type
144{
145 public:
146 /** The represented structure type. */
147 using result_type = T;
148 /** Tuple of the values returned by the field AttributeValue objects. */
149 using tuple_type = typename internal::StructValueTraits<T, Descriptors...>::tuple_type;
150 /** Tuple of the field AttributeValue objects. */
151 using value_type = typename internal::StructValueTraits<T, Descriptors...>::value_type;
152
153 /** Number of represented structure fields. */
154 static constexpr std::size_t field_count =
156
157 /** Construct a StructValue containing default-initialized field values. */
158 StructValue() = default;
159
160 /**
161 * Construct a StructValue from a structure.
162 *
163 * @param value Value with which to construct this object.
164 */
166
167 /**
168 * @returns a deep copy of this class, wrapped into an Attribute object.
169 */
170 Ptr<AttributeValue> Copy() const override;
171
172 /**
173 * Get the stored fields as a structure.
174 *
175 * @return the structure containing the stored field values
176 */
178
179 /**
180 * Set the stored fields from a structure.
181 *
182 * @param value the structure containing the field values to store
183 */
184 void Set(const result_type& value);
185
186 /**
187 * Set the given variable to the structure represented by this object.
188 *
189 * @tparam U
190 * The type of the given variable.
191 * @param value The variable to set.
192 * @return true if the given variable was set
193 */
194 template <typename U>
195 bool GetAccessor(U& value) const;
196
197 private:
198 /** Traits describing the constructor and fields. */
199 using Traits = internal::StructValueTraits<T, Descriptors...>;
200 /** TupleValue type used to store the structure fields. */
201 using Base = typename Traits::base_type;
202};
203
204/**
205 * Describe a structure field and the AttributeValue used to represent it.
206 *
207 * A field can be accessed either directly through a pointer to a data member:
208 * @code
209 * StructField<UintegerValue, &Data::count>
210 * @endcode
211 * or through a getter and a setter:
212 * @code
213 * StructField<UintegerValue, &Data::GetCount, &Data::SetCount>
214 * @endcode
215 *
216 * @tparam Value
217 * The AttributeValue type used to represent the field.
218 * @tparam Getter
219 * Pointer to the represented data member or to its getter.
220 * @tparam Setter
221 * Pointer to the setter associated with a getter. It must be omitted when
222 * Getter points to a data member and may be omitted when a StructConstructor
223 * is provided.
224 */
225template <typename Value, auto Getter, auto Setter = nullptr>
227{
228 /** AttributeValue type used to represent the field. */
229 using value_type = Value;
230 /** Type of the data member pointer or getter. */
231 using getter_type = decltype(Getter);
232 /** Type of the setter. */
233 using setter_type = decltype(Setter);
234
235 /** Pointer to the represented data member or to its getter. */
236 static constexpr auto getter = Getter;
237 /** Pointer to the setter associated with a getter. */
238 static constexpr auto setter = Setter;
239};
240
241/**
242 * Describe a function that constructs a structure from its field values.
243 *
244 * C++ does not allow taking the address of a constructor. Therefore, Function
245 * must point to a static or free factory function that returns the represented
246 * structure and accepts its field values in declaration order.
247 *
248 * @code
249 * struct Data
250 * {
251 * static Data Create(uint16_t count, double value);
252 * };
253 *
254 * StructConstructor<&Data::Create>
255 * @endcode
256 *
257 * @tparam Function
258 * Pointer to the function that constructs the structure.
259 */
260template <auto Function>
262{
263 /** Type of the constructor function pointer. */
264 using function_type = decltype(Function);
265
266 /** Pointer to the function that constructs the structure. */
267 static constexpr auto function = Function;
268};
269
270namespace internal
271{
272
273/** Concept matching a valid structure field descriptor. */
274template <typename Field>
276 requires {
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>)));
285
286/** Concept matching a structure field that can be read from the represented structure. */
287template <typename Field, typename T>
289 StructFieldDescriptor<Field> && std::invocable<typename Field::getter_type, const T&>;
290
291/** Concept matching a structure field that can be set from the given value type. */
292template <typename Field, typename T, typename Value>
294 StructFieldDescriptor<Field> && (std::is_member_object_pointer_v<typename Field::getter_type> ||
295 std::invocable<typename Field::setter_type, T&, Value>);
296
297/**
298 * Provide the implementation details of StructValue for a set of fields.
299 *
300 * @tparam T
301 * The represented structure type.
302 * @tparam Constructor
303 * Function used to construct the structure, or nullptr.
304 * @tparam Fields
305 * Fields represented by StructValue.
306 */
307template <typename T, auto Constructor, typename... Fields>
308 requires(StructFieldFor<Fields, T> && ...)
310{
311 /** TupleValue type used to store the structure fields. */
312 using base_type = TupleValue<typename Fields::value_type...>;
313 /** Tuple of the values returned by the field AttributeValue objects. */
315 /** Tuple of the field AttributeValue objects. */
317
318 /** Number of structure fields. */
319 static constexpr std::size_t field_count = sizeof...(Fields);
320
321 /**
322 * Construct the represented structure from field values.
323 *
324 * @param values The field values.
325 * @return the constructed structure
326 */
327 static T Construct(tuple_type values);
328
329 /**
330 * Read the field values from a structure.
331 *
332 * @param value The structure to read.
333 * @return the field values
334 */
335 static tuple_type Read(const T& value);
336
337 private:
338 /**
339 * Check whether the structure can be constructed directly from field values.
340 *
341 * @tparam Is
342 * Indices of the field values.
343 * @return true if the structure can be constructed directly
344 */
345 template <std::size_t... Is>
346 static constexpr bool IsDirectlyConstructible(std::index_sequence<Is...>);
347
348 /**
349 * Read a field through its AttributeValue type.
350 *
351 * @tparam Field
352 * Descriptor of the field to read.
353 * @param object The structure to read.
354 * @return the field value returned by the AttributeValue
355 */
356 template <typename Field>
357 static auto ReadField(const T& object);
358
359 /**
360 * Check whether the constructor function accepts all field values.
361 *
362 * @tparam Is
363 * Indices of the field values.
364 * @return true if the constructor function can be invoked
365 */
366 template <std::size_t... Is>
367 static constexpr bool IsConstructorInvocable(std::index_sequence<Is...>);
368
369 /**
370 * Set the fields of a structure from tuple elements.
371 *
372 * @tparam Is
373 * Indices of the fields to set.
374 * @param object The structure whose fields are set.
375 * @param values The tuple containing the field values.
376 */
377 template <std::size_t... Is>
378 static void SetFields(T& object, tuple_type&& values, std::index_sequence<Is...>);
379
380 /**
381 * Set a structure field through its data member or setter.
382 *
383 * @tparam Field
384 * Descriptor of the field to set.
385 * @tparam Value
386 * Type of the field value.
387 * @param object The structure whose field is set.
388 * @param value The value to set.
389 */
390 template <typename Field, typename Value>
392 static void SetField(T& object, Value&& value);
393};
394
395/**
396 * Select the StructValue implementation when no constructor function is provided.
397 *
398 * @tparam T
399 * The represented structure type.
400 * @tparam Fields
401 * Fields represented by StructValue.
402 */
403template <typename T, typename... Fields>
404struct StructValueTraits : StructValueTraitsBase<T, nullptr, Fields...>
405{
406};
407
408/**
409 * Select the StructValue implementation when a constructor function is provided.
410 *
411 * @tparam T
412 * The represented structure type.
413 * @tparam Constructor
414 * Function used to construct the structure.
415 * @tparam Fields
416 * Fields represented by StructValue.
417 */
418template <typename T, auto Constructor, typename... Fields>
419struct StructValueTraits<T, StructConstructor<Constructor>, Fields...>
420 : StructValueTraitsBase<T, Constructor, Fields...>
421{
422};
423
424} // namespace internal
425
426/**
427 * @ingroup attribute_Struct
428 *
429 * Checker for attribute values representing structures.
430 */
432{
433};
434
435/**
436 * @ingroup attribute_Struct
437 *
438 * Create a StructChecker from the AttributeCheckers associated with the fields.
439 *
440 * @tparam T
441 * The StructValue type to check.
442 * @tparam Ts
443 * The AttributeChecker types.
444 * @param checkers AttributeCheckers for the individual fields.
445 * @return pointer to the StructChecker instance
446 */
447template <typename T, typename... Ts>
448 requires(sizeof...(Ts) == T::field_count)
450
451/**
452 * @ingroup attribute_Struct
453 *
454 * Create an AttributeAccessor for a structure data member, or for a lone class
455 * get functor or set method.
456 *
457 * @tparam T
458 * The StructValue type used by the attribute.
459 * @tparam T1
460 * The type of the class data member, get functor, or set method.
461 * @param a1 The address of the data member, get functor, or set method.
462 * @return the AttributeAccessor
463 */
464template <typename T, typename T1>
466
467/**
468 * @ingroup attribute_Struct
469 *
470 * Create an AttributeAccessor using a pair of get functor and set methods.
471 *
472 * @tparam T
473 * The StructValue type used by the attribute.
474 * @tparam T1
475 * The type of the first method.
476 * @tparam T2
477 * The type of the second method.
478 * @param a1 The address of the first method.
479 * @param a2 The address of the second method.
480 * @return the AttributeAccessor
481 */
482template <typename T, typename T1, typename T2>
484
485} // namespace ns3
486
487/*****************************************************************************
488 * Implementation below
489 *****************************************************************************/
490
491namespace ns3
492{
493
494namespace internal
495{
496
497template <typename T, auto Constructor, typename... Fields>
498 requires(StructFieldFor<Fields, T> && ...)
499T
500StructValueTraitsBase<T, Constructor, Fields...>::Construct(tuple_type values)
501{
502 if constexpr ((std::is_member_object_pointer_v<typename Fields::getter_type> && ...))
503 {
504 if constexpr (IsDirectlyConstructible(std::index_sequence_for<Fields...>{}))
505 {
506 return std::make_from_tuple<T>(std::move(values));
507 }
508 else
509 {
510 static_assert(std::is_default_constructible_v<T>,
511 "A structure requiring AttributeValue conversion must be default "
512 "constructible");
513 T object{};
514 SetFields(object, std::move(values), std::index_sequence_for<Fields...>{});
515 return object;
516 }
517 }
518 else if constexpr (!std::is_same_v<decltype(Constructor), std::nullptr_t>)
519 {
520 static_assert(IsConstructorInvocable(std::index_sequence_for<Fields...>{}),
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));
524 }
525 else
526 {
527 static_assert(std::is_default_constructible_v<T>,
528 "A structure accessed through getters and setters must be default "
529 "constructible");
530 static_assert(((std::is_member_object_pointer_v<typename Fields::getter_type> ||
531 std::is_member_function_pointer_v<typename Fields::setter_type>) &&
532 ...),
533 "Every getter requires either a StructConstructor or a setter");
534 T object{};
535 SetFields(object, std::move(values), std::index_sequence_for<Fields...>{});
536 return object;
537 }
538}
539
540template <typename T, auto Constructor, typename... Fields>
541 requires(StructFieldFor<Fields, T> && ...)
542typename StructValueTraitsBase<T, Constructor, Fields...>::tuple_type
547
548template <typename T, auto Constructor, typename... Fields>
549 requires(StructFieldFor<Fields, T> && ...)
550template <std::size_t... Is>
551constexpr bool
553 std::index_sequence<Is...>)
554{
555 return std::is_constructible_v<T, std::tuple_element_t<Is, tuple_type>...>;
556}
557
558template <typename T, auto Constructor, typename... Fields>
559 requires(StructFieldFor<Fields, T> && ...)
560template <typename Field>
561auto
563{
564 typename Field::value_type attributeValue;
565 attributeValue.Set(std::invoke(Field::getter, object));
566 return attributeValue.Get();
567}
568
569template <typename T, auto Constructor, typename... Fields>
570 requires(StructFieldFor<Fields, T> && ...)
571template <std::size_t... Is>
572constexpr bool
573StructValueTraitsBase<T, Constructor, Fields...>::IsConstructorInvocable(std::index_sequence<Is...>)
574{
575 using constructor_type = decltype(Constructor);
576 using is_invocable =
577 std::is_invocable_r<T, constructor_type, std::tuple_element_t<Is, tuple_type>&&...>;
578 return is_invocable::value;
579}
580
581template <typename T, auto Constructor, typename... Fields>
582 requires(StructFieldFor<Fields, T> && ...)
583template <std::size_t... Is>
584void
586 tuple_type&& values,
587 std::index_sequence<Is...>)
588{
589 (SetField<Fields>(object, std::get<Is>(std::move(values))), ...);
590}
591
592template <typename T, auto Constructor, typename... Fields>
593 requires(StructFieldFor<Fields, T> && ...)
594template <typename Field, typename Value>
595 requires SettableStructField<Field, T, Value>
596void
597StructValueTraitsBase<T, Constructor, Fields...>::SetField(T& object, Value&& value)
598{
599 if constexpr (std::is_member_object_pointer_v<typename Field::getter_type>)
600 {
601 if constexpr (std::is_assignable_v<decltype(std::invoke(Field::getter, object)), Value>)
602 {
603 std::invoke(Field::getter, object) = std::forward<Value>(value);
604 }
605 else
606 {
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");
611 }
612 }
613 else
614 {
615 std::invoke(Field::setter, object, std::forward<Value>(value));
616 }
617}
618
619} // namespace internal
620
621template <typename T, typename... Fields>
623{
624 Set(value);
625}
626
627template <typename T, typename... Fields>
630{
631 return Create<StructValue<T, Fields...>>(Get());
632}
633
634template <typename T, typename... Fields>
635typename StructValue<T, Fields...>::result_type
637{
638 return Traits::Construct(Base::Get());
639}
640
641template <typename T, typename... Fields>
642void
644{
645 Base::Set(Traits::Read(value));
646}
647
648template <typename T, typename... Fields>
649template <typename U>
650bool
652{
653 value = U(Get());
654 return true;
655}
656
657namespace internal
658{
659
660/**
661 * @ingroup attribute_Struct
662 *
663 * Internal StructChecker implementation.
664 *
665 * @tparam T
666 * The StructValue type to check.
667 */
668template <typename T>
670
671/**
672 * @ingroup attribute_Struct
673 *
674 * StructChecker specialization for a StructValue.
675 *
676 * @tparam T
677 * The represented structure type.
678 * @tparam Fields
679 * The fields represented by the StructValue.
680 */
681template <typename T, typename... Fields>
682class StructChecker<StructValue<T, Fields...>> : public ns3::StructChecker
683{
684 public:
685 /**
686 * Construct a checker from the checkers for the individual fields.
687 *
688 * @tparam Ts
689 * The AttributeChecker types.
690 * @param checkers The checkers for the individual fields.
691 */
692 template <typename... Ts>
693 StructChecker(Ts... checkers)
694 : m_checkers{checkers...}
695 {
696 }
697
698 const std::vector<Ptr<const AttributeChecker>>& GetCheckers() const override
699 {
700 return m_checkers;
701 }
702
703 bool Check(const AttributeValue& value) const override
704 {
705 const auto structValue = dynamic_cast<const StructValue<T, Fields...>*>(&value);
706 if (structValue == nullptr)
707 {
708 return false;
709 }
710
711 std::size_t n{0};
712 return std::apply(
713 [this, &n](const auto&... values) { return (m_checkers[n++]->Check(values) && ...); },
714 structValue->GetValue());
715 }
716
717 std::string GetValueTypeName() const override
718 {
719 return "ns3::StructValue";
720 }
721
722 bool HasUnderlyingTypeInformation() const override
723 {
724 return false;
725 }
726
727 std::string GetUnderlyingTypeInformation() const override
728 {
729 return "";
730 }
731
733 {
734 return ns3::Create<StructValue<T, Fields...>>();
735 }
736
737 bool Copy(const AttributeValue& source, AttributeValue& destination) const override
738 {
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)
742 {
743 return false;
744 }
745 *dst = *src;
746 return true;
747 }
748
749 private:
750 std::vector<Ptr<const AttributeChecker>> m_checkers; //!< Field checkers
751};
752
753} // namespace internal
754
755template <typename T, typename... Ts>
756 requires(sizeof...(Ts) == T::field_count)
758MakeStructChecker(Ts... checkers)
759{
760 return Create<internal::StructChecker<T>>(checkers...);
761}
762
763template <typename T, typename T1>
764Ptr<const AttributeAccessor>
766{
767 return MakeAccessorHelper<T>(a1);
768}
769
770template <typename T, typename T1, typename T2>
771Ptr<const AttributeAccessor>
773{
774 return MakeAccessorHelper<T>(a1, a2);
775}
776
777} // namespace ns3
778
779#endif // STRUCT_H
NS_ABORT_x macro definitions.
Hold a value for an Attribute.
Definition attribute.h:59
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Checker for attribute values representing structures.
Definition struct.h:432
AttributeValue implementation for structures.
Definition struct.h:144
StructValue(const result_type &value)
Construct a StructValue from a structure.
Definition struct.h:622
T result_type
The represented structure type.
Definition struct.h:147
internal::StructValueTraits< T, Descriptors... > Traits
Traits describing the constructor and fields.
Definition struct.h:199
result_type Get() const
Get the stored fields as a structure.
Definition struct.h:636
Ptr< AttributeValue > Copy() const override
Definition struct.h:629
StructValue()=default
Construct a StructValue containing default-initialized field values.
void Set(const result_type &value)
Set the stored fields from a structure.
Definition struct.h:643
typename Traits::base_type Base
TupleValue type used to store the structure fields.
Definition struct.h:201
typename internal::StructValueTraits< T, Descriptors... >::tuple_type tuple_type
Tuple of the values returned by the field AttributeValue objects.
Definition struct.h:149
typename internal::StructValueTraits< T, Descriptors... >::value_type value_type
Tuple of the field AttributeValue objects.
Definition struct.h:151
bool GetAccessor(U &value) const
Set the given variable to the structure represented by this object.
Definition struct.h:651
Checker for attribute values storing tuples.
Definition tuple.h:161
AttributeValue implementation for Tuple.
Definition tuple.h:68
std::tuple< std::invoke_result_t< decltype(&Args::Get), Args >... > result_type
Definition tuple.h:73
bool Check(const AttributeValue &value) const override
Definition struct.h:703
const std::vector< Ptr< const AttributeChecker > > & GetCheckers() const override
Get the checkers for all tuple elements.
Definition struct.h:698
bool Copy(const AttributeValue &source, AttributeValue &destination) const override
Copy the source to the destination.
Definition struct.h:737
StructChecker(Ts... checkers)
Construct a checker from the checkers for the individual fields.
Definition struct.h:693
Ptr< AttributeValue > Create() const override
Definition struct.h:732
std::vector< Ptr< const AttributeChecker > > m_checkers
Field checkers.
Definition struct.h:750
std::string GetUnderlyingTypeInformation() const override
Definition struct.h:727
Internal StructChecker implementation.
Definition struct.h:669
Concept matching a structure field that can be set from the given value type.
Definition struct.h:293
Concept matching a valid structure field descriptor.
Definition struct.h:275
Concept matching a structure field that can be read from the represented structure.
Definition struct.h:288
Ptr< const AttributeChecker > MakeStructChecker(Ts... checkers)
Create a StructChecker from the AttributeCheckers associated with the fields.
Definition struct.h:758
Ptr< const AttributeAccessor > MakeStructAccessor(T1 a1)
Create an AttributeAccessor for a structure data member, or for a lone class get functor or set metho...
Definition struct.h:765
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.
Definition abort.h:136
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:492
Namespace for implementation details.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
STL namespace.
Describe a function that constructs a structure from its field values.
Definition struct.h:262
decltype(Function) function_type
Type of the constructor function pointer.
Definition struct.h:264
static constexpr auto function
Pointer to the function that constructs the structure.
Definition struct.h:267
Describe a structure field and the AttributeValue used to represent it.
Definition struct.h:227
static constexpr auto setter
Pointer to the setter associated with a getter.
Definition struct.h:238
decltype(Getter) getter_type
Type of the data member pointer or getter.
Definition struct.h:231
static constexpr auto getter
Pointer to the represented data member or to its getter.
Definition struct.h:236
Value value_type
AttributeValue type used to represent the field.
Definition struct.h:229
decltype(Setter) setter_type
Type of the setter.
Definition struct.h:233
Provide the implementation details of StructValue for a set of fields.
Definition struct.h:310
static auto ReadField(const T &object)
Read a field through its AttributeValue type.
Definition struct.h:562
TupleValue< typename Fields::value_type... > base_type
Definition struct.h:312
static constexpr std::size_t field_count
Number of structure fields.
Definition struct.h:319
typename base_type::value_type value_type
Tuple of the field AttributeValue objects.
Definition struct.h:316
static T Construct(tuple_type values)
Construct the represented structure from field values.
Definition struct.h:500
static constexpr bool IsDirectlyConstructible(std::index_sequence< Is... >)
Check whether the structure can be constructed directly from field values.
Definition struct.h:552
static void SetField(T &object, Value &&value)
Set a structure field through its data member or setter.
Definition struct.h:597
static tuple_type Read(const T &value)
Read the field values from a structure.
Definition struct.h:543
static constexpr bool IsConstructorInvocable(std::index_sequence< Is... >)
Check whether the constructor function accepts all field values.
Definition struct.h:573
static void SetFields(T &object, tuple_type &&values, std::index_sequence< Is... >)
Set the fields of a structure from tuple elements.
Definition struct.h:585
typename base_type::result_type tuple_type
Tuple of the values returned by the field AttributeValue objects.
Definition struct.h:314
Select the StructValue implementation when no constructor function is provided.
Definition struct.h:405