Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Declare functions "const" (Sonar).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 27 Oct 2022 11:57:41 +0000 (13:57 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 27 Oct 2022 12:23:41 +0000 (14:23 +0200)
include/simgrid/s4u/NetZone.hpp
src/kernel/resource/FactorSet.cpp
src/kernel/resource/FactorSet.hpp
src/kernel/resource/NetworkModelFactors.cpp
src/kernel/resource/NetworkModelFactors.hpp
src/kernel/resource/NetworkModelFactors_test.cpp
src/s4u/s4u_Netzone.cpp
src/surf/network_cm02.cpp
src/surf/network_cm02.hpp

index fb0576f..fbd304a 100644 (file)
@@ -155,12 +155,14 @@ public:
   /** @brief Seal this netzone configuration */
   NetZone* seal();
 
-  void set_latency_factor_cb(std::function<double(double size, const s4u::Host* src, const s4u::Host* dst,
-                                                  const std::vector<s4u::Link*>& /*links*/,
-                                                  const std::unordered_set<s4u::NetZone*>& /*netzones*/)> const& cb);
-  void set_bandwidth_factor_cb(std::function<double(double size, const s4u::Host* src, const s4u::Host* dst,
-                                                    const std::vector<s4u::Link*>& /*links*/,
-                                                    const std::unordered_set<s4u::NetZone*>& /*netzones*/)> const& cb);
+  void
+  set_latency_factor_cb(std::function<double(double size, const s4u::Host* src, const s4u::Host* dst,
+                                             const std::vector<s4u::Link*>& /*links*/,
+                                             const std::unordered_set<s4u::NetZone*>& /*netzones*/)> const& cb) const;
+  void
+  set_bandwidth_factor_cb(std::function<double(double size, const s4u::Host* src, const s4u::Host* dst,
+                                               const std::vector<s4u::Link*>& /*links*/,
+                                               const std::unordered_set<s4u::NetZone*>& /*netzones*/)> const& cb) const;
 };
 
 // External constructors so that the types (and the types of their content) remain hidden
index 81012bd..47a129d 100644 (file)
@@ -87,12 +87,12 @@ FactorSet::FactorSet(const std::string& name, double default_value,
 {
 }
 
-double FactorSet::operator()()
+double FactorSet::operator()() const
 {
   return default_value_;
 }
 
-double FactorSet::operator()(double size)
+double FactorSet::operator()(double size) const
 {
   if (factors_.empty())
     return default_value_;
index 7817188..ef39f8b 100644 (file)
@@ -37,9 +37,9 @@ public:
   void parse(const std::string& string_values);
   bool is_initialized() const { return initialized_; }
   // Get the default value
-  double operator()();
+  double operator()() const;
   // Get the factor to use for the provided size
-  double operator()(double size);
+  double operator()(double size) const;
 };
 
 } // namespace simgrid::kernel::resource
index 2e0e311..79526a3 100644 (file)
@@ -24,7 +24,7 @@ static config::Flag<std::string> cfg_bandwidth_factor_str(
     "network/bandwidth-factor", std::initializer_list<const char*>{"smpi/bw-factor"},
     "Correction factor to apply to the provided bandwidth (default value overridden by network model)", "1.0");
 
-double NetworkModelFactors::get_bandwidth_factor()
+double NetworkModelFactors::get_bandwidth_factor() const
 {
   xbt_assert(not bw_factor_cb_,
              "Cannot access the global bandwidth factor since a callback is used. Please go for the advanced API.");
@@ -35,7 +35,7 @@ double NetworkModelFactors::get_bandwidth_factor()
   return cfg_bandwidth_factor(0);
 }
 
-double NetworkModelFactors::get_latency_factor()
+double NetworkModelFactors::get_latency_factor() const
 {
   xbt_assert(not lat_factor_cb_,
              "Cannot access the global latency factor since a callback is used. Please go for the advanced API.");
@@ -48,7 +48,7 @@ double NetworkModelFactors::get_latency_factor()
 
 double NetworkModelFactors::get_latency_factor(double size, const s4u::Host* src, const s4u::Host* dst,
                                                const std::vector<s4u::Link*>& links,
-                                               const std::unordered_set<s4u::NetZone*>& netzones)
+                                               const std::unordered_set<s4u::NetZone*>& netzones) const
 {
   if (lat_factor_cb_)
     return lat_factor_cb_(size, src, dst, links, netzones);
@@ -61,7 +61,7 @@ double NetworkModelFactors::get_latency_factor(double size, const s4u::Host* src
 
 double NetworkModelFactors::get_bandwidth_factor(double size, const s4u::Host* src, const s4u::Host* dst,
                                                  const std::vector<s4u::Link*>& links,
-                                                 const std::unordered_set<s4u::NetZone*>& netzones)
+                                                 const std::unordered_set<s4u::NetZone*>& netzones) const
 {
   if (bw_factor_cb_)
     return bw_factor_cb_(size, src, dst, links, netzones);
index de3aea1..ee8b7be 100644 (file)
@@ -33,10 +33,11 @@ public:
    * this factor.
    */
   double get_latency_factor(double size, const s4u::Host* src, const s4u::Host* dst,
-                            const std::vector<s4u::Link*>& links, const std::unordered_set<s4u::NetZone*>& netzones);
+                            const std::vector<s4u::Link*>& links,
+                            const std::unordered_set<s4u::NetZone*>& netzones) const;
 
   /** Get the right multiplicative factor for the bandwidth (only if no callback was defined) */
-  double get_latency_factor();
+  double get_latency_factor() const;
 
   /**
    * @brief Get the right multiplicative factor for the bandwidth.
@@ -46,10 +47,11 @@ public:
    * gets this factor.
    */
   double get_bandwidth_factor(double size, const s4u::Host* src, const s4u::Host* dst,
-                              const std::vector<s4u::Link*>& links, const std::unordered_set<s4u::NetZone*>& netzones);
+                              const std::vector<s4u::Link*>& links,
+                              const std::unordered_set<s4u::NetZone*>& netzones) const;
 
   /** Get the right multiplicative factor for the bandwidth (only if no callback was defined) */
-  double get_bandwidth_factor();
+  double get_bandwidth_factor() const;
 
   /**
    * @brief Callback to set the bandwidth and latency factors used in a communication
@@ -72,7 +74,7 @@ public:
   void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb);
 
   /** Returns whether a callback was set for latency-factor OR bandwidth-factor */
-  bool has_network_factor_cb() { return lat_factor_cb_ || bw_factor_cb_; }
+  bool has_network_factor_cb() const { return lat_factor_cb_ || bw_factor_cb_; }
 };
 
 } // namespace simgrid::kernel::resource
index 27919db..4a89333 100644 (file)
@@ -32,7 +32,7 @@ TEST_CASE("kernel::resource::NetworkModelFactors: Factors invalid callbacks: exc
 
     SECTION("Model: " + model)
     {
-      auto zone = e.get_netzone_root();
+      const auto* zone = e.get_netzone_root();
       REQUIRE_THROWS_AS(zone->set_latency_factor_cb({}), std::invalid_argument);
       REQUIRE_THROWS_AS(zone->set_latency_factor_cb(nullptr), std::invalid_argument);
       REQUIRE_THROWS_AS(zone->set_bandwidth_factor_cb({}), std::invalid_argument);
@@ -59,7 +59,7 @@ TEST_CASE("kernel::resource::NetworkModelFactors: Invalid network/latency-factor
 
     SECTION("Model: " + model)
     {
-      auto zone = e.get_netzone_root();
+      const auto* zone = e.get_netzone_root();
       REQUIRE_THROWS_AS(zone->set_latency_factor_cb(factor_cb), std::invalid_argument);
       REQUIRE_THROWS_AS(zone->set_bandwidth_factor_cb(factor_cb), std::invalid_argument);
     }
index f1ebe44..388cdd4 100644 (file)
@@ -116,14 +116,14 @@ NetZone* NetZone::seal()
 void NetZone::set_latency_factor_cb(
     std::function<double(double size, const s4u::Host* src, const s4u::Host* dst,
                          const std::vector<s4u::Link*>& /*links*/,
-                         const std::unordered_set<s4u::NetZone*>& /*netzones*/)> const& cb)
+                         const std::unordered_set<s4u::NetZone*>& /*netzones*/)> const& cb) const
 {
   kernel::actor::simcall_answered([this, &cb]() { pimpl_->get_network_model()->set_lat_factor_cb(cb); });
 }
 void NetZone::set_bandwidth_factor_cb(
     std::function<double(double size, const s4u::Host* src, const s4u::Host* dst,
                          const std::vector<s4u::Link*>& /*links*/,
-                         const std::unordered_set<s4u::NetZone*>& /*netzones*/)> const& cb)
+                         const std::unordered_set<s4u::NetZone*>& /*netzones*/)> const& cb) const
 {
   kernel::actor::simcall_answered([this, &cb]() { pimpl_->get_network_model()->set_bw_factor_cb(cb); });
 }
index 8e7a837..a0f4776 100644 (file)
@@ -328,7 +328,7 @@ bool NetworkCm02Model::comm_get_route_info(const s4u::Host* src, const s4u::Host
 void NetworkCm02Model::comm_action_set_bounds(const s4u::Host* src, const s4u::Host* dst, double size,
                                               NetworkCm02Action* action, const std::vector<StandardLinkImpl*>& route,
                                               const std::unordered_set<kernel::routing::NetZoneImpl*>& netzones,
-                                              double rate)
+                                              double rate) const
 {
   std::vector<s4u::Link*> s4u_route;
   std::unordered_set<s4u::NetZone*> s4u_netzones;
index 1f6b46b..6025e13 100644 (file)
@@ -42,7 +42,7 @@ class NetworkCm02Model : public NetworkModel {
   /** @brief Set communication bounds for latency and bandwidth */
   void comm_action_set_bounds(const s4u::Host* src, const s4u::Host* dst, double size, NetworkCm02Action* action,
                               const std::vector<StandardLinkImpl*>& route,
-                              const std::unordered_set<kernel::routing::NetZoneImpl*>& netzones, double rate);
+                              const std::unordered_set<kernel::routing::NetZoneImpl*>& netzones, double rate) const;
   /** @brief Create maxmin variable in communication action */
   void comm_action_set_variable(NetworkCm02Action* action, const std::vector<StandardLinkImpl*>& route,
                                 const std::vector<StandardLinkImpl*>& back_route);