From: Frederic Suter Date: Tue, 9 Feb 2021 12:05:04 +0000 (+0100) Subject: Cannot do anything with dependencies X-Git-Tag: v3.27~414 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/69eee1c0952cb9e577d980faff5fec94caf95e36 Cannot do anything with dependencies --- diff --git a/include/simgrid/s4u/Activity.hpp b/include/simgrid/s4u/Activity.hpp index ab1e57bb80..68635874c7 100644 --- a/include/simgrid/s4u/Activity.hpp +++ b/include/simgrid/s4u/Activity.hpp @@ -7,6 +7,7 @@ #define SIMGRID_S4U_ACTIVITY_HPP #include "xbt/asserts.h" +#include #include #include #include @@ -51,10 +52,30 @@ protected: void add_successor(ActivityPtr a) { + if(this == a) + throw std::invalid_argument("Cannot be its own successor"); + auto p = std::find_if(successors_.begin(), successors_.end(), [a](ActivityPtr const& i){ return i.get() == a.get(); }); + if (p != successors_.end()) + throw std::invalid_argument("Dependency already exists"); + successors_.push_back(a); a->dependencies_.insert({this}); } + void remove_successor(ActivityPtr a) + { + if(this == a) + throw std::invalid_argument("Cannot ask to remove its from successors"); + + auto p = std::find_if(successors_.begin(), successors_.end(), [a](ActivityPtr const& i){ return i.get() == a.get(); }); + if (p != successors_.end()){ + successors_.erase(p); + a->dependencies_.erase({this}); + } else + throw std::invalid_argument("Dependency does not exist. Can not be removed."); + + } + public: void vetoable_start() { @@ -155,7 +176,11 @@ public: Activity::add_successor(a); return static_cast(this); } - + AnyActivity* remove_successor(ActivityPtr a) + { + Activity::remove_successor(a); + return static_cast(this); + } AnyActivity* set_name(const std::string& name) { xbt_assert(get_state() == State::INITED, "Cannot change the name of an activity after its start");