diff --git a/phlex/configuration.cpp b/phlex/configuration.cpp index 10d1281a..03cb6daa 100644 --- a/phlex/configuration.cpp +++ b/phlex/configuration.cpp @@ -25,7 +25,7 @@ namespace phlex { { using detail::value_decorate_exception; auto query_object = jv.as_object(); - return product_query{.spec = {value_decorate_exception(query_object, "product")}, - .layer = value_decorate_exception(query_object, "layer")}; + return product_query{{value_decorate_exception(query_object, "product")}, + value_decorate_exception(query_object, "layer")}; } } diff --git a/phlex/core/declared_provider.hpp b/phlex/core/declared_provider.hpp index c15c9e18..2ef92c58 100644 --- a/phlex/core/declared_provider.hpp +++ b/phlex/core/declared_provider.hpp @@ -67,7 +67,7 @@ namespace phlex::experimental { AlgorithmBits alg, product_query output) : declared_provider{std::move(name), output}, - output_{output.spec}, + output_{output.spec()}, provider_{ g, concurrency, [this, ft = alg.release_algorithm()](message const& msg, auto& output) { auto& [stay_in_graph, to_output] = output; diff --git a/phlex/core/detail/filter_impl.cpp b/phlex/core/detail/filter_impl.cpp index 2f403afd..a7156cc9 100644 --- a/phlex/core/detail/filter_impl.cpp +++ b/phlex/core/detail/filter_impl.cpp @@ -5,11 +5,13 @@ #include namespace { - phlex::product_query const output_dummy{phlex::experimental::product_specification{ - phlex::experimental::algorithm_name{"for_output_only", ""}, - "for_output_only", - phlex::experimental::type_id{}}}; - std::vector const for_output_only{output_dummy}; + phlex::product_query const output_dummy{ + phlex::experimental::product_specification{ + phlex::experimental::algorithm_name{"for_output_only", ""}, + "for_output_only", + phlex::experimental::type_id{}}, + "dummy_layer"}; + phlex::product_queries const for_output_only{output_dummy}; } namespace phlex::experimental { @@ -78,7 +80,7 @@ namespace phlex::experimental { // Fill slots in the order of the input arguments to the downstream node. for (std::size_t i = 0; i != nargs_; ++i) { - if (elem[i] or not store->contains_product((*product_names_)[i].spec.full())) + if (elem[i] or not store->contains_product((*product_names_)[i].spec().full())) continue; elem[i] = store; } diff --git a/phlex/core/edge_creation_policy.cpp b/phlex/core/edge_creation_policy.cpp index 136d0b57..1ab4ab71 100644 --- a/phlex/core/edge_creation_policy.cpp +++ b/phlex/core/edge_creation_policy.cpp @@ -9,7 +9,7 @@ namespace phlex::experimental { edge_creation_policy::named_output_port const* edge_creation_policy::find_producer( product_query const& query) const { - auto const& spec = query.spec; + auto const& spec = query.spec(); auto [b, e] = producers_.equal_range(spec.name()); if (b == e) { spdlog::debug( diff --git a/phlex/core/input_arguments.hpp b/phlex/core/input_arguments.hpp index c31ea791..1083692f 100644 --- a/phlex/core/input_arguments.hpp +++ b/phlex/core/input_arguments.hpp @@ -19,7 +19,7 @@ namespace phlex::experimental { auto retrieve(auto const& messages) const { return std::get(messages).store->template get_handle( - query.spec.name()); + query.spec().name()); } }; diff --git a/phlex/core/message.cpp b/phlex/core/message.cpp index eaa2d8c6..eed87a7d 100644 --- a/phlex/core/message.cpp +++ b/phlex/core/message.cpp @@ -26,7 +26,7 @@ namespace phlex::experimental { auto const [b, e] = std::tuple{cbegin(product_labels), cend(product_labels)}; auto it = std::find(b, e, product_label); if (it == e) { - throw std::runtime_error("Algorithm does not accept product '" + product_label.spec.name() + + throw std::runtime_error("Algorithm does not accept product '" + product_label.spec().name() + "'."); } return std::distance(b, it); diff --git a/phlex/core/multiplexer.cpp b/phlex/core/multiplexer.cpp index 10f983f9..9c60b7c8 100644 --- a/phlex/core/multiplexer.cpp +++ b/phlex/core/multiplexer.cpp @@ -66,7 +66,7 @@ namespace phlex::experimental { auto start_time = steady_clock::now(); for (auto const& [product_label, port] : provider_input_ports_ | std::views::values) { - if (auto store_to_send = store_for(store, product_label.layer)) { + if (auto store_to_send = store_for(store, product_label.layer())) { port->try_put({std::move(store_to_send), eom, message_id}); } } diff --git a/phlex/core/product_query.cpp b/phlex/core/product_query.cpp index 4ad570d2..5f442e70 100644 --- a/phlex/core/product_query.cpp +++ b/phlex/core/product_query.cpp @@ -2,12 +2,17 @@ #include "fmt/format.h" -#include #include -#include -namespace phlex::experimental { - product_query product_tag::operator()(std::string data_layer) && +namespace phlex { + product_query::product_query() = default; + + product_query::product_query(experimental::product_specification spec, std::string layer) : + spec_{std::move(spec)}, layer_{std::move(layer)} + { + } + + product_query experimental::product_tag::operator()(std::string data_layer) && { if (data_layer.empty()) { throw std::runtime_error("Cannot specify the empty string as a data layer."); @@ -15,32 +20,12 @@ namespace phlex::experimental { return {std::move(spec), std::move(data_layer)}; } - std::ostream& operator<<(std::ostream& os, product_query const& query) - { - os << query.to_string(); - return os; - } -} - -namespace phlex { std::string product_query::to_string() const { - if (layer.empty()) { - return spec.full(); + if (layer_.empty()) { + return spec_.full(); } - return fmt::format("{} ϵ {}", spec.full(), layer); - } - - bool operator==(product_query const& a, product_query const& b) - { - return std::tie(a.spec, a.layer) == std::tie(b.spec, b.layer); - } - - bool operator!=(product_query const& a, product_query const& b) { return !(a == b); } - - bool operator<(product_query const& a, product_query const& b) - { - return std::tie(a.spec, a.layer) < std::tie(b.spec, b.layer); + return fmt::format("{} ϵ {}", spec_.full(), layer_); } experimental::product_tag operator""_in(char const* product_name, std::size_t length) diff --git a/phlex/core/product_query.hpp b/phlex/core/product_query.hpp index 1083a30d..55cc3956 100644 --- a/phlex/core/product_query.hpp +++ b/phlex/core/product_query.hpp @@ -3,22 +3,30 @@ #include "phlex/model/product_specification.hpp" -#include -#include -#include +// #include #include #include namespace phlex { - struct product_query { - experimental::product_specification spec; - std::string layer; + class product_query { + public: + // FIXME: Boost JSON's parameter retrieval facilities require a default constructor + // whenever the type is (e.g.) std::array. + product_query(); + product_query(experimental::product_specification spec, std::string layer); + + auto const& spec() const noexcept { return spec_; } + auto const& layer() const noexcept { return layer_; } + void set_type(experimental::type_id&& type) { spec_.set_type(std::move(type)); } + std::string to_string() const; - }; - bool operator==(product_query const& a, product_query const& b); - bool operator!=(product_query const& a, product_query const& b); - bool operator<(product_query const& a, product_query const& b); + auto operator<=>(product_query const&) const = default; + + private: + experimental::product_specification spec_; + std::string layer_; + }; using product_queries = std::vector; } @@ -29,8 +37,6 @@ namespace phlex::experimental { product_query operator()(std::string layer) &&; }; - std::ostream& operator<<(std::ostream& os, product_query const& query); - namespace detail { // C is a container of product_queries template @@ -45,7 +51,7 @@ namespace phlex::experimental { template void set_type(C& container) { - container.at(index_).spec.set_type(make_type_id()); + container.at(index_).set_type(make_type_id()); ++index_; } diff --git a/phlex/core/registration_api.hpp b/phlex/core/registration_api.hpp index b1db71ec..66ceae60 100644 --- a/phlex/core/registration_api.hpp +++ b/phlex/core/registration_api.hpp @@ -136,7 +136,7 @@ namespace phlex::experimental { using return_type = return_type; using provider_type = provider_node; - output.spec.set_type(make_type_id()); + output.set_type(make_type_id()); registrar_.set_creator( [this, output = std::move(output)](auto /* predicates */, auto /* output_products */) { diff --git a/phlex/model/algorithm_name.cpp b/phlex/model/algorithm_name.cpp index 10b48f9c..f4d83fae 100644 --- a/phlex/model/algorithm_name.cpp +++ b/phlex/model/algorithm_name.cpp @@ -55,20 +55,6 @@ namespace phlex::experimental { return false; } - auto algorithm_name::cmp_tuple() const { return std::tie(plugin_, algorithm_, fields_); } - - bool algorithm_name::operator==(algorithm_name const& other) const - { - return cmp_tuple() == other.cmp_tuple(); - } - - bool algorithm_name::operator!=(algorithm_name const& other) const { return !operator==(other); } - - bool algorithm_name::operator<(algorithm_name const& other) const - { - return cmp_tuple() < other.cmp_tuple(); - } - algorithm_name algorithm_name::create(char const* spec) { return create(std::string{spec}); } algorithm_name algorithm_name::create(std::string const& spec) { diff --git a/phlex/model/algorithm_name.hpp b/phlex/model/algorithm_name.hpp index 55a3a0e8..4ff1c5d3 100644 --- a/phlex/model/algorithm_name.hpp +++ b/phlex/model/algorithm_name.hpp @@ -21,9 +21,7 @@ namespace phlex::experimental { std::string const& algorithm() const noexcept { return algorithm_; } bool match(algorithm_name const& other) const; - bool operator==(algorithm_name const& other) const; - bool operator!=(algorithm_name const& other) const; - bool operator<(algorithm_name const& other) const; + auto operator<=>(algorithm_name const&) const = default; static algorithm_name create(char const* spec); static algorithm_name create(std::string const& spec); diff --git a/phlex/model/product_specification.cpp b/phlex/model/product_specification.cpp index f844d2cf..93fe1dfe 100644 --- a/phlex/model/product_specification.cpp +++ b/phlex/model/product_specification.cpp @@ -28,23 +28,6 @@ namespace phlex::experimental { return qualifier + "/" + name_; } - bool product_specification::operator==(product_specification const& other) const - { - return std::tie(qualifier_, name_, type_id_) == - std::tie(other.qualifier_, other.name_, other.type_id_); - } - - bool product_specification::operator!=(product_specification const& other) const - { - return !operator==(other); - } - - bool product_specification::operator<(product_specification const& other) const - { - return std::tie(qualifier_, name_, type_id_) < - std::tie(other.qualifier_, other.name_, type_id_); - } - product_specification product_specification::create(char const* c) { return create(std::string{c}); diff --git a/phlex/model/product_specification.hpp b/phlex/model/product_specification.hpp index b3c19750..18a09e05 100644 --- a/phlex/model/product_specification.hpp +++ b/phlex/model/product_specification.hpp @@ -25,9 +25,7 @@ namespace phlex::experimental { void set_type(type_id&& type) { type_id_ = std::move(type); } - bool operator==(product_specification const& other) const; - bool operator!=(product_specification const& other) const; - bool operator<(product_specification const& other) const; + auto operator<=>(product_specification const&) const = default; static product_specification create(char const* c); static product_specification create(std::string const& s);