From c09d443a234957ebfa6c9ed05a164b2e00acc84b Mon Sep 17 00:00:00 2001 From: Tony Xiang Date: Sun, 29 Sep 2024 10:27:37 +0200 Subject: [PATCH 1/8] remove static in buffer Signed-off-by: Tony Xiang --- .../include/power_grid_model_cpp/buffer.hpp | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/buffer.hpp b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/buffer.hpp index c4f9cd7ca..a32ca05e7 100644 --- a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/buffer.hpp +++ b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/buffer.hpp @@ -21,43 +21,32 @@ class Buffer { Idx size() const { return size_; } - static void set_nan(Buffer& buffer, Idx buffer_offset, Idx size) { - buffer.handle_.call_with(PGM_buffer_set_nan, buffer.component_, buffer.buffer_.get(), buffer_offset, size); + void set_nan() { set_nan(0, size_); } + void set_nan(Idx buffer_offset) { set_nan(buffer_offset, 1); } + void set_nan(Idx buffer_offset, Idx size) { + handle_.call_with(PGM_buffer_set_nan, component_, buffer_.get(), buffer_offset, size); } - void set_nan() { set_nan(*this, 0, size_); } - void set_nan(Idx buffer_offset) { set_nan(*this, buffer_offset, 1); } - void set_nan(Idx buffer_offset, Idx size) { set_nan(*this, buffer_offset, size); } - static void set_value(MetaAttribute const* attribute, Buffer& buffer, // NOSONAR: no reference-to-const - RawDataConstPtr src_ptr, Idx buffer_offset, Idx size, Idx src_stride) { - buffer.handle_.call_with(PGM_buffer_set_value, attribute, buffer.buffer_.get(), src_ptr, buffer_offset, size, - src_stride); - } void set_value(MetaAttribute const* attribute, RawDataConstPtr src_ptr, Idx src_stride) { - set_value(attribute, *this, src_ptr, 0, size_, src_stride); + set_value(attribute, src_ptr, 0, size_, src_stride); } void set_value(MetaAttribute const* attribute, RawDataConstPtr src_ptr, Idx buffer_offset, Idx src_stride) { - set_value(attribute, *this, src_ptr, buffer_offset, 1, src_stride); + set_value(attribute, src_ptr, buffer_offset, 1, src_stride); } void set_value(MetaAttribute const* attribute, RawDataConstPtr src_ptr, Idx buffer_offset, Idx size, Idx src_stride) { - set_value(attribute, *this, src_ptr, buffer_offset, size, src_stride); + handle_.call_with(PGM_buffer_set_value, attribute, buffer_.get(), src_ptr, buffer_offset, size, src_stride); } - static void get_value(MetaAttribute const* attribute, Buffer const& buffer, RawDataPtr dest_ptr, Idx buffer_offset, - Idx size, Idx dest_stride) { - buffer.handle_.call_with(PGM_buffer_get_value, attribute, buffer.buffer_.get(), dest_ptr, buffer_offset, size, - dest_stride); - } void get_value(MetaAttribute const* attribute, RawDataPtr dest_ptr, Idx dest_stride) const { - get_value(attribute, *this, dest_ptr, 0, size_, dest_stride); + get_value(attribute, dest_ptr, 0, size_, dest_stride); } void get_value(MetaAttribute const* attribute, RawDataPtr dest_ptr, Idx buffer_offset, Idx dest_stride) const { - get_value(attribute, *this, dest_ptr, buffer_offset, 1, dest_stride); + get_value(attribute, dest_ptr, buffer_offset, 1, dest_stride); } void get_value(MetaAttribute const* attribute, RawDataPtr dest_ptr, Idx buffer_offset, Idx size, Idx dest_stride) const { - get_value(attribute, *this, dest_ptr, buffer_offset, size, dest_stride); + handle_.call_with(PGM_buffer_get_value, attribute, buffer_.get(), dest_ptr, buffer_offset, size, dest_stride); } private: From d327ac7fa11bf757e0d13bbf2f9af8e57823893a Mon Sep 17 00:00:00 2001 From: Tony Xiang Date: Sun, 29 Sep 2024 10:31:57 +0200 Subject: [PATCH 2/8] remove static in dataset Signed-off-by: Tony Xiang --- .../include/power_grid_model_cpp/dataset.hpp | 141 +++++------------- 1 file changed, 34 insertions(+), 107 deletions(-) diff --git a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/dataset.hpp b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/dataset.hpp index 039860304..5fa0dc52e 100644 --- a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/dataset.hpp +++ b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/dataset.hpp @@ -23,42 +23,25 @@ class DatasetInfo { DatasetInfo& operator=(const DatasetInfo&) = delete; // No copy assignment ~DatasetInfo() = default; - static std::string name(DatasetInfo const& info) { - return std::string{info.handle_.call_with(PGM_dataset_info_name, info.info_)}; - } - std::string name() const { return name(*this); } + std::string name() const { return std::string{handle_.call_with(PGM_dataset_info_name, info_)}; } - static Idx is_batch(DatasetInfo const& info) { - return info.handle_.call_with(PGM_dataset_info_is_batch, info.info_); - } - Idx is_batch() const { return is_batch(*this); } + Idx is_batch() const { return handle_.call_with(PGM_dataset_info_is_batch, info_); } - static Idx batch_size(DatasetInfo const& info) { - return info.handle_.call_with(PGM_dataset_info_batch_size, info.info_); - } - Idx batch_size() const { return batch_size(*this); } + Idx batch_size() const { return handle_.call_with(PGM_dataset_info_batch_size, info_); } - static Idx n_components(DatasetInfo const& info) { - return info.handle_.call_with(PGM_dataset_info_n_components, info.info_); - } - Idx n_components() const { return n_components(*this); } + Idx n_components() const { return handle_.call_with(PGM_dataset_info_n_components, info_); } - static std::string component_name(DatasetInfo const& info, Idx component_idx) { - return std::string{info.handle_.call_with(PGM_dataset_info_component_name, info.info_, component_idx)}; + std::string component_name(Idx component_idx) const { + return std::string{handle_.call_with(PGM_dataset_info_component_name, info_, component_idx)}; } - std::string component_name(Idx component_idx) const { return component_name(*this, component_idx); } - static Idx component_elements_per_scenario(DatasetInfo const& info, Idx component_idx) { - return info.handle_.call_with(PGM_dataset_info_elements_per_scenario, info.info_, component_idx); - } Idx component_elements_per_scenario(Idx component_idx) const { - return component_elements_per_scenario(*this, component_idx); + return handle_.call_with(PGM_dataset_info_elements_per_scenario, info_, component_idx); } - static Idx component_total_elements(DatasetInfo const& info, Idx component_idx) { - return info.handle_.call_with(PGM_dataset_info_total_elements, info.info_, component_idx); + Idx component_total_elements(Idx component_idx) const { + return handle_.call_with(PGM_dataset_info_total_elements, info_, component_idx); } - Idx component_total_elements(Idx component_idx) const { return component_total_elements(*this, component_idx); } private: Handle handle_{}; @@ -77,42 +60,24 @@ class DatasetWritable { RawWritableDataset* get() const { return dataset_; } - static DatasetInfo const& get_info(DatasetWritable const& dataset) { return dataset.info_; } - DatasetInfo const& get_info() const { return get_info(*this); } + DatasetInfo const& get_info() const { return info_; } - static void set_buffer(DatasetWritable& dataset, // NOSONAR: no reference-to-const - std::string const& component, Idx* indptr, RawDataPtr data) { - dataset.handle_.call_with(PGM_dataset_writable_set_buffer, dataset.dataset_, component.c_str(), indptr, data); - } void set_buffer(std::string const& component, Idx* indptr, RawDataPtr data) { - set_buffer(*this, component, indptr, data); + handle_.call_with(PGM_dataset_writable_set_buffer, dataset_, component.c_str(), indptr, data); } - static void set_buffer(DatasetWritable& dataset, // NOSONAR: no reference-to-const - std::string const& component, Idx* indptr, Buffer const& data) { - dataset.handle_.call_with(PGM_dataset_writable_set_buffer, dataset.dataset_, component.c_str(), indptr, - data.get()); - } void set_buffer(std::string const& component, Idx* indptr, Buffer const& data) { - set_buffer(*this, component, indptr, data); + handle_.call_with(PGM_dataset_writable_set_buffer, dataset_, component.c_str(), indptr, data.get()); } - static void set_attribute_buffer(DatasetWritable& dataset, // NOSONAR: no reference-to-const - std::string const& component, std::string const& attribute, RawDataPtr data) { - dataset.handle_.call_with(PGM_dataset_writable_set_attribute_buffer, dataset.dataset_, component.c_str(), - attribute.c_str(), data); - } void set_attribute_buffer(std::string const& component, std::string const& attribute, RawDataPtr data) { - set_attribute_buffer(*this, component, attribute, data); + handle_.call_with(PGM_dataset_writable_set_attribute_buffer, dataset_, component.c_str(), attribute.c_str(), + data); } - static void set_attribute_buffer(DatasetWritable& dataset, // NOSONAR: no reference-to-const - std::string const& component, std::string const& attribute, Buffer const& data) { - dataset.handle_.call_with(PGM_dataset_writable_set_attribute_buffer, dataset.dataset_, component.c_str(), - attribute.c_str(), data.get()); - } void set_attribute_buffer(std::string const& component, std::string const& attribute, Buffer const& data) { - set_attribute_buffer(*this, component, attribute, data); + handle_.call_with(PGM_dataset_writable_set_attribute_buffer, dataset_, component.c_str(), attribute.c_str(), + data.get()); } private: @@ -129,48 +94,29 @@ class DatasetMutable { RawMutableDataset* get() const { return dataset_.get(); } - static void add_buffer(DatasetMutable& dataset, // NOSONAR: no reference-to-const - std::string const& component, Idx elements_per_scenario, Idx total_elements, - Idx const* indptr, RawDataPtr data) { - dataset.handle_.call_with(PGM_dataset_mutable_add_buffer, dataset.dataset_.get(), component.c_str(), - elements_per_scenario, total_elements, indptr, data); - } void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr, RawDataPtr data) { - add_buffer(*this, component, elements_per_scenario, total_elements, indptr, data); + handle_.call_with(PGM_dataset_mutable_add_buffer, dataset_.get(), component.c_str(), elements_per_scenario, + total_elements, indptr, data); } - static void add_buffer(DatasetMutable& dataset, // NOSONAR: no reference-to-const - std::string const& component, Idx elements_per_scenario, Idx total_elements, - Idx const* indptr, Buffer const& data) { - dataset.handle_.call_with(PGM_dataset_mutable_add_buffer, dataset.dataset_.get(), component.c_str(), - elements_per_scenario, total_elements, indptr, data.get()); - } void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr, Buffer const& data) { - add_buffer(*this, component, elements_per_scenario, total_elements, indptr, data); + handle_.call_with(PGM_dataset_mutable_add_buffer, dataset_.get(), component.c_str(), elements_per_scenario, + total_elements, indptr, data.get()); } - static void add_attribute_buffer(DatasetMutable& dataset, // NOSONAR: no reference-to-const - std::string const& component, std::string const& attribute, RawDataPtr data) { - dataset.handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, dataset.dataset_.get(), component.c_str(), - attribute.c_str(), data); - } void add_attribute_buffer(std::string const& component, std::string const& attribute, RawDataPtr data) { - add_attribute_buffer(*this, component, attribute, data); + handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, dataset_.get(), component.c_str(), + attribute.c_str(), data); } - static void add_attribute_buffer(DatasetMutable& dataset, // NOSONAR: no reference-to-const - std::string const& component, std::string const& attribute, Buffer const& data) { - dataset.handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, dataset.dataset_.get(), component.c_str(), - attribute.c_str(), data.get()); - } void add_attribute_buffer(std::string const& component, std::string const& attribute, Buffer const& data) { - add_attribute_buffer(*this, component, attribute, data); + handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, dataset_.get(), component.c_str(), + attribute.c_str(), data.get()); } - static DatasetInfo const& get_info(DatasetMutable const& dataset) { return dataset.info_; } - DatasetInfo const& get_info() const { return get_info(*this); } + DatasetInfo const& get_info() const { return info_; } private: Handle handle_{}; @@ -192,48 +138,29 @@ class DatasetConst { RawConstDataset* get() const { return dataset_.get(); } - static void add_buffer(DatasetConst& dataset, // NOSONAR: no reference-to-const - std::string const& component, Idx elements_per_scenario, Idx total_elements, - Idx const* indptr, RawDataConstPtr data) { - dataset.handle_.call_with(PGM_dataset_const_add_buffer, dataset.dataset_.get(), component.c_str(), - elements_per_scenario, total_elements, indptr, data); - } void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr, RawDataConstPtr data) { - add_buffer(*this, component, elements_per_scenario, total_elements, indptr, data); + handle_.call_with(PGM_dataset_const_add_buffer, dataset_.get(), component.c_str(), elements_per_scenario, + total_elements, indptr, data); } - static void add_buffer(DatasetConst& dataset, // NOSONAR: no reference-to-const - std::string const& component, Idx elements_per_scenario, Idx total_elements, - Idx const* indptr, Buffer const& data) { - dataset.handle_.call_with(PGM_dataset_const_add_buffer, dataset.dataset_.get(), component.c_str(), - elements_per_scenario, total_elements, indptr, data.get()); - } void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr, Buffer const& data) { - add_buffer(*this, component, elements_per_scenario, total_elements, indptr, data); + handle_.call_with(PGM_dataset_const_add_buffer, dataset_.get(), component.c_str(), elements_per_scenario, + total_elements, indptr, data.get()); } - static void add_attribute_buffer(DatasetConst& dataset, // NOSONAR: no reference-to-const - std::string const& component, std::string const& attribute, RawDataConstPtr data) { - dataset.handle_.call_with(PGM_dataset_const_add_attribute_buffer, dataset.dataset_.get(), component.c_str(), - attribute.c_str(), data); - } void add_attribute_buffer(std::string const& component, std::string const& attribute, RawDataConstPtr data) { - add_attribute_buffer(*this, component, attribute, data); + handle_.call_with(PGM_dataset_const_add_attribute_buffer, dataset_.get(), component.c_str(), attribute.c_str(), + data); } - static void add_attribute_buffer(DatasetConst& dataset, // NOSONAR: no reference-to-const - std::string const& component, std::string const& attribute, Buffer const& data) { - dataset.handle_.call_with(PGM_dataset_const_add_attribute_buffer, dataset.dataset_.get(), component.c_str(), - attribute.c_str(), data.get()); - } void add_attribute_buffer(std::string const& component, std::string const& attribute, Buffer const& data) { - add_attribute_buffer(*this, component, attribute, data); + handle_.call_with(PGM_dataset_const_add_attribute_buffer, dataset_.get(), component.c_str(), attribute.c_str(), + data.get()); } - static DatasetInfo const& get_info(DatasetConst const& dataset) { return dataset.info_; } - DatasetInfo const& get_info() const { return get_info(*this); } + DatasetInfo const& get_info() const { return info_; } private: Handle handle_{}; From 36943f3488c35718630cd262c521dd917a554c07 Mon Sep 17 00:00:00 2001 From: Tony Xiang Date: Sun, 29 Sep 2024 10:33:51 +0200 Subject: [PATCH 3/8] remove static in handle Signed-off-by: Tony Xiang --- .../include/power_grid_model_cpp/handle.hpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/handle.hpp b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/handle.hpp index 84ec8283b..f32686d4e 100644 --- a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/handle.hpp +++ b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/handle.hpp @@ -53,18 +53,17 @@ class Handle { public: RawHandle* get() const { return handle_.get(); } - static void clear_error(Handle const& handle) { PGM_clear_error(handle.get()); } - void clear_error() const { clear_error(*this); } + void clear_error() const { PGM_clear_error(get()); } - static void check_error(Handle const& handle) { - RawHandle const* handle_ptr = handle.get(); + void check_error() const { + RawHandle const* handle_ptr = get(); Idx const error_code = PGM_error_code(handle_ptr); std::string const error_message = error_code == PGM_no_error ? "" : PGM_error_message(handle_ptr); switch (error_code) { case PGM_no_error: return; case PGM_regular_error: - Handle::clear_error(handle); + clear_error(); throw PowerGridRegularError{error_message}; case PGM_batch_error: { Idx const n_failed_scenarios = PGM_n_failed_scenarios(handle_ptr); @@ -75,18 +74,17 @@ class Handle { failed_scenarios[i] = PowerGridBatchError::FailedScenario{failed_scenario_seqs[i], failed_scenario_messages[i]}; } - Handle::clear_error(handle); + clear_error(); throw PowerGridBatchError{error_message, std::move(failed_scenarios)}; } case PGM_serialization_error: - Handle::clear_error(handle); + clear_error(); throw PowerGridSerializationError{error_message}; default: - Handle::clear_error(handle); + clear_error(); throw PowerGridError{error_message}; } } - void check_error() const { check_error(*this); } template auto call_with(Func&& func, Args&&... args) const { if constexpr (std::is_void_v(func)(get(), std::forward(args)...))>) { From 90a2b92118759436a67cc7c7f814f5b78965d9cc Mon Sep 17 00:00:00 2001 From: Tony Xiang Date: Sun, 29 Sep 2024 10:36:05 +0200 Subject: [PATCH 4/8] remove static in model Signed-off-by: Tony Xiang --- .../include/power_grid_model_cpp/model.hpp | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/model.hpp b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/model.hpp index b6d6e294a..03455cefa 100644 --- a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/model.hpp +++ b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/model.hpp @@ -37,32 +37,20 @@ class Model { PowerGridModel* get() const { return model_.get(); } - static void update(Model const& model, DatasetConst const& update_dataset) { - model.handle_.call_with(PGM_update_model, model.get(), update_dataset.get()); - } - void update(DatasetConst const& update_dataset) const { update(*this, update_dataset); } - - static void get_indexer(Model const& model, std::string const& component, Idx size, ID const* ids, Idx* indexer) { - model.handle_.call_with(PGM_get_indexer, model.get(), component.c_str(), size, ids, indexer); + void update(DatasetConst const& update_dataset) const { + handle_.call_with(PGM_update_model, model_.get(), update_dataset.get()); } void get_indexer(std::string const& component, Idx size, ID const* ids, Idx* indexer) const { - get_indexer(*this, component, size, ids, indexer); + handle_.call_with(PGM_get_indexer, model_.get(), component.c_str(), size, ids, indexer); } - static void calculate(Model const& model, Options const& opt, DatasetMutable const& output_dataset, - DatasetConst const& batch_dataset) { - model.handle_.call_with(PGM_calculate, model.get(), opt.get(), output_dataset.get(), batch_dataset.get()); - } void calculate(Options const& opt, DatasetMutable const& output_dataset, DatasetConst const& batch_dataset) const { - calculate(*this, opt, output_dataset, batch_dataset); + handle_.call_with(PGM_calculate, model_.get(), opt.get(), output_dataset.get(), batch_dataset.get()); } - static void calculate(Model const& model, Options const& opt, DatasetMutable const& output_dataset) { - model.handle_.call_with(PGM_calculate, model.get(), opt.get(), output_dataset.get(), nullptr); - } void calculate(Options const& opt, DatasetMutable const& output_dataset) const { - calculate(*this, opt, output_dataset); + handle_.call_with(PGM_calculate, model_.get(), opt.get(), output_dataset.get(), nullptr); } private: From 90fc9ab6936b21db85c28a8932cf4b08ab68fe60 Mon Sep 17 00:00:00 2001 From: Tony Xiang Date: Sun, 29 Sep 2024 10:37:35 +0200 Subject: [PATCH 5/8] remove static in options Signed-off-by: Tony Xiang --- .../include/power_grid_model_cpp/options.hpp | 45 ++++--------------- 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/options.hpp b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/options.hpp index 2d81d2555..e72bab95e 100644 --- a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/options.hpp +++ b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/options.hpp @@ -18,55 +18,28 @@ class Options { RawOptions* get() const { return options_.get(); } - static void set_calculation_type(Options const& options, Idx type) { - options.handle_.call_with(PGM_set_calculation_type, options.get(), type); - } - void set_calculation_type(Idx type) const { set_calculation_type(*this, type); } + void set_calculation_type(Idx type) const { handle_.call_with(PGM_set_calculation_type, get(), type); } - static void set_calculation_method(Options const& options, Idx method) { - options.handle_.call_with(PGM_set_calculation_method, options.get(), method); - } - void set_calculation_method(Idx method) const { set_calculation_method(*this, method); } + void set_calculation_method(Idx method) const { handle_.call_with(PGM_set_calculation_method, get(), method); } - static void set_symmetric(Options const& options, Idx sym) { - options.handle_.call_with(PGM_set_symmetric, options.get(), sym); - } - void set_symmetric(Idx sym) const { set_symmetric(*this, sym); } + void set_symmetric(Idx sym) const { handle_.call_with(PGM_set_symmetric, get(), sym); } - static void set_err_tol(Options const& options, double err_tol) { - options.handle_.call_with(PGM_set_err_tol, options.get(), err_tol); - } - void set_err_tol(double err_tol) const { set_err_tol(*this, err_tol); } + void set_err_tol(double err_tol) const { handle_.call_with(PGM_set_err_tol, get(), err_tol); } - static void set_max_iter(Options const& options, Idx max_iter) { - options.handle_.call_with(PGM_set_max_iter, options.get(), max_iter); - } - void set_max_iter(Idx max_iter) const { set_max_iter(*this, max_iter); } + void set_max_iter(Idx max_iter) const { handle_.call_with(PGM_set_max_iter, get(), max_iter); } - static void set_threading(Options const& options, Idx threading) { - options.handle_.call_with(PGM_set_threading, options.get(), threading); - } - void set_threading(Idx threading) const { set_threading(*this, threading); } + void set_threading(Idx threading) const { handle_.call_with(PGM_set_threading, get(), threading); } - static void set_short_circuit_voltage_scaling(Options const& options, Idx short_circuit_voltage_scaling) { - options.handle_.call_with(PGM_set_short_circuit_voltage_scaling, options.get(), short_circuit_voltage_scaling); - } void set_short_circuit_voltage_scaling(Idx short_circuit_voltage_scaling) const { - set_short_circuit_voltage_scaling(*this, short_circuit_voltage_scaling); + handle_.call_with(PGM_set_short_circuit_voltage_scaling, get(), short_circuit_voltage_scaling); } - static void set_tap_changing_strategy(Options const& options, Idx tap_changing_strategy) { - options.handle_.call_with(PGM_set_tap_changing_strategy, options.get(), tap_changing_strategy); - } void set_tap_changing_strategy(Idx tap_changing_strategy) const { - set_tap_changing_strategy(*this, tap_changing_strategy); + handle_.call_with(PGM_set_tap_changing_strategy, get(), tap_changing_strategy); } - static void set_experimental_features(Options const& options, Idx experimental_features) { - options.handle_.call_with(PGM_set_experimental_features, options.get(), experimental_features); - } void set_experimental_features(Idx experimental_features) const { - set_experimental_features(*this, experimental_features); + handle_.call_with(PGM_set_experimental_features, get(), experimental_features); } private: From 012fef8e42ab1bdc0796904c600652d172c301ad Mon Sep 17 00:00:00 2001 From: Tony Xiang Date: Sun, 29 Sep 2024 10:39:20 +0200 Subject: [PATCH 6/8] remove static in serialization Signed-off-by: Tony Xiang --- .../power_grid_model_cpp/serialization.hpp | 37 +++++-------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/serialization.hpp b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/serialization.hpp index 9a0b4b808..0035c9682 100644 --- a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/serialization.hpp +++ b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/serialization.hpp @@ -33,13 +33,9 @@ class Deserializer { RawDeserializer* get() const { return deserializer_.get(); } - static DatasetWritable& get_dataset(Deserializer& deserializer) { return deserializer.dataset_; } - DatasetWritable& get_dataset() { return get_dataset(*this); } + DatasetWritable& get_dataset() { return dataset_; } - static void parse_to_buffer(Deserializer const& deserializer) { - deserializer.handle_.call_with(PGM_deserializer_parse_to_buffer, deserializer.get()); - } - void parse_to_buffer() const { parse_to_buffer(*this); } + void parse_to_buffer() const { handle_.call_with(PGM_deserializer_parse_to_buffer, get()); } private: Handle handle_{}; @@ -54,22 +50,18 @@ class Serializer { RawSerializer* get() const { return serializer_.get(); } - static std::string_view get_to_binary_buffer(Serializer const& serializer, Idx use_compact_list) { + std::string_view get_to_binary_buffer(Idx use_compact_list) const { char const* temp_data{}; Idx buffer_size{}; - serializer.handle_.call_with(PGM_serializer_get_to_binary_buffer, serializer.get(), use_compact_list, - &temp_data, &buffer_size); + handle_.call_with(PGM_serializer_get_to_binary_buffer, get(), use_compact_list, &temp_data, &buffer_size); if (temp_data == nullptr) { return std::string_view{}; } // empty data return std::string_view{temp_data, static_cast(buffer_size)}; } - std::string_view get_to_binary_buffer(Idx use_compact_list) const { - return get_to_binary_buffer(*this, use_compact_list); - } - static void get_to_binary_buffer(Serializer const& serializer, Idx use_compact_list, std::vector& data) { - auto temp_data = get_to_binary_buffer(serializer, use_compact_list); + void get_to_binary_buffer(Idx use_compact_list, std::vector& data) const { + auto temp_data = get_to_binary_buffer(use_compact_list); if (!temp_data.empty()) { data.resize(temp_data.size()); std::memcpy(data.data(), temp_data.data(), temp_data.size()); @@ -77,28 +69,19 @@ class Serializer { data.resize(0); // empty data } } - void get_to_binary_buffer(Idx use_compact_list, std::vector& data) const { - get_to_binary_buffer(*this, use_compact_list, data); - } - static void get_to_binary_buffer(Serializer const& serializer, Idx use_compact_list, std::vector& data) { - auto temp_data = get_to_binary_buffer(serializer, use_compact_list); + void get_to_binary_buffer(Idx use_compact_list, std::vector& data) const { + auto temp_data = get_to_binary_buffer(use_compact_list); if (!temp_data.empty()) { data.assign(temp_data.begin(), temp_data.end()); } else { data.resize(0); // empty data } } - void get_to_binary_buffer(Idx use_compact_list, std::vector& data) const { - get_to_binary_buffer(*this, use_compact_list, data); - } - static std::string get_to_zero_terminated_string(Serializer const& serializer, Idx use_compact_list, Idx indent) { - return std::string{serializer.handle_.call_with(PGM_serializer_get_to_zero_terminated_string, serializer.get(), - use_compact_list, indent)}; - } std::string get_to_zero_terminated_string(Idx use_compact_list, Idx indent) const { - return get_to_zero_terminated_string(*this, use_compact_list, indent); + return std::string{ + handle_.call_with(PGM_serializer_get_to_zero_terminated_string, get(), use_compact_list, indent)}; } private: From 4fb4259b9bf38a2456a46a8ae6d42618cde94582 Mon Sep 17 00:00:00 2001 From: Martijn Govers Date: Mon, 30 Sep 2024 08:26:02 +0200 Subject: [PATCH 7/8] suppress sonar cloud warnings Signed-off-by: Martijn Govers --- .../include/power_grid_model_cpp/buffer.hpp | 2 +- .../include/power_grid_model_cpp/dataset.hpp | 20 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/buffer.hpp b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/buffer.hpp index a32ca05e7..722b4b457 100644 --- a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/buffer.hpp +++ b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/buffer.hpp @@ -34,7 +34,7 @@ class Buffer { set_value(attribute, src_ptr, buffer_offset, 1, src_stride); } void set_value(MetaAttribute const* attribute, RawDataConstPtr src_ptr, Idx buffer_offset, Idx size, - Idx src_stride) { + Idx src_stride) { // NOSONAR: no const handle_.call_with(PGM_buffer_set_value, attribute, buffer_.get(), src_ptr, buffer_offset, size, src_stride); } diff --git a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/dataset.hpp b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/dataset.hpp index 5fa0dc52e..495727de9 100644 --- a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/dataset.hpp +++ b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/dataset.hpp @@ -95,23 +95,25 @@ class DatasetMutable { RawMutableDataset* get() const { return dataset_.get(); } void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr, - RawDataPtr data) { + RawDataPtr data) { // NOSONAR: no const handle_.call_with(PGM_dataset_mutable_add_buffer, dataset_.get(), component.c_str(), elements_per_scenario, total_elements, indptr, data); } void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr, - Buffer const& data) { + Buffer const& data) { // NOSONAR: no const handle_.call_with(PGM_dataset_mutable_add_buffer, dataset_.get(), component.c_str(), elements_per_scenario, total_elements, indptr, data.get()); } - void add_attribute_buffer(std::string const& component, std::string const& attribute, RawDataPtr data) { + void add_attribute_buffer(std::string const& component, std::string const& attribute, + RawDataPtr data) { // NOSONAR: no const handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, dataset_.get(), component.c_str(), attribute.c_str(), data); } - void add_attribute_buffer(std::string const& component, std::string const& attribute, Buffer const& data) { + void add_attribute_buffer(std::string const& component, std::string const& attribute, + Buffer const& data) { // NOSONAR: no const handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, dataset_.get(), component.c_str(), attribute.c_str(), data.get()); } @@ -139,23 +141,25 @@ class DatasetConst { RawConstDataset* get() const { return dataset_.get(); } void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr, - RawDataConstPtr data) { + RawDataConstPtr data) { // NOSONAR: no const handle_.call_with(PGM_dataset_const_add_buffer, dataset_.get(), component.c_str(), elements_per_scenario, total_elements, indptr, data); } void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr, - Buffer const& data) { + Buffer const& data) { // NOSONAR: no const handle_.call_with(PGM_dataset_const_add_buffer, dataset_.get(), component.c_str(), elements_per_scenario, total_elements, indptr, data.get()); } - void add_attribute_buffer(std::string const& component, std::string const& attribute, RawDataConstPtr data) { + void add_attribute_buffer(std::string const& component, std::string const& attribute, + RawDataConstPtr data) { // NOSONAR: no const handle_.call_with(PGM_dataset_const_add_attribute_buffer, dataset_.get(), component.c_str(), attribute.c_str(), data); } - void add_attribute_buffer(std::string const& component, std::string const& attribute, Buffer const& data) { + void add_attribute_buffer(std::string const& component, std::string const& attribute, + Buffer const& data) { // NOSONAR: no const handle_.call_with(PGM_dataset_const_add_attribute_buffer, dataset_.get(), component.c_str(), attribute.c_str(), data.get()); } From c5b7e6d5f0b473f62347a788570b913ec8874060 Mon Sep 17 00:00:00 2001 From: Martijn Govers Date: Mon, 30 Sep 2024 08:40:15 +0200 Subject: [PATCH 8/8] minor fix Signed-off-by: Martijn Govers --- .../include/power_grid_model_cpp/buffer.hpp | 2 +- .../include/power_grid_model_cpp/dataset.hpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/buffer.hpp b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/buffer.hpp index 722b4b457..890060c80 100644 --- a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/buffer.hpp +++ b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/buffer.hpp @@ -34,7 +34,7 @@ class Buffer { set_value(attribute, src_ptr, buffer_offset, 1, src_stride); } void set_value(MetaAttribute const* attribute, RawDataConstPtr src_ptr, Idx buffer_offset, Idx size, - Idx src_stride) { // NOSONAR: no const + Idx src_stride) { // NOSONAR: no-const handle_.call_with(PGM_buffer_set_value, attribute, buffer_.get(), src_ptr, buffer_offset, size, src_stride); } diff --git a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/dataset.hpp b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/dataset.hpp index 495727de9..7caf14043 100644 --- a/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/dataset.hpp +++ b/power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/dataset.hpp @@ -95,25 +95,25 @@ class DatasetMutable { RawMutableDataset* get() const { return dataset_.get(); } void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr, - RawDataPtr data) { // NOSONAR: no const + RawDataPtr data) { // NOSONAR: no-const handle_.call_with(PGM_dataset_mutable_add_buffer, dataset_.get(), component.c_str(), elements_per_scenario, total_elements, indptr, data); } void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr, - Buffer const& data) { // NOSONAR: no const + Buffer const& data) { // NOSONAR: no-const handle_.call_with(PGM_dataset_mutable_add_buffer, dataset_.get(), component.c_str(), elements_per_scenario, total_elements, indptr, data.get()); } void add_attribute_buffer(std::string const& component, std::string const& attribute, - RawDataPtr data) { // NOSONAR: no const + RawDataPtr data) { // NOSONAR: no-const handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, dataset_.get(), component.c_str(), attribute.c_str(), data); } void add_attribute_buffer(std::string const& component, std::string const& attribute, - Buffer const& data) { // NOSONAR: no const + Buffer const& data) { // NOSONAR: no-const handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, dataset_.get(), component.c_str(), attribute.c_str(), data.get()); } @@ -141,25 +141,25 @@ class DatasetConst { RawConstDataset* get() const { return dataset_.get(); } void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr, - RawDataConstPtr data) { // NOSONAR: no const + RawDataConstPtr data) { // NOSONAR: no-const handle_.call_with(PGM_dataset_const_add_buffer, dataset_.get(), component.c_str(), elements_per_scenario, total_elements, indptr, data); } void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr, - Buffer const& data) { // NOSONAR: no const + Buffer const& data) { // NOSONAR: no-const handle_.call_with(PGM_dataset_const_add_buffer, dataset_.get(), component.c_str(), elements_per_scenario, total_elements, indptr, data.get()); } void add_attribute_buffer(std::string const& component, std::string const& attribute, - RawDataConstPtr data) { // NOSONAR: no const + RawDataConstPtr data) { // NOSONAR: no-const handle_.call_with(PGM_dataset_const_add_attribute_buffer, dataset_.get(), component.c_str(), attribute.c_str(), data); } void add_attribute_buffer(std::string const& component, std::string const& attribute, - Buffer const& data) { // NOSONAR: no const + Buffer const& data) { // NOSONAR: no-const handle_.call_with(PGM_dataset_const_add_attribute_buffer, dataset_.get(), component.c_str(), attribute.c_str(), data.get()); }