diff --git a/src/libs/antares/study/include/antares/study/study.h b/src/libs/antares/study/include/antares/study/study.h index 65f8f531fd..c7a5382c19 100644 --- a/src/libs/antares/study/include/antares/study/study.h +++ b/src/libs/antares/study/include/antares/study/study.h @@ -391,10 +391,6 @@ class Study: public Yuni::NonCopyable, public LayerData ** \brief Re-Initialize/Re-Load the scenario builder data */ void scenarioRulesCreate(); - /*! - ** \brief Re-Initialize/Re-Load the scenario builder data but consider a single ruleset only - */ - void scenarioRulesCreate(const RulesScenarioName& thisoneonly); /*! ** \brief Release the scenario builder @@ -586,7 +582,7 @@ class Study: public Yuni::NonCopyable, public LayerData //! \name Scenario Builder //@{ //! Rules for building scenarios (can be null) - ScenarioBuilder::Sets* scenarioRules = nullptr; + std::shared_ptr scenarioRules; //@} TimeSeries::TS scenarioInitialHydroLevels; diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index 01d91b3abb..3f22be34bc 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -104,7 +104,7 @@ Study::~Study() void Study::clear() { - FreeAndNil(scenarioRules); + scenarioRules.reset(); FreeAndNil(uiinfo); // areas diff --git a/src/libs/antares/study/study.extra.cpp b/src/libs/antares/study/study.extra.cpp index 1ec628c321..da0b5a86da 100644 --- a/src/libs/antares/study/study.extra.cpp +++ b/src/libs/antares/study/study.extra.cpp @@ -35,32 +35,16 @@ String StudyIconFile; void Study::scenarioRulesCreate() { // releasing the previous instance of the scenario builder - delete scenarioRules; + scenarioRules.reset(); // When ran from the solver, the scenario builder must be present - scenarioRules = new ScenarioBuilder::Sets(); - scenarioRules->loadFromStudy(*this); -} - -void Study::scenarioRulesCreate(const RulesScenarioName& /*thisoneonly*/) -{ - // releasing the previous instance of the scenario builder - delete scenarioRules; - // When ran from the solver, the scenario builder must be present - scenarioRules = new ScenarioBuilder::Sets(); + scenarioRules = std::make_shared(); scenarioRules->loadFromStudy(*this); } void Study::scenarioRulesDestroy() { - if (scenarioRules) - { - // releasing the previous instance of the scenario builder - // safety dereferencing for the interface if running - ScenarioBuilder::Sets* sb = scenarioRules; - scenarioRules = nullptr; - delete sb; - } + scenarioRules.reset(); } void Study::scenarioRulesLoadIfNotAvailable() @@ -68,7 +52,7 @@ void Study::scenarioRulesLoadIfNotAvailable() if (!scenarioRules) { // When ran from the solver, the scenario builder must be present - scenarioRules = new ScenarioBuilder::Sets(); + scenarioRules = std::make_shared(); scenarioRules->loadFromStudy(*this); } } diff --git a/src/tests/inmemory-study/in-memory-study.cpp b/src/tests/inmemory-study/in-memory-study.cpp index 1f3f78c194..5ad43e42e7 100644 --- a/src/tests/inmemory-study/in-memory-study.cpp +++ b/src/tests/inmemory-study/in-memory-study.cpp @@ -172,7 +172,7 @@ averageResults OutputRetriever::thermalNbUnitsON(ThermalCluster* cluster) ScenarioBuilderRule::ScenarioBuilderRule(Study& study) { study.scenarioRulesCreate(); - ScenarioBuilder::Sets* sets = study.scenarioRules; + auto sets = study.scenarioRules; if (sets && !sets->empty()) { rules_ = sets->createNew("Custom"); diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 64813637fc..1674bc2725 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -188,7 +188,7 @@ struct commonFixture study->bindingConstraintsGroups.add("group3"); // Scenario builder initialization - study->scenarioRules = new ScenarioBuilder::Sets(); + study->scenarioRules = std::make_shared(); study->scenarioRules->setStudy(*study); my_rule = study->scenarioRules->createNew("my rule name"); BOOST_CHECK(my_rule->reset()); diff --git a/src/ui/simulator/application/main/main.cpp b/src/ui/simulator/application/main/main.cpp index 3b321e6c12..31865edc53 100644 --- a/src/ui/simulator/application/main/main.cpp +++ b/src/ui/simulator/application/main/main.cpp @@ -702,7 +702,7 @@ void ApplWnd::onSectionNotebookPageChanging(Component::Notebook::Page& page) auto* job = new JobLoadScenarioBuilder(*study); wxTheApp->Yield(); job->run(); - study->scenarioRules = job->scenarioBuilder(); + study->scenarioRules.reset(job->scenarioBuilder()); job->Destroy(); }