A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
struct.h File Reference

Guidelines for defining attributes represented by structures. More...

#include "abort.h"
#include "tuple.h"
#include <concepts>
#include <functional>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
Include dependency graph for struct.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  ns3::StructChecker
 Checker for attribute values representing structures. More...
class  ns3::internal::StructChecker< StructValue< T, Fields... > >
 StructChecker specialization for a StructValue. More...
struct  ns3::StructConstructor< Function >
 Describe a function that constructs a structure from its field values. More...
struct  ns3::StructField< Value, Getter, Setter >
 Describe a structure field and the AttributeValue used to represent it. More...
class  ns3::StructValue< T, Descriptors >
 AttributeValue implementation for structures. More...
struct  ns3::internal::StructValueTraits< T, Fields >
 Select the StructValue implementation when no constructor function is provided. More...
struct  ns3::internal::StructValueTraits< T, StructConstructor< Constructor >, Fields... >
 Select the StructValue implementation when a constructor function is provided. More...
struct  ns3::internal::StructValueTraitsBase< T, Constructor, Fields >
 Provide the implementation details of StructValue for a set of fields. More...

Namespaces

namespace  ns3
 Every class exported by the ns3 library is enclosed in the ns3 namespace.
namespace  ns3::internal
 Namespace for implementation details.

Concepts

concept  ns3::internal::SettableStructField
 Concept matching a structure field that can be set from the given value type.
concept  ns3::internal::StructFieldDescriptor
 Concept matching a valid structure field descriptor.
concept  ns3::internal::StructFieldFor
 Concept matching a structure field that can be read from the represented structure.

Functions

template<typename T, typename T1>
Ptr< const AttributeAccessor > ns3::MakeStructAccessor (T1 a1)
 Create an AttributeAccessor for a structure data member, or for a lone class get functor or set method.
template<typename T, typename T1, typename T2>
Ptr< const AttributeAccessor > ns3::MakeStructAccessor (T1 a1, T2 a2)
 Create an AttributeAccessor using a pair of get functor and set methods.
template<typename T, typename... Ts>
Ptr< const AttributeChecker > ns3::MakeStructChecker (Ts... checkers)
 Create a StructChecker from the AttributeCheckers associated with the fields.

Detailed Description

Guidelines for defining attributes represented by structures.

StructValue allows a structure to use the attribute system's accessors, checkers, serialization, and deserialization facilities. To define a StructValue, provide one StructField descriptor for every field, in the same order in which the field values are serialized. Choose one of the following forms according to how the structure exposes and initializes its fields (

See also
StructValue for more information):
  1. Public data members. If all fields are publicly accessible, each StructField specifies the field's AttributeValue type and a pointer to the data member, for example StructField<UintegerValue, &Data::count>. StructValue reconstructs the structure directly from the field values. If an AttributeValue returns a different type, its GetAccessor() method converts the value to the data member type.
  2. Private data members with getters and a factory. Each private field must have a getter, and its StructField specifies the AttributeValue type and a pointer to that getter, for example StructField<UintegerValue, &Data::GetCount>. For any public data member, a getter is not required, as its StructField descriptor can specify the field's AttributeValue type and a pointer to the data member. A StructConstructor descriptor must precede the StructField descriptors and identify a static member or free factory function that accepts all field values in order and returns the structure, for example StructConstructor<&Data::Create>.
  3. Private data members with getters and setters. Each private field must have both a getter and a setter, and its StructField specifies the AttributeValue type and pointers to both methods, for example StructField<UintegerValue, &Data::GetCount, &Data::SetCount>. For any public data member, getter and setter are not required, as its StructField descriptor can specify the field's AttributeValue type and a pointer to the data member. The structure must be default constructible; StructValue reconstructs it by default-constructing an instance and invoking the setter, for private data members, or accessing the pointer, for public data members.

StructValue stores the fields internally as a TupleValue. MakeStructAccessor() and MakeStructChecker() can then be used to register the structure as an attribute and validate its individual fields.

See also
StructValueTestSuite for Example programs of all three forms.

Definition in file struct.h.