Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions phlex/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "boost/json.hpp"

#include <optional>
#include <utility>

namespace phlex::experimental {
class configuration {
Expand Down Expand Up @@ -32,6 +33,25 @@
return get_if_present<T>(key).value_or(std::forward<T>(default_value));
}

// Internal function for prototype purposes; do not use as this will change.
std::pair<boost::json::kind, bool> kind(std::string const& key) const
{
auto const& value = config_.at(key); // may throw

Check warning on line 39 in phlex/configuration.hpp

View check run for this annotation

Codecov / codecov/patch

phlex/configuration.hpp#L39

Added line #L39 was not covered by tests

auto k = value.kind();
bool is_array = k == boost::json::kind::array;

Check warning on line 42 in phlex/configuration.hpp

View check run for this annotation

Codecov / codecov/patch

phlex/configuration.hpp#L41-L42

Added lines #L41 - L42 were not covered by tests

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();

Check warning on line 49 in phlex/configuration.hpp

View check run for this annotation

Codecov / codecov/patch

phlex/configuration.hpp#L44-L49

Added lines #L44 - L49 were not covered by tests
}

return std::make_pair(k, is_array);

Check warning on line 52 in phlex/configuration.hpp

View check run for this annotation

Codecov / codecov/patch

phlex/configuration.hpp#L52

Added line #L52 was not covered by tests
}

private:
boost::json::object config_;
};
Expand Down
5 changes: 3 additions & 2 deletions test/python/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
namespace {
class number_generator {
public:
number_generator(phlex::experimental::configuration const& config) :
n_{config.get<int>("max_numbers")}
number_generator(phlex::experimental::configuration const& config) n_{0}
{
if (config.kind("max_numbers") == boost::json::kind::int64_t)
n_ = config.get<int>("max_numbers";
}

void next(phlex::experimental::framework_driver& driver) const
Expand Down
Loading