From: Arnaud Giersch Date: Thu, 27 Oct 2022 11:57:41 +0000 (+0200) Subject: Declare functions "const" (Sonar). X-Git-Tag: v3.34~728 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a3625e2b5b3077b38b70da8e345175568938738a Declare functions "const" (Sonar). --- diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index fb0576f787..fbd304a3bd 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -155,12 +155,14 @@ public: /** @brief Seal this netzone configuration */ NetZone* seal(); - void set_latency_factor_cb(std::function& /*links*/, - const std::unordered_set& /*netzones*/)> const& cb); - void set_bandwidth_factor_cb(std::function& /*links*/, - const std::unordered_set& /*netzones*/)> const& cb); + void + set_latency_factor_cb(std::function& /*links*/, + const std::unordered_set& /*netzones*/)> const& cb) const; + void + set_bandwidth_factor_cb(std::function& /*links*/, + const std::unordered_set& /*netzones*/)> const& cb) const; }; // External constructors so that the types (and the types of their content) remain hidden diff --git a/src/kernel/resource/FactorSet.cpp b/src/kernel/resource/FactorSet.cpp index 81012bd2a5..47a129d43b 100644 --- a/src/kernel/resource/FactorSet.cpp +++ b/src/kernel/resource/FactorSet.cpp @@ -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_; diff --git a/src/kernel/resource/FactorSet.hpp b/src/kernel/resource/FactorSet.hpp index 78171886e7..ef39f8b35c 100644 --- a/src/kernel/resource/FactorSet.hpp +++ b/src/kernel/resource/FactorSet.hpp @@ -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 diff --git a/src/kernel/resource/NetworkModelFactors.cpp b/src/kernel/resource/NetworkModelFactors.cpp index 2e0e31102f..79526a3787 100644 --- a/src/kernel/resource/NetworkModelFactors.cpp +++ b/src/kernel/resource/NetworkModelFactors.cpp @@ -24,7 +24,7 @@ static config::Flag cfg_bandwidth_factor_str( "network/bandwidth-factor", std::initializer_list{"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& links, - const std::unordered_set& netzones) + const std::unordered_set& 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& links, - const std::unordered_set& netzones) + const std::unordered_set& netzones) const { if (bw_factor_cb_) return bw_factor_cb_(size, src, dst, links, netzones); diff --git a/src/kernel/resource/NetworkModelFactors.hpp b/src/kernel/resource/NetworkModelFactors.hpp index de3aea1d4d..ee8b7be599 100644 --- a/src/kernel/resource/NetworkModelFactors.hpp +++ b/src/kernel/resource/NetworkModelFactors.hpp @@ -33,10 +33,11 @@ public: * this factor. */ double get_latency_factor(double size, const s4u::Host* src, const s4u::Host* dst, - const std::vector& links, const std::unordered_set& netzones); + const std::vector& links, + const std::unordered_set& 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& links, const std::unordered_set& netzones); + const std::vector& links, + const std::unordered_set& 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& 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 diff --git a/src/kernel/resource/NetworkModelFactors_test.cpp b/src/kernel/resource/NetworkModelFactors_test.cpp index 27919dbd1b..4a89333b7e 100644 --- a/src/kernel/resource/NetworkModelFactors_test.cpp +++ b/src/kernel/resource/NetworkModelFactors_test.cpp @@ -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); } diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index f1ebe44aff..388cdd41ec 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -116,14 +116,14 @@ NetZone* NetZone::seal() void NetZone::set_latency_factor_cb( std::function& /*links*/, - const std::unordered_set& /*netzones*/)> const& cb) + const std::unordered_set& /*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& /*links*/, - const std::unordered_set& /*netzones*/)> const& cb) + const std::unordered_set& /*netzones*/)> const& cb) const { kernel::actor::simcall_answered([this, &cb]() { pimpl_->get_network_model()->set_bw_factor_cb(cb); }); } diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 8e7a837018..a0f4776d03 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -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& route, const std::unordered_set& netzones, - double rate) + double rate) const { std::vector s4u_route; std::unordered_set s4u_netzones; diff --git a/src/surf/network_cm02.hpp b/src/surf/network_cm02.hpp index 1f6b46b0ef..6025e1384f 100644 --- a/src/surf/network_cm02.hpp +++ b/src/surf/network_cm02.hpp @@ -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& route, - const std::unordered_set& netzones, double rate); + const std::unordered_set& netzones, double rate) const; /** @brief Create maxmin variable in communication action */ void comm_action_set_variable(NetworkCm02Action* action, const std::vector& route, const std::vector& back_route);