Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'dev-unit_test_cleanup' into 'master'
[simgrid.git] / src / kernel / resource / profile / ProfileBuilder.cpp
index d7ba428..bbfb98d 100644 (file)
 #include <cstddef>
 #include <fstream>
 #include <sstream>
+#include <string_view>
 
-
-namespace simgrid {
-namespace kernel {
-namespace profile {
+namespace simgrid::kernel::profile {
 
 bool DatedValue::operator==(DatedValue const& e2) const
 {
@@ -72,19 +70,19 @@ class LegacyUpdateCb {
   bool loop;
   double loop_delay = 0.0;
 
-  static bool is_comment_or_empty_line(const std::string& val)
+  static bool is_comment_or_empty_line(std::string_view val)
   {
-    return (val[0] == '#' || val[0] == '\0' || val[0] == '%');
+    return (val.empty() || val.front() == '#' || val.front() == '%');
   }
 
-  static bool is_normal_distribution(const std::string& val)
+  static bool is_normal_distribution(std::string_view val)
   {
     return (val == "NORM" || val == "NORMAL" || val == "GAUSS" || val == "GAUSSIAN");
   }
 
-  static bool is_exponential_distribution(const std::string& val) { return (val == "EXP" || val == "EXPONENTIAL"); }
+  static bool is_exponential_distribution(std::string_view val) { return (val == "EXP" || val == "EXPONENTIAL"); }
 
-  static bool is_uniform_distribution(const std::string& val) { return (val == "UNIF" || val == "UNIFORM"); }
+  static bool is_uniform_distribution(std::string_view val) { return (val == "UNIF" || val == "UNIFORM"); }
 
 public:
   LegacyUpdateCb(const std::string& input, double periodicity) : loop(periodicity > 0)
@@ -214,6 +212,8 @@ public:
         event_list.at(initial_size).date_ += loop_delay;
     }
   }
+
+  std::vector<StochasticDatedValue> get_pattern() { return pattern; } 
 };
 
 Profile* ProfileBuilder::from_string(const std::string& name, const std::string& input, double periodicity)
@@ -245,7 +245,12 @@ Profile* ProfileBuilder::from_callback(const std::string& name, const std::funct
   return new Profile(name, cb, repeat_delay);
 }
 
+} // namespace simgrid::kernel::profile
+
+std::vector<simgrid::kernel::profile::StochasticDatedValue> trace2selist( const char*  c_str) {
+  std::string str(c_str);
+  simgrid::kernel::profile::LegacyUpdateCb cb(str,0);
+  return cb.get_pattern();
+}
+
 
-} // namespace profile
-} // namespace kernel
-} // namespace simgrid