diff --git a/phlex/configuration.hpp b/phlex/configuration.hpp index 30f4406f9..51a022f68 100644 --- a/phlex/configuration.hpp +++ b/phlex/configuration.hpp @@ -4,6 +4,7 @@ #include "boost/json.hpp" #include +#include namespace phlex::experimental { class configuration { @@ -32,6 +33,25 @@ namespace phlex::experimental { return get_if_present(key).value_or(std::forward(default_value)); } + // Internal function for prototype purposes; do not use as this will change. + std::pair kind(std::string const& key) const + { + auto const& value = config_.at(key); // may throw + + auto k = value.kind(); + bool is_array = k == boost::json::kind::array; + + if (is_array) { + // The current configuration interface only supports homogenous containers, + // thus checking only the first element suffices. (This assumes arrays are + // not nested, which is fine for now.) + boost::json::array const& arr = value.as_array(); + k = arr.empty() ? boost::json::kind::null : arr[0].kind(); + } + + return std::make_pair(k, is_array); + } + private: boost::json::object config_; }; diff --git a/test/python/driver.cpp b/test/python/driver.cpp index 8111b3d8e..a879473bb 100644 --- a/test/python/driver.cpp +++ b/test/python/driver.cpp @@ -6,9 +6,10 @@ namespace { class number_generator { public: - number_generator(phlex::experimental::configuration const& config) : - n_{config.get("max_numbers")} + number_generator(phlex::experimental::configuration const& config) n_{0} { + if (config.kind("max_numbers") == boost::json::kind::int64_t) + n_ = config.get("max_numbers"; } void next(phlex::experimental::framework_driver& driver) const