A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
wifi-opt-field.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2024 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 WIFI_OPT_FIELD_H
10
#define WIFI_OPT_FIELD_H
11
12
#include <functional>
13
#include <optional>
14
15
namespace
ns3
16
{
17
18
/**
19
* \ingroup wifi
20
*
21
* OptFieldWithPresenceInd is a class modeling an optional field (in an Information Element, a
22
* management frame, etc.) having an associated Presence Indicator bit. This class is a wrapper
23
* around std::optional (most of its functions are exposed, more can be added if needed) that
24
* additionally sets the Presence Indicator flag appropriately when operations like reset or
25
* assignment of a value are performed on the optional field.
26
*/
27
template
<
typename
T>
28
class
OptFieldWithPresenceInd
29
{
30
public
:
31
/// @brief constructor
32
/// @param presenceFlag the Presence Indicator flag
33
OptFieldWithPresenceInd
(
bool
& presenceFlag);
34
35
/// @brief Destroy the value (if any) contained in the optional field.
36
/// @return a reference to this object
37
constexpr
OptFieldWithPresenceInd
&
operator=
(std::nullopt_t);
38
39
/// @brief Assign the given value to the optional field
40
/// @param other the given value
41
/// @return a reference to this object
42
constexpr
OptFieldWithPresenceInd
&
operator=
(
const
std::optional<T>& other);
43
44
/// @brief Assign the given value to the optional field
45
/// @param other the given value
46
/// @return a reference to this object
47
constexpr
OptFieldWithPresenceInd
&
operator=
(std::optional<T>&& other);
48
49
/// @brief Operator bool
50
/// @return whether this object contains a value
51
constexpr
explicit
operator
bool()
const
;
52
53
/// @brief Check whether this object contains a value
54
/// @return whether this object contains a value
55
constexpr
bool
has_value
()
const
;
56
57
/// @return a pointer to the contained value
58
constexpr
const
T*
operator->
()
const
;
59
60
/// @return a pointer to the contained value
61
constexpr
T*
operator->
();
62
63
/// @return a reference to the contained value
64
constexpr
const
T&
operator*
()
const
;
65
66
/// @return a reference to the contained value
67
constexpr
T&
operator*
();
68
69
/// @brief Construct the contained value in-place
70
/// @tparam Args the type of arguments to pass to the constructor
71
/// @param args the arguments to pass to the constructor
72
/// @return a reference to the new contained value
73
template
<
class
... Args>
74
constexpr
T&
emplace
(Args&&... args);
75
76
/// @brief Destroy the value (if any) contained in the optional field
77
constexpr
void
reset
();
78
79
private
:
80
std::optional<T>
m_field
;
///< the optional field
81
std::reference_wrapper<bool>
m_presenceFlag
;
///< the Presence Indicator flag
82
};
83
84
}
// namespace ns3
85
86
/***************************************************************
87
* Implementation of the templates declared above.
88
***************************************************************/
89
90
namespace
ns3
91
{
92
93
template
<
typename
T>
94
OptFieldWithPresenceInd<T>::OptFieldWithPresenceInd
(
bool
& presenceFlag)
95
: m_presenceFlag(presenceFlag)
96
{
97
m_presenceFlag
.get() =
false
;
98
}
99
100
template
<
typename
T>
101
constexpr
OptFieldWithPresenceInd<T>
&
102
OptFieldWithPresenceInd<T>::operator=
(std::nullopt_t)
103
{
104
m_field.
reset
();
105
m_presenceFlag.get() =
false
;
106
return
*
this
;
107
}
108
109
template
<
typename
T>
110
constexpr
OptFieldWithPresenceInd<T>
&
111
OptFieldWithPresenceInd<T>::operator=
(
const
std::optional<T>& other)
112
{
113
m_field = other;
114
m_presenceFlag.get() = other.
has_value
();
115
return
*
this
;
116
}
117
118
template
<
typename
T>
119
constexpr
OptFieldWithPresenceInd<T>
&
120
OptFieldWithPresenceInd<T>::operator=
(std::optional<T>&& other)
121
{
122
m_field = std::move(other);
123
m_presenceFlag.get() = other.has_value();
124
return
*
this
;
125
}
126
127
template
<
typename
T>
128
constexpr
OptFieldWithPresenceInd<T>::operator
bool()
const
129
{
130
return
m_field.
has_value
();
131
}
132
133
template
<
typename
T>
134
constexpr
bool
135
OptFieldWithPresenceInd<T>::has_value
()
const
136
{
137
return
m_field.has_value();
138
}
139
140
template
<
typename
T>
141
constexpr
const
T*
142
OptFieldWithPresenceInd<T>::operator->
()
const
143
{
144
return
&(*m_field);
145
}
146
147
template
<
typename
T>
148
constexpr
T*
149
OptFieldWithPresenceInd<T>::operator->
()
150
{
151
return
&(*m_field);
152
}
153
154
template
<
typename
T>
155
constexpr
const
T&
156
OptFieldWithPresenceInd<T>::operator*
()
const
157
{
158
return
*m_field;
159
}
160
161
template
<
typename
T>
162
constexpr
T&
163
OptFieldWithPresenceInd<T>::operator*
()
164
{
165
return
*m_field;
166
}
167
168
template
<
typename
T>
169
template
<
class
... Args>
170
constexpr
T&
171
OptFieldWithPresenceInd<T>::emplace
(Args&&... args)
172
{
173
m_field.emplace(std::forward<Args>(args)...);
174
m_presenceFlag.get() =
true
;
175
return
*m_field;
176
}
177
178
template
<
typename
T>
179
constexpr
void
180
OptFieldWithPresenceInd<T>::reset
()
181
{
182
m_field.reset();
183
m_presenceFlag.get() =
false
;
184
}
185
186
}
// namespace ns3
187
188
#endif
/* WIFI_OPT_FIELD_H */
ns3::OptFieldWithPresenceInd
OptFieldWithPresenceInd is a class modeling an optional field (in an Information Element,...
Definition
wifi-opt-field.h:29
ns3::OptFieldWithPresenceInd::m_field
std::optional< T > m_field
the optional field
Definition
wifi-opt-field.h:80
ns3::OptFieldWithPresenceInd::reset
constexpr void reset()
Destroy the value (if any) contained in the optional field.
Definition
wifi-opt-field.h:180
ns3::OptFieldWithPresenceInd::m_presenceFlag
std::reference_wrapper< bool > m_presenceFlag
the Presence Indicator flag
Definition
wifi-opt-field.h:81
ns3::OptFieldWithPresenceInd::operator=
constexpr OptFieldWithPresenceInd & operator=(std::nullopt_t)
Destroy the value (if any) contained in the optional field.
Definition
wifi-opt-field.h:102
ns3::OptFieldWithPresenceInd::operator=
constexpr OptFieldWithPresenceInd & operator=(std::optional< T > &&other)
Assign the given value to the optional field.
Definition
wifi-opt-field.h:120
ns3::OptFieldWithPresenceInd::operator->
constexpr const T * operator->() const
Definition
wifi-opt-field.h:142
ns3::OptFieldWithPresenceInd::emplace
constexpr T & emplace(Args &&... args)
Construct the contained value in-place.
Definition
wifi-opt-field.h:171
ns3::OptFieldWithPresenceInd::operator->
constexpr T * operator->()
Definition
wifi-opt-field.h:149
ns3::OptFieldWithPresenceInd::OptFieldWithPresenceInd
OptFieldWithPresenceInd(bool &presenceFlag)
constructor
Definition
wifi-opt-field.h:94
ns3::OptFieldWithPresenceInd::operator=
constexpr OptFieldWithPresenceInd & operator=(const std::optional< T > &other)
Assign the given value to the optional field.
Definition
wifi-opt-field.h:111
ns3::OptFieldWithPresenceInd::has_value
constexpr bool has_value() const
Check whether this object contains a value.
Definition
wifi-opt-field.h:135
ns3::OptFieldWithPresenceInd::operator*
constexpr T & operator*()
Definition
wifi-opt-field.h:163
ns3::OptFieldWithPresenceInd::operator*
constexpr const T & operator*() const
Definition
wifi-opt-field.h:156
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
wifi
model
wifi-opt-field.h
Generated on Fri Nov 8 2024 13:59:08 for ns-3 by
1.11.0