Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/default_val.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ std::string s = p.last_name.value();

API convenience:

- .get(), .value(), operator()() — access the underlying value (const and non-const overloads).
- .get(), .value(), operator()(), operator*() — access the underlying value (const and non-const overloads).
- set(...) — assign underlying value.

## JSON behaviour
Expand Down
3 changes: 3 additions & 0 deletions docs/flatten_structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ This flattens all fields into a single JSON object:
{"firstName":"Homer","lastName":"Simpson","age":45,"salary":60000.0}
```

## API convenience

`rfl::Flatten` behaves like a thin wrapper around the underlying type. You can access the underlying value using `.get()`, `.value()`, `operator()()`, or `operator*()` (const and non-const overloads).
2 changes: 1 addition & 1 deletion docs/generic.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The resulting JSON strings looks as follows:

`rfl::Generic` contains some convenience methods that allow you to handle parsed data:

You can retrieve the underlying `std::variant` using `.get()`. This then allows you to handle allow possible seven cases using the [visitor pattern](https://en.cppreference.com/w/cpp/utility/variant/visit).
You can retrieve the underlying `std::variant` using `.get()`, `.value()`, `operator()()`, or `operator*()`. This then allows you to handle all possible seven cases using the [visitor pattern](https://en.cppreference.com/w/cpp/utility/variant/visit).

If you have a guess what the types of a particular field might be, you can use any of the seven convenience methods `.to_array()`, `.to_bool()`, `.to_double()`, `.to_int()`, `.to_null()`, `.to_object()`, `.to_string()`. Each
of these methods will return an `rfl::Result<...>` with the corresponding type, if the `rfl::Generic` does indeed contain such a type.
Expand Down
2 changes: 2 additions & 0 deletions docs/json_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ const std::string json_schema = rfl::json::to_schema<Person>(rfl::json::pretty);
}
```

`rfl::Description` behaves like a thin wrapper around the underlying type. Much like `rfl::Field`, you can access the underlying value using `.get()`, `.value()`, `operator()()`, or `operator*()` (const and non-const overloads).

You also add a description to the entire JSON schema:

```cpp
Expand Down
4 changes: 4 additions & 0 deletions docs/named_tuple.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ person.apply([](const auto& f) {
auto field_name = f.name();
const auto& value = f.value();
});

### `rfl::Field` API convenience

`rfl::Field` behaves like a thin wrapper around the underlying type. You can access the underlying value using `.get()`, `.value()`, `operator()()`, or `operator*()` (const and non-const overloads).
```

### Monadic operations: `.transform` and `.and_then`
Expand Down
2 changes: 1 addition & 1 deletion docs/number_systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ This results in the following JSON:
Note that the contained type must be integral for `rfl::Hex` and `rfl::Oct`. For `rfl::Binary`, it must be unsigned. Moreover,
the number of digits for `rfl::Binary` will be determined by the bitsize of the type.

You can access the contained value using `.value()`, `.get()` or simply `operator()`.
You can access the contained value using `.value()`, `.get()`, `operator()()`, or `operator*()` (const and non-const overloads).

You can produce the string representation using `.str()`.
1 change: 1 addition & 0 deletions docs/rfl_skip.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ You can access the underlying value in the field `town` using any of the followi
person.town();
person.town.get();
person.town.value();
*person.town;
```

You can assign the underlying field just like any other field:
Expand Down
2 changes: 2 additions & 0 deletions docs/supported_formats/xml.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ This will result in the following XML string:

Note that only boolean values, string values, integral values or floating point values can be represented as attributes.

`rfl::Attribute` behaves like a thin wrapper around the underlying type. Much like `rfl::Field`, you can access the underlying value using `.get()`, `.value()`, `operator()()`, or `operator*()` (const and non-const overloads).

There also is a special field name called `xml_content` to be used when you want a value directly inserted into the content.
Again, only boolean values, string values, integral values or floating point values can be represented this way:

Expand Down
3 changes: 1 addition & 2 deletions docs/timestamps.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const auto person1 = Person{.birthday = "1970-01-01"};
const auto person2 = Person{.birthday = std::tm{...}};
```

You can access the underlying `std::tm` struct using the `.tm()` method and you can generate
the string representation using the `.str()` method.
You can access the underlying `std::tm` struct using the `.tm()`, `.get()`, `.value()`, `operator()()`, or `operator*()` method (const and non-const overloads). You can generate the string representation using the `.str()` method.

```cpp
const std::tm birthday = person1.birthday.tm();
Expand Down
2 changes: 1 addition & 1 deletion docs/validating_numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using IntGreaterThan10 = rfl::Validator<int, rfl::Minimum<10>>;
When you then use the type `IntGreaterThan10` inside you `rfl::Field`, the condition will be automatically
validated.

The underlying value can be retrieved using the `.value()` method.
The underlying value can be retrieved using the `.get()`, `.value()`, `operator()()`, or `operator*()` method (const and non-const overloads).

The current conditions are currently supported by reflect-cpp:

Expand Down
19 changes: 14 additions & 5 deletions include/rfl/Attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,22 @@ struct Attribute {
~Attribute() = default;

/// Returns the underlying object.
const Type& get() const { return value_; }
const Type& get() const noexcept { return value_; }

/// Returns the underlying object.
Type& operator()() { return value_; }
Type& get() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator()() const { return value_; }
Type& operator*() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator*() const noexcept { return value_; }

/// Returns the underlying object.
Type& operator()() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator()() const noexcept { return value_; }

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

/// Returns the underlying object.
Type& value() { return value_; }
Type& value() noexcept { return value_; }

/// Returns the underlying object.
const Type& value() const { return value_; }
const Type& value() const noexcept { return value_; }

/// The underlying value.
Type value_;
Expand Down
19 changes: 14 additions & 5 deletions include/rfl/Binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,22 @@ struct Binary {
~Binary() = default;

/// Returns the underlying object.
const Type& get() const { return value_; }
const Type& get() const noexcept { return value_; }

/// Returns the underlying object.
Type& operator()() { return value_; }
Type& get() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator()() const { return value_; }
Type& operator*() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator*() const noexcept { return value_; }

/// Returns the underlying object.
Type& operator()() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator()() const noexcept { return value_; }

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

/// Returns the underlying object.
Type& value() { return value_; }
Type& value() noexcept { return value_; }

/// Returns the underlying object.
const Type& value() const { return value_; }
const Type& value() const noexcept { return value_; }

/// The underlying value.
Type value_;
Expand Down
19 changes: 14 additions & 5 deletions include/rfl/DefaultVal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,22 @@ struct DefaultVal {
~DefaultVal() = default;

/// Returns the underlying object.
const Type& get() const { return value_; }
const Type& get() const noexcept { return value_; }

/// Returns the underlying object.
Type& operator()() { return value_; }
Type& get() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator()() const { return value_; }
Type& operator*() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator*() const noexcept { return value_; }

/// Returns the underlying object.
Type& operator()() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator()() const noexcept { return value_; }

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

/// Returns the underlying object.
Type& value() { return value_; }
Type& value() noexcept { return value_; }

/// Returns the underlying object.
const Type& value() const { return value_; }
const Type& value() const noexcept { return value_; }

/// The underlying value.
Type value_;
Expand Down
19 changes: 14 additions & 5 deletions include/rfl/Description.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,22 @@ struct Description {
constexpr static const internal::StringLiteral description_ = _description;

/// Returns the underlying object.
const Type& get() const { return value_; }
const Type& get() const noexcept { return value_; }

/// Returns the underlying object.
Type& operator()() { return value_; }
Type& get() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator()() const { return value_; }
Type& operator*() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator*() const noexcept { return value_; }

/// Returns the underlying object.
Type& operator()() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator()() const noexcept { return value_; }

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

/// Returns the underlying object.
Type& value() { return value_; }
Type& value() noexcept { return value_; }

/// Returns the underlying object.
const Type& value() const { return value_; }
const Type& value() const noexcept { return value_; }

/// The underlying value.
Type value_;
Expand Down
19 changes: 14 additions & 5 deletions include/rfl/Field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,25 @@ struct Field {
constexpr static const internal::StringLiteral name_ = _name;

/// Returns the underlying object.
const Type& get() const { return value_; }
const Type& get() const noexcept { return value_; }

/// Returns the underlying object.
Type& get() noexcept { return value_; }

/// Returns the underlying object.
Type& operator*() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator*() const noexcept { return value_; }

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

/// Returns the underlying object.
Type& operator()() { return value_; }
Type& operator()() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator()() const { return value_; }
const Type& operator()() const noexcept { return value_; }

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

/// Returns the underlying object.
Type& value() { return value_; }
Type& value() noexcept { return value_; }

/// Returns the underlying object.
const Type& value() const { return value_; }
const Type& value() const noexcept { return value_; }

/// The underlying value.
Type value_;
Expand Down
20 changes: 16 additions & 4 deletions include/rfl/Flatten.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,28 @@ struct Flatten {
~Flatten() = default;

/// Returns the underlying object.
Type& get() { return value_; }
Type& get() noexcept { return value_; }

/// Returns the underlying object.
const Type& get() const { return value_; }
const Type& get() const noexcept { return value_; }

/// Returns the underlying object.
Type& operator()() { return value_; }
Type& operator*() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator()() const { return value_; }
const Type& operator*() const noexcept { return value_; }

/// Returns the underlying object.
Type& operator()() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator()() const noexcept { return value_; }

/// Returns the underlying object.
Type& value() noexcept { return value_; }

/// Returns the underlying object.
const Type& value() const noexcept { return value_; }

/// Assigns the underlying object.
Flatten& operator=(const T& _value) {
Expand Down
23 changes: 22 additions & 1 deletion include/rfl/Generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,28 @@ class RFL_API Generic {
~Generic();

/// Returns the underlying object.
const VariantType& get() const { return value_; }
const VariantType& get() const noexcept { return value_; }

/// Returns the underlying object.
VariantType& get() noexcept { return value_; }

/// Returns the underlying object.
VariantType& operator*() noexcept { return value_; }

/// Returns the underlying object.
const VariantType& operator*() const noexcept { return value_; }

/// Returns the underlying object.
VariantType& operator()() noexcept { return value_; }

/// Returns the underlying object.
const VariantType& operator()() const noexcept { return value_; }

/// Returns the underlying object.
VariantType& value() noexcept { return value_; }

/// Returns the underlying object.
const VariantType& value() const noexcept { return value_; }

/// Whether the object contains the null value.
bool is_null() const noexcept;
Expand Down
19 changes: 14 additions & 5 deletions include/rfl/Hex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,22 @@ struct Hex {
~Hex() = default;

/// Returns the underlying object.
const Type& get() const { return value_; }
const Type& get() const noexcept { return value_; }

/// Returns the underlying object.
Type& operator()() { return value_; }
Type& get() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator()() const { return value_; }
Type& operator*() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator*() const noexcept { return value_; }

/// Returns the underlying object.
Type& operator()() noexcept { return value_; }

/// Returns the underlying object.
const Type& operator()() const noexcept { return value_; }

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

/// Returns the underlying object.
Type& value() { return value_; }
Type& value() noexcept { return value_; }

/// Returns the underlying object.
const Type& value() const { return value_; }
const Type& value() const noexcept { return value_; }

/// The underlying value.
Type value_;
Expand Down
Loading
Loading