From b1d3014521a3717133a97ca1789dc36dbb52be19 Mon Sep 17 00:00:00 2001 From: Phil Miller Date: Tue, 7 Nov 2023 17:44:41 -0800 Subject: [PATCH] Bmi_*_Adapter: make them non-copyable and non-movable --- include/bmi/Bmi_C_Adapter.hpp | 5 ++--- include/bmi/Bmi_Cpp_Adapter.hpp | 4 ++-- include/bmi/Bmi_Fortran_Adapter.hpp | 3 +++ include/bmi/Bmi_Py_Adapter.hpp | 3 +++ src/realizations/catchment/Bmi_C_Formulation.cpp | 3 +-- src/realizations/catchment/Bmi_Cpp_Formulation.cpp | 3 +-- src/realizations/catchment/Bmi_Py_Formulation.cpp | 3 +-- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/bmi/Bmi_C_Adapter.hpp b/include/bmi/Bmi_C_Adapter.hpp index 0eeb09fe8e..fc83f97a18 100755 --- a/include/bmi/Bmi_C_Adapter.hpp +++ b/include/bmi/Bmi_C_Adapter.hpp @@ -92,10 +92,9 @@ namespace models { // once original object closes the handle for its dynamically loaded lib) it make more sense to remove the // copy constructor. // TODO: However, it may make sense to bring it back once it's possible to serialize/deserialize the model. - //Bmi_C_Adapter(Bmi_C_Adapter &adapter); + Bmi_C_Adapter(Bmi_C_Adapter &adapter) = delete; - // Move constructor - Bmi_C_Adapter(Bmi_C_Adapter &&adapter) noexcept = default; + Bmi_C_Adapter(Bmi_C_Adapter &&adapter) noexcept = delete; /** * Class destructor. diff --git a/include/bmi/Bmi_Cpp_Adapter.hpp b/include/bmi/Bmi_Cpp_Adapter.hpp index b8c54fd8b2..f702ed500a 100644 --- a/include/bmi/Bmi_Cpp_Adapter.hpp +++ b/include/bmi/Bmi_Cpp_Adapter.hpp @@ -102,10 +102,10 @@ namespace models { // once original object closes the handle for its dynamically loaded lib) it make more sense to remove the // copy constructor. // TODO: However, it may make sense to bring it back once it's possible to serialize/deserialize the model. - //Bmi_Cpp_Adapter(Bmi_Cpp_Adapter &adapter); + Bmi_Cpp_Adapter(Bmi_Cpp_Adapter &adapter) = delete; // Move constructor - Bmi_Cpp_Adapter(Bmi_Cpp_Adapter &&adapter) noexcept = default; + Bmi_Cpp_Adapter(Bmi_Cpp_Adapter &&adapter) noexcept = delete; /** * Class destructor. diff --git a/include/bmi/Bmi_Fortran_Adapter.hpp b/include/bmi/Bmi_Fortran_Adapter.hpp index 4818c8ade6..bb8f6e2532 100644 --- a/include/bmi/Bmi_Fortran_Adapter.hpp +++ b/include/bmi/Bmi_Fortran_Adapter.hpp @@ -76,6 +76,9 @@ namespace models { } } + Bmi_Fortran_Adapter(Bmi_Fortran_Adapter const&) = delete; + Bmi_Fortran_Adapter(Bmi_Fortran_Adapter&&) = delete; + std::string GetComponentName() override; /** diff --git a/include/bmi/Bmi_Py_Adapter.hpp b/include/bmi/Bmi_Py_Adapter.hpp index b69eb9f2ea..377e8a35d2 100644 --- a/include/bmi/Bmi_Py_Adapter.hpp +++ b/include/bmi/Bmi_Py_Adapter.hpp @@ -41,6 +41,9 @@ namespace models { std::string forcing_file_path, bool allow_exceed_end, bool has_fixed_time_step, utils::StreamHandler output); + Bmi_Py_Adapter(Bmi_Py_Adapter const&) = delete; + Bmi_Py_Adapter(Bmi_Py_Adapter&&) = delete; + /** * Copy the given BMI variable's values from the backing numpy array to a C++ array. * diff --git a/src/realizations/catchment/Bmi_C_Formulation.cpp b/src/realizations/catchment/Bmi_C_Formulation.cpp index 5a5ec2a389..04a0106795 100644 --- a/src/realizations/catchment/Bmi_C_Formulation.cpp +++ b/src/realizations/catchment/Bmi_C_Formulation.cpp @@ -25,7 +25,6 @@ std::shared_ptr Bmi_C_Formulation::construct_model(const geojson: std::string reg_func = reg_func_itr == properties.end() ? BMI_C_DEFAULT_REGISTRATION_FUNC : reg_func_itr->second.as_string(); return std::make_shared( - Bmi_C_Adapter( get_model_type_name(), lib_file, get_bmi_init_config(), @@ -33,7 +32,7 @@ std::shared_ptr Bmi_C_Formulation::construct_model(const geojson: get_allow_model_exceed_end_time(), is_bmi_model_time_step_fixed(), reg_func, - output)); + output); } std::string Bmi_C_Formulation::get_output_header_line(std::string delimiter) { diff --git a/src/realizations/catchment/Bmi_Cpp_Formulation.cpp b/src/realizations/catchment/Bmi_Cpp_Formulation.cpp index 82e16a312b..24419b2c75 100644 --- a/src/realizations/catchment/Bmi_Cpp_Formulation.cpp +++ b/src/realizations/catchment/Bmi_Cpp_Formulation.cpp @@ -34,7 +34,6 @@ std::shared_ptr Bmi_Cpp_Formulation::construct_model(const geoj json_prop_itr == properties.end() ? BMI_REALIZATION_CFG_PARAM_OPT__CPP_DESTROY_FUNC_DEFAULT : json_prop_itr->second.as_string(); return std::make_shared( - Bmi_Cpp_Adapter( get_model_type_name(), lib_file, get_bmi_init_config(), @@ -43,7 +42,7 @@ std::shared_ptr Bmi_Cpp_Formulation::construct_model(const geoj is_bmi_model_time_step_fixed(), model_create_fname, model_destroy_fname, - output)); + output); } std::string Bmi_Cpp_Formulation::get_output_header_line(std::string delimiter) { diff --git a/src/realizations/catchment/Bmi_Py_Formulation.cpp b/src/realizations/catchment/Bmi_Py_Formulation.cpp index e52f2ffa17..cc69a80a32 100644 --- a/src/realizations/catchment/Bmi_Py_Formulation.cpp +++ b/src/realizations/catchment/Bmi_Py_Formulation.cpp @@ -23,13 +23,12 @@ shared_ptr Bmi_Py_Formulation::construct_model(const geojson::Pr std::string python_type_name = python_type_name_iter->second.as_string(); return std::make_shared( - Bmi_Py_Adapter( get_model_type_name(), get_bmi_init_config(), python_type_name, get_allow_model_exceed_end_time(), is_bmi_model_time_step_fixed(), - output)); + output); } time_t realization::Bmi_Py_Formulation::convert_model_time(const double &model_time) {