diff --git a/src/solver/systemParser/converter.cpp b/src/solver/systemParser/converter.cpp index 20e8fd0d4a..b78b8abb8a 100644 --- a/src/solver/systemParser/converter.cpp +++ b/src/solver/systemParser/converter.cpp @@ -71,7 +71,7 @@ static std::pair splitLibraryModelString(const std::st return {library, model}; } -static const SystemModel::Model* getModel(const std::vector& libraries, +static const SystemModel::Model& getModel(const std::vector& libraries, const std::string& libraryId, const std::string& modelId) { @@ -82,15 +82,13 @@ static const SystemModel::Model* getModel(const std::vectorModels().at(modelId); - return &model; - } - catch (const std::out_of_range&) + auto search = lib->Models().find(modelId); + if (search == lib->Models().end()) { throw ModelNotFound(modelId); } + + return search->second; } static SystemModel::Component createComponent(const SystemParser::Component& c, @@ -99,7 +97,7 @@ static SystemModel::Component createComponent(const SystemParser::Component& c, const auto [libraryId, modelId] = splitLibraryModelString(c.model); SystemModel::ModelBuilder model_builder; - const SystemModel::Model* model = getModel(libraries, libraryId, modelId); + const SystemModel::Model& model = getModel(libraries, libraryId, modelId); SystemModel::ComponentBuilder component_builder; @@ -110,7 +108,7 @@ static SystemModel::Component createComponent(const SystemParser::Component& c, } auto component = component_builder.withId(c.id) - .withModel(model) + .withModel(&model) .withScenarioGroupId(c.scenarioGroup) .withParameterValues(parameters) .build(); diff --git a/src/tests/src/study/system-model/test_component.cpp b/src/tests/src/study/system-model/test_component.cpp index 584bd447ec..ca8e0c93f4 100644 --- a/src/tests/src/study/system-model/test_component.cpp +++ b/src/tests/src/study/system-model/test_component.cpp @@ -159,7 +159,8 @@ BOOST_AUTO_TEST_CASE(fail_on_no_params1) .withScenarioGroupId("scenario_group"); BOOST_CHECK_EXCEPTION(component_builder.build(), std::invalid_argument, - checkMessage("The component \"component\" has 0 parameter(s), but its model has 2")); + checkMessage( + "The component \"component\" has 0 parameter(s), but its model has 2")); } BOOST_AUTO_TEST_CASE(fail_on_no_params2) @@ -171,7 +172,8 @@ BOOST_AUTO_TEST_CASE(fail_on_no_params2) .withScenarioGroupId("scenario_group"); BOOST_CHECK_EXCEPTION(component_builder.build(), std::invalid_argument, - checkMessage("The component \"component\" has 0 parameter(s), but its model has 2")); + checkMessage( + "The component \"component\" has 0 parameter(s), but its model has 2")); } BOOST_AUTO_TEST_CASE(fail_on_missing_param) @@ -183,7 +185,8 @@ BOOST_AUTO_TEST_CASE(fail_on_missing_param) .withScenarioGroupId("scenario_group"); BOOST_CHECK_EXCEPTION(component_builder.build(), std::invalid_argument, - checkMessage("The component \"component\" has 1 parameter(s), but its model has 2")); + checkMessage( + "The component \"component\" has 1 parameter(s), but its model has 2")); } BOOST_AUTO_TEST_CASE(fail_on_missing_wrong_param) @@ -195,7 +198,8 @@ BOOST_AUTO_TEST_CASE(fail_on_missing_wrong_param) .withScenarioGroupId("scenario_group"); BOOST_CHECK_EXCEPTION(component_builder.build(), std::invalid_argument, - checkMessage("The component \"component\" has no value for parameter 'param1'")); + checkMessage( + "The component \"component\" has no value for parameter 'param1'")); } BOOST_AUTO_TEST_CASE(fail_on_too_many_params1) @@ -207,7 +211,8 @@ BOOST_AUTO_TEST_CASE(fail_on_too_many_params1) .withScenarioGroupId("scenario_group"); BOOST_CHECK_EXCEPTION(component_builder.build(), std::invalid_argument, - checkMessage("The component \"component\" has 3 parameter(s), but its model has 2")); + checkMessage( + "The component \"component\" has 3 parameter(s), but its model has 2")); } BOOST_AUTO_TEST_CASE(fail_on_too_many_params2) @@ -219,7 +224,8 @@ BOOST_AUTO_TEST_CASE(fail_on_too_many_params2) .withScenarioGroupId("scenario_group"); BOOST_CHECK_EXCEPTION(component_builder.build(), std::invalid_argument, - checkMessage("The component \"component\" has 1 parameter(s), but its model has 0")); + checkMessage( + "The component \"component\" has 1 parameter(s), but its model has 0")); } BOOST_AUTO_TEST_SUITE_END()