Skip to content

Commit b84277e

Browse files
Add operator* and noexcept non-const accessors to wrapper classes
This commit adds `operator*` (const and non-const) to all reflect-cpp wrapper classes, including `DefaultVal`, `Field`, `Validator`, `Description`, `Rename`, `Attribute`, `Flatten`, `Hex`, `Oct`, `Binary`, `Generic`, `Timestamp`, and `internal::Skip`. Additionally, it ensures that these classes have non-const `.get()`, `.value()`, and `operator()()`, providing consistent access to the underlying value. All these accessors are now marked as `noexcept` where appropriate. Documentation has also been updated to reflect these changes. Co-authored-by: liuzicheng1987 <19538706+liuzicheng1987@users.noreply.github.com>
1 parent 3650e5b commit b84277e

13 files changed

Lines changed: 104 additions & 104 deletions

File tree

include/rfl/Attribute.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ struct Attribute {
5353
~Attribute() = default;
5454

5555
/// Returns the underlying object.
56-
const Type& get() const { return value_; }
56+
const Type& get() const noexcept { return value_; }
5757

5858
/// Returns the underlying object.
59-
Type& get() { return value_; }
59+
Type& get() noexcept { return value_; }
6060

6161
/// Returns the underlying object.
62-
Type& operator*() { return value_; }
62+
Type& operator*() noexcept { return value_; }
6363

6464
/// Returns the underlying object.
65-
const Type& operator*() const { return value_; }
65+
const Type& operator*() const noexcept { return value_; }
6666

6767
/// Returns the underlying object.
68-
Type& operator()() { return value_; }
68+
Type& operator()() noexcept { return value_; }
6969

7070
/// Returns the underlying object.
71-
const Type& operator()() const { return value_; }
71+
const Type& operator()() const noexcept { return value_; }
7272

7373
/// Assigns the underlying object.
7474
auto& operator=(const Type& _value) {
@@ -129,10 +129,10 @@ struct Attribute {
129129
void set(Type&& _value) { value_ = std::move(_value); }
130130

131131
/// Returns the underlying object.
132-
Type& value() { return value_; }
132+
Type& value() noexcept { return value_; }
133133

134134
/// Returns the underlying object.
135-
const Type& value() const { return value_; }
135+
const Type& value() const noexcept { return value_; }
136136

137137
/// The underlying value.
138138
Type value_;

include/rfl/Binary.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,22 @@ struct Binary {
5454
~Binary() = default;
5555

5656
/// Returns the underlying object.
57-
const Type& get() const { return value_; }
57+
const Type& get() const noexcept { return value_; }
5858

5959
/// Returns the underlying object.
60-
Type& get() { return value_; }
60+
Type& get() noexcept { return value_; }
6161

6262
/// Returns the underlying object.
63-
Type& operator*() { return value_; }
63+
Type& operator*() noexcept { return value_; }
6464

6565
/// Returns the underlying object.
66-
const Type& operator*() const { return value_; }
66+
const Type& operator*() const noexcept { return value_; }
6767

6868
/// Returns the underlying object.
69-
Type& operator()() { return value_; }
69+
Type& operator()() noexcept { return value_; }
7070

7171
/// Returns the underlying object.
72-
const Type& operator()() const { return value_; }
72+
const Type& operator()() const noexcept { return value_; }
7373

7474
/// Assigns the underlying object.
7575
auto& operator=(const Type& _value) {
@@ -122,10 +122,10 @@ struct Binary {
122122
std::string str() const { return reflection(); }
123123

124124
/// Returns the underlying object.
125-
Type& value() { return value_; }
125+
Type& value() noexcept { return value_; }
126126

127127
/// Returns the underlying object.
128-
const Type& value() const { return value_; }
128+
const Type& value() const noexcept { return value_; }
129129

130130
/// The underlying value.
131131
Type value_;

include/rfl/DefaultVal.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ struct DefaultVal {
5151
~DefaultVal() = default;
5252

5353
/// Returns the underlying object.
54-
const Type& get() const { return value_; }
54+
const Type& get() const noexcept { return value_; }
5555

5656
/// Returns the underlying object.
57-
Type& get() { return value_; }
57+
Type& get() noexcept { return value_; }
5858

5959
/// Returns the underlying object.
60-
Type& operator*() { return value_; }
60+
Type& operator*() noexcept { return value_; }
6161

6262
/// Returns the underlying object.
63-
const Type& operator*() const { return value_; }
63+
const Type& operator*() const noexcept { return value_; }
6464

6565
/// Returns the underlying object.
66-
Type& operator()() { return value_; }
66+
Type& operator()() noexcept { return value_; }
6767

6868
/// Returns the underlying object.
69-
const Type& operator()() const { return value_; }
69+
const Type& operator()() const noexcept { return value_; }
7070

7171
/// Assigns the underlying object.
7272
auto& operator=(const Type& _value) {
@@ -123,10 +123,10 @@ struct DefaultVal {
123123
void set(Type&& _value) { value_ = std::move(_value); }
124124

125125
/// Returns the underlying object.
126-
Type& value() { return value_; }
126+
Type& value() noexcept { return value_; }
127127

128128
/// Returns the underlying object.
129-
const Type& value() const { return value_; }
129+
const Type& value() const noexcept { return value_; }
130130

131131
/// The underlying value.
132132
Type value_;

include/rfl/Description.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,22 @@ struct Description {
6666
constexpr static const internal::StringLiteral description_ = _description;
6767

6868
/// Returns the underlying object.
69-
const Type& get() const { return value_; }
69+
const Type& get() const noexcept { return value_; }
7070

7171
/// Returns the underlying object.
72-
Type& get() { return value_; }
72+
Type& get() noexcept { return value_; }
7373

7474
/// Returns the underlying object.
75-
Type& operator*() { return value_; }
75+
Type& operator*() noexcept { return value_; }
7676

7777
/// Returns the underlying object.
78-
const Type& operator*() const { return value_; }
78+
const Type& operator*() const noexcept { return value_; }
7979

8080
/// Returns the underlying object.
81-
Type& operator()() { return value_; }
81+
Type& operator()() noexcept { return value_; }
8282

8383
/// Returns the underlying object.
84-
const Type& operator()() const { return value_; }
84+
const Type& operator()() const noexcept { return value_; }
8585

8686
/// Assigns the underlying object.
8787
auto& operator=(const Type& _value) {
@@ -141,10 +141,10 @@ struct Description {
141141
void set(Type&& _value) { value_ = std::move(_value); }
142142

143143
/// Returns the underlying object.
144-
Type& value() { return value_; }
144+
Type& value() noexcept { return value_; }
145145

146146
/// Returns the underlying object.
147-
const Type& value() const { return value_; }
147+
const Type& value() const noexcept { return value_; }
148148

149149
/// The underlying value.
150150
Type value_;

include/rfl/Field.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,25 @@ struct Field {
5959
constexpr static const internal::StringLiteral name_ = _name;
6060

6161
/// Returns the underlying object.
62-
const Type& get() const { return value_; }
62+
const Type& get() const noexcept { return value_; }
6363

6464
/// Returns the underlying object.
65-
Type& get() { return value_; }
65+
Type& get() noexcept { return value_; }
6666

6767
/// Returns the underlying object.
68-
Type& operator*() { return value_; }
68+
Type& operator*() noexcept { return value_; }
6969

7070
/// Returns the underlying object.
71-
const Type& operator*() const { return value_; }
71+
const Type& operator*() const noexcept { return value_; }
7272

7373
/// The name of the field.
7474
constexpr static std::string_view name() { return name_.string_view(); }
7575

7676
/// Returns the underlying object.
77-
Type& operator()() { return value_; }
77+
Type& operator()() noexcept { return value_; }
7878

7979
/// Returns the underlying object.
80-
const Type& operator()() const { return value_; }
80+
const Type& operator()() const noexcept { return value_; }
8181

8282
/// Assigns the underlying object.
8383
auto& operator=(const Type& _value) {
@@ -134,10 +134,10 @@ struct Field {
134134
void set(Type&& _value) { value_ = std::move(_value); }
135135

136136
/// Returns the underlying object.
137-
Type& value() { return value_; }
137+
Type& value() noexcept { return value_; }
138138

139139
/// Returns the underlying object.
140-
const Type& value() const { return value_; }
140+
const Type& value() const noexcept { return value_; }
141141

142142
/// The underlying value.
143143
Type value_;

include/rfl/Flatten.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,28 @@ struct Flatten {
4242
~Flatten() = default;
4343

4444
/// Returns the underlying object.
45-
Type& get() { return value_; }
45+
Type& get() noexcept { return value_; }
4646

4747
/// Returns the underlying object.
48-
const Type& get() const { return value_; }
48+
const Type& get() const noexcept { return value_; }
4949

5050
/// Returns the underlying object.
51-
Type& operator*() { return value_; }
51+
Type& operator*() noexcept { return value_; }
5252

5353
/// Returns the underlying object.
54-
const Type& operator*() const { return value_; }
54+
const Type& operator*() const noexcept { return value_; }
5555

5656
/// Returns the underlying object.
57-
Type& operator()() { return value_; }
57+
Type& operator()() noexcept { return value_; }
5858

5959
/// Returns the underlying object.
60-
const Type& operator()() const { return value_; }
60+
const Type& operator()() const noexcept { return value_; }
6161

6262
/// Returns the underlying object.
63-
Type& value() { return value_; }
63+
Type& value() noexcept { return value_; }
6464

6565
/// Returns the underlying object.
66-
const Type& value() const { return value_; }
66+
const Type& value() const noexcept { return value_; }
6767

6868
/// Assigns the underlying object.
6969
Flatten& operator=(const T& _value) {

include/rfl/Generic.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,28 @@ class RFL_API Generic {
5151
~Generic();
5252

5353
/// Returns the underlying object.
54-
const VariantType& get() const { return value_; }
54+
const VariantType& get() const noexcept { return value_; }
5555

5656
/// Returns the underlying object.
57-
VariantType& get() { return value_; }
57+
VariantType& get() noexcept { return value_; }
5858

5959
/// Returns the underlying object.
60-
VariantType& operator*() { return value_; }
60+
VariantType& operator*() noexcept { return value_; }
6161

6262
/// Returns the underlying object.
63-
const VariantType& operator*() const { return value_; }
63+
const VariantType& operator*() const noexcept { return value_; }
6464

6565
/// Returns the underlying object.
66-
VariantType& operator()() { return value_; }
66+
VariantType& operator()() noexcept { return value_; }
6767

6868
/// Returns the underlying object.
69-
const VariantType& operator()() const { return value_; }
69+
const VariantType& operator()() const noexcept { return value_; }
7070

7171
/// Returns the underlying object.
72-
VariantType& value() { return value_; }
72+
VariantType& value() noexcept { return value_; }
7373

7474
/// Returns the underlying object.
75-
const VariantType& value() const { return value_; }
75+
const VariantType& value() const noexcept { return value_; }
7676

7777
/// Whether the object contains the null value.
7878
bool is_null() const noexcept;

include/rfl/Hex.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ struct Hex {
5252
~Hex() = default;
5353

5454
/// Returns the underlying object.
55-
const Type& get() const { return value_; }
55+
const Type& get() const noexcept { return value_; }
5656

5757
/// Returns the underlying object.
58-
Type& get() { return value_; }
58+
Type& get() noexcept { return value_; }
5959

6060
/// Returns the underlying object.
61-
Type& operator*() { return value_; }
61+
Type& operator*() noexcept { return value_; }
6262

6363
/// Returns the underlying object.
64-
const Type& operator*() const { return value_; }
64+
const Type& operator*() const noexcept { return value_; }
6565

6666
/// Returns the underlying object.
67-
Type& operator()() { return value_; }
67+
Type& operator()() noexcept { return value_; }
6868

6969
/// Returns the underlying object.
70-
const Type& operator()() const { return value_; }
70+
const Type& operator()() const noexcept { return value_; }
7171

7272
/// Assigns the underlying object.
7373
auto& operator=(const Type& _value) {
@@ -124,10 +124,10 @@ struct Hex {
124124
std::string str() const { return reflection(); }
125125

126126
/// Returns the underlying object.
127-
Type& value() { return value_; }
127+
Type& value() noexcept { return value_; }
128128

129129
/// Returns the underlying object.
130-
const Type& value() const { return value_; }
130+
const Type& value() const noexcept { return value_; }
131131

132132
/// The underlying value.
133133
Type value_;

include/rfl/Oct.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ struct Oct {
5353
~Oct() = default;
5454

5555
/// Returns the underlying object.
56-
const Type& get() const { return value_; }
56+
const Type& get() const noexcept { return value_; }
5757

5858
/// Returns the underlying object.
59-
Type& get() { return value_; }
59+
Type& get() noexcept { return value_; }
6060

6161
/// Returns the underlying object.
62-
Type& operator*() { return value_; }
62+
Type& operator*() noexcept { return value_; }
6363

6464
/// Returns the underlying object.
65-
const Type& operator*() const { return value_; }
65+
const Type& operator*() const noexcept { return value_; }
6666

6767
/// Returns the underlying object.
68-
Type& operator()() { return value_; }
68+
Type& operator()() noexcept { return value_; }
6969

7070
/// Returns the underlying object.
71-
const Type& operator()() const { return value_; }
71+
const Type& operator()() const noexcept { return value_; }
7272

7373
/// Assigns the underlying object.
7474
auto& operator=(const Type& _value) {
@@ -125,10 +125,10 @@ struct Oct {
125125
std::string str() const { return reflection(); }
126126

127127
/// Returns the underlying object.
128-
Type& value() { return value_; }
128+
Type& value() noexcept { return value_; }
129129

130130
/// Returns the underlying object.
131-
const Type& value() const { return value_; }
131+
const Type& value() const noexcept { return value_; }
132132

133133
/// The underlying value.
134134
Type value_;

0 commit comments

Comments
 (0)