Skip to content
Merged
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
4 changes: 2 additions & 2 deletions phlex/core/declared_unfold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<product_store>(parent)},
node_name_{node_name},
node_name_{std::move(node_name)},
new_level_name_{new_level_name}
{
}
Expand Down
4 changes: 2 additions & 2 deletions phlex/core/declared_unfold.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<level_id::hash_type, std::size_t> child_counts_;
};
Expand Down
37 changes: 22 additions & 15 deletions phlex/model/product_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,49 @@ 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}
{
}

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}
{
}

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
{
Expand Down Expand Up @@ -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; }
Expand Down
23 changes: 12 additions & 11 deletions phlex/model/product_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ namespace phlex::experimental {
class product_store : public std::enable_shared_from_this<product_store> {
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;

auto begin() const noexcept { return products_.begin(); }
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;
Expand All @@ -58,26 +58,27 @@ namespace phlex::experimental {
void add_product(std::string const& key, std::unique_ptr<product<T>>&& 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_;
};

Expand Down
4 changes: 2 additions & 2 deletions test/hierarchical_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::time_t>("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);
}
Expand Down