Commit 44127021 authored by Dominik Charousset's avatar Dominik Charousset

Specialize config_value_access for builtin types

parent 2b5b8b4f
......@@ -217,10 +217,39 @@ private:
// -- SumType-like access ------------------------------------------------------
template <class T>
struct default_config_value_access {
static bool is(const config_value& x) {
return holds_alternative<T>(x.get_data());
}
static const T* get_if(const config_value* x) {
return caf::get_if<T>(&(x->get_data()));
}
static T get(const config_value& x) {
return caf::get<T>(x.get_data());
}
};
/// @relates config_value
template <class T>
struct config_value_access;
#define CAF_DEFAULT_CONFIG_VALUE_ACCESS(type) \
template <> \
struct config_value_access<type> : default_config_value_access<type> {}
CAF_DEFAULT_CONFIG_VALUE_ACCESS(bool);
CAF_DEFAULT_CONFIG_VALUE_ACCESS(double);
CAF_DEFAULT_CONFIG_VALUE_ACCESS(atom_value);
CAF_DEFAULT_CONFIG_VALUE_ACCESS(timespan);
CAF_DEFAULT_CONFIG_VALUE_ACCESS(std::string);
CAF_DEFAULT_CONFIG_VALUE_ACCESS(config_value::list);
CAF_DEFAULT_CONFIG_VALUE_ACCESS(config_value::dictionary);
#undef CAF_DEFAULT_CONFIG_VALUE_ACCESS
/// Delegates to config_value_access for all specialized versions.
template <class T, bool IsIntegral = std::is_integral<T>::value>
struct select_config_value_access {
......@@ -328,8 +357,6 @@ struct sum_type_access<config_value> {
template <>
struct config_value_access<float> {
static constexpr bool specialized = true;
static bool is(const config_value& x) {
return holds_alternative<double>(x.get_data());
}
......@@ -353,8 +380,6 @@ template <class T>
struct config_value_access<std::vector<T>> {
using vector_type = std::vector<T>;
static constexpr bool specialized = true;
static bool is(const config_value& x) {
auto lst = caf::get_if<config_value::list>(&x);
if (lst != nullptr) {
......@@ -396,8 +421,6 @@ template <class... Ts>
struct config_value_access<std::tuple<Ts...>> {
using tuple_type = std::tuple<Ts...>;
static constexpr bool specialized = true;
static bool is(const config_value& x) {
if (auto lst = caf::get_if<config_value::list>(&x)) {
if (lst->size() != sizeof...(Ts))
......@@ -469,8 +492,6 @@ struct config_value_access<dictionary<V>> {
using kvp = std::pair<const std::string, config_value>;
static constexpr bool specialized = true;
static bool is(const config_value& x) {
auto lst = caf::get_if<config_value::dictionary>(&x);
if (lst != nullptr) {
......
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