From 69eee1c0952cb9e577d980faff5fec94caf95e36 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 9 Feb 2021 13:05:04 +0100 Subject: [PATCH] Cannot do anything with dependencies --- include/simgrid/s4u/Activity.hpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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"); -- 2.20.1