Skip to content

Commit

Permalink
Committing clang-format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenberry committed Feb 27, 2025
1 parent d5a872b commit 231ba2c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 50 deletions.
88 changes: 52 additions & 36 deletions include/glaze/core/opts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ namespace glz
#ifndef GLZ_NULL_TERMINATED
#define GLZ_NULL_TERMINATED true
#endif

enum struct opts_internal : uint32_t {
none = 0,
opening_handled = 1 << 0, // the opening character has been handled
closing_handled = 1 << 1, // the closing character has been handled
ws_handled = 1 << 2, // whitespace has already been parsed
no_header = 1 << 3, // whether or not a binary header is needed
disable_write_unknown =
1 << 4, // whether to turn off writing unknown fields for a glz::meta specialized for unknown writing
1 << 4, // whether to turn off writing unknown fields for a glz::meta specialized for unknown writing
is_padded = 1 << 5, // whether or not the read buffer is padded
disable_padding = 1 << 6, // to explicitly disable padding for contexts like includers
write_unchecked = 1 << 7 // the write buffer has sufficient space and does not need to be checked
};

// NOTE TO USER:
// glz::opts are the default options for using Glaze
// You can create your own options struct with more or less fields as long as your struct has:
Expand Down Expand Up @@ -99,104 +99,120 @@ namespace glz

bool partial_read =
false; // Reads into the deepest structural object and then exits without parsing the rest of the input

// INTERNAL OPTIONS
uint32_t internal{}; // default should be 0

[[nodiscard]] constexpr bool operator==(const opts&) const noexcept = default;
};

// Add these to a custom options struct if you want to use them
// OTHER AVAILABLE OPTIONS (and default values):

// ---
// bool validate_skipped = false;
// If full validation should be performed on skipped values

// ---
// bool validate_trailing_whitespace = false;
// If, after parsing a value, we want to validate the trailing whitespace

// ---
// bool concatenate = true;
// Concatenates ranges of std::pair into single objects when writing

// ---
// bool allow_conversions = true;
// Whether conversions between convertible types are allowed in binary, e.g. double -> float

// ---
// bool write_type_info = true;
// Write type info for meta objects in variants

// ---
// bool shrink_to_fit = false;
// Shrinks dynamic containers to new size to save memory

// ---
// bool hide_non_invocable = true;
// Hides non-invocable members from the cli_menu (may be applied elsewhere in the future)

consteval bool check_validate_skipped(auto&& Opts) {

consteval bool check_validate_skipped(auto&& Opts)
{
if constexpr (requires { Opts.validate_skipped; }) {
return Opts.validate_skipped;
} else {
}
else {
return false;
}
}

consteval bool check_validate_trailing_whitespace(auto&& Opts) {

consteval bool check_validate_trailing_whitespace(auto&& Opts)
{
if constexpr (requires { Opts.validate_trailing_whitespace; }) {
return Opts.validate_trailing_whitespace;
} else {
}
else {
return false;
}
}

consteval bool check_partial_read(auto&& Opts) {

consteval bool check_partial_read(auto&& Opts)
{
if constexpr (requires { Opts.partial_read; }) {
return Opts.partial_read;
} else {
}
else {
return false;
}
}

consteval bool check_concatenate(auto&& Opts) {

consteval bool check_concatenate(auto&& Opts)
{
if constexpr (requires { Opts.concatenate; }) {
return Opts.concatenate;
} else {
}
else {
return true;
}
}

consteval bool check_allow_conversions(auto&& Opts) {

consteval bool check_allow_conversions(auto&& Opts)
{
if constexpr (requires { Opts.allow_conversions; }) {
return Opts.allow_conversions;
} else {
}
else {
return true;
}
}

consteval bool check_write_type_info(auto&& Opts) {

consteval bool check_write_type_info(auto&& Opts)
{
if constexpr (requires { Opts.write_type_info; }) {
return Opts.write_type_info;
} else {
}
else {
return true;
}
}

consteval bool check_shrink_to_fit(auto&& Opts) {

consteval bool check_shrink_to_fit(auto&& Opts)
{
if constexpr (requires { Opts.shrink_to_fit; }) {
return Opts.shrink_to_fit;
} else {
}
else {
return false;
}
}

consteval bool check_hide_non_invocable(auto&& Opts) {

consteval bool check_hide_non_invocable(auto&& Opts)
{
if constexpr (requires { Opts.hide_non_invocable; }) {
return Opts.hide_non_invocable;
} else {
}
else {
return true;
}
}
Expand Down
8 changes: 3 additions & 5 deletions include/glaze/json/read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3220,7 +3220,7 @@ namespace glz
value = buffer;
}
};

struct opts_validate : opts
{
bool validate_skipped = true;
Expand All @@ -3232,17 +3232,15 @@ namespace glz
{
context ctx{};
glz::skip skip_value{};
return read<opts_validate{}>(
skip_value, std::forward<Buffer>(buffer), ctx);
return read<opts_validate{}>(skip_value, std::forward<Buffer>(buffer), ctx);
}

template <is_buffer Buffer>
[[nodiscard]] error_ctx validate_jsonc(Buffer&& buffer) noexcept
{
context ctx{};
glz::skip skip_value{};
return read<opts_validate{{opts{.comments = true}}}>(
skip_value, std::forward<Buffer>(buffer), ctx);
return read<opts_validate{{opts{.comments = true}}}>(skip_value, std::forward<Buffer>(buffer), ctx);
}

template <class T, is_buffer Buffer>
Expand Down
17 changes: 8 additions & 9 deletions tests/json_test/json_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ suite container_types = [] {
"vector pair"_test = [] {
std::vector<std::pair<int, int>> v;
expect(!glz::read<opts_concatenate{{}, false}>(v, R"([{"1":2},{"3":4}])"));
//constexpr glz::opts opts{.prettify = true};
// constexpr glz::opts opts{.prettify = true};
const auto s = glz::write<opts_concatenate{{glz::opts{.prettify = true}}, false}>(v).value_or("error");
expect(s == R"([
{
Expand Down Expand Up @@ -9586,10 +9586,8 @@ suite TestSettingsData_test = [] {
};

static constexpr opts_allow_conversions write_options{{glz::opts{.comments = true, .prettify = true}}};
static constexpr opts_allow_conversions read_options{{glz::opts{.comments = true,
.error_on_unknown_keys = false,
.skip_null_members = true,
.error_on_missing_keys = false}}};
static constexpr opts_allow_conversions read_options{{glz::opts{
.comments = true, .error_on_unknown_keys = false, .skip_null_members = true, .error_on_missing_keys = false}}};

"TestSettingsData options"_test = [] {
TestSettingsData obj{};
Expand Down Expand Up @@ -10023,13 +10021,14 @@ struct Foo
suite ndjson_options = [] {
"ndjson_options"_test = [] {
std::vector<Foo> assets{};

struct opts : glz::opts {

struct opts : glz::opts
{
bool validate_skipped = true;
};

const auto ec = glz::read<opts{{glz::opts{.format = glz::NDJSON, .error_on_unknown_keys = false}}}>(
assets, "{\"x\":1}\n{\"x\":2}");
assets, "{\"x\":1}\n{\"x\":2}");
expect(not ec);
};
};
Expand Down

0 comments on commit 231ba2c

Please sign in to comment.