Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Friendly set_latency, accepts strings.
[simgrid.git] / src / s4u / s4u_Link.cpp
index e4a4494..7b195fb 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <algorithm>
 
+#include "simgrid/Exception.hpp"
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Link.hpp"
 #include "simgrid/sg_config.hpp"
@@ -13,6 +14,7 @@
 #include "src/surf/network_interface.hpp"
 #include "src/surf/network_wifi.hpp"
 #include "xbt/log.h"
+#include "xbt/parse_units.hpp"
 
 namespace simgrid {
 
@@ -67,6 +69,17 @@ Link* Link::set_latency(double value)
   return this;
 }
 
+Link* Link::set_latency(const std::string& value)
+{
+  double d_value = 0.0;
+  try {
+    d_value = xbt_parse_get_time("", 0, value.c_str(), nullptr, "");
+  } catch (const simgrid::ParseError&) {
+    xbt_die("Link: Impossible to latency, invalid value %s", value.c_str());
+  }
+  return set_latency(d_value);
+}
+
 double Link::get_bandwidth() const
 {
   return this->pimpl_->get_bandwidth();