Unverified Commit 150a5a50 authored by Joseph Noir's avatar Joseph Noir Committed by GitHub

Merge pull request #734

Add URI to config_value
parents 0f6b0596 9fe3598e
......@@ -36,6 +36,7 @@
#include "caf/sum_type_access.hpp"
#include "caf/sum_type_token.hpp"
#include "caf/timestamp.hpp"
#include "caf/uri.hpp"
#include "caf/variant.hpp"
namespace caf {
......@@ -63,7 +64,7 @@ public:
using dictionary = caf::dictionary<config_value>;
using types = detail::type_list<integer, boolean, real, atom, timespan,
using types = detail::type_list<integer, boolean, real, atom, timespan, uri,
string, list, dictionary>;
using variant_type = detail::tl_apply_t<types, variant>;
......@@ -157,8 +158,8 @@ private:
}
template <class T>
detail::enable_if_t<
detail::is_one_of<T, real, atom, timespan, string, list, dictionary>::value>
detail::enable_if_t<detail::is_one_of<T, real, atom, timespan, uri, string,
list, dictionary>::value>
set(T x) {
data_ = std::move(x);
}
......
......@@ -28,8 +28,10 @@
#include "caf/detail/parser/read_bool.hpp"
#include "caf/detail/parser/read_number_or_timespan.hpp"
#include "caf/detail/parser/read_string.hpp"
#include "caf/detail/parser/read_uri.hpp"
#include "caf/detail/scope_guard.hpp"
#include "caf/pec.hpp"
#include "caf/uri_builder.hpp"
CAF_PUSH_UNUSED_LABEL_WARNING
......@@ -140,6 +142,32 @@ void read_ini_map(state<Iterator, Sentinel>& ps, Consumer&& consumer) {
fin();
}
template <class Iterator, class Sentinel, class Consumer>
void read_ini_uri(state<Iterator, Sentinel>& ps, Consumer&& consumer) {
uri_builder builder;
auto g = make_scope_guard([&] {
if (ps.code <= pec::trailing_character)
consumer.value(builder.make());
});
start();
state(init) {
transition(init, " \t\n")
transition(before_uri, '<')
}
state(before_uri) {
transition(before_uri, " \t\n")
fsm_epsilon(read_uri(ps, builder), after_uri)
}
state(after_uri) {
transition(after_uri, " \t\n")
transition(done, '>')
}
term_state(done) {
// nop
}
fin();
}
template <class Iterator, class Sentinel, class Consumer>
void read_ini_value(state<Iterator, Sentinel>& ps, Consumer&& consumer) {
start();
......@@ -149,6 +177,7 @@ void read_ini_value(state<Iterator, Sentinel>& ps, Consumer&& consumer) {
fsm_epsilon(read_number(ps, consumer), done, '.')
fsm_epsilon(read_bool(ps, consumer), done, "ft")
fsm_epsilon(read_number_or_timespan(ps, consumer), done, "0123456789+-")
fsm_epsilon(read_ini_uri(ps, consumer), done, '<')
fsm_transition(read_ini_list(ps, consumer.begin_list()), done, '[')
fsm_transition(read_ini_map(ps, consumer.begin_map()), done, '{')
}
......
......@@ -35,6 +35,7 @@ const char* type_names[] {
"real",
"atom",
"timespan",
"uri",
"string",
"list",
"dictionary",
......
......@@ -63,7 +63,12 @@ struct test_consumer {
template <class T>
void value(T x) {
add_entry("value: ", deep_to_string(x));
config_value cv{std::move(x)};
std::string entry = "value (";
entry += cv.type_name();
entry += "): ";
entry += to_string(cv);
log.emplace_back(std::move(entry));
}
void add_entry(const char* prefix, std::string str) {
......@@ -87,8 +92,10 @@ struct fixture {
res.i = str.begin();
res.e = str.end();
detail::parser::read_ini(res, f);
if ((res.code == pec::success) != expect_success)
if ((res.code == pec::success) != expect_success) {
CAF_MESSAGE("unexpected parser result state: " << res.code);
CAF_MESSAGE("input remainder: " << std::string(res.i, res.e));
}
return std::move(f.log);
}
};
......@@ -125,17 +132,61 @@ entry1=123,
entry3= "abc",
entry4 = 'def', ; some comment and a trailing comma
}
[middleman]
preconnect=[<
tcp://localhost:8080
>,<udp://remotehost?trust=false>]
)";
const auto ini0_log = make_log(
"key: logger", "{", "key: padding", "value: 10", "key: file-name",
"value: \"foobar.ini\"", "}", "key: scheduler", "{", "key: timing",
"value: 2000ns", "key: impl", "value: 'foo'", "key: x_",
"value: " + deep_to_string(.123), "key: some-bool", "value: true",
"key: some-other-bool", "value: false", "key: some-list", "[", "value: 123",
"value: 23", "value: \"abc\"", "value: 'def'", "]", "key: some-map", "{",
"key: entry1", "value: 123", "key: entry2", "value: 23", "key: entry3",
"value: \"abc\"", "key: entry4", "value: 'def'", "}", "}");
"key: logger",
"{",
"key: padding",
"value (integer): 10",
"key: file-name",
"value (string): \"foobar.ini\"",
"}",
"key: scheduler",
"{",
"key: timing",
"value (timespan): 2000ns",
"key: impl",
"value (atom): 'foo'",
"key: x_",
"value (real): " + deep_to_string(.123),
"key: some-bool",
"value (boolean): true",
"key: some-other-bool",
"value (boolean): false",
"key: some-list",
"[",
"value (integer): 123",
"value (integer): 23",
"value (string): \"abc\"",
"value (atom): 'def'",
"]",
"key: some-map",
"{",
"key: entry1",
"value (integer): 123",
"key: entry2",
"value (integer): 23",
"key: entry3",
"value (string): \"abc\"",
"key: entry4",
"value (atom): 'def'",
"}",
"}",
"key: middleman",
"{",
"key: preconnect",
"[",
"value (uri): tcp://localhost:8080",
"value (uri): udp://remotehost?trust=false",
"]",
"}"
);
} // namespace <anonymous>
......
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