11#ifndef PHLEX_CORE_PRODUCT_QUERY_HPP
22#define PHLEX_CORE_PRODUCT_QUERY_HPP
33
4+ #include " phlex/model/product_specification.hpp"
45#include " phlex/model/type_id.hpp"
56
6- #include < iosfwd>
77#include < optional>
88#include < string>
99#include < vector>
@@ -24,7 +24,7 @@ namespace phlex {
2424
2525 required_creator_name (std::string_view rhs) : content_(rhs) {}
2626
27- T&& release() {return std::move (content_);}
27+ T&& release() { return std::move (content_); }
2828
2929 private:
3030 std::string content_;
@@ -42,7 +42,7 @@ namespace phlex {
4242
4343 required_layer_name (std::string_view rhs) : content_(rhs) {}
4444
45- T&& release() {return std::move (content_);}
45+ T&& release() { return std::move (content_); }
4646
4747 private:
4848 std::string content_;
@@ -55,20 +55,46 @@ namespace phlex {
5555 std::optional<std::string> suffix;
5656 std::optional<std::string> stage;
5757 };
58-
58+
5959 class product_query {
6060 public:
6161 product_query () = default ; // Required by boost JSON
62- product_query (product_tag&& tag) : creator_(tag.creator.release()), layer_(tag.layer.release()), suffix_(std::move(tag.suffix)), stage_(std::move(tag.stage)) {}
62+ product_query (product_tag&& tag) :
63+ creator_ (tag.creator.release()),
64+ layer_ (tag.layer.release()),
65+ suffix_ (std::move(tag.suffix)),
66+ stage_ (std::move(tag.stage))
67+ {
68+ if (creator_.empty ()) {
69+ throw std::runtime_error (" Cannot specify product with empty creator name." );
70+ }
71+ if (layer_.empty ()) {
72+ throw std::runtime_error (" Cannot specify the empty string as a data layer." );
73+ }
74+ }
6375 void set_type (experimental::type_id&& type);
6476
65- std::string const & creator () const noexcept {return creator_;}
66- std::string const & layer () const noexcept {return layer_;}
67- std::optional<std::string> const & suffix () const noexcept {return suffix_;}
68- std::optional<std::string> const & stage () const noexcept {return stage_;}
69- experimental::type_id const & type () const noexcept {return type_id_;}
77+ std::string const & creator () const noexcept { return creator_; }
78+ std::string const & layer () const noexcept { return layer_; }
79+ std::optional<std::string> const & suffix () const noexcept { return suffix_; }
80+ std::optional<std::string> const & stage () const noexcept { return stage_; }
81+ experimental::type_id const & type () const noexcept { return type_id_; }
82+
83+ // Check that all products selected by /other/ would satisfy this query
84+ bool match (product_query const & other) const ;
85+
86+ // Check if a product_specification satisfies this query
87+ bool match (experimental::product_specification const & spec) const ;
88+
7089 std::string to_string () const ;
7190
91+ // temporary additional members for transition
92+ experimental::product_specification spec () const ;
93+ bool operator ==(product_query const & rhs) const
94+ {
95+ return this ->spec () == rhs.spec () && this ->layer_ == rhs.layer_ ;
96+ }
97+
7298 private:
7399 std::string creator_;
74100 std::string layer_;
@@ -78,8 +104,6 @@ namespace phlex {
78104 };
79105
80106 using product_queries = std::vector<product_query>;
81- std::ostream& operator <<(std::ostream& os, product_query const & label);
82-
83107 namespace detail {
84108 // C is a container of product_queries
85109 template <typename C, typename T>
@@ -94,7 +118,7 @@ namespace phlex {
94118 template <typename T>
95119 void set_type (C& container)
96120 {
97- container.at (index_).set_type (make_type_id<T>());
121+ container.at (index_).set_type (experimental:: make_type_id<T>());
98122 ++index_;
99123 }
100124
0 commit comments