Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cannot do anything with dependencies
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 9 Feb 2021 12:05:04 +0000 (13:05 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 9 Feb 2021 12:23:34 +0000 (13:23 +0100)
include/simgrid/s4u/Activity.hpp

index ab1e57b..6863587 100644 (file)
@@ -7,6 +7,7 @@
 #define SIMGRID_S4U_ACTIVITY_HPP
 
 #include "xbt/asserts.h"
+#include <algorithm>
 #include <atomic>
 #include <set>
 #include <simgrid/forward.h>
@@ -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<AnyActivity*>(this);
   }
-
+  AnyActivity* remove_successor(ActivityPtr a)
+  {
+    Activity::remove_successor(a);
+    return static_cast<AnyActivity*>(this);
+  }
   AnyActivity* set_name(const std::string& name)
   {
     xbt_assert(get_state() == State::INITED, "Cannot change the name of an activity after its start");