Skip to content

Commit bfcc27a

Browse files
Added DOxygen-style doctrings to most functions and methods (#663)
1 parent dc1af1b commit bfcc27a

246 files changed

Lines changed: 7011 additions & 699 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/rfl/AddStructName.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace rfl {
1616
template <internal::StringLiteral field_name_>
1717
struct AddStructName {
1818
/// Adds the name of the struct as a new field.
19+
/// @param _view The view of the struct
20+
/// @return A new named tuple with the struct name added as a field
1921
template <class StructType>
2022
static auto process(const auto& _view) {
2123
using LiteralType = Literal<

include/rfl/AddTagsToVariants.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ namespace rfl {
88
/// they might encounter.
99
struct AddTagsToVariants {
1010
public:
11+
/// Processes a named tuple (a tuple-like structure with named fields) without modification.
12+
/// This method exists to satisfy the processor interface but doesn't transform the data.
13+
/// @tparam StructType The type of the struct being processed
14+
/// @param _named_tuple The named tuple representing the struct's fields
15+
/// @return The unmodified named tuple
1116
template <class StructType>
1217
static auto process(auto&& _named_tuple) {
1318
return _named_tuple;
@@ -19,6 +24,11 @@ struct AddTagsToVariants {
1924
/// they might encounter.
2025
struct AddNamespacedTagsToVariants {
2126
public:
27+
/// Processes a named tuple (a tuple-like structure with named fields) without modification.
28+
/// This method exists to satisfy the processor interface but doesn't transform the data.
29+
/// @tparam StructType The type of the struct being processed
30+
/// @param _named_tuple The named tuple representing the struct's fields
31+
/// @return The unmodified named tuple
2232
template <class StructType>
2333
static auto process(auto&& _named_tuple) {
2434
return _named_tuple;

include/rfl/AllOf.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@
88

99
namespace rfl {
1010

11-
/// Requires that all of the contraints C and Cs be true.
11+
/// Requires that all of the constraints C and Cs be true.
1212
template <class C, class... Cs>
1313
struct AllOf {
14+
/// Validates that all constraints are satisfied.
15+
/// @param _value The value to validate
16+
/// @return The value if all constraints pass, otherwise an error
1417
template <class T>
1518
static rfl::Result<T> validate(T _value) noexcept {
1619
return validate_impl<T, C, Cs...>(_value);
1720
}
1821

22+
/// Converts the validator to a JSON schema type.
23+
/// @return A ValidationType representing all-of schema
1924
template <class T>
2025
static parsing::schema::ValidationType to_schema() {
2126
using ValidationType = parsing::schema::ValidationType;

include/rfl/AllowRawPtrs.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33

44
namespace rfl {
55

6-
/// This is a "fake" processor - it doesn't do much in itself, but its
7-
/// inclusion instructs the parsers to allow raw pointers.
6+
/// A processor that instructs parsers to allow raw pointers in structs.
7+
/// This is a marker type (doesn't modify data) that changes parser behavior.
8+
/// By default, reflect-cpp does not support raw pointers to avoid memory management issues.
9+
/// When AllowRawPtrs is added as a processor, raw pointers (T*) in structs will be accepted
10+
/// and serialized/deserialized. Use with caution as this can lead to memory leaks or dangling pointers.
11+
/// Usage: rfl::json::read<MyStruct, AllowRawPtrs>(json_str)
812
struct AllowRawPtrs {
913
public:
14+
/// Identity process function - returns the named tuple unchanged.
15+
/// The actual raw pointer handling happens in the parser, not here.
16+
/// @tparam StructType The struct type being processed
17+
/// @param _named_tuple The named tuple representation of the struct
18+
/// @return The same named tuple (unchanged)
1019
template <class StructType>
1120
static auto process(auto&& _named_tuple) {
1221
return _named_tuple;

include/rfl/AnyOf.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@
1111

1212
namespace rfl {
1313

14-
/// Requires that all of the contraints C and Cs be true.
14+
/// Requires that at least one of the constraints C and Cs be true.
1515
template <class C, class... Cs>
1616
struct AnyOf {
17+
/// Validates that at least one constraint is satisfied.
18+
/// @param _value The value to validate
19+
/// @return The value if at least one constraint passes, otherwise an error
1720
template <class T>
1821
static rfl::Result<T> validate(const T& _value) noexcept {
1922
return validate_impl<T, C, Cs...>(_value, {});
2023
}
2124

25+
/// Converts the validator to a JSON schema type.
26+
/// @return A ValidationType representing any-of schema
2227
template <class T>
2328
static parsing::schema::ValidationType to_schema() {
2429
using ValidationType = parsing::schema::ValidationType;
@@ -28,6 +33,9 @@ struct AnyOf {
2833
}
2934

3035
private:
36+
/// Creates an error message from a list of errors.
37+
/// @param _errors The list of errors from failed validations
38+
/// @return A formatted error message
3139
static std::string make_error_message(const std::vector<Error>& _errors) {
3240
std::stringstream stream;
3341
stream << "Expected at least one of the following validations to pass, but "

include/rfl/Attribute.hpp

Lines changed: 86 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,126 +12,190 @@
1212

1313
namespace rfl {
1414

15+
/// Wraps a field value to mark it as an XML attribute.
16+
/// In XML serialization, fields wrapped in Attribute will be rendered as attributes
17+
/// on the XML element rather than child elements. For non-XML formats, this wrapper
18+
/// is transparent and behaves like a normal field.
19+
/// Example: <element attr="value"> instead of <element><field>value</field></element>
20+
/// @tparam T The type of the attribute value
1521
template <class T>
1622
struct Attribute {
1723
using Type = T;
1824
using ReflectionType = T;
1925

26+
/// Default constructor.
2027
Attribute() : value_(Type()) {}
2128

29+
/// Constructs from a const reference to the value.
30+
/// @param _value The value to store
2231
Attribute(const Type& _value) : value_(_value) {}
2332

33+
/// Constructs from an rvalue reference to the value.
34+
/// @param _value The value to store (will be moved)
2435
Attribute(Type&& _value) noexcept : value_(std::move(_value)) {}
2536

37+
/// Move constructor.
38+
/// @param _attr The Attribute to move from
2639
Attribute(Attribute<T>&& _attr) noexcept = default;
2740

41+
/// Copy constructor.
42+
/// @param _attr The Attribute to copy from
2843
Attribute(const Attribute<Type>& _attr) = default;
2944

45+
/// Copy constructor from Attribute with compatible type.
46+
/// @tparam U Type compatible with T
47+
/// @param _attr The Attribute to copy the value from
3048
template <class U>
3149
Attribute(const Attribute<U>& _attr) : value_(_attr.get()) {}
3250

51+
/// Move constructor from Attribute with compatible type.
52+
/// @tparam U Type compatible with T
53+
/// @param _attr The Attribute to move the value from
3354
template <class U>
3455
Attribute(Attribute<U>&& _attr) : value_(_attr.get()) {}
3556

57+
/// Constructs from any type convertible to Type (copy).
58+
/// @tparam U Type convertible to T
59+
/// @param _value The value to convert and store
3660
template <class U>
3761
requires std::is_convertible_v<U, Type>
3862
Attribute(const U& _value) : value_(_value) {}
3963

64+
/// Constructs from any type convertible to Type (move).
65+
/// @tparam U Type convertible to T
66+
/// @param _value The value to convert and store (will be moved)
4067
template <class U>
4168
requires std::is_convertible_v<U, Type>
4269
Attribute(U&& _value) noexcept : value_(std::forward<U>(_value)) {}
4370

71+
/// Constructs from an Attribute with compatible type.
72+
/// @tparam U Type convertible to T
73+
/// @param _attr The Attribute to copy the value from
4474
template <class U>
4575
requires std::is_convertible_v<U, Type>
4676
Attribute(const Attribute<U>& _attr) : value_(_attr.value()) {}
4777

48-
/// Assigns the underlying object to its default value.
78+
/// Assigns the underlying object to its default value using the Default sentinel.
79+
/// @tparam U The type (must be default constructible)
80+
/// @param The default sentinel value
4981
template <class U = Type>
5082
requires std::is_default_constructible_v<U>
5183
Attribute(const Default&) : value_(Type()) {}
5284

85+
/// Destructor.
5386
~Attribute() = default;
5487

55-
/// Returns the underlying object.
88+
/// Returns the underlying value.
89+
/// @return Const reference to the stored value
5690
const Type& get() const noexcept { return value_; }
5791

58-
/// Returns the underlying object.
92+
/// Returns the underlying value.
93+
/// @return Reference to the stored value
5994
Type& get() noexcept { return value_; }
6095

61-
/// Returns the underlying object.
96+
/// Dereference operator - returns the underlying value.
97+
/// @return Reference to the stored value
6298
Type& operator*() noexcept { return value_; }
6399

64-
/// Returns the underlying object.
100+
/// Dereference operator (const) - returns the underlying value.
101+
/// @return Const reference to the stored value
65102
const Type& operator*() const noexcept { return value_; }
66103

67-
/// Returns the underlying object.
104+
/// Function call operator - returns the underlying value.
105+
/// @return Reference to the stored value
68106
Type& operator()() noexcept { return value_; }
69107

70-
/// Returns the underlying object.
108+
/// Function call operator (const) - returns the underlying value.
109+
/// @return Const reference to the stored value
71110
const Type& operator()() const noexcept { return value_; }
72111

73-
/// Assigns the underlying object.
112+
/// Assigns a new value.
113+
/// @param _value The value to assign
114+
/// @return Reference to this Attribute
74115
auto& operator=(const Type& _value) {
75116
value_ = _value;
76117
return *this;
77118
}
78119

79-
/// Assigns the underlying object.
120+
/// Assigns a new value (move version).
121+
/// @param _value The value to assign (will be moved)
122+
/// @return Reference to this Attribute
80123
auto& operator=(Type&& _value) noexcept {
81124
value_ = std::move(_value);
82125
return *this;
83126
}
84127

85-
/// Assigns the underlying object.
128+
/// Assigns from any type convertible to the underlying type.
129+
/// @tparam U Type convertible to T
130+
/// @param _value The value to convert and assign
131+
/// @return Reference to this Attribute
86132
template <class U>
87133
requires std::is_convertible_v<U, Type>
88134
auto& operator=(const U& _value) {
89135
value_ = _value;
90136
return *this;
91137
}
92138

93-
/// Assigns the underlying object to its default value.
139+
/// Assigns the value to its default using the Default sentinel.
140+
/// @tparam U The type (must be default constructible)
141+
/// @param The default sentinel value
142+
/// @return Reference to this Attribute
94143
template <class U = Type>
95144
requires std::is_default_constructible_v<U>
96145
auto& operator=(const Default&) {
97146
value_ = Type();
98147
return *this;
99148
}
100149

101-
/// Assigns the underlying object.
150+
/// Copy assignment operator.
151+
/// @param _attr The Attribute to copy from
152+
/// @return Reference to this Attribute
102153
Attribute<T>& operator=(const Attribute<T>& _attr) = default;
103154

104-
/// Assigns the underlying object.
155+
/// Move assignment operator.
156+
/// @param _attr The Attribute to move from
157+
/// @return Reference to this Attribute
105158
Attribute<T>& operator=(Attribute<T>&& _attr) = default;
106159

107-
/// Assigns the underlying object.
160+
/// Assigns from another Attribute with compatible type (copy).
161+
/// @tparam U Type compatible with T
162+
/// @param _attr The Attribute to copy the value from
163+
/// @return Reference to this Attribute
108164
template <class U>
109165
auto& operator=(const Attribute<U>& _attr) {
110166
value_ = _attr.get();
111167
return *this;
112168
}
113169

114-
/// Assigns the underlying object.
170+
/// Assigns from another Attribute with compatible type (move).
171+
/// @tparam U Type compatible with T
172+
/// @param _attr The Attribute to move the value from
173+
/// @return Reference to this Attribute
115174
template <class U>
116175
auto& operator=(Attribute<U>&& _attr) {
117-
value_ = std::forward<T>(_attr.value_);
176+
value_ = std::move(_attr.value_);
118177
return *this;
119178
}
120179

121-
/// We want all parsers other than the XML parser to treat attributes like
122-
/// normal fields, so we just implement the reflection interface.
180+
/// Returns the underlying value for reflection (used by parsers).
181+
/// Non-XML parsers treat attributes like normal fields.
182+
/// @return Const reference to the stored value
123183
const ReflectionType& reflection() const { return value_; }
124184

125-
/// Assigns the underlying object.
185+
/// Sets the value (copy version).
186+
/// @param _value The value to set
126187
void set(const Type& _value) { value_ = _value; }
127188

128-
/// Assigns the underlying object.
189+
/// Sets the value (move version).
190+
/// @param _value The value to set (will be moved)
129191
void set(Type&& _value) { value_ = std::move(_value); }
130192

131-
/// Returns the underlying object.
193+
/// Returns the underlying value.
194+
/// @return Reference to the stored value
132195
Type& value() noexcept { return value_; }
133196

134-
/// Returns the underlying object.
197+
/// Returns the underlying value (const).
198+
/// @return Const reference to the stored value
135199
const Type& value() const noexcept { return value_; }
136200

137201
/// The underlying value.

0 commit comments

Comments
 (0)