Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove explicit conversion to std::string when it's not required.
[simgrid.git] / src / plugins / host_energy.cpp
index ef191bfd51f32206a6b56d4568a46028e136818d..abb4fcdff5bc7f3fb7ca69a16bc4d2c580d2942f 100644 (file)
@@ -115,8 +115,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(host_energy, kernel, "Logging specific to the ho
 // Forwards declaration needed to make this function a friend (because friends have external linkage by default)
 static void on_simulation_end();
 
-namespace simgrid {
-namespace plugin {
+namespace simgrid::plugin {
 
 class PowerRange {
 public:
@@ -217,10 +216,10 @@ HostEnergy::HostEnergy(simgrid::s4u::Host* ptr) : host_(ptr)
   const char* off_power_str = host_->get_property("wattage_off");
   if (off_power_str != nullptr) {
     try {
-      this->watts_off_ = std::stod(std::string(off_power_str));
+      this->watts_off_ = std::stod(off_power_str);
     } catch (const std::invalid_argument&) {
-      throw std::invalid_argument(std::string("Invalid value for property wattage_off of host ") + host_->get_cname() +
-                                  ": " + off_power_str);
+      throw std::invalid_argument("Invalid value for property wattage_off of host " + host_->get_name() + ": " +
+                                  off_power_str);
     }
   }
   /* watts_off is 0 by default */
@@ -391,8 +390,7 @@ void HostEnergy::init_watts_range_list()
 
   has_pstate_power_values_ = true;
 }
-} // namespace plugin
-} // namespace simgrid
+} // namespace simgrid::plugin
 
 using simgrid::plugin::HostEnergy;
 
@@ -414,8 +412,7 @@ static void on_action_state_change(simgrid::kernel::resource::CpuAction const& a
     simgrid::s4u::Host* host = cpu->get_iface();
     if (host != nullptr) {
       // If it's a VM, take the corresponding PM
-      const simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host);
-      if (vm) // If it's a VM, take the corresponding PM
+      if (const auto* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host))
         host = vm->get_pm();
 
       // Get the host_energy extension for the relevant host
@@ -492,8 +489,7 @@ void sg_host_energy_plugin_init()
   simgrid::s4u::Exec::on_start_cb([](simgrid::s4u::Exec const& activity) {
     if (activity.get_host_number() == 1) { // We only run on one host
       simgrid::s4u::Host* host         = activity.get_host();
-      const simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host);
-      if (vm != nullptr)
+      if (const auto* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host))
         host = vm->get_pm();
       xbt_assert(host != nullptr);
       host->extension<HostEnergy>()->update();