diff --git a/.clang-format b/.clang-format index f265bfb..4c7523b 100644 --- a/.clang-format +++ b/.clang-format @@ -6,7 +6,6 @@ AllowShortBlocksOnASingleLine: Always AllowShortCompoundRequirementOnASingleLine: true AllowShortEnumsOnASingleLine: true AllowShortFunctionsOnASingleLine: true -AllowShortIfStatementsOnASingleLine: WithoutElse AllowShortLoopsOnASingleLine: true BasedOnStyle: Chromium BinPackArguments: false diff --git a/.clang-tidy b/.clang-tidy index f075861..5078384 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -15,7 +15,6 @@ Checks: > -llvm-include-order, -llvmlibc-*, -misc-non-private-member-variables-in-classes, - -modernize-use-trailing-return-type, -readability-braces-around-statements, -readability-implicit-bool-conversion, -readability-isolate-declaration, diff --git a/include/rfl/Box.hpp b/include/rfl/Box.hpp index 02ea43b..f9de560 100644 --- a/include/rfl/Box.hpp +++ b/include/rfl/Box.hpp @@ -25,7 +25,9 @@ namespace rfl { /// You can generate them from unique_ptrs as well, in which case it will /// return an Error, if the unique_ptr is not set. static Result> make(std::unique_ptr&& _ptr) { - if (!_ptr) { return Error("std::unique_ptr was a nullptr."); } + if (!_ptr) { + return Error("std::unique_ptr was a nullptr."); + } return Box(std::move(_ptr)); } diff --git a/include/rfl/Literal.hpp b/include/rfl/Literal.hpp index 8fdfc92..2bc6070 100644 --- a/include/rfl/Literal.hpp +++ b/include/rfl/Literal.hpp @@ -297,7 +297,9 @@ namespace rfl { template static Result find_value(const std::string& _str) { using FieldType = typename std::tuple_element<_i, FieldsType>::type; - if (FieldType::field_.str() == _str) { return _i; } + if (FieldType::field_.str() == _str) { + return _i; + } if constexpr (_i + 1 == num_fields_) { return Error( "Literal does not support string '" + _str + diff --git a/include/rfl/NamedTuple.hpp b/include/rfl/NamedTuple.hpp index 9c35379..bcd1a23 100644 --- a/include/rfl/NamedTuple.hpp +++ b/include/rfl/NamedTuple.hpp @@ -487,13 +487,16 @@ namespace rfl { if constexpr (size == _index) { return make_replaced<_index, V, T>( - std::forward(_values), std::forward(_val), - std::forward(_args)..., FieldType(std::forward(_val)) + std::forward(_values), + std::forward(_val), + std::forward(_args)..., + FieldType(std::forward(_val)) ); } else { using U = typename FieldType::Type; return make_replaced<_index, V, T>( - std::forward(_values), std::forward(_val), + std::forward(_values), + std::forward(_val), std::forward(_args)..., FieldType(std::forward(std::get(_values))) ); diff --git a/include/rfl/OneOf.hpp b/include/rfl/OneOf.hpp index 55aed9f..9969e1e 100644 --- a/include/rfl/OneOf.hpp +++ b/include/rfl/OneOf.hpp @@ -52,7 +52,9 @@ namespace rfl { _r.or_else(push_back); if constexpr (sizeof...(Tail) == 0) { - if (_errors.size() == sizeof...(Cs)) { return _value; } + if (_errors.size() == sizeof...(Cs)) { + return _value; + } return make_error_message(_errors); } else { return validate_impl( diff --git a/include/rfl/Ref.hpp b/include/rfl/Ref.hpp index 343dffb..b94d508 100644 --- a/include/rfl/Ref.hpp +++ b/include/rfl/Ref.hpp @@ -25,14 +25,18 @@ namespace rfl { /// You can generate them from shared_ptrs as well, in which case it will /// return an Error, if the shared_ptr is not set. static Result> make(std::shared_ptr&& _ptr) { - if (!_ptr) { return Error("std::shared_ptr was a nullptr."); } + if (!_ptr) { + return Error("std::shared_ptr was a nullptr."); + } return Ref(std::move(_ptr)); } /// You can generate them from shared_ptrs as well, in which case it will /// return an Error, if the shared_ptr is not set. static Result> make(const std::shared_ptr& _ptr) { - if (!_ptr) { return Error("std::shared_ptr was a nullptr."); } + if (!_ptr) { + return Error("std::shared_ptr was a nullptr."); + } return Ref(_ptr); } diff --git a/include/rfl/Result.hpp b/include/rfl/Result.hpp index 625d511..980ac4e 100644 --- a/include/rfl/Result.hpp +++ b/include/rfl/Result.hpp @@ -188,7 +188,9 @@ namespace rfl { /// Assigns the underlying object. Result& operator=(const Result& _other) { - if (this == &_other) { return *this; } + if (this == &_other) { + return *this; + } destroy(); success_ = _other.success_; copy_from_other(_other); @@ -197,7 +199,9 @@ namespace rfl { /// Assigns the underlying object. Result& operator=(Result&& _other) noexcept { - if (this == &_other) { return *this; } + if (this == &_other) { + return *this; + } destroy(); success_ = _other.success_; move_from_other(_other); diff --git a/include/rfl/Timestamp.hpp b/include/rfl/Timestamp.hpp index 0d94bad..fba028f 100644 --- a/include/rfl/Timestamp.hpp +++ b/include/rfl/Timestamp.hpp @@ -78,7 +78,9 @@ namespace rfl { std::istringstream input(_s); input.imbue(std::locale(setlocale(LC_ALL, nullptr))); input >> std::get_time(_tm, _f); - if (input.fail()) { return NULL; } + if (input.fail()) { + return NULL; + } return (char*)(_s + input.tellg()); } #endif diff --git a/include/rfl/bson/Reader.hpp b/include/rfl/bson/Reader.hpp index 2521305..3eebbb4 100644 --- a/include/rfl/bson/Reader.hpp +++ b/include/rfl/bson/Reader.hpp @@ -60,7 +60,9 @@ namespace rfl { if (bson_iter_init(&iter, &b)) { while (bson_iter_next(&iter)) { auto key = std::string(bson_iter_key(&iter)); - if (key == _name) { return to_input_var(&iter); } + if (key == _name) { + return to_input_var(&iter); + } } } } @@ -146,7 +148,9 @@ namespace rfl { if (bson_iter_init(&iter, &b)) { while (bson_iter_next(&iter)) { const auto err = _array_reader.read(to_input_var(&iter)); - if (err) { return err; } + if (err) { + return err; + } } } } diff --git a/include/rfl/bson/Writer.hpp b/include/rfl/bson/Writer.hpp index d3310d1..f516879 100644 --- a/include/rfl/bson/Writer.hpp +++ b/include/rfl/bson/Writer.hpp @@ -127,7 +127,9 @@ namespace rfl { ) const noexcept { subdocs_->emplace_back(rfl::Box()); bson_append_document_begin( - _parent->val_, _name.data(), static_cast(_name.size()), + _parent->val_, + _name.data(), + static_cast(_name.size()), &(subdocs_->back()->val_) ); return OutputObjectType( @@ -169,8 +171,11 @@ namespace rfl { ) const noexcept { if constexpr (std::is_same, std::string>()) { bson_append_utf8( - _parent->val_, _name.data(), static_cast(_name.size()), - _var.c_str(), static_cast(_var.size()) + _parent->val_, + _name.data(), + static_cast(_name.size()), + _var.c_str(), + static_cast(_var.size()) ); } else if constexpr (std::is_same, bool>()) { bson_append_bool( @@ -178,12 +183,16 @@ namespace rfl { ); } else if constexpr (std::is_floating_point>()) { bson_append_double( - _parent->val_, _name.data(), static_cast(_name.size()), + _parent->val_, + _name.data(), + static_cast(_name.size()), static_cast(_var) ); } else if constexpr (std::is_integral>()) { bson_append_int64( - _parent->val_, _name.data(), static_cast(_name.size()), + _parent->val_, + _name.data(), + static_cast(_name.size()), static_cast(_var) ); } else if constexpr (std::is_same, bson_oid_t>( diff --git a/include/rfl/cbor/Reader.hpp b/include/rfl/cbor/Reader.hpp index b6ac62b..2ce6b84 100644 --- a/include/rfl/cbor/Reader.hpp +++ b/include/rfl/cbor/Reader.hpp @@ -52,21 +52,33 @@ namespace rfl { CborValue val; auto buffer = std::vector(); auto err = cbor_value_enter_container(_obj.val_, &val); - if (err != CborNoError) { return Error(cbor_error_string(err)); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } size_t length = 0; err = cbor_value_get_map_length(_obj.val_, &length); - if (err != CborNoError) { return Error(cbor_error_string(err)); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } for (size_t i = 0; i < length; ++i) { if (!cbor_value_is_text_string(&val)) { return Error("Expected the key to be a string value."); } err = get_string(&val, &buffer); - if (err != CborNoError) { return Error(cbor_error_string(err)); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } err = cbor_value_advance(&val); - if (err != CborNoError) { return Error(cbor_error_string(err)); } - if (_name == buffer.data()) { return to_input_var(&val); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } + if (_name == buffer.data()) { + return to_input_var(&val); + } err = cbor_value_advance(&val); - if (err != CborNoError) { return Error(cbor_error_string(err)); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } } return Error("No field named '" + _name + "' was found."); } @@ -83,7 +95,9 @@ namespace rfl { } std::vector buffer; const auto err = get_string(_var.val_, &buffer); - if (err != CborNoError) { return Error(cbor_error_string(err)); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } return std::string(buffer.data()); } else if constexpr (std::is_same, bool>()) { if (!cbor_value_is_boolean(_var.val_)) { @@ -91,24 +105,32 @@ namespace rfl { } bool result = false; const auto err = cbor_value_get_boolean(_var.val_, &result); - if (err != CborNoError) { return Error(cbor_error_string(err)); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } return result; } else if constexpr (std::is_floating_point>() || std::is_integral>()) { if (cbor_value_is_integer(_var.val_)) { std::int64_t result = 0; const auto err = cbor_value_get_int64(_var.val_, &result); - if (err != CborNoError) { return Error(cbor_error_string(err)); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } return static_cast(result); } else if (cbor_value_is_float(_var.val_)) { float result = 0.0; const auto err = cbor_value_get_float(_var.val_, &result); - if (err != CborNoError) { return Error(cbor_error_string(err)); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } return static_cast(result); } else if (cbor_value_is_double(_var.val_)) { double result = 0.0; const auto err = cbor_value_get_double(_var.val_, &result); - if (err != CborNoError) { return Error(cbor_error_string(err)); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } return static_cast(result); } return rfl::Error( @@ -156,7 +178,9 @@ namespace rfl { } for (size_t i = 0; i < length; ++i) { const auto err2 = _array_reader.read(to_input_var(&val)); - if (err2) { return err2; } + if (err2) { + return err2; + } err = cbor_value_advance(&val); if (err != CborNoError && err != CborErrorOutOfMemory) { return Error(cbor_error_string(err)); @@ -172,19 +196,27 @@ namespace rfl { ) const noexcept { size_t length = 0; auto err = cbor_value_get_map_length(_obj.val_, &length); - if (err != CborNoError) { return Error(cbor_error_string(err)); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } CborValue val; err = cbor_value_enter_container(_obj.val_, &val); - if (err != CborNoError) { return Error(cbor_error_string(err)); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } auto buffer = std::vector(); for (size_t i = 0; i < length; ++i) { err = get_string(&val, &buffer); - if (err != CborNoError) { return Error(cbor_error_string(err)); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } err = cbor_value_advance(&val); - if (err != CborNoError) { return Error(cbor_error_string(err)); } + if (err != CborNoError) { + return Error(cbor_error_string(err)); + } const auto name = std::string_view(buffer.data(), buffer.size() - 1); _object_reader.read(name, InputVarType {&val}); cbor_value_advance(&val); @@ -206,7 +238,9 @@ namespace rfl { const noexcept { size_t length = 0; auto err = cbor_value_get_string_length(_ptr, &length); - if (err != CborNoError && err != CborErrorOutOfMemory) { return err; } + if (err != CborNoError && err != CborErrorOutOfMemory) { + return err; + } _buffer->resize(length + 1); (*_buffer)[length] = '\0'; return cbor_value_copy_text_string( diff --git a/include/rfl/cbor/write.hpp b/include/rfl/cbor/write.hpp index d776332..23720fe 100644 --- a/include/rfl/cbor/write.hpp +++ b/include/rfl/cbor/write.hpp @@ -23,8 +23,10 @@ namespace rfl { using T = std::remove_cvref_t; using ParentType = parsing::Parent; cbor_encoder_init( - _encoder, reinterpret_cast(_buffer->data()), - _buffer->size(), 0 + _encoder, + reinterpret_cast(_buffer->data()), + _buffer->size(), + 0 ); const auto writer = Writer(_encoder); Parser>::write( diff --git a/include/rfl/enums.hpp b/include/rfl/enums.hpp index 0b9b0ce..4abdbd6 100644 --- a/include/rfl/enums.hpp +++ b/include/rfl/enums.hpp @@ -29,8 +29,8 @@ namespace rfl { // to their values. template auto get_enumerators() { - constexpr auto names = internal::enums::get_enum_names< - EnumType, internal::enums::is_flag_enum>(); + constexpr auto names = internal::enums:: + get_enum_names>(); return internal::enums::names_to_enumerator_named_tuple(names); } @@ -38,8 +38,8 @@ namespace rfl { // to their underlying values. template auto get_underlying_enumerators() { - constexpr auto names = internal::enums::get_enum_names< - EnumType, internal::enums::is_flag_enum>(); + constexpr auto names = internal::enums:: + get_enum_names>(); return internal::enums::names_to_underlying_enumerator_named_tuple(names); } @@ -47,8 +47,8 @@ namespace rfl { // std::string_view) and values. template constexpr auto get_enumerator_array() { - constexpr auto names = internal::enums::get_enum_names< - EnumType, internal::enums::is_flag_enum>(); + constexpr auto names = internal::enums:: + get_enum_names>(); return internal::enums::names_to_enumerator_array(names); } @@ -56,8 +56,8 @@ namespace rfl { // std::string_view) and underlying values. template constexpr auto get_underlying_enumerator_array() { - constexpr auto names = internal::enums::get_enum_names< - EnumType, internal::enums::is_flag_enum>(); + constexpr auto names = internal::enums:: + get_enum_names>(); return internal::enums::names_to_underlying_enumerator_array(names); } diff --git a/include/rfl/flexbuf/Reader.hpp b/include/rfl/flexbuf/Reader.hpp index 5b095b7..b9faa17 100644 --- a/include/rfl/flexbuf/Reader.hpp +++ b/include/rfl/flexbuf/Reader.hpp @@ -49,7 +49,9 @@ namespace rfl { ) const noexcept { const auto keys = _obj.Keys(); for (size_t i = 0; i < keys.size(); ++i) { - if (_name == keys[i].AsString().c_str()) { return _obj.Values()[i]; } + if (_name == keys[i].AsString().c_str()) { + return _obj.Values()[i]; + } } return rfl::Error( "Map does not contain any element called '" + _name + "'." @@ -95,7 +97,9 @@ namespace rfl { const auto size = _arr.size(); for (size_t i = 0; i < size; ++i) { const auto err = _array_reader.read(InputVarType(_arr[i])); - if (err) { return err; } + if (err) { + return err; + } } return std::nullopt; } @@ -128,7 +132,9 @@ namespace rfl { rfl::Result to_object(const InputVarType& _var ) const noexcept { - if (!_var.IsMap()) { return rfl::Error("Could not cast to Map!"); } + if (!_var.IsMap()) { + return rfl::Error("Could not cast to Map!"); + } return _var.AsMap(); } diff --git a/include/rfl/from_named_tuple.hpp b/include/rfl/from_named_tuple.hpp index 95b7961..cba1e60 100644 --- a/include/rfl/from_named_tuple.hpp +++ b/include/rfl/from_named_tuple.hpp @@ -17,7 +17,8 @@ namespace rfl { auto from_named_tuple(NamedTupleType&& _n) { using RequiredType = std::remove_cvref_t>; if constexpr (!std::is_same< - std::remove_cvref_t, RequiredType>()) { + std::remove_cvref_t, + RequiredType>()) { return from_named_tuple(RequiredType(std::forward(_n)) ); } else if constexpr (internal::has_fields()) { @@ -40,7 +41,8 @@ namespace rfl { auto from_named_tuple(const NamedTupleType& _n) { using RequiredType = std::remove_cvref_t>; if constexpr (!std::is_same< - std::remove_cvref_t, RequiredType>()) { + std::remove_cvref_t, + RequiredType>()) { return from_named_tuple(RequiredType(_n)); } else if constexpr (internal::has_fields()) { return internal::copy_from_named_tuple(_n); diff --git a/include/rfl/internal/Getter.hpp b/include/rfl/internal/Getter.hpp index d3eeb8f..fdfff5a 100644 --- a/include/rfl/internal/Getter.hpp +++ b/include/rfl/internal/Getter.hpp @@ -42,7 +42,8 @@ namespace rfl::internal { static_assert( std::is_same< typename std::tuple_element< - index, typename NamedTupleType::Fields>::type::Type, + index, + typename NamedTupleType::Fields>::type::Type, typename Field::Type>(), "If two fields have the same name, " "their type must be the same as " @@ -73,7 +74,8 @@ namespace rfl::internal { static_assert( std::is_same< typename std::tuple_element< - index, typename NamedTupleType::Fields>::type::Type, + index, + typename NamedTupleType::Fields>::type::Type, typename Field::Type>(), "If two fields have the same name, " "their type must be the same as " diff --git a/include/rfl/internal/StringLiteral.hpp b/include/rfl/internal/StringLiteral.hpp index 6e29363..801b235 100644 --- a/include/rfl/internal/StringLiteral.hpp +++ b/include/rfl/internal/StringLiteral.hpp @@ -38,7 +38,9 @@ namespace rfl { const StringLiteral& _first, const StringLiteral& _second ) { - if constexpr (N1 != N2) { return false; } + if constexpr (N1 != N2) { + return false; + } return _first.string_view() == _second.string_view(); } diff --git a/include/rfl/internal/enums/get_enum_names.hpp b/include/rfl/internal/enums/get_enum_names.hpp index 6d8db6b..d1f0585 100644 --- a/include/rfl/internal/enums/get_enum_names.hpp +++ b/include/rfl/internal/enums/get_enum_names.hpp @@ -124,17 +124,26 @@ namespace rfl { return NamesType {}; } else { return get_enum_names_impl< - EnumType, NamesType, _max, _is_flag, _i + 1>(); + EnumType, + NamesType, + _max, + _is_flag, + _i + 1>(); } } else { using NewNames = typename NamesType::template AddOneType< - Literal()>, static_cast(j)>; + Literal()>, + static_cast(j)>; if constexpr (j == _max) { return NewNames {}; } else { return get_enum_names_impl< - EnumType, NewNames, _max, _is_flag, _i + 1>(); + EnumType, + NewNames, + _max, + _is_flag, + _i + 1>(); } } } diff --git a/include/rfl/internal/get_field_names.hpp b/include/rfl/internal/get_field_names.hpp index a911bca..bb73421 100644 --- a/include/rfl/internal/get_field_names.hpp +++ b/include/rfl/internal/get_field_names.hpp @@ -139,7 +139,8 @@ namespace rfl::internal { const auto get = [](std::index_sequence) { return concat_literals( get_field_name< - Type, wrap(std::get(bind_fake_object_to_tuple()))>()... + Type, + wrap(std::get(bind_fake_object_to_tuple()))>()... ); }; #else diff --git a/include/rfl/internal/get_type_name.hpp b/include/rfl/internal/get_type_name.hpp index e5ba355..7af0363 100644 --- a/include/rfl/internal/get_type_name.hpp +++ b/include/rfl/internal/get_type_name.hpp @@ -29,7 +29,9 @@ namespace rfl { auto split = func_name.substr(0, func_name.size() - 7); split = split.substr(split.find("get_type_name_str_view<") + 23); auto pos = split.find(" "); - if (pos != std::string_view::npos) { return split.substr(pos + 1); } + if (pos != std::string_view::npos) { + return split.substr(pos + 1); + } return split; #else static_assert( diff --git a/include/rfl/internal/move_and_flatten_field_tuple.hpp b/include/rfl/internal/move_and_flatten_field_tuple.hpp index cff7701..dd8d8db 100644 --- a/include/rfl/internal/move_and_flatten_field_tuple.hpp +++ b/include/rfl/internal/move_and_flatten_field_tuple.hpp @@ -18,14 +18,16 @@ namespace rfl { using T = std::tuple_element_t>; if constexpr (is_flatten_field::value) { return move_and_flatten_field_tuple( - std::move(_t), std::move(_args)..., + std::move(_t), + std::move(_args)..., move_and_flatten_field_tuple( move_to_field_tuple(std::move(std::get(_t).value_)) ) ); } else { return move_and_flatten_field_tuple( - std::move(_t), std::move(_args)..., + std::move(_t), + std::move(_args)..., std::make_tuple(std::move(std::get(_t))) ); } diff --git a/include/rfl/internal/move_from_named_tuple.hpp b/include/rfl/internal/move_from_named_tuple.hpp index 9892784..079e6e0 100644 --- a/include/rfl/internal/move_from_named_tuple.hpp +++ b/include/rfl/internal/move_from_named_tuple.hpp @@ -29,8 +29,8 @@ namespace rfl { std::remove_cvref_t>; if constexpr (is_named_tuple_v) { - using SubPtrNamedTupleType = typename std::invoke_result< - decltype(nt_to_ptr_named_tuple), T>::type; + using SubPtrNamedTupleType = typename std:: + invoke_result), T>::type; return make_ptr_fields( _n, _args..., SubPtrNamedTupleType(_n).fields() @@ -63,7 +63,8 @@ namespace rfl { if constexpr (is_field_v) { return move_from_ptr_fields( - _ptrs, std::move(_args)..., + _ptrs, + std::move(_args)..., rfl::make_field( std::move(*std::get(_ptrs).value()) ) @@ -76,7 +77,8 @@ namespace rfl { typename std::tuple_element_t::Type>>; return move_from_ptr_fields( - _ptrs, std::move(_args)..., + _ptrs, + std::move(_args)..., move_from_ptr_fields(std::get(_ptrs)) ); } diff --git a/include/rfl/internal/move_from_tuple.hpp b/include/rfl/internal/move_from_tuple.hpp index fda9139..43a4c3f 100644 --- a/include/rfl/internal/move_from_tuple.hpp +++ b/include/rfl/internal/move_from_tuple.hpp @@ -54,8 +54,11 @@ namespace rfl { calc_flattened_size(); return unflatten_ptr_tuple< - TargetTupleType, PtrTupleType, _j + flattened_size>( - _t, _args..., + TargetTupleType, + PtrTupleType, + _j + flattened_size>( + _t, + _args..., unflatten_ptr_tuple(_t) ); @@ -88,7 +91,8 @@ namespace rfl { typename std::tuple_element_t>::Type>; return move_from_pointers( - _ptrs, std::move(_args)..., + _ptrs, + std::move(_args)..., move_from_pointers(std::get(_ptrs)) ); } diff --git a/include/rfl/internal/nt_to_ptr_named_tuple.hpp b/include/rfl/internal/nt_to_ptr_named_tuple.hpp index 30a802e..2b8f739 100644 --- a/include/rfl/internal/nt_to_ptr_named_tuple.hpp +++ b/include/rfl/internal/nt_to_ptr_named_tuple.hpp @@ -45,7 +45,8 @@ namespace rfl { using FieldType = typename std::tuple_element::type; using T = std::remove_cvref_t; return nt_to_ptr_named_tuple( - _nt, _a..., + _nt, + _a..., Field(&std::get(_nt.values())) ); } diff --git a/include/rfl/internal/num_fields.hpp b/include/rfl/internal/num_fields.hpp index 1139ad3..7906ca0 100644 --- a/include/rfl/internal/num_fields.hpp +++ b/include/rfl/internal/num_fields.hpp @@ -83,11 +83,13 @@ namespace rfl { template static consteval bool constructible_with_nested() { return - [](std::index_sequence, std::index_sequence, std::index_sequence) { return requires { T {any(i)..., {any(j)...}, any(k)...}; }; - }(std::make_index_sequence(), std::make_index_sequence(), + }(std::make_index_sequence(), + std::make_index_sequence(), std::make_index_sequence()); } @@ -122,7 +124,8 @@ namespace rfl { std:: size_t... r>(std::index_sequence, std::index_sequence) { return requires { - T {any_empty_base(l)..., any_base(0), + T {any_empty_base(l)..., + any_base(0), any_empty_base(r)...}; }; }; diff --git a/include/rfl/internal/remove_namespaces.hpp b/include/rfl/internal/remove_namespaces.hpp index 77230c0..ceb47a8 100644 --- a/include/rfl/internal/remove_namespaces.hpp +++ b/include/rfl/internal/remove_namespaces.hpp @@ -14,7 +14,9 @@ namespace rfl { consteval auto remove_namespaces() { constexpr auto name = _name.string_view(); constexpr size_t pos = name.find_last_of(":"); - if constexpr (pos == std::string_view::npos) { return _name; } + if constexpr (pos == std::string_view::npos) { + return _name; + } constexpr auto substr = name.substr(pos + 1); const auto to_str_lit = [&](std::index_sequence) { return StringLiteral {substr[Ns]...}; diff --git a/include/rfl/internal/strings/join.hpp b/include/rfl/internal/strings/join.hpp index 152d6da..cc6914a 100644 --- a/include/rfl/internal/strings/join.hpp +++ b/include/rfl/internal/strings/join.hpp @@ -13,7 +13,9 @@ namespace rfl { const std::string& _delimiter, const std::vector& _strings ) { - if (_strings.size() == 0) { return ""; } + if (_strings.size() == 0) { + return ""; + } auto res = _strings[0]; for (size_t i = 1; i < _strings.size(); ++i) { res += _delimiter + _strings[i]; diff --git a/include/rfl/internal/to_flattened_ptr_tuple.hpp b/include/rfl/internal/to_flattened_ptr_tuple.hpp index 33dd478..2eb3be3 100644 --- a/include/rfl/internal/to_flattened_ptr_tuple.hpp +++ b/include/rfl/internal/to_flattened_ptr_tuple.hpp @@ -22,12 +22,14 @@ namespace rfl { using T = std::tuple_element_t>; if constexpr (is_flatten_field_v) { return flatten_ptr_tuple( - std::forward(_t), std::forward(_args)..., + std::forward(_t), + std::forward(_args)..., flatten_ptr_tuple(to_ptr_tuple(std::get(_t)->get())) ); } else { return flatten_ptr_tuple( - std::forward(_t), std::forward(_args)..., + std::forward(_t), + std::forward(_args)..., std::make_tuple(std::get(_t)) ); } diff --git a/include/rfl/internal/to_ptr_named_tuple.hpp b/include/rfl/internal/to_ptr_named_tuple.hpp index 0318a69..e35274d 100644 --- a/include/rfl/internal/to_ptr_named_tuple.hpp +++ b/include/rfl/internal/to_ptr_named_tuple.hpp @@ -30,7 +30,8 @@ namespace rfl { if constexpr (internal::is_flatten_field::value) { auto subtuple = internal::to_ptr_field_tuple(*std::get(_t).get()); return flatten_ptr_field_tuple( - _t, std::forward(_args)..., + _t, + std::forward(_args)..., flatten_ptr_field_tuple(subtuple) ); } else { diff --git a/include/rfl/internal/transform_snake_case.hpp b/include/rfl/internal/transform_snake_case.hpp index 74c6808..1c7bb12 100644 --- a/include/rfl/internal/transform_snake_case.hpp +++ b/include/rfl/internal/transform_snake_case.hpp @@ -30,10 +30,18 @@ namespace rfl::internal { return transform_snake_case<_name, false, _name.arr_.size(), chars...>(); } else if constexpr (_capitalize) { return transform_snake_case< - _name, false, _i + 1, chars..., to_upper<_name.arr_[_i]>()>(); + _name, + false, + _i + 1, + chars..., + to_upper<_name.arr_[_i]>()>(); } else { return transform_snake_case< - _name, false, _i + 1, chars..., _name.arr_[_i]>(); + _name, + false, + _i + 1, + chars..., + _name.arr_[_i]>(); } } } // namespace rfl::internal diff --git a/include/rfl/json/Reader.hpp b/include/rfl/json/Reader.hpp index 2c6bc7c..5295c14 100644 --- a/include/rfl/json/Reader.hpp +++ b/include/rfl/json/Reader.hpp @@ -71,7 +71,9 @@ namespace rfl { yyjson_arr_iter_init(_arr.val_, &iter); while ((val = yyjson_arr_iter_next(&iter))) { const auto err = _array_reader.read(InputVarType(val)); - if (err) { return err; } + if (err) { + return err; + } } return std::nullopt; } @@ -95,7 +97,9 @@ namespace rfl { rfl::Result to_basic_type(const InputVarType _var) const noexcept { if constexpr (std::is_same, std::string>()) { const auto r = yyjson_get_str(_var.val_); - if (r == NULL) { return rfl::Error("Could not cast to string."); } + if (r == NULL) { + return rfl::Error("Could not cast to string."); + } return std::string(r); } else if constexpr (std::is_same, bool>()) { if (!yyjson_is_bool(_var.val_)) { diff --git a/include/rfl/json/read.hpp b/include/rfl/json/read.hpp index 4829cd4..0cbb1a0 100644 --- a/include/rfl/json/read.hpp +++ b/include/rfl/json/read.hpp @@ -28,7 +28,9 @@ namespace rfl { Result> read(const std::string& _json_str ) { yyjson_doc* doc = yyjson_read(_json_str.c_str(), _json_str.size(), 0); - if (!doc) { return Error("Could not parse document"); } + if (!doc) { + return Error("Could not parse document"); + } yyjson_val* root = yyjson_doc_get_root(doc); const auto r = Reader(); auto res = Parser>::read(r, InputVarType(root)); diff --git a/include/rfl/json/to_schema.hpp b/include/rfl/json/to_schema.hpp index 7759ce2..46a692f 100644 --- a/include/rfl/json/to_schema.hpp +++ b/include/rfl/json/to_schema.hpp @@ -225,7 +225,9 @@ namespace rfl::json { auto required = std::vector(); for (const auto& [k, v] : _t.types_) { properties[k] = type_to_json_schema_type(v); - if (!is_optional(v)) { required.push_back(k); } + if (!is_optional(v)) { + required.push_back(k); + } } return schema::Type { .value = diff --git a/include/rfl/msgpack/Reader.hpp b/include/rfl/msgpack/Reader.hpp index 4446adb..65615e9 100644 --- a/include/rfl/msgpack/Reader.hpp +++ b/include/rfl/msgpack/Reader.hpp @@ -45,7 +45,9 @@ namespace rfl { } const auto current_name = std::string_view(key.via.str.ptr, key.via.str.size); - if (_name == current_name) { return _obj.ptr[i].val; } + if (_name == current_name) { + return _obj.ptr[i].val; + } } return Error("No field named '" + _name + "' was found."); } @@ -111,7 +113,9 @@ namespace rfl { ) const noexcept { for (uint32_t i = 0; i < _arr.size; ++i) { const auto err = _array_reader.read(_arr.ptr[i]); - if (err) { return err; } + if (err) { + return err; + } } return std::nullopt; } diff --git a/include/rfl/parsing/FieldVariantParser.hpp b/include/rfl/parsing/FieldVariantParser.hpp index e3c165b..bc91a2f 100644 --- a/include/rfl/parsing/FieldVariantParser.hpp +++ b/include/rfl/parsing/FieldVariantParser.hpp @@ -45,7 +45,9 @@ namespace rfl { &_r, &field_variant ); auto err = _r.read_object(reader, _obj); - if (err) { return *err; } + if (err) { + return *err; + } if (!field_variant) { return Error( "Could not parse: Expected the object to have " diff --git a/include/rfl/parsing/MapParser.hpp b/include/rfl/parsing/MapParser.hpp index a2aee25..64cdf4f 100644 --- a/include/rfl/parsing/MapParser.hpp +++ b/include/rfl/parsing/MapParser.hpp @@ -97,8 +97,12 @@ namespace rfl { const auto map_reader = MapReader(&_r, &map, &errors); const auto err = _r.read_object(map_reader, _obj); - if (err) { return *err; } - if (errors.size() != 0) { return to_single_error_message(errors); } + if (err) { + return *err; + } + if (errors.size() != 0) { + return to_single_error_message(errors); + } return map; } }; diff --git a/include/rfl/parsing/NamedTupleParser.hpp b/include/rfl/parsing/NamedTupleParser.hpp index 3d1d4be..a1778ec 100644 --- a/include/rfl/parsing/NamedTupleParser.hpp +++ b/include/rfl/parsing/NamedTupleParser.hpp @@ -65,7 +65,9 @@ namespace rfl { using ViewType = std::remove_cvref_t; const auto err = Parser::read_view(_r, _var, &view); - if (err) [[unlikely]] { return *err; } + if (err) [[unlikely]] { + return *err; + } return *ptr; } @@ -76,7 +78,9 @@ namespace rfl { NamedTuple* _view ) noexcept { auto obj = _r.to_object(_var); - if (!obj) [[unlikely]] { return obj.error(); } + if (!obj) [[unlikely]] { + return obj.error(); + } return read_object(_r, *obj, _view); } @@ -106,8 +110,8 @@ namespace rfl { if constexpr (_i == size) { return Type {Type::Object {_values}}; } else { - using F = std::tuple_element_t< - _i, typename NamedTuple::Fields>; + using F = std:: + tuple_element_t<_i, typename NamedTuple::Fields>; using U = typename F::Type; if constexpr (!internal::is_skip_v) { _values[std::string(F::name())] = @@ -217,9 +221,14 @@ namespace rfl { &_r, _view, &found, &set, &errors ); const auto err = _r.read_object(object_reader, _obj); - if (err) { return *err; } + if (err) { + return *err; + } handle_missing_fields( - found, *_view, &set, &errors, + found, + *_view, + &set, + &errors, std::make_integer_sequence() ); if (errors.size() != 0) { diff --git a/include/rfl/parsing/Parser_default.hpp b/include/rfl/parsing/Parser_default.hpp index 5658b61..cac139d 100644 --- a/include/rfl/parsing/Parser_default.hpp +++ b/include/rfl/parsing/Parser_default.hpp @@ -165,7 +165,8 @@ namespace rfl { .description_ = typename U::Content().str(), .type_ = Ref::make(Parser< - R, W, std::remove_cvref_t, + R, W, + std::remove_cvref_t, ProcessorsType>::to_schema(_definitions)) } }; @@ -244,7 +245,9 @@ namespace rfl { using ViewType = std::remove_cvref_t; const auto err = Parser::read_view(_r, _var, &view); - if (err) [[unlikely]] { return *err; } + if (err) [[unlikely]] { + return *err; + } return std::move(*ptr); } diff --git a/include/rfl/parsing/Parser_optional.hpp b/include/rfl/parsing/Parser_optional.hpp index 385084e..be627e3 100644 --- a/include/rfl/parsing/Parser_optional.hpp +++ b/include/rfl/parsing/Parser_optional.hpp @@ -25,7 +25,9 @@ namespace rfl { static Result> read(const R& _r, const InputVarType& _var) noexcept { - if (_r.is_empty(_var)) { return std::optional(); } + if (_r.is_empty(_var)) { + return std::optional(); + } const auto to_opt = [](auto&& _t) { return std::make_optional(_t); }; return Parser, ProcessorsType>::read( _r, _var diff --git a/include/rfl/parsing/Parser_pair.hpp b/include/rfl/parsing/Parser_pair.hpp index 1aa3e03..99039de 100644 --- a/include/rfl/parsing/Parser_pair.hpp +++ b/include/rfl/parsing/Parser_pair.hpp @@ -46,7 +46,9 @@ namespace rfl { ) noexcept { const auto tup = std::make_tuple(&_p.first, &_p.second); Parser< - R, W, std::tuple, + R, + W, + std::tuple, ProcessorsType>::write(_w, tup, _parent); } diff --git a/include/rfl/parsing/Parser_shared_ptr.hpp b/include/rfl/parsing/Parser_shared_ptr.hpp index 1755820..010b1d6 100644 --- a/include/rfl/parsing/Parser_shared_ptr.hpp +++ b/include/rfl/parsing/Parser_shared_ptr.hpp @@ -24,7 +24,9 @@ namespace rfl::parsing { static Result> read(const R& _r, const InputVarType& _var) noexcept { - if (_r.is_empty(_var)) { return std::shared_ptr(); } + if (_r.is_empty(_var)) { + return std::shared_ptr(); + } const auto to_ptr = [](auto&& _t) { return std::make_shared(std::move(_t)); }; diff --git a/include/rfl/parsing/Parser_skip.hpp b/include/rfl/parsing/Parser_skip.hpp index 763460c..88ec4ad 100644 --- a/include/rfl/parsing/Parser_skip.hpp +++ b/include/rfl/parsing/Parser_skip.hpp @@ -41,8 +41,9 @@ namespace rfl { ); } else { const auto to_skip = [&](auto&& _t) { - return internal::Skip< - T, _skip_serialization, _skip_deserialization>(std::move(_t)); + return internal:: + Skip(std::move(_t + )); }; return Parser, ProcessorsType>::read( _r, _var @@ -60,7 +61,9 @@ namespace rfl { ) noexcept { if constexpr (_skip_serialization) { using ReflectionType = std::remove_cvref_t::ReflectionType>; + T, + _skip_serialization, + _skip_deserialization>::ReflectionType>; Parser::write( _w, ReflectionType(), _parent ); diff --git a/include/rfl/parsing/Parser_tagged_union.hpp b/include/rfl/parsing/Parser_tagged_union.hpp index f179fbd..c1155d3 100644 --- a/include/rfl/parsing/Parser_tagged_union.hpp +++ b/include/rfl/parsing/Parser_tagged_union.hpp @@ -82,8 +82,8 @@ namespace rfl { const InputVarType& _var ) noexcept { if constexpr (_i == sizeof...(AlternativeTypes)) { - const auto names = TaggedUnion< - _discriminator, AlternativeTypes...>::PossibleTags::names(); + const auto names = TaggedUnion<_discriminator, AlternativeTypes...>:: + PossibleTags::names(); return Error( "Could not parse tagged union, could not match " + _discriminator.str() + " '" + _disc_value + @@ -91,9 +91,9 @@ namespace rfl { internal::strings::join(",", names) ); } else { - using AlternativeType = - std::remove_cvref_t>>; + using AlternativeType = std::remove_cvref_t< + std:: + variant_alternative_t<_i, std::variant>>; if (contains_disc_value(_disc_value)) { const auto to_tagged_union = [](auto&& _val) { diff --git a/include/rfl/parsing/Parser_unique_ptr.hpp b/include/rfl/parsing/Parser_unique_ptr.hpp index bec5fae..dd66633 100644 --- a/include/rfl/parsing/Parser_unique_ptr.hpp +++ b/include/rfl/parsing/Parser_unique_ptr.hpp @@ -25,7 +25,9 @@ namespace rfl { static Result> read(const R& _r, const InputVarType& _var) noexcept { - if (_r.is_empty(_var)) { return std::unique_ptr(); } + if (_r.is_empty(_var)) { + return std::unique_ptr(); + } const auto to_ptr = [](auto&& _t) { return std::make_unique(std::move(_t)); }; diff --git a/include/rfl/parsing/Parser_variant.hpp b/include/rfl/parsing/Parser_variant.hpp index 0f811b9..418633a 100644 --- a/include/rfl/parsing/Parser_variant.hpp +++ b/include/rfl/parsing/Parser_variant.hpp @@ -73,8 +73,8 @@ namespace rfl { std::vector _types = {} ) { if constexpr (internal::all_fields>()) { - return FieldVariantParser< - R, W, ProcessorsType, FieldTypes...>::to_schema(_definitions); + return FieldVariantParser:: + to_schema(_definitions); } else { using Type = schema::Type; constexpr size_t size = sizeof...(FieldTypes); diff --git a/include/rfl/parsing/Parser_wstring.hpp b/include/rfl/parsing/Parser_wstring.hpp index 96d0186..475e42b 100644 --- a/include/rfl/parsing/Parser_wstring.hpp +++ b/include/rfl/parsing/Parser_wstring.hpp @@ -24,7 +24,9 @@ namespace rfl { static Result read(const R& _r, const InputVarType& _var) noexcept { - if (_r.is_empty(_var)) { return std::wstring(); } + if (_r.is_empty(_var)) { + return std::wstring(); + } auto inStr = Parser::read(_r, _var); if (auto err = inStr.error(); err.has_value()) { diff --git a/include/rfl/parsing/TupleParser.hpp b/include/rfl/parsing/TupleParser.hpp index 78fb46b..de599b0 100644 --- a/include/rfl/parsing/TupleParser.hpp +++ b/include/rfl/parsing/TupleParser.hpp @@ -38,7 +38,11 @@ namespace rfl::parsing { alignas(std::tuple) unsigned char buf[sizeof(std::tuple)]; auto ptr = reinterpret_cast*>(buf); const auto tuple_reader = TupleReader< - R, W, std::tuple, _ignore_empty_containers, _all_required, + R, + W, + std::tuple, + _ignore_empty_containers, + _all_required, ProcessorsType>(&_r, ptr); auto err = _r.read_array(tuple_reader, _arr); if (err) { diff --git a/include/rfl/parsing/TupleReader.hpp b/include/rfl/parsing/TupleReader.hpp index 663e3d8..e6be37c 100644 --- a/include/rfl/parsing/TupleReader.hpp +++ b/include/rfl/parsing/TupleReader.hpp @@ -31,7 +31,9 @@ namespace rfl::parsing { std::optional handle_missing_fields() const { std::optional err; - if (i_ < size_) { handle_missing_fields_impl(&err); } + if (i_ < size_) { + handle_missing_fields_impl(&err); + } return err; } @@ -46,7 +48,9 @@ namespace rfl::parsing { template void call_destructors_where_necessary() const { if constexpr (_i < size_) { - if (_i >= i_) { return; } + if (_i >= i_) { + return; + } using CurrentType = std::remove_cvref_t>; if constexpr (!std::is_array_v && diff --git a/include/rfl/parsing/VectorParser.hpp b/include/rfl/parsing/VectorParser.hpp index 9503032..a368660 100644 --- a/include/rfl/parsing/VectorParser.hpp +++ b/include/rfl/parsing/VectorParser.hpp @@ -61,7 +61,9 @@ namespace rfl { auto vector_reader = VectorReader(&_r, &vec); const auto err = _r.read_array(vector_reader, _arr); - if (err) { return *err; } + if (err) { + return *err; + } return vec; }; return _r.to_array(_var).and_then(parse); diff --git a/include/rfl/parsing/VectorReader.hpp b/include/rfl/parsing/VectorReader.hpp index d7d0ee5..9df7278 100644 --- a/include/rfl/parsing/VectorReader.hpp +++ b/include/rfl/parsing/VectorReader.hpp @@ -48,7 +48,9 @@ namespace rfl::parsing { using K = std::remove_cvref_t; using V = std::remove_cvref_t; return Parser< - R, W, std::remove_cvref_t>, + R, + W, + std::remove_cvref_t>, ProcessorsType>::read(*r_, _var); } diff --git a/include/rfl/parsing/ViewReader.hpp b/include/rfl/parsing/ViewReader.hpp index 8aef08b..a7402b5 100644 --- a/include/rfl/parsing/ViewReader.hpp +++ b/include/rfl/parsing/ViewReader.hpp @@ -34,7 +34,13 @@ namespace rfl::parsing { /// such a field exists in the underlying view. void read(const std::string_view& _name, const InputVarType& _var) const { assign_to_matching_field( - *r_, _name, _var, view_, errors_, found_, set_, + *r_, + _name, + _var, + view_, + errors_, + found_, + set_, std::make_integer_sequence() ); } @@ -90,7 +96,13 @@ namespace rfl::parsing { assign_to_matching_field(const R& _r, const std::string_view& _current_name, const auto& _var, auto* _view, auto* _errors, auto* _found, auto* _set, std::integer_sequence) { bool already_assigned = false; (assign_if_field_matches( - _r, _current_name, _var, _view, _errors, _found, _set, + _r, + _current_name, + _var, + _view, + _errors, + _found, + _set, &already_assigned ), ...); @@ -116,7 +128,9 @@ namespace rfl::parsing { if constexpr (!std::is_array_v && std::is_pointer_v && std::is_destructible_v) { - if (std::get<_i>(*set_)) { rfl::get<_i>(*view_)->~ValueType(); } + if (std::get<_i>(*set_)) { + rfl::get<_i>(*view_)->~ValueType(); + } } else if constexpr (std::is_array_v) { if (std::get<_i>(*set_)) { auto ptr = rfl::get<_i>(*view_); diff --git a/include/rfl/parsing/is_required.hpp b/include/rfl/parsing/is_required.hpp index 1fd3bd3..835f9a6 100644 --- a/include/rfl/parsing/is_required.hpp +++ b/include/rfl/parsing/is_required.hpp @@ -39,7 +39,8 @@ namespace rfl { using Type = std::remove_cvref_t>; if constexpr (internal::has_reflection_type_v) { return is_required< - typename Type::ReflectionType, _ignore_empty_containers>(); + typename Type::ReflectionType, + _ignore_empty_containers>(); } else if constexpr (internal::is_rename_v) { return is_required(); } else { diff --git a/include/rfl/toml/Reader.hpp b/include/rfl/toml/Reader.hpp index 8f0d767..b4b4739 100644 --- a/include/rfl/toml/Reader.hpp +++ b/include/rfl/toml/Reader.hpp @@ -47,19 +47,27 @@ namespace rfl::toml { rfl::Result to_basic_type(const InputVarType& _var) const noexcept { if constexpr (std::is_same, std::string>()) { const auto ptr = _var->as(); - if (!ptr) { return Error("Could not cast the node to std::string!"); } + if (!ptr) { + return Error("Could not cast the node to std::string!"); + } return **ptr; } else if constexpr (std::is_same, bool>()) { const auto ptr = _var->as(); - if (!ptr) { return Error("Could not cast the node to bool!"); } + if (!ptr) { + return Error("Could not cast the node to bool!"); + } return **ptr; } else if constexpr (std::is_floating_point>()) { const auto ptr = _var->as(); - if (!ptr) { return Error("Could not cast the node to double!"); } + if (!ptr) { + return Error("Could not cast the node to double!"); + } return static_cast>(**ptr); } else if constexpr (std::is_integral>()) { const auto ptr = _var->as(); - if (!ptr) { return Error("Could not cast the node to int64_t!"); } + if (!ptr) { + return Error("Could not cast the node to int64_t!"); + } return static_cast>(**ptr); } else { static_assert(rfl::always_false_v, "Unsupported type."); @@ -69,7 +77,9 @@ namespace rfl::toml { rfl::Result to_array(const InputVarType& _var ) const noexcept { const auto ptr = _var->as_array(); - if (!ptr) { return rfl::Error("Could not cast to an array!"); } + if (!ptr) { + return rfl::Error("Could not cast to an array!"); + } return ptr; } @@ -80,7 +90,9 @@ namespace rfl::toml { ) const noexcept { for (auto& node : *_arr) { const auto err = _array_reader.read(&node); - if (err) { return err; } + if (err) { + return err; + } } return std::nullopt; } @@ -99,7 +111,9 @@ namespace rfl::toml { rfl::Result to_object(const InputVarType& _var ) const noexcept { const auto ptr = _var->as_table(); - if (!ptr) { return rfl::Error("Could not cast to a table!"); } + if (!ptr) { + return rfl::Error("Could not cast to a table!"); + } return ptr; } diff --git a/include/rfl/xml/Reader.hpp b/include/rfl/xml/Reader.hpp index 1748fe0..2bef7ba 100644 --- a/include/rfl/xml/Reader.hpp +++ b/include/rfl/xml/Reader.hpp @@ -142,7 +142,9 @@ namespace rfl { const auto name = _arr.node_.name(); for (auto node = _arr.node_; node; node = node.next_sibling(name)) { const auto err = _array_reader.read(InputVarType(node)); - if (err) { return err; } + if (err) { + return err; + } } return std::nullopt; } diff --git a/include/rfl/yaml/Reader.hpp b/include/rfl/yaml/Reader.hpp index 171e6fb..ead8b0a 100644 --- a/include/rfl/yaml/Reader.hpp +++ b/include/rfl/yaml/Reader.hpp @@ -91,7 +91,9 @@ namespace rfl { ) const noexcept { for (size_t i = 0; i < _arr.node_.size(); ++i) { const auto err = _array_reader.read(_arr.node_[i]); - if (err) { return err; } + if (err) { + return err; + } } return std::nullopt; } diff --git a/include/util/numtypes.h b/include/util/numtypes.h index 93438c6..dc4a82f 100644 --- a/include/util/numtypes.h +++ b/include/util/numtypes.h @@ -1,7 +1,10 @@ #pragma once +#include #include +#define fn auto + // Unsigned integers using u8 = std::uint8_t; using u16 = std::uint16_t; diff --git a/include/yyjson.h b/include/yyjson.h index cc57174..e1ee159 100644 --- a/include/yyjson.h +++ b/include/yyjson.h @@ -869,8 +869,10 @@ extern "C" { size_t mul = (size_t)12 + !(flg & YYJSON_READ_INSITU); size_t pad = 256; size_t max = (size_t)(~(size_t)0); - if (flg & YYJSON_READ_STOP_WHEN_DONE) len = len < 256 ? 256 : len; - if (len >= (max - pad - mul) / mul) return 0; + if (flg & YYJSON_READ_STOP_WHEN_DONE) + len = len < 256 ? 256 : len; + if (len >= (max - pad - mul) / mul) + return 0; return len * mul + pad; } @@ -1756,10 +1758,12 @@ extern "C" { } @endcode */ -#define yyjson_arr_foreach(arr, idx, max, val) \ - for ((idx) = 0, (max) = yyjson_arr_size(arr), \ - (val) = yyjson_arr_get_first(arr); \ - (idx) < (max); (idx)++, (val) = unsafe_yyjson_get_next(val)) +#define yyjson_arr_foreach(arr, idx, max, val) \ + for ((idx) = 0, \ + (max) = yyjson_arr_size(arr), \ + (val) = yyjson_arr_get_first(arr); \ + (idx) < (max); \ + (idx)++, (val) = unsafe_yyjson_get_next(val)) /*============================================================================== * JSON Object API @@ -1922,10 +1926,12 @@ extern "C" { } @endcode */ -#define yyjson_obj_foreach(obj, idx, max, key, val) \ - for ((idx) = 0, (max) = yyjson_obj_size(obj), \ - (key) = (obj) ? unsafe_yyjson_get_first(obj) : NULL, (val) = (key) + 1; \ - (idx) < (max); \ +#define yyjson_obj_foreach(obj, idx, max, key, val) \ + for ((idx) = 0, \ + (max) = yyjson_obj_size(obj), \ + (key) = (obj) ? unsafe_yyjson_get_first(obj) : NULL, \ + (val) = (key) + 1; \ + (idx) < (max); \ (idx)++, (key) = unsafe_yyjson_get_next(val), (val) = (key) + 1) /*============================================================================== @@ -2443,10 +2449,12 @@ extern "C" { } @endcode */ -#define yyjson_mut_arr_foreach(arr, idx, max, val) \ - for ((idx) = 0, (max) = yyjson_mut_arr_size(arr), \ - (val) = yyjson_mut_arr_get_first(arr); \ - (idx) < (max); (idx)++, (val) = (val)->next) +#define yyjson_mut_arr_foreach(arr, idx, max, val) \ + for ((idx) = 0, \ + (max) = yyjson_mut_arr_size(arr), \ + (val) = yyjson_mut_arr_get_first(arr); \ + (idx) < (max); \ + (idx)++, (val) = (val)->next) /*============================================================================== * Mutable JSON Array Creation API @@ -3357,11 +3365,13 @@ extern "C" { } @endcode */ -#define yyjson_mut_obj_foreach(obj, idx, max, key, val) \ - for ((idx) = 0, (max) = yyjson_mut_obj_size(obj), \ - (key) = (max) ? ((yyjson_mut_val*)(obj)->uni.ptr)->next->next : NULL, \ - (val) = (key) ? (key)->next : NULL; \ - (idx) < (max); (idx)++, (key) = (val)->next, (val) = (key)->next) +#define yyjson_mut_obj_foreach(obj, idx, max, key, val) \ + for ((idx) = 0, \ + (max) = yyjson_mut_obj_size(obj), \ + (key) = (max) ? ((yyjson_mut_val*)(obj)->uni.ptr)->next->next : NULL, \ + (val) = (key) ? (key)->next : NULL; \ + (idx) < (max); \ + (idx)++, (key) = (val)->next, (val) = (key)->next) /*============================================================================== * Mutable JSON Object Creation API @@ -4823,7 +4833,8 @@ extern "C" { yyjson_api_inline void yyjson_doc_free(yyjson_doc* doc) { if (doc) { yyjson_alc alc = doc->alc; - if (doc->str_pool) alc.free(alc.ctx, doc->str_pool); + if (doc->str_pool) + alc.free(alc.ctx, doc->str_pool); alc.free(alc.ctx, doc); } } @@ -4985,64 +4996,76 @@ extern "C" { yyjson_api bool unsafe_yyjson_equals(yyjson_val* lhs, yyjson_val* rhs); yyjson_api_inline bool yyjson_equals(yyjson_val* lhs, yyjson_val* rhs) { - if (yyjson_unlikely(!lhs || !rhs)) return false; + if (yyjson_unlikely(!lhs || !rhs)) + return false; return unsafe_yyjson_equals(lhs, rhs); } yyjson_api_inline bool yyjson_set_raw(yyjson_val* val, const char* raw, size_t len) { - if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) + return false; unsafe_yyjson_set_raw(val, raw, len); return true; } yyjson_api_inline bool yyjson_set_null(yyjson_val* val) { - if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) + return false; unsafe_yyjson_set_null(val); return true; } yyjson_api_inline bool yyjson_set_bool(yyjson_val* val, bool num) { - if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) + return false; unsafe_yyjson_set_bool(val, num); return true; } yyjson_api_inline bool yyjson_set_uint(yyjson_val* val, uint64_t num) { - if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) + return false; unsafe_yyjson_set_uint(val, num); return true; } yyjson_api_inline bool yyjson_set_sint(yyjson_val* val, int64_t num) { - if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) + return false; unsafe_yyjson_set_sint(val, num); return true; } yyjson_api_inline bool yyjson_set_int(yyjson_val* val, int num) { - if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) + return false; unsafe_yyjson_set_sint(val, (int64_t)num); return true; } yyjson_api_inline bool yyjson_set_real(yyjson_val* val, double num) { - if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) + return false; unsafe_yyjson_set_real(val, num); return true; } yyjson_api_inline bool yyjson_set_str(yyjson_val* val, const char* str) { - if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; - if (yyjson_unlikely(!str)) return false; + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) + return false; + if (yyjson_unlikely(!str)) + return false; unsafe_yyjson_set_str(val, str); return true; } yyjson_api_inline bool yyjson_set_strn(yyjson_val* val, const char* str, size_t len) { - if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; - if (yyjson_unlikely(!str)) return false; + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) + return false; + if (yyjson_unlikely(!str)) + return false; unsafe_yyjson_set_strn(val, str, len); return true; } @@ -5107,7 +5130,8 @@ extern "C" { iter->cur = unsafe_yyjson_get_first(arr); return true; } - if (iter) memset(iter, 0, sizeof(yyjson_arr_iter)); + if (iter) + memset(iter, 0, sizeof(yyjson_arr_iter)); return false; } @@ -5174,7 +5198,8 @@ extern "C" { iter->obj = obj; return true; } - if (iter) memset(iter, 0, sizeof(yyjson_obj_iter)); + if (iter) + memset(iter, 0, sizeof(yyjson_obj_iter)); return false; } @@ -5333,7 +5358,8 @@ extern "C" { yyjson_api_inline char* unsafe_yyjson_mut_strncpy(yyjson_mut_doc* doc, const char* str, size_t len) { char* mem = unsafe_yyjson_mut_str_alc(doc, len); - if (yyjson_unlikely(!mem)) return NULL; + if (yyjson_unlikely(!mem)) + return NULL; memcpy((void*)mem, (const void*)str, len); mem[len] = '\0'; return mem; @@ -5365,7 +5391,8 @@ extern "C" { yyjson_api_inline void yyjson_mut_doc_set_root(yyjson_mut_doc* doc, yyjson_mut_val* root) { - if (doc) doc->root = root; + if (doc) + doc->root = root; } /*============================================================================== @@ -5499,76 +5526,88 @@ extern "C" { yyjson_api_inline bool yyjson_mut_equals(yyjson_mut_val* lhs, yyjson_mut_val* rhs) { - if (yyjson_unlikely(!lhs || !rhs)) return false; + if (yyjson_unlikely(!lhs || !rhs)) + return false; return unsafe_yyjson_mut_equals(lhs, rhs); } yyjson_api_inline bool yyjson_mut_set_raw(yyjson_mut_val* val, const char* raw, size_t len) { - if (yyjson_unlikely(!val || !raw)) return false; + if (yyjson_unlikely(!val || !raw)) + return false; unsafe_yyjson_set_raw(val, raw, len); return true; } yyjson_api_inline bool yyjson_mut_set_null(yyjson_mut_val* val) { - if (yyjson_unlikely(!val)) return false; + if (yyjson_unlikely(!val)) + return false; unsafe_yyjson_set_null(val); return true; } yyjson_api_inline bool yyjson_mut_set_bool(yyjson_mut_val* val, bool num) { - if (yyjson_unlikely(!val)) return false; + if (yyjson_unlikely(!val)) + return false; unsafe_yyjson_set_bool(val, num); return true; } yyjson_api_inline bool yyjson_mut_set_uint(yyjson_mut_val* val, uint64_t num) { - if (yyjson_unlikely(!val)) return false; + if (yyjson_unlikely(!val)) + return false; unsafe_yyjson_set_uint(val, num); return true; } yyjson_api_inline bool yyjson_mut_set_sint(yyjson_mut_val* val, int64_t num) { - if (yyjson_unlikely(!val)) return false; + if (yyjson_unlikely(!val)) + return false; unsafe_yyjson_set_sint(val, num); return true; } yyjson_api_inline bool yyjson_mut_set_int(yyjson_mut_val* val, int num) { - if (yyjson_unlikely(!val)) return false; + if (yyjson_unlikely(!val)) + return false; unsafe_yyjson_set_sint(val, (int64_t)num); return true; } yyjson_api_inline bool yyjson_mut_set_real(yyjson_mut_val* val, double num) { - if (yyjson_unlikely(!val)) return false; + if (yyjson_unlikely(!val)) + return false; unsafe_yyjson_set_real(val, num); return true; } yyjson_api_inline bool yyjson_mut_set_str(yyjson_mut_val* val, const char* str) { - if (yyjson_unlikely(!val || !str)) return false; + if (yyjson_unlikely(!val || !str)) + return false; unsafe_yyjson_set_str(val, str); return true; } yyjson_api_inline bool yyjson_mut_set_strn(yyjson_mut_val* val, const char* str, size_t len) { - if (yyjson_unlikely(!val || !str)) return false; + if (yyjson_unlikely(!val || !str)) + return false; unsafe_yyjson_set_strn(val, str, len); return true; } yyjson_api_inline bool yyjson_mut_set_arr(yyjson_mut_val* val) { - if (yyjson_unlikely(!val)) return false; + if (yyjson_unlikely(!val)) + return false; unsafe_yyjson_set_arr(val, 0); return true; } yyjson_api_inline bool yyjson_mut_set_obj(yyjson_mut_val* val) { - if (yyjson_unlikely(!val)) return false; + if (yyjson_unlikely(!val)) + return false; unsafe_yyjson_set_obj(val, 0); return true; } @@ -5579,7 +5618,8 @@ extern "C" { yyjson_api_inline yyjson_mut_val* yyjson_mut_raw(yyjson_mut_doc* doc, const char* str) { - if (yyjson_likely(str)) return yyjson_mut_rawn(doc, str, strlen(str)); + if (yyjson_likely(str)) + return yyjson_mut_rawn(doc, str, strlen(str)); return NULL; } @@ -5598,7 +5638,8 @@ extern "C" { yyjson_api_inline yyjson_mut_val* yyjson_mut_rawcpy(yyjson_mut_doc* doc, const char* str) { - if (yyjson_likely(str)) return yyjson_mut_rawncpy(doc, str, strlen(str)); + if (yyjson_likely(str)) + return yyjson_mut_rawncpy(doc, str, strlen(str)); return NULL; } @@ -5707,7 +5748,8 @@ extern "C" { yyjson_api_inline yyjson_mut_val* yyjson_mut_str(yyjson_mut_doc* doc, const char* str) { - if (yyjson_likely(str)) return yyjson_mut_strn(doc, str, strlen(str)); + if (yyjson_likely(str)) + return yyjson_mut_strn(doc, str, strlen(str)); return NULL; } @@ -5726,7 +5768,8 @@ extern "C" { yyjson_api_inline yyjson_mut_val* yyjson_mut_strcpy(yyjson_mut_doc* doc, const char* str) { - if (yyjson_likely(str)) return yyjson_mut_strncpy(doc, str, strlen(str)); + if (yyjson_likely(str)) + return yyjson_mut_strncpy(doc, str, strlen(str)); return NULL; } @@ -5792,7 +5835,8 @@ extern "C" { iter->arr = arr; return true; } - if (iter) memset(iter, 0, sizeof(yyjson_mut_arr_iter)); + if (iter) + memset(iter, 0, sizeof(yyjson_mut_arr_iter)); return false; } @@ -5828,7 +5872,8 @@ extern "C" { yyjson_mut_val* prev = iter->pre; yyjson_mut_val* cur = iter->cur; yyjson_mut_val* next = cur->next; - if (yyjson_unlikely(iter->idx == iter->max)) iter->arr->uni.ptr = prev; + if (yyjson_unlikely(iter->idx == iter->max)) + iter->arr->uni.ptr = prev; iter->idx--; iter->max--; unsafe_yyjson_set_len(iter->arr, iter->max); @@ -6030,7 +6075,8 @@ extern "C" { uint64_t len = (uint64_t)strlen(vals[i]); val->tag = (len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = vals[i]; - if (yyjson_unlikely(!val->uni.str)) return NULL; + if (yyjson_unlikely(!val->uni.str)) + return NULL; }); } @@ -6040,11 +6086,13 @@ extern "C" { const size_t* lens, size_t count ) { - if (yyjson_unlikely(count > 0 && !lens)) return NULL; + if (yyjson_unlikely(count > 0 && !lens)) + return NULL; yyjson_mut_arr_with_func({ val->tag = ((uint64_t)lens[i] << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = vals[i]; - if (yyjson_unlikely(!val->uni.str)) return NULL; + if (yyjson_unlikely(!val->uni.str)) + return NULL; }); } @@ -6057,11 +6105,13 @@ extern "C" { const char* str; yyjson_mut_arr_with_func({ str = vals[i]; - if (!str) return NULL; + if (!str) + return NULL; len = strlen(str); val->tag = ((uint64_t)len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = unsafe_yyjson_mut_strncpy(doc, str, len); - if (yyjson_unlikely(!val->uni.str)) return NULL; + if (yyjson_unlikely(!val->uni.str)) + return NULL; }); } @@ -6073,13 +6123,15 @@ extern "C" { ) { size_t len; const char* str; - if (yyjson_unlikely(count > 0 && !lens)) return NULL; + if (yyjson_unlikely(count > 0 && !lens)) + return NULL; yyjson_mut_arr_with_func({ str = vals[i]; len = lens[i]; val->tag = ((uint64_t)len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = unsafe_yyjson_mut_strncpy(doc, str, len); - if (yyjson_unlikely(!val->uni.str)) return NULL; + if (yyjson_unlikely(!val->uni.str)) + return NULL; }); } @@ -6172,7 +6224,8 @@ extern "C" { } prev->next = val; val->next = next->next; - if ((void*)next == arr->uni.ptr) arr->uni.ptr = val; + if ((void*)next == arr->uni.ptr) + arr->uni.ptr = val; return next; } else { yyjson_mut_val* prev = ((yyjson_mut_val*)arr->uni.ptr); @@ -6199,7 +6252,8 @@ extern "C" { next = next->next; } prev->next = next->next; - if ((void*)next == arr->uni.ptr) arr->uni.ptr = prev; + if ((void*)next == arr->uni.ptr) + arr->uni.ptr = prev; return next; } else { return ((yyjson_mut_val*)arr->uni.ptr); @@ -6258,17 +6312,21 @@ extern "C" { yyjson_mut_val *prev, *next; bool tail_removed; size_t len = unsafe_yyjson_get_len(arr); - if (yyjson_unlikely(_idx + _len > len)) return false; - if (yyjson_unlikely(_len == 0)) return true; + if (yyjson_unlikely(_idx + _len > len)) + return false; + if (yyjson_unlikely(_len == 0)) + return true; unsafe_yyjson_set_len(arr, len - _len); - if (yyjson_unlikely(len == _len)) return true; + if (yyjson_unlikely(len == _len)) + return true; tail_removed = (_idx + _len == len); prev = ((yyjson_mut_val*)arr->uni.ptr); while (_idx-- > 0) prev = prev->next; next = prev->next; while (_len-- > 0) next = next->next; prev->next = next; - if (yyjson_unlikely(tail_removed)) arr->uni.ptr = prev; + if (yyjson_unlikely(tail_removed)) + arr->uni.ptr = prev; return true; } return false; @@ -6499,7 +6557,8 @@ extern "C" { iter->obj = obj; return true; } - if (iter) memset(iter, 0, sizeof(yyjson_mut_obj_iter)); + if (iter) + memset(iter, 0, sizeof(yyjson_mut_obj_iter)); return false; } @@ -6541,7 +6600,8 @@ extern "C" { yyjson_mut_val* prev = iter->pre; yyjson_mut_val* cur = iter->cur; yyjson_mut_val* next = cur->next->next; - if (yyjson_unlikely(iter->idx == iter->max)) iter->obj->uni.ptr = prev; + if (yyjson_unlikely(iter->idx == iter->max)) + iter->obj->uni.ptr = prev; iter->idx--; iter->max--; unsafe_yyjson_set_len(iter->obj, iter->max); @@ -6572,7 +6632,8 @@ extern "C" { if (unsafe_yyjson_get_len(cur) == key_len && memcmp(cur->uni.str, key, key_len) == 0) { iter->idx += idx; - if (iter->idx > max) iter->idx -= max + 1; + if (iter->idx > max) + iter->idx -= max + 1; iter->pre = pre; iter->cur = cur; return cur->next; @@ -6702,10 +6763,12 @@ extern "C" { for (i = 0; i < obj_len; i++) { if (key_tag == cur_key->tag && memcmp(key, cur_key->uni.ptr, key_len) == 0) { - if (!removed_item) removed_item = cur_key->next; + if (!removed_item) + removed_item = cur_key->next; cur_key = cur_key->next->next; pre_key->next->next = cur_key; - if (i + 1 == obj_len) obj->uni.ptr = pre_key; + if (i + 1 == obj_len) + obj->uni.ptr = pre_key; i--; obj_len--; } else { @@ -6791,7 +6854,8 @@ extern "C" { } } } - if (!replaced && val) unsafe_yyjson_mut_obj_add(obj, key, val, iter.max); + if (!replaced && val) + unsafe_yyjson_mut_obj_add(obj, key, val, iter.max); return true; } @@ -6998,7 +7062,8 @@ extern "C" { const char* _key, const char* _val ) { - if (yyjson_unlikely(!_val)) return false; + if (yyjson_unlikely(!_val)) + return false; yyjson_mut_obj_add_func({ val->tag = ((uint64_t)strlen(_val) << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = _val; @@ -7012,7 +7077,8 @@ extern "C" { const char* _val, size_t _len ) { - if (yyjson_unlikely(!_val)) return false; + if (yyjson_unlikely(!_val)) + return false; yyjson_mut_obj_add_func({ val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = _val; @@ -7025,11 +7091,13 @@ extern "C" { const char* _key, const char* _val ) { - if (yyjson_unlikely(!_val)) return false; + if (yyjson_unlikely(!_val)) + return false; yyjson_mut_obj_add_func({ size_t _len = strlen(_val); val->uni.str = unsafe_yyjson_mut_strncpy(doc, _val, _len); - if (yyjson_unlikely(!val->uni.str)) return false; + if (yyjson_unlikely(!val->uni.str)) + return false; val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; }); } @@ -7041,10 +7109,12 @@ extern "C" { const char* _val, size_t _len ) { - if (yyjson_unlikely(!_val)) return false; + if (yyjson_unlikely(!_val)) + return false; yyjson_mut_obj_add_func({ val->uni.str = unsafe_yyjson_mut_strncpy(doc, _val, _len); - if (yyjson_unlikely(!val->uni.str)) return false; + if (yyjson_unlikely(!val->uni.str)) + return false; val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; }); } @@ -7055,7 +7125,8 @@ extern "C" { const char* _key, yyjson_mut_val* _val ) { - if (yyjson_unlikely(!_val)) return false; + if (yyjson_unlikely(!_val)) + return false; yyjson_mut_obj_add_func({ val = _val; }); } @@ -7077,7 +7148,8 @@ extern "C" { while ((key = yyjson_mut_obj_iter_next(&iter)) != NULL) { if (unsafe_yyjson_get_len(key) == _len && memcmp(key->uni.str, _key, _len) == 0) { - if (!val_removed) val_removed = key->next; + if (!val_removed) + val_removed = key->next; yyjson_mut_obj_iter_remove(&iter); } } @@ -7092,7 +7164,8 @@ extern "C" { const char* key, const char* new_key ) { - if (!key || !new_key) return false; + if (!key || !new_key) + return false; return yyjson_mut_obj_rename_keyn( doc, obj, key, strlen(key), new_key, strlen(new_key) ); @@ -7109,13 +7182,15 @@ extern "C" { char* cpy_key = NULL; yyjson_mut_val* old_key; yyjson_mut_obj_iter iter; - if (!doc || !obj || !key || !new_key) return false; + if (!doc || !obj || !key || !new_key) + return false; yyjson_mut_obj_iter_init(obj, &iter); while ((old_key = yyjson_mut_obj_iter_next(&iter))) { if (unsafe_yyjson_equals_strn((void*)old_key, key, len)) { if (!cpy_key) { cpy_key = unsafe_yyjson_mut_strncpy(doc, new_key, new_len); - if (!cpy_key) return false; + if (!cpy_key) + return false; } yyjson_mut_set_strn(old_key, cpy_key, new_len); } @@ -7187,7 +7262,8 @@ extern "C" { yyjson_api_inline yyjson_val* yyjson_doc_ptr_get(yyjson_doc* doc, const char* ptr) { - if (yyjson_unlikely(!ptr)) return NULL; + if (yyjson_unlikely(!ptr)) + return NULL; return yyjson_doc_ptr_getn(doc, ptr, strlen(ptr)); } @@ -7211,7 +7287,9 @@ extern "C" { yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); return NULL; } - if (yyjson_unlikely(len == 0)) { return doc->root; } + if (yyjson_unlikely(len == 0)) { + return doc->root; + } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return NULL; @@ -7221,7 +7299,8 @@ extern "C" { yyjson_api_inline yyjson_val* yyjson_ptr_get(yyjson_val* val, const char* ptr) { - if (yyjson_unlikely(!ptr)) return NULL; + if (yyjson_unlikely(!ptr)) + return NULL; return yyjson_ptr_getn(val, ptr, strlen(ptr)); } @@ -7241,7 +7320,9 @@ extern "C" { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return NULL; } - if (yyjson_unlikely(len == 0)) { return val; } + if (yyjson_unlikely(len == 0)) { + return val; + } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return NULL; @@ -7251,7 +7332,8 @@ extern "C" { yyjson_api_inline yyjson_mut_val* yyjson_mut_doc_ptr_get(yyjson_mut_doc* doc, const char* ptr) { - if (!ptr) return NULL; + if (!ptr) + return NULL; return yyjson_mut_doc_ptr_getn(doc, ptr, strlen(ptr)); } @@ -7268,7 +7350,8 @@ extern "C" { yyjson_ptr_err* err ) { yyjson_ptr_set_err(NONE, NULL); - if (ctx) memset(ctx, 0, sizeof(*ctx)); + if (ctx) + memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!doc || !ptr)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); @@ -7278,7 +7361,9 @@ extern "C" { yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); return NULL; } - if (yyjson_unlikely(len == 0)) { return doc->root; } + if (yyjson_unlikely(len == 0)) { + return doc->root; + } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return NULL; @@ -7288,7 +7373,8 @@ extern "C" { yyjson_api_inline yyjson_mut_val* yyjson_mut_ptr_get(yyjson_mut_val* val, const char* ptr) { - if (!ptr) return NULL; + if (!ptr) + return NULL; return yyjson_mut_ptr_getn(val, ptr, strlen(ptr)); } @@ -7305,13 +7391,16 @@ extern "C" { yyjson_ptr_err* err ) { yyjson_ptr_set_err(NONE, NULL); - if (ctx) memset(ctx, 0, sizeof(*ctx)); + if (ctx) + memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!val || !ptr)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return NULL; } - if (yyjson_unlikely(len == 0)) { return val; } + if (yyjson_unlikely(len == 0)) { + return val; + } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return NULL; @@ -7324,7 +7413,8 @@ extern "C" { const char* ptr, yyjson_mut_val* new_val ) { - if (yyjson_unlikely(!ptr)) return false; + if (yyjson_unlikely(!ptr)) + return false; return yyjson_mut_doc_ptr_addn(doc, ptr, strlen(ptr), new_val); } @@ -7347,7 +7437,8 @@ extern "C" { yyjson_ptr_err* err ) { yyjson_ptr_set_err(NONE, NULL); - if (ctx) memset(ctx, 0, sizeof(*ctx)); + if (ctx) + memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!doc || !ptr || !new_val)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); @@ -7395,7 +7486,8 @@ extern "C" { yyjson_mut_val* new_val, yyjson_mut_doc* doc ) { - if (yyjson_unlikely(!ptr)) return false; + if (yyjson_unlikely(!ptr)) + return false; return yyjson_mut_ptr_addn(val, ptr, strlen(ptr), new_val, doc); } @@ -7420,7 +7512,8 @@ extern "C" { yyjson_ptr_err* err ) { yyjson_ptr_set_err(NONE, NULL); - if (ctx) memset(ctx, 0, sizeof(*ctx)); + if (ctx) + memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!val || !ptr || !new_val || !doc)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); @@ -7444,7 +7537,8 @@ extern "C" { const char* ptr, yyjson_mut_val* new_val ) { - if (yyjson_unlikely(!ptr)) return false; + if (yyjson_unlikely(!ptr)) + return false; return yyjson_mut_doc_ptr_setn(doc, ptr, strlen(ptr), new_val); } @@ -7467,14 +7561,16 @@ extern "C" { yyjson_ptr_err* err ) { yyjson_ptr_set_err(NONE, NULL); - if (ctx) memset(ctx, 0, sizeof(*ctx)); + if (ctx) + memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!doc || !ptr)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return false; } if (yyjson_unlikely(len == 0)) { - if (ctx) ctx->old = doc->root; + if (ctx) + ctx->old = doc->root; doc->root = new_val; return true; } @@ -7518,7 +7614,8 @@ extern "C" { yyjson_mut_val* new_val, yyjson_mut_doc* doc ) { - if (yyjson_unlikely(!ptr)) return false; + if (yyjson_unlikely(!ptr)) + return false; return yyjson_mut_ptr_setn(val, ptr, strlen(ptr), new_val, doc); } @@ -7543,7 +7640,8 @@ extern "C" { yyjson_ptr_err* err ) { yyjson_ptr_set_err(NONE, NULL); - if (ctx) memset(ctx, 0, sizeof(*ctx)); + if (ctx) + memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!val || !ptr || !doc)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); @@ -7570,7 +7668,8 @@ extern "C" { const char* ptr, yyjson_mut_val* new_val ) { - if (!ptr) return NULL; + if (!ptr) + return NULL; return yyjson_mut_doc_ptr_replacen(doc, ptr, strlen(ptr), new_val); } @@ -7592,7 +7691,8 @@ extern "C" { yyjson_ptr_err* err ) { yyjson_ptr_set_err(NONE, NULL); - if (ctx) memset(ctx, 0, sizeof(*ctx)); + if (ctx) + memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!doc || !ptr || !new_val)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); @@ -7604,7 +7704,8 @@ extern "C" { yyjson_ptr_set_err(RESOLVE, "JSON pointer cannot be resolved"); return NULL; } - if (ctx) ctx->old = root; + if (ctx) + ctx->old = root; doc->root = new_val; return root; } @@ -7626,7 +7727,8 @@ extern "C" { const char* ptr, yyjson_mut_val* new_val ) { - if (!ptr) return NULL; + if (!ptr) + return NULL; return yyjson_mut_ptr_replacen(val, ptr, strlen(ptr), new_val); } @@ -7648,7 +7750,8 @@ extern "C" { yyjson_ptr_err* err ) { yyjson_ptr_set_err(NONE, NULL); - if (ctx) memset(ctx, 0, sizeof(*ctx)); + if (ctx) + memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!val || !ptr || !new_val)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); @@ -7667,7 +7770,8 @@ extern "C" { yyjson_api_inline yyjson_mut_val* yyjson_mut_doc_ptr_remove(yyjson_mut_doc* doc, const char* ptr) { - if (!ptr) return NULL; + if (!ptr) + return NULL; return yyjson_mut_doc_ptr_removen(doc, ptr, strlen(ptr)); } @@ -7684,7 +7788,8 @@ extern "C" { yyjson_ptr_err* err ) { yyjson_ptr_set_err(NONE, NULL); - if (ctx) memset(ctx, 0, sizeof(*ctx)); + if (ctx) + memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!doc || !ptr)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); @@ -7696,7 +7801,8 @@ extern "C" { } if (yyjson_unlikely(len == 0)) { yyjson_mut_val* root = doc->root; - if (ctx) ctx->old = root; + if (ctx) + ctx->old = root; doc->root = NULL; return root; } @@ -7709,7 +7815,8 @@ extern "C" { yyjson_api_inline yyjson_mut_val* yyjson_mut_ptr_remove(yyjson_mut_val* val, const char* ptr) { - if (!ptr) return NULL; + if (!ptr) + return NULL; return yyjson_mut_ptr_removen(val, ptr, strlen(ptr)); } @@ -7726,7 +7833,8 @@ extern "C" { yyjson_ptr_err* err ) { yyjson_ptr_set_err(NONE, NULL); - if (ctx) memset(ctx, 0, sizeof(*ctx)); + if (ctx) + memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!val || !ptr)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); @@ -7749,11 +7857,13 @@ extern "C" { yyjson_mut_val* val ) { yyjson_mut_val *ctn, *pre_key, *pre_val, *cur_key, *cur_val; - if (!ctx || !ctx->ctn || !val) return false; + if (!ctx || !ctx->ctn || !val) + return false; ctn = ctx->ctn; if (yyjson_mut_is_obj(ctn)) { - if (!key) return false; + if (!key) + return false; key->next = val; pre_key = ctx->pre; if (unsafe_yyjson_get_len(ctn) == 0) { @@ -7772,7 +7882,8 @@ extern "C" { cur_val = cur_key->next; val->next = cur_val->next; cur_val->next = key; - if (ctn->uni.ptr == cur_key) ctn->uni.ptr = key; + if (ctn->uni.ptr == cur_key) + ctn->uni.ptr = key; ctx->pre = cur_key; } } else { @@ -7791,7 +7902,8 @@ extern "C" { cur_val = pre_val->next; val->next = cur_val->next; cur_val->next = val; - if (ctn->uni.ptr == cur_val) ctn->uni.ptr = val; + if (ctn->uni.ptr == cur_val) + ctn->uni.ptr = val; ctx->pre = cur_val; } } @@ -7802,7 +7914,8 @@ extern "C" { yyjson_api_inline bool yyjson_ptr_ctx_replace(yyjson_ptr_ctx* ctx, yyjson_mut_val* val) { yyjson_mut_val *ctn, *pre_key, *cur_key, *pre_val, *cur_val; - if (!ctx || !ctx->ctn || !ctx->pre || !val) return false; + if (!ctx || !ctx->ctn || !ctx->pre || !val) + return false; ctn = ctx->ctn; if (yyjson_mut_is_obj(ctn)) { pre_key = ctx->pre; @@ -7820,7 +7933,8 @@ extern "C" { if (pre_val != cur_val) { val->next = cur_val->next; pre_val->next = val; - if (ctn->uni.ptr == cur_val) ctn->uni.ptr = val; + if (ctn->uni.ptr == cur_val) + ctn->uni.ptr = val; } else { val->next = val; ctn->uni.ptr = val; @@ -7834,7 +7948,8 @@ extern "C" { yyjson_api_inline bool yyjson_ptr_ctx_remove(yyjson_ptr_ctx* ctx) { yyjson_mut_val *ctn, *pre_key, *pre_val, *cur_key, *cur_val; size_t len; - if (!ctx || !ctx->ctn || !ctx->pre) return false; + if (!ctx || !ctx->ctn || !ctx->pre) + return false; ctn = ctx->ctn; if (yyjson_mut_is_obj(ctn)) { pre_key = ctx->pre; @@ -7843,7 +7958,8 @@ extern "C" { cur_val = cur_key->next; /* remove current key-value */ pre_val->next = cur_val->next; - if (ctn->uni.ptr == cur_key) ctn->uni.ptr = pre_key; + if (ctn->uni.ptr == cur_key) + ctn->uni.ptr = pre_key; ctx->pre = NULL; ctx->old = cur_val; } else { @@ -7851,12 +7967,14 @@ extern "C" { cur_val = pre_val->next; /* remove current key-value */ pre_val->next = cur_val->next; - if (ctn->uni.ptr == cur_val) ctn->uni.ptr = pre_val; + if (ctn->uni.ptr == cur_val) + ctn->uni.ptr = pre_val; ctx->pre = NULL; ctx->old = cur_val; } len = unsafe_yyjson_get_len(ctn) - 1; - if (len == 0) ctn->uni.ptr = NULL; + if (len == 0) + ctn->uni.ptr = NULL; unsafe_yyjson_set_len(ctn, len); return true; } diff --git a/src/main.cpp b/src/main.cpp index a6c2de5..120c331 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,10 +13,9 @@ struct BytesToGiB { template <> struct fmt::formatter : formatter { - template - typename FormatContext::iterator - format(const BytesToGiB BTG, FormatContext& ctx) { - typename FormatContext::iterator out = formatter::format( + template + fn format(const BytesToGiB BTG, FmtCtx& ctx) -> typename FmtCtx::iterator { + typename FmtCtx::iterator out = formatter::format( static_cast(BTG.value) / pow(1024, 3), ctx ); *out++ = 'G'; @@ -26,53 +25,35 @@ struct fmt::formatter : formatter { } }; -enum DateNum { Ones, Twos, Threes, Default }; - -DateNum ParseDate(string const& input) { - if (input == "1" || input == "21" || input == "31") return Ones; - if (input == "2" || input == "22") return Twos; - if (input == "3" || input == "23") return Threes; - return Default; -} - -int main() { - const Config& config = Config::getInstance(); - - if (config.getNowPlaying().getEnabled()) fmt::println("{}", GetNowPlaying()); - - fmt::println("Hello {}!", config.getGeneral().getName()); - - const u64 memInfo = GetMemInfo(); - - fmt::println("{:.2f}", BytesToGiB {memInfo}); - +fn GetDate() -> string { const std::tm localTime = fmt::localtime(time(nullptr)); string date = fmt::format("{:%e}", localTime); - auto start = date.begin(); - while (start != date.end() && std::isspace(*start)) ++start; - date.erase(date.begin(), start); + if (!date.empty() && std::isspace(date.front())) + date.erase(date.begin()); - switch (ParseDate(date)) { - case Ones: - date += "st"; - break; + if (date == "1" || date == "21" || date == "31") + date += "st"; + else if (date == "2" || date == "22") + date += "nd"; + else if (date == "3" || date == "23") + date += "rd"; + else + date += "th"; - case Twos: - date += "nd"; - break; + return fmt::format("{:%B} {}, {:%-I:%0M %p}", localTime, date, localTime); +} - case Threes: - date += "rd"; - break; +fn main() -> int { + const Config& config = Config::getInstance(); - case Default: - date += "th"; - break; - } + if (config.getNowPlaying().getEnabled()) + fmt::println("{}", GetNowPlaying()); - fmt::println("{:%B} {}, {:%-I:%0M %p}", localTime, date, localTime); + fmt::println("Hello {}!", config.getGeneral().getName()); + fmt::println("Installed RAM: {:.2f}", BytesToGiB {GetMemInfo()}); + fmt::println("Today is: {}", GetDate()); Weather::WeatherOutput json = config.getWeather().getWeatherInfo(); diff --git a/src/os/linux.cpp b/src/os/linux.cpp index 2308756..cc19c41 100644 --- a/src/os/linux.cpp +++ b/src/os/linux.cpp @@ -93,13 +93,15 @@ std::vector GetMprisPlayers(sdbus::IConnection& connection) { std::vector mprisPlayers; for (const std::basic_string& name : names) - if (name.contains(mprisInterfaceName)) mprisPlayers.push_back(name); + if (name.contains(mprisInterfaceName)) + mprisPlayers.push_back(name); return mprisPlayers; } std::string GetActivePlayer(const std::vector& mprisPlayers) { - if (!mprisPlayers.empty()) return mprisPlayers.front(); + if (!mprisPlayers.empty()) + return mprisPlayers.front(); return ""; } @@ -114,11 +116,13 @@ std::string GetNowPlaying() { std::vector mprisPlayers = GetMprisPlayers(*connection); - if (mprisPlayers.empty()) return ""; + if (mprisPlayers.empty()) + return ""; std::string activePlayer = GetActivePlayer(mprisPlayers); - if (activePlayer.empty()) return ""; + if (activePlayer.empty()) + return ""; std::unique_ptr playerProxy = sdbus::createProxy(*connection, activePlayer, playerObjectPath);