Skip to content

Commit f40f9f1

Browse files
Added to short
1 parent 48c388b commit f40f9f1

1 file changed

Lines changed: 82 additions & 20 deletions

File tree

include/rfl/Short.hpp

Lines changed: 82 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,114 +21,176 @@ struct Short {
2121

2222
static_assert(_name.length == 1, "Short name must be exactly one character.");
2323

24-
Short() requires std::is_default_constructible_v<Type>
24+
/// @brief Default constructor.
25+
/// @details Constructs the underlying value using its default constructor.
26+
/// @requires Type must be default constructible.
27+
Short()
28+
requires std::is_default_constructible_v<Type>
2529
: value_(Type()) {}
2630

31+
/// @brief Constructs the Short wrapper from a const reference to the
32+
/// underlying value.
33+
/// @param _value The value to assign to the underlying field.
2734
Short(const Type& _value) : value_(_value) {}
2835

36+
/// @brief Constructs the Short wrapper by moving the underlying value.
37+
/// @param _value The value to move into the underlying field.
2938
Short(Type&& _value) noexcept : value_(std::move(_value)) {}
3039

40+
/// @brief Move constructor.
41+
/// @param _field The Short field to move from.
3142
Short(Short<_name, T>&& _field) noexcept = default;
3243

44+
/// @brief Copy constructor.
45+
/// @param _field The Short field to copy from.
3346
Short(const Short<_name, T>& _field) = default;
3447

48+
/// @brief Constructs from another Short with a convertible underlying type.
49+
/// @tparam U The type of the other Short's underlying value.
50+
/// @param _field The other Short field to copy from.
3551
template <class U>
3652
Short(const Short<_name, U>& _field) : value_(_field.get()) {}
3753

54+
/// @brief Move constructs from another Short with a convertible underlying
55+
/// type.
56+
/// @tparam U The type of the other Short's underlying value.
57+
/// @param _field The other Short field to move from.
3858
template <class U>
3959
Short(Short<_name, U>&& _field) : value_(std::move(_field.value_)) {}
4060

61+
/// @brief Constructs from a value convertible to the underlying type.
62+
/// @tparam U The type of the value.
63+
/// @param _value The value to assign.
4164
template <class U>
4265
requires std::is_convertible_v<U, Type>
4366
Short(const U& _value) : value_(_value) {}
4467

68+
/// @brief Move constructs from a value convertible to the underlying type.
69+
/// @tparam U The type of the value.
70+
/// @param _value The value to move.
4571
template <class U>
4672
requires std::is_convertible_v<U, Type>
4773
Short(U&& _value) noexcept : value_(std::forward<U>(_value)) {}
4874

49-
/// Assigns the underlying object to its default value.
75+
/// @brief Constructs the underlying object to its default value using Default
76+
/// tag.
77+
/// @tparam U The type to default construct (defaults to Type).
78+
/// @param unused Default tag.
5079
template <class U = Type>
5180
requires std::is_default_constructible_v<U>
5281
Short(const Default&) : value_(Type()) {}
5382

83+
/// @brief Destructor.
84+
/// @details Defaulted destructor for Short.
5485
~Short() = default;
5586

56-
/// Returns the underlying object.
87+
/// @brief Returns a const reference to the underlying object.
88+
/// @return Const reference to the underlying value.
5789
const Type& get() const noexcept { return value_; }
5890

59-
/// Returns the underlying object.
91+
/// @brief Returns a reference to the underlying object.
92+
/// @return Reference to the underlying value.
6093
Type& get() noexcept { return value_; }
6194

62-
/// Returns the underlying object.
95+
/// @brief Dereference operator.
96+
/// @return Reference to the underlying value.
6397
Type& operator*() noexcept { return value_; }
6498

65-
/// Returns the underlying object.
99+
/// @brief Dereference operator (const).
100+
/// @return Const reference to the underlying value.
66101
const Type& operator*() const noexcept { return value_; }
67102

68-
/// Returns the underlying object.
103+
/// @brief Function call operator.
104+
/// @return Reference to the underlying value.
69105
Type& operator()() noexcept { return value_; }
70106

71-
/// Returns the underlying object.
107+
/// @brief Function call operator (const).
108+
/// @return Const reference to the underlying value.
72109
const Type& operator()() const noexcept { return value_; }
73110

74-
/// Assigns the underlying object.
111+
/// @brief Assigns a new value to the underlying object.
112+
/// @param _value The value to assign.
113+
/// @return Reference to this Short.
75114
auto& operator=(const Type& _value) {
76115
value_ = _value;
77116
return *this;
78117
}
79118

80-
/// Assigns the underlying object.
119+
/// @brief Move-assigns a new value to the underlying object.
120+
/// @param _value The value to move.
121+
/// @return Reference to this Short.
81122
auto& operator=(Type&& _value) noexcept {
82123
value_ = std::move(_value);
83124
return *this;
84125
}
85126

86-
/// Assigns the underlying object.
127+
/// @brief Assigns a value convertible to the underlying type.
128+
/// @tparam U The type of the value.
129+
/// @param _value The value to assign.
130+
/// @return Reference to this Short.
87131
template <class U>
88132
requires std::is_convertible_v<U, Type>
89133
auto& operator=(const U& _value) {
90134
value_ = _value;
91135
return *this;
92136
}
93137

94-
/// Assigns the underlying object to its default value.
138+
/// @brief Assigns the underlying object to its default value using Default
139+
/// tag.
140+
/// @tparam U The type to default construct (defaults to Type).
141+
/// @param unused Default tag.
142+
/// @return Reference to this Short.
95143
template <class U = Type>
96144
requires std::is_default_constructible_v<U>
97145
auto& operator=(const Default&) {
98146
value_ = Type();
99147
return *this;
100148
}
101149

102-
/// Assigns the underlying object.
150+
/// @brief Copy assignment operator.
151+
/// @param _field The Short field to copy from.
152+
/// @return Reference to this Short.
103153
Short<_name, T>& operator=(const Short<_name, T>& _field) = default;
104154

105-
/// Assigns the underlying object.
155+
/// @brief Move assignment operator.
156+
/// @param _field The Short field to move from.
157+
/// @return Reference to this Short.
106158
Short<_name, T>& operator=(Short<_name, T>&& _field) = default;
107159

108-
/// Assigns the underlying object.
160+
/// @brief Assigns from another Short with a convertible underlying type.
161+
/// @tparam U The type of the other Short's underlying value.
162+
/// @param _field The other Short field to copy from.
163+
/// @return Reference to this Short.
109164
template <class U>
110165
auto& operator=(const Short<_name, U>& _field) {
111166
value_ = _field.get();
112167
return *this;
113168
}
114169

115-
/// Assigns the underlying object.
170+
/// @brief Move-assigns from another Short with a convertible underlying type.
171+
/// @tparam U The type of the other Short's underlying value.
172+
/// @param _field The other Short field to move from.
173+
/// @return Reference to this Short.
116174
template <class U>
117175
auto& operator=(Short<_name, U>&& _field) {
118176
value_ = std::move(_field.value_);
119177
return *this;
120178
}
121179

122-
/// Assigns the underlying object.
180+
/// @brief Sets the underlying object to a new value.
181+
/// @param _value The value to assign.
123182
void set(const Type& _value) { value_ = _value; }
124183

125-
/// Assigns the underlying object.
184+
/// @brief Sets the underlying object to a new value by moving.
185+
/// @param _value The value to move.
126186
void set(Type&& _value) { value_ = std::move(_value); }
127187

128-
/// Returns the underlying object.
188+
/// @brief Returns a reference to the underlying value.
189+
/// @return Reference to the underlying value.
129190
Type& value() noexcept { return value_; }
130191

131-
/// Returns the underlying object.
192+
/// @brief Returns a const reference to the underlying value.
193+
/// @return Const reference to the underlying value.
132194
const Type& value() const noexcept { return value_; }
133195

134196
/// The underlying value.

0 commit comments

Comments
 (0)