diff --git a/phlex/core/declared_unfold.cpp b/phlex/core/declared_unfold.cpp index 298ea7ce..615ace95 100644 --- a/phlex/core/declared_unfold.cpp +++ b/phlex/core/declared_unfold.cpp @@ -8,10 +8,10 @@ namespace phlex::experimental { generator::generator(product_store_const_ptr const& parent, - std::string const& node_name, + std::string node_name, std::string const& new_level_name) : parent_{std::const_pointer_cast(parent)}, - node_name_{node_name}, + node_name_{std::move(node_name)}, new_level_name_{new_level_name} { } diff --git a/phlex/core/declared_unfold.hpp b/phlex/core/declared_unfold.hpp index 201f56ab..7b0477ba 100644 --- a/phlex/core/declared_unfold.hpp +++ b/phlex/core/declared_unfold.hpp @@ -36,7 +36,7 @@ namespace phlex::experimental { class generator { public: explicit generator(product_store_const_ptr const& parent, - std::string const& node_name, + std::string node_name, std::string const& new_level_name); product_store_const_ptr flush_store() const; @@ -48,7 +48,7 @@ namespace phlex::experimental { private: product_store_const_ptr make_child(std::size_t i, products new_products); product_store_ptr parent_; - std::string_view node_name_; + std::string node_name_; std::string const& new_level_name_; std::map child_counts_; }; diff --git a/phlex/model/product_store.cpp b/phlex/model/product_store.cpp index a5be9780..22823a49 100644 --- a/phlex/model/product_store.cpp +++ b/phlex/model/product_store.cpp @@ -8,13 +8,13 @@ namespace phlex::experimental { product_store::product_store(product_store_const_ptr parent, level_id_ptr id, - std::string_view source, + std::string source, stage processing_stage, products new_products) : parent_{std::move(parent)}, products_{std::move(new_products)}, id_{std::move(id)}, - source_{source}, + source_{std::move(source)}, stage_{processing_stage} { } @@ -22,12 +22,12 @@ namespace phlex::experimental { product_store::product_store(product_store_const_ptr parent, std::size_t new_level_number, std::string const& new_level_name, - std::string_view source, + std::string source, products new_products) : parent_{parent}, products_{std::move(new_products)}, id_{parent->id()->make_child(new_level_number, new_level_name)}, - source_{source}, + source_{std::move(source)}, stage_{stage::process} { } @@ -35,18 +35,22 @@ namespace phlex::experimental { product_store::product_store(product_store_const_ptr parent, std::size_t new_level_number, std::string const& new_level_name, - std::string_view source, + std::string source, stage processing_stage) : parent_{parent}, id_{parent->id()->make_child(new_level_number, new_level_name)}, - source_{source}, + source_{std::move(source)}, stage_{processing_stage} { } product_store::~product_store() = default; - product_store_ptr product_store::base() { return product_store_ptr{new product_store}; } + product_store_ptr product_store::base(std::string base_name) + { + return product_store_ptr{ + new product_store{nullptr, level_id::base_ptr(), std::move(base_name)}}; + } product_store_const_ptr product_store::parent(std::string const& level_name) const noexcept { @@ -77,33 +81,36 @@ namespace phlex::experimental { return product_store_ptr{new product_store{parent_, id_, "[inserted]", stage::flush}}; } - product_store_ptr product_store::make_continuation(std::string_view source, + product_store_ptr product_store::make_continuation(std::string source, products new_products) const { return product_store_ptr{ - new product_store{parent_, id_, source, stage::process, std::move(new_products)}}; + new product_store{parent_, id_, std::move(source), stage::process, std::move(new_products)}}; } product_store_ptr product_store::make_child(std::size_t new_level_number, std::string const& new_level_name, - std::string_view source, + std::string source, products new_products) { - return product_store_ptr{new product_store{ - shared_from_this(), new_level_number, new_level_name, source, std::move(new_products)}}; + return product_store_ptr{new product_store{shared_from_this(), + new_level_number, + new_level_name, + std::move(source), + std::move(new_products)}}; } product_store_ptr product_store::make_child(std::size_t new_level_number, std::string const& new_level_name, - std::string_view source, + std::string source, stage processing_stage) { return product_store_ptr{new product_store{ - shared_from_this(), new_level_number, new_level_name, source, processing_stage}}; + shared_from_this(), new_level_number, new_level_name, std::move(source), processing_stage}}; } std::string const& product_store::level_name() const noexcept { return id_->level_name(); } - std::string_view product_store::source() const noexcept { return source_; } + std::string const& product_store::source() const noexcept { return source_; } product_store_const_ptr product_store::parent() const noexcept { return parent_; } level_id_ptr const& product_store::id() const noexcept { return id_; } bool product_store::is_flush() const noexcept { return stage_ == stage::flush; } diff --git a/phlex/model/product_store.hpp b/phlex/model/product_store.hpp index 1aed24cc..c0060902 100644 --- a/phlex/model/product_store.hpp +++ b/phlex/model/product_store.hpp @@ -17,7 +17,7 @@ namespace phlex::experimental { class product_store : public std::enable_shared_from_this { public: ~product_store(); - static product_store_ptr base(); + static product_store_ptr base(std::string base_name = "Source"); product_store_const_ptr store_for_product(std::string const& product_name) const; @@ -25,18 +25,18 @@ namespace phlex::experimental { auto end() const noexcept { return products_.end(); } std::string const& level_name() const noexcept; - std::string_view source() const noexcept; // FIXME: Think carefully of using std::string_view + std::string const& source() const noexcept; product_store_const_ptr parent(std::string const& level_name) const noexcept; product_store_const_ptr parent() const noexcept; product_store_ptr make_flush() const; - product_store_ptr make_continuation(std::string_view source, products new_products = {}) const; + product_store_ptr make_continuation(std::string source, products new_products = {}) const; product_store_ptr make_child(std::size_t new_level_number, std::string const& new_level_name, - std::string_view source, + std::string source, products new_products); product_store_ptr make_child(std::size_t new_level_number, std::string const& new_level_name, - std::string_view source = {}, + std::string source = {}, stage st = stage::process); level_id_ptr const& id() const noexcept; bool is_flush() const noexcept; @@ -58,26 +58,27 @@ namespace phlex::experimental { void add_product(std::string const& key, std::unique_ptr>&& t); private: - explicit product_store(product_store_const_ptr parent = nullptr, - level_id_ptr id = level_id::base_ptr(), - std::string_view source = {}, + explicit product_store(product_store_const_ptr parent, + level_id_ptr id, + std::string source, stage processing_stage = stage::process, products new_products = {}); explicit product_store(product_store_const_ptr parent, std::size_t new_level_number, std::string const& new_level_name, - std::string_view source, + std::string source, products new_products); explicit product_store(product_store_const_ptr parent, std::size_t new_level_number, std::string const& new_level_name, - std::string_view source, + std::string source, stage processing_stage); product_store_const_ptr parent_{nullptr}; products products_{}; level_id_ptr id_; - std::string_view source_; + std::string + source_; // FIXME: Should not have to copy the string (the source should outlive the product store) stage stage_; }; diff --git a/test/hierarchical_nodes.cpp b/test/hierarchical_nodes.cpp index c72d81e1..588d618b 100644 --- a/test/hierarchical_nodes.cpp +++ b/test/hierarchical_nodes.cpp @@ -43,11 +43,11 @@ namespace { auto job_store = product_store::base(); driver.yield(job_store); for (unsigned i : std::views::iota(0u, index_limit)) { - auto run_store = job_store->make_child(i, "run"); + auto run_store = job_store->make_child(i, "run", "levels_to_process"); run_store->add_product("time", std::time(nullptr)); driver.yield(run_store); for (unsigned j : std::views::iota(0u, number_limit)) { - auto event_store = run_store->make_child(j, "event"); + auto event_store = run_store->make_child(j, "event", "levels_to_process"); event_store->add_product("number", i + j); driver.yield(event_store); }