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
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Stefano Avallone <stavallo@unina.it>
18
*/
19
20
#ifndef WIFI_OPT_FIELD_H
21
#define WIFI_OPT_FIELD_H
22
23
#include <functional>
24
#include <optional>
25
26
namespace
ns3
27
{
28
29
/**
30
* \ingroup wifi
31
*
32
* OptFieldWithPresenceInd is a class modeling an optional field (in an Information Element, a
33
* management frame, etc.) having an associated Presence Indicator bit. This class is a wrapper
34
* around std::optional (most of its functions are exposed, more can be added if needed) that
35
* additionally sets the Presence Indicator flag appropriately when operations like reset or
36
* assignment of a value are performed on the optional field.
37
*/
38
template
<
typename
T>
39
class
OptFieldWithPresenceInd
40
{
41
public
:
42
/// @brief constructor
43
/// @param presenceFlag the Presence Indicator flag
44
OptFieldWithPresenceInd
(
bool
& presenceFlag);
45
46
/// @brief Destroy the value (if any) contained in the optional field.
47
/// @return a reference to this object
48
constexpr
OptFieldWithPresenceInd
&
operator=
(std::nullopt_t);
49
50
/// @brief Assign the given value to the optional field
51
/// @param other the given value
52
/// @return a reference to this object
53
constexpr
OptFieldWithPresenceInd
&
operator=
(
const
std::optional<T>& other);
54
55
/// @brief Assign the given value to the optional field
56
/// @param other the given value
57
/// @return a reference to this object
58
constexpr
OptFieldWithPresenceInd
&
operator=
(std::optional<T>&& other);
59
60
/// @brief Operator bool
61
/// @return whether this object contains a value
62
constexpr
explicit
operator
bool()
const
;
63
64
/// @brief Check whether this object contains a value
65
/// @return whether this object contains a value
66
constexpr
bool
has_value
()
const
;
67
68
/// @return a pointer to the contained value
69
constexpr
const
T*
operator->
()
const
;
70
71
/// @return a pointer to the contained value
72
constexpr
T*
operator->
();
73
74
/// @return a reference to the contained value
75
constexpr
const
T&
operator*
()
const
;
76
77
/// @return a reference to the contained value
78
constexpr
T&
operator*
();
79
80
/// @brief Construct the contained value in-place
81
/// @tparam Args the type of arguments to pass to the constructor
82
/// @param args the arguments to pass to the constructor
83
/// @return a reference to the new contained value
84
template
<
class
... Args>
85
constexpr
T&
emplace
(Args&&... args);
86
87
/// @brief Destroy the value (if any) contained in the optional field
88
constexpr
void
reset
();
89
90
private
:
91
std::optional<T>
m_field
;
///< the optional field
92
std::reference_wrapper<bool>
m_presenceFlag
;
///< the Presence Indicator flag
93
};
94
95
}
// namespace ns3
96
97
/***************************************************************
98
* Implementation of the templates declared above.
99
***************************************************************/
100
101
namespace
ns3
102
{
103
104
template
<
typename
T>
105
OptFieldWithPresenceInd<T>::OptFieldWithPresenceInd
(
bool
& presenceFlag)
106
: m_presenceFlag(presenceFlag)
107
{
108
m_presenceFlag
.get() =
false
;
109
}
110
111
template
<
typename
T>
112
constexpr
OptFieldWithPresenceInd<T>
&
113
OptFieldWithPresenceInd<T>::operator=
(std::nullopt_t)
114
{
115
m_field.
reset
();
116
m_presenceFlag.get() =
false
;
117
return
*
this
;
118
}
119
120
template
<
typename
T>
121
constexpr
OptFieldWithPresenceInd<T>
&
122
OptFieldWithPresenceInd<T>::operator=
(
const
std::optional<T>& other)
123
{
124
m_field = other;
125
m_presenceFlag.get() = other.
has_value
();
126
return
*
this
;
127
}
128
129
template
<
typename
T>
130
constexpr
OptFieldWithPresenceInd<T>
&
131
OptFieldWithPresenceInd<T>::operator=
(std::optional<T>&& other)
132
{
133
m_field = std::move(other);
134
m_presenceFlag.get() = other.has_value();
135
return
*
this
;
136
}
137
138
template
<
typename
T>
139
constexpr
OptFieldWithPresenceInd<T>::operator
bool()
const
140
{
141
return
m_field.
has_value
();
142
}
143
144
template
<
typename
T>
145
constexpr
bool
146
OptFieldWithPresenceInd<T>::has_value
()
const
147
{
148
return
m_field.has_value();
149
}
150
151
template
<
typename
T>
152
constexpr
const
T*
153
OptFieldWithPresenceInd<T>::operator->
()
const
154
{
155
return
&(*m_field);
156
}
157
158
template
<
typename
T>
159
constexpr
T*
160
OptFieldWithPresenceInd<T>::operator->
()
161
{
162
return
&(*m_field);
163
}
164
165
template
<
typename
T>
166
constexpr
const
T&
167
OptFieldWithPresenceInd<T>::operator*
()
const
168
{
169
return
*m_field;
170
}
171
172
template
<
typename
T>
173
constexpr
T&
174
OptFieldWithPresenceInd<T>::operator*
()
175
{
176
return
*m_field;
177
}
178
179
template
<
typename
T>
180
template
<
class
... Args>
181
constexpr
T&
182
OptFieldWithPresenceInd<T>::emplace
(Args&&... args)
183
{
184
m_field.emplace(std::forward<Args>(args)...);
185
m_presenceFlag.get() =
true
;
186
return
*m_field;
187
}
188
189
template
<
typename
T>
190
constexpr
void
191
OptFieldWithPresenceInd<T>::reset
()
192
{
193
m_field.reset();
194
m_presenceFlag.get() =
false
;
195
}
196
197
}
// namespace ns3
198
199
#endif
/* WIFI_OPT_FIELD_H */
ns3::OptFieldWithPresenceInd
OptFieldWithPresenceInd is a class modeling an optional field (in an Information Element,...
Definition:
wifi-opt-field.h:40
ns3::OptFieldWithPresenceInd::m_field
std::optional< T > m_field
the optional field
Definition:
wifi-opt-field.h:91
ns3::OptFieldWithPresenceInd::reset
constexpr void reset()
Destroy the value (if any) contained in the optional field.
Definition:
wifi-opt-field.h:191
ns3::OptFieldWithPresenceInd::m_presenceFlag
std::reference_wrapper< bool > m_presenceFlag
the Presence Indicator flag
Definition:
wifi-opt-field.h:92
ns3::OptFieldWithPresenceInd::operator=
constexpr OptFieldWithPresenceInd & operator=(std::nullopt_t)
Destroy the value (if any) contained in the optional field.
Definition:
wifi-opt-field.h:113
ns3::OptFieldWithPresenceInd::operator=
constexpr OptFieldWithPresenceInd & operator=(std::optional< T > &&other)
Assign the given value to the optional field.
Definition:
wifi-opt-field.h:131
ns3::OptFieldWithPresenceInd::operator->
constexpr const T * operator->() const
Definition:
wifi-opt-field.h:153
ns3::OptFieldWithPresenceInd::emplace
constexpr T & emplace(Args &&... args)
Construct the contained value in-place.
Definition:
wifi-opt-field.h:182
ns3::OptFieldWithPresenceInd::operator->
constexpr T * operator->()
Definition:
wifi-opt-field.h:160
ns3::OptFieldWithPresenceInd::OptFieldWithPresenceInd
OptFieldWithPresenceInd(bool &presenceFlag)
constructor
Definition:
wifi-opt-field.h:105
ns3::OptFieldWithPresenceInd::operator=
constexpr OptFieldWithPresenceInd & operator=(const std::optional< T > &other)
Assign the given value to the optional field.
Definition:
wifi-opt-field.h:122
ns3::OptFieldWithPresenceInd::has_value
constexpr bool has_value() const
Check whether this object contains a value.
Definition:
wifi-opt-field.h:146
ns3::OptFieldWithPresenceInd::operator*
constexpr T & operator*()
Definition:
wifi-opt-field.h:174
ns3::OptFieldWithPresenceInd::operator*
constexpr const T & operator*() const
Definition:
wifi-opt-field.h:167
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
wifi
model
wifi-opt-field.h
Generated on Tue May 28 2024 23:40:39 for ns-3 by
1.9.6