Skip to content

Commit

Permalink
Revert "[DEV] remove detach function"
Browse files Browse the repository at this point in the history
This reverts commit e620d6e.
  • Loading branch information
payetvin committed Dec 20, 2023
1 parent 9096788 commit f9a5d52
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/libs/antares/study/parts/common/cluster_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ const ClusterT* ClusterList<ClusterT>::find(const ClusterT* p) const
return (it != clusters.end()) ? it->get() : nullptr;
}

template<class ClusterT>
typename std::shared_ptr<ClusterT> ClusterList<ClusterT>::detach(iterator i)
{
SharedPtr c = *i;
clusters.erase(i);
rebuildIndex();
return c;
}

template<class ClusterT>
bool ClusterList<ClusterT>::exists(const Data::ClusterName& id) const
{
Expand Down
9 changes: 9 additions & 0 deletions src/libs/antares/study/parts/common/cluster_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ class ClusterList
*/

SharedPtr add(const SharedPtr clusters);
/*!
** \brief Detach a clusters represented by an iterator
**
** The clusters will be removed from the list but _not_
** destroyed.
** The iterator should considered as invalid after using this method.
** \return A pointer to the clusters, NULL if an error has occured
*/
SharedPtr detach(iterator i);

/*!
** \brief Try to find a clusters from its id (const)
Expand Down
8 changes: 4 additions & 4 deletions src/libs/antares/study/parts/thermal/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ uint PartThermal::prepareClustersInMustRunMode()
do
{
mustContinue = false;
for (auto& c : clusters)
for (auto i = list.begin(); i != list.end(); ++i)
{
if (c->mustrun)
if ((*i)->mustrun)
{
list.remove(c->id());
std::shared_ptr<ThermalCluster> cluster(c);
// Detaching the thermal cluster from the main list...
std::shared_ptr<ThermalCluster> cluster = list.detach(i);
if (!cluster->enabled)
continue;
// ...and attaching it into the second list
Expand Down
2 changes: 1 addition & 1 deletion src/ui/simulator/toolbox/components/map/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ void Manager::selectFromBoundingBox(const wxPoint& a, const wxPoint& b, const si
for (Data::ThermalClusterList::iterator t = area->thermal.list.begin();
t != tend;
++t)
clusterlist.push_back(t->get());
clusterlist.push_back((*t).get());
}
continue;
}
Expand Down

0 comments on commit f9a5d52

Please sign in to comment.