Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix some sonar issues in includes, after upgrade to c++17.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 24 May 2023 12:28:22 +0000 (14:28 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 24 May 2023 16:25:27 +0000 (18:25 +0200)
include/simgrid/kernel/resource/Action.hpp
include/simgrid/plugins/ProducerConsumer.hpp
include/simgrid/s4u/Activity.hpp

index 9524e89..b75750e 100644 (file)
@@ -13,6 +13,7 @@
 #include <boost/heap/pairing_heap.hpp>
 #include <boost/optional.hpp>
 #include <string>
+#include <string_view>
 
 static constexpr double NO_MAX_DURATION = -1.0;
 
@@ -225,7 +226,7 @@ public:
   /** @brief Get the tracing category associated to the current action */
   const std::string& get_category() const { return category_; }
   /** @brief Set the tracing category of the current Action */
-  void set_category(const std::string& category) { category_ = category; }
+  void set_category(std::string_view category) { category_ = category; }
 
   /** @brief Get the sharing_penalty (RTT or 1/thread_count) of the current Action */
   double get_sharing_penalty() const { return sharing_penalty_; };
index 87d4cfa..d4438e4 100644 (file)
@@ -140,7 +140,7 @@ public:
    */
   s4u::CommPtr put_async(T* data, size_t simulated_size_in_bytes)
   {
-    std::unique_lock<s4u::Mutex> lock(*mutex_);
+    std::unique_lock lock(*mutex_);
     s4u::CommPtr comm = nullptr;
     XBT_CVERB(producer_consumer, (size() < max_queue_size_) ? "can put" : "must wait");
 
@@ -177,7 +177,7 @@ public:
    */
   s4u::CommPtr get_async(T** data)
   {
-    std::unique_lock<s4u::Mutex> lock(*mutex_);
+    std::unique_lock lock(*mutex_);
     s4u::CommPtr comm = nullptr;
     XBT_CVERB(producer_consumer, empty() ? "must wait" : "can get");
     while (empty())
index 0dade94..fb157dd 100644 (file)
@@ -12,6 +12,7 @@
 #include <simgrid/forward.h>
 #include <stdexcept>
 #include <string>
+#include <string_view>
 #include <vector>
 #include <xbt/Extendable.hpp>
 #include <xbt/asserts.h>
@@ -74,8 +75,8 @@ protected:
   {
     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())
+
+    if (std::any_of(begin(successors_), end(successors_), [a](ActivityPtr const& i) { return i.get() == a.get(); }))
       throw std::invalid_argument("Dependency already exists");
 
     successors_.push_back(a);
@@ -87,12 +88,13 @@ protected:
     if(this == a)
       throw std::invalid_argument("Cannot ask to remove itself from successors list");
 
-    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
+    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 does not exist. Can not be removed.");
+
+    successors_.erase(p);
+    a->dependencies_.erase({this});
   }
 
   static std::set<Activity*>* vetoed_activities_;
@@ -262,7 +264,7 @@ public:
     Activity::remove_successor(a);
     return static_cast<AnyActivity*>(this);
   }
-  AnyActivity* set_name(const std::string& name)
+  AnyActivity* set_name(std::string_view name)
   {
     name_ = name;
     return static_cast<AnyActivity*>(this);
@@ -270,7 +272,7 @@ public:
   const std::string& get_name() const override { return name_; }
   const char* get_cname() const override { return name_.c_str(); }
 
-  AnyActivity* set_tracing_category(const std::string& category)
+  AnyActivity* set_tracing_category(std::string_view category)
   {
     xbt_assert(get_state() == State::INITED || get_state() == State::STARTING,
                "Cannot change the tracing category of an activity after its start");