Commit f4c56936 authored by Dominik Charousset's avatar Dominik Charousset

Integrate review feedback

parent 09696f0a
...@@ -474,11 +474,11 @@ expected<T> get_as(const config_value& x, inspector_access_type::list) { ...@@ -474,11 +474,11 @@ expected<T> get_as(const config_value& x, inspector_access_type::list) {
if (auto wrapped_values = x.to_list()) { if (auto wrapped_values = x.to_list()) {
using value_type = typename T::value_type; using value_type = typename T::value_type;
T result; T result;
if constexpr (detail::has_reserve_t<T>) if constexpr (detail::has_reserve_v<T>)
result.reserve(wrapped_values->size()); result.reserve(wrapped_values->size());
for (const auto& wrapped_value : *wrapped_values) for (const auto& wrapped_value : *wrapped_values)
if (auto maybe_value = get_as<value_type>(wrapped_value)) { if (auto maybe_value = get_as<value_type>(wrapped_value)) {
if constexpr (detail::has_emplace_back_t<T>) if constexpr (detail::has_emplace_back_v<T>)
result.emplace_back(std::move(*maybe_value)); result.emplace_back(std::move(*maybe_value));
else else
result.insert(result.end(), std::move(*maybe_value)); result.insert(result.end(), std::move(*maybe_value));
......
...@@ -213,104 +213,6 @@ void parse(string_parser_state& ps, ...@@ -213,104 +213,6 @@ void parse(string_parser_state& ps,
x = value_type{since_epoch}; x = value_type{since_epoch};
} }
/*
// -- container types ----------------------------------------------------------
CAF_CORE_EXPORT void parse_element(string_parser_state& ps, std::string& x,
const char* char_blacklist);
template <class T>
enable_if_t<!is_pair<T>::value>
parse_element(string_parser_state& ps, T& x, const char*);
template <class First, class Second, size_t N>
void parse_element(string_parser_state& ps, std::pair<First, Second>& kvp,
const char (&char_blacklist)[N]);
struct require_opening_char_t {};
constexpr auto require_opening_char = require_opening_char_t{};
struct allow_omitting_opening_char_t {};
constexpr auto allow_omitting_opening_char = allow_omitting_opening_char_t{};
template <class T, class Policy = allow_omitting_opening_char_t>
enable_if_tt<is_iterable<T>>
parse(string_parser_state& ps, T& xs, Policy = {}) {
using value_type = deconst_kvp_t<typename T::value_type>;
static constexpr auto is_map_type = is_pair<value_type>::value;
static constexpr auto opening_char = is_map_type ? '{' : '[';
static constexpr auto closing_char = is_map_type ? '}' : ']';
auto out = std::inserter(xs, xs.end());
// List/map using [] or {} notation.
if (ps.consume(opening_char)) {
char char_blacklist[] = {closing_char, ',', '\0'};
do {
if (ps.consume(closing_char)) {
ps.skip_whitespaces();
ps.code = ps.at_end() ? pec::success : pec::trailing_character;
return;
}
value_type tmp;
parse_element(ps, tmp, char_blacklist);
if (ps.code > pec::trailing_character)
return;
*out++ = std::move(tmp);
} while (ps.consume(','));
if (ps.consume(closing_char)) {
ps.skip_whitespaces();
ps.code = ps.at_end() ? pec::success : pec::trailing_character;
} else {
ps.code = pec::unexpected_character;
}
return;
}
if constexpr (std::is_same<Policy, require_opening_char_t>::value) {
ps.code = pec::unexpected_character;
} else {
// An empty string simply results in an empty list/map.
if (ps.at_end())
return;
// List/map without [] or {}.
do {
char char_blacklist[] = {',', '\0'};
value_type tmp;
parse_element(ps, tmp, char_blacklist);
if (ps.code > pec::trailing_character)
return;
*out++ = std::move(tmp);
} while (ps.consume(','));
ps.code = ps.at_end() ? pec::success : pec::trailing_character;
}
}
template <class T>
enable_if_t<!is_pair<T>::value>
parse_element(string_parser_state& ps, T& x, const char*) {
parse(ps, x);
}
template <class First, class Second, size_t N>
void parse_element(string_parser_state& ps, std::pair<First, Second>& kvp,
const char (&char_blacklist)[N]) {
static_assert(N > 0, "empty array");
// TODO: consider to guard the blacklist computation with
// `if constexpr (is_same_v<First, string>)` when switching to C++17.
char key_blacklist[N + 1];
if (N > 1)
memcpy(key_blacklist, char_blacklist, N - 1);
key_blacklist[N - 1] = '=';
key_blacklist[N] = '\0';
parse_element(ps, kvp.first, key_blacklist);
if (ps.code > pec::trailing_character)
return;
if (!ps.consume('=')) {
ps.code = pec::unexpected_character;
return;
}
parse_element(ps, kvp.second, char_blacklist);
}
*/
// -- convenience functions ---------------------------------------------------- // -- convenience functions ----------------------------------------------------
CAF_CORE_EXPORT CAF_CORE_EXPORT
......
...@@ -701,7 +701,7 @@ public: ...@@ -701,7 +701,7 @@ public:
}; };
template <class T> template <class T>
constexpr bool has_reserve_t = has_reserve<T>::value; constexpr bool has_reserve_v = has_reserve<T>::value;
template <class T> template <class T>
struct has_emplace_back { struct has_emplace_back {
...@@ -721,7 +721,7 @@ public: ...@@ -721,7 +721,7 @@ public:
}; };
template <class T> template <class T>
constexpr bool has_emplace_back_t = has_emplace_back<T>::value; constexpr bool has_emplace_back_v = has_emplace_back<T>::value;
template <class T> template <class T>
class has_call_error_handler { class has_call_error_handler {
......
...@@ -70,7 +70,7 @@ struct state { ...@@ -70,7 +70,7 @@ struct state {
.add(my_app_request, "request,r", "") .add(my_app_request, "request,r", "")
.add(my_app_request_pair, "request-pair,R", ""); .add(my_app_request_pair, "request-pair,R", "");
config_option_adder{options, "sys"} config_option_adder{options, "sys"}
.add<std::string>("path,p", "") .add<std::string>("query,q", "")
.add<int8_t>("threads,tTd", ""); .add<int8_t>("threads,tTd", "");
} }
...@@ -162,6 +162,13 @@ struct fixture { ...@@ -162,6 +162,13 @@ struct fixture {
"", "",
R"_(my { app { request-pair { first { a = 1, b = 2 }, R"_(my { app { request-pair { first { a = 1, b = 2 },
second { a = 3, b = 4 } } } })_"); second { a = 3, b = 4 } } } })_");
add_test({}, "sys{threads=2}", R"_(sys { threads = 2 })_");
add_test({"-t", "1"}, "sys{threads=2}", R"_(sys { threads = 1 })_");
add_test({"-T", "1"}, "sys{threads=2}", R"_(sys { threads = 1 })_");
add_test({"-d", "1"}, "sys{threads=2}", R"_(sys { threads = 1 })_");
add_test({"--sys.threads=1"}, "sys{threads=2}", R"_(sys { threads = 1 })_");
add_test({"--sys.query=foo"}, "", R"_(sys { query = "foo" })_");
add_test({"-q", "\"a\" in b"}, "", R"_(sys { query = "\"a\" in b" })_");
} }
}; };
......
...@@ -551,13 +551,13 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture; ...@@ -551,13 +551,13 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
} while (false) } while (false)
#define CAF_CHECK(...) \ #define CAF_CHECK(...) \
([](bool expr_result) { \ [](bool expr_result) { \
return ::caf::test::detail::check_un(expr_result, __FILE__, __LINE__, \ return ::caf::test::detail::check_un(expr_result, __FILE__, __LINE__, \
#__VA_ARGS__); \ #__VA_ARGS__); \
})(static_cast<bool>(__VA_ARGS__)) }(static_cast<bool>(__VA_ARGS__))
#define CAF_CHECK_FUNC(func, x_expr, y_expr) \ #define CAF_CHECK_FUNC(func, x_expr, y_expr) \
([](auto&& x_val, auto&& y_val) { \ [](auto&& x_val, auto&& y_val) { \
func comparator; \ func comparator; \
auto caf_check_res \ auto caf_check_res \
= ::caf::test::detail::check(::caf::test::engine::current_test(), \ = ::caf::test::detail::check(::caf::test::engine::current_test(), \
...@@ -567,7 +567,7 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture; ...@@ -567,7 +567,7 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
::caf::test::engine::last_check_file(__FILE__); \ ::caf::test::engine::last_check_file(__FILE__); \
::caf::test::engine::last_check_line(__LINE__); \ ::caf::test::engine::last_check_line(__LINE__); \
return caf_check_res; \ return caf_check_res; \
})(x_expr, y_expr) }(x_expr, y_expr)
#define CAF_CHECK_FAIL(...) \ #define CAF_CHECK_FAIL(...) \
do { \ do { \
...@@ -643,80 +643,80 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture; ...@@ -643,80 +643,80 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
// -- CAF_CHECK* predicate family ---------------------------------------------- // -- CAF_CHECK* predicate family ----------------------------------------------
#define CAF_CHECK_EQUAL(x_expr, y_expr) \ #define CAF_CHECK_EQUAL(x_expr, y_expr) \
([](const auto& x_val, const auto& y_val) { \ [](const auto& x_val, const auto& y_val) { \
return ::caf::test::detail::check_bin(x_val == y_val, __FILE__, __LINE__, \ return ::caf::test::detail::check_bin(x_val == y_val, __FILE__, __LINE__, \
#x_expr " == " #y_expr, \ #x_expr " == " #y_expr, \
caf::deep_to_string(x_val), \ caf::deep_to_string(x_val), \
caf::deep_to_string(y_val)); \ caf::deep_to_string(y_val)); \
})(x_expr, y_expr) }(x_expr, y_expr)
#define CAF_CHECK_NOT_EQUAL(x_expr, y_expr) \ #define CAF_CHECK_NOT_EQUAL(x_expr, y_expr) \
([](const auto& x_val, const auto& y_val) { \ [](const auto& x_val, const auto& y_val) { \
return ::caf::test::detail::check_bin(x_val != y_val, __FILE__, __LINE__, \ return ::caf::test::detail::check_bin(x_val != y_val, __FILE__, __LINE__, \
#x_expr " != " #y_expr, \ #x_expr " != " #y_expr, \
caf::deep_to_string(x_val), \ caf::deep_to_string(x_val), \
caf::deep_to_string(y_val)); \ caf::deep_to_string(y_val)); \
})(x_expr, y_expr) }(x_expr, y_expr)
#define CAF_CHECK_LESS(x_expr, y_expr) \ #define CAF_CHECK_LESS(x_expr, y_expr) \
([](const auto& x_val, const auto& y_val) { \ [](const auto& x_val, const auto& y_val) { \
return ::caf::test::detail::check_bin(x_val < y_val, __FILE__, __LINE__, \ return ::caf::test::detail::check_bin(x_val < y_val, __FILE__, __LINE__, \
#x_expr " < " #y_expr, \ #x_expr " < " #y_expr, \
caf::deep_to_string(x_val), \ caf::deep_to_string(x_val), \
caf::deep_to_string(y_val)); \ caf::deep_to_string(y_val)); \
})(x_expr, y_expr) }(x_expr, y_expr)
#define CAF_CHECK_NOT_LESS(x_expr, y_expr) \ #define CAF_CHECK_NOT_LESS(x_expr, y_expr) \
([](const auto& x_val, const auto& y_val) { \ [](const auto& x_val, const auto& y_val) { \
return ::caf::test::detail::check_bin( \ return ::caf::test::detail::check_bin( \
!(x_val < y_val), __FILE__, __LINE__, "not " #x_expr " < " #y_expr, \ !(x_val < y_val), __FILE__, __LINE__, "not " #x_expr " < " #y_expr, \
caf::deep_to_string(x_val), caf::deep_to_string(y_val)); \ caf::deep_to_string(x_val), caf::deep_to_string(y_val)); \
})(x_expr, y_expr) }(x_expr, y_expr)
#define CAF_CHECK_LESS_OR_EQUAL(x_expr, y_expr) \ #define CAF_CHECK_LESS_OR_EQUAL(x_expr, y_expr) \
([](const auto& x_val, const auto& y_val) { \ [](const auto& x_val, const auto& y_val) { \
return ::caf::test::detail::check_bin(x_val <= y_val, __FILE__, __LINE__, \ return ::caf::test::detail::check_bin(x_val <= y_val, __FILE__, __LINE__, \
#x_expr " <= " #y_expr, \ #x_expr " <= " #y_expr, \
caf::deep_to_string(x_val), \ caf::deep_to_string(x_val), \
caf::deep_to_string(y_val)); \ caf::deep_to_string(y_val)); \
})(x_expr, y_expr) }(x_expr, y_expr)
#define CAF_CHECK_NOT_LESS_OR_EQUAL(x_expr, y_expr) \ #define CAF_CHECK_NOT_LESS_OR_EQUAL(x_expr, y_expr) \
([](const auto& x_val, const auto& y_val) { \ [](const auto& x_val, const auto& y_val) { \
return ::caf::test::detail::check_bin( \ return ::caf::test::detail::check_bin( \
!(x_val <= y_val), __FILE__, __LINE__, "not " #x_expr " <= " #y_expr, \ !(x_val <= y_val), __FILE__, __LINE__, "not " #x_expr " <= " #y_expr, \
caf::deep_to_string(x_val), caf::deep_to_string(y_val)); \ caf::deep_to_string(x_val), caf::deep_to_string(y_val)); \
})(x_expr, y_expr) }(x_expr, y_expr)
#define CAF_CHECK_GREATER(x_expr, y_expr) \ #define CAF_CHECK_GREATER(x_expr, y_expr) \
([](const auto& x_val, const auto& y_val) { \ [](const auto& x_val, const auto& y_val) { \
return ::caf::test::detail::check_bin(x_val > y_val, __FILE__, __LINE__, \ return ::caf::test::detail::check_bin(x_val > y_val, __FILE__, __LINE__, \
#x_expr " > " #y_expr, \ #x_expr " > " #y_expr, \
caf::deep_to_string(x_val), \ caf::deep_to_string(x_val), \
caf::deep_to_string(y_val)); \ caf::deep_to_string(y_val)); \
})(x_expr, y_expr) }(x_expr, y_expr)
#define CAF_CHECK_NOT_GREATER(x_expr, y_expr) \ #define CAF_CHECK_NOT_GREATER(x_expr, y_expr) \
([](const auto& x_val, const auto& y_val) { \ [](const auto& x_val, const auto& y_val) { \
return ::caf::test::detail::check_bin( \ return ::caf::test::detail::check_bin( \
!(x_val > y_val), __FILE__, __LINE__, "not " #x_expr " > " #y_expr, \ !(x_val > y_val), __FILE__, __LINE__, "not " #x_expr " > " #y_expr, \
caf::deep_to_string(x_val), caf::deep_to_string(y_val)); \ caf::deep_to_string(x_val), caf::deep_to_string(y_val)); \
})(x_expr, y_expr) }(x_expr, y_expr)
#define CAF_CHECK_GREATER_OR_EQUAL(x_expr, y_expr) \ #define CAF_CHECK_GREATER_OR_EQUAL(x_expr, y_expr) \
([](const auto& x_val, const auto& y_val) { \ [](const auto& x_val, const auto& y_val) { \
return ::caf::test::detail::check_bin(x_val >= y_val, __FILE__, __LINE__, \ return ::caf::test::detail::check_bin(x_val >= y_val, __FILE__, __LINE__, \
#x_expr " >= " #y_expr, \ #x_expr " >= " #y_expr, \
caf::deep_to_string(x_val), \ caf::deep_to_string(x_val), \
caf::deep_to_string(y_val)); \ caf::deep_to_string(y_val)); \
})(x_expr, y_expr) }(x_expr, y_expr)
#define CAF_CHECK_NOT_GREATER_OR_EQUAL(x_expr, y_expr) \ #define CAF_CHECK_NOT_GREATER_OR_EQUAL(x_expr, y_expr) \
([](const auto& x_val, const auto& y_val) { \ [](const auto& x_val, const auto& y_val) { \
return ::caf::test::detail::check_bin( \ return ::caf::test::detail::check_bin( \
!(x_val >= y_val), __FILE__, __LINE__, "not " #x_expr " >= " #y_expr, \ !(x_val >= y_val), __FILE__, __LINE__, "not " #x_expr " >= " #y_expr, \
caf::deep_to_string(x_val), caf::deep_to_string(y_val)); \ caf::deep_to_string(x_val), caf::deep_to_string(y_val)); \
})(x_expr, y_expr) }(x_expr, y_expr)
// -- CAF_CHECK* predicate family ---------------------------------------------- // -- CAF_CHECK* predicate family ----------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment