diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model.hpp index f47b871ce..c35da97e2 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model.hpp @@ -108,10 +108,7 @@ class MainModelImpl, ComponentLis explicit MainModelImpl(double system_frequency, ConstDataset const& input_data, Idx pos = 0) : system_frequency_{system_frequency}, meta_data_{&input_data.meta_data()} { assert(input_data.get_description().dataset->name == std::string_view("input")); - auto const add_func = [this, pos, &input_data]() { - this->add_component(input_data.get_buffer_span(pos)); - }; - run_functor_with_all_types_return_void(add_func); + add_components(input_data, pos); set_construction_complete(); } @@ -158,6 +155,13 @@ class MainModelImpl, ComponentLis main_core::add_component(state_, begin, end, system_frequency_); } + void add_components(ConstDataset const& input_data, Idx pos = 0) { + auto const add_func = [this, pos, &input_data]() { + this->add_component(input_data.get_buffer_span(pos)); + }; + run_functor_with_all_types_return_void(add_func); + } + // template to update components // using forward interators // different selection based on component type diff --git a/tests/power_grid_model_static/include/power_grid_model_static/main_model_wrapper.hpp b/tests/power_grid_model_static/include/power_grid_model_static/main_model_wrapper.hpp index 3041fc38e..2566817e1 100644 --- a/tests/power_grid_model_static/include/power_grid_model_static/main_model_wrapper.hpp +++ b/tests/power_grid_model_static/include/power_grid_model_static/main_model_wrapper.hpp @@ -45,7 +45,12 @@ class MainModelWrapper { template void add_component(std::vector const& components) { add_component(std::span{components}); } - template void add_component(std::span components); + template void add_component(std::span components) { + ConstDataset dataset{false, 1, "input", meta_data::meta_data_gen::meta_data}; + dataset.add_buffer(CompType::name, components.size(), components.size(), nullptr, components.data()); + add_components(dataset); + } + template void update_component(ConstDataset const& update_data, Idx pos = 0); template MathOutput>> calculate_power_flow(Options const& options); @@ -70,6 +75,8 @@ class MainModelWrapper { private: std::unique_ptr impl_; + + void add_components(ConstDataset const& input_data, Idx pos = 0); }; } // namespace power_grid_model::pgm_static diff --git a/tests/power_grid_model_static/src/main_model_wrapper.cpp b/tests/power_grid_model_static/src/main_model_wrapper.cpp index 12a7b6e1e..f731eddd1 100644 --- a/tests/power_grid_model_static/src/main_model_wrapper.cpp +++ b/tests/power_grid_model_static/src/main_model_wrapper.cpp @@ -61,38 +61,11 @@ void MainModelWrapper::restore_components(ConstDataset const& update_data) { impl_->restore_components(impl_->get_sequence_idx_map(update_data)); } -template -void MainModelWrapper::add_component(std::span components) { +void MainModelWrapper::add_components(ConstDataset const& input_data, Idx pos) { assert(impl_ != nullptr); - impl_->add_component(components); + impl_->add_components(input_data, pos); } -template void MainModelWrapper::add_component(std::span components); -template void MainModelWrapper::add_component(std::span components); -template void MainModelWrapper::add_component(std::span components); -template void MainModelWrapper::add_component(std::span components); -template void MainModelWrapper::add_component( - std::span components); -template void MainModelWrapper::add_component(std::span components); -template void MainModelWrapper::add_component(std::span components); -template void -MainModelWrapper::add_component(std::span components); -template void -MainModelWrapper::add_component(std::span components); -template void MainModelWrapper::add_component(std::span components); -template void MainModelWrapper::add_component(std::span components); -template void -MainModelWrapper::add_component(std::span components); -template void -MainModelWrapper::add_component(std::span components); -template void -MainModelWrapper::add_component(std::span components); -template void -MainModelWrapper::add_component(std::span components); -template void MainModelWrapper::add_component(std::span components); -template void MainModelWrapper::add_component( - std::span components); - template void MainModelWrapper::update_component(ConstDataset const& update_data, Idx pos) { assert(impl_ != nullptr); impl_->update_component(update_data, pos);