From: Christian Heinrich Date: Fri, 29 Jun 2018 09:21:34 +0000 (+0200) Subject: [S4U] Host: Add 'const' keyword to getter methods X-Git-Tag: v3_21~605 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b60613a2c7267d689bc14020155ea38efc8135f9?ds=sidebyside [S4U] Host: Add 'const' keyword to getter methods This signals to users that calling these methods will not change the state of the object. --- diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index 477bb22515..cbb94851d1 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -92,11 +92,11 @@ public: /** Turns that host off. All actors are forcefully stopped. */ void turn_off(); /** Returns if that host is currently up and running */ - bool is_on(); + bool is_on() const; /** Returns if that host is currently down and offline */ - bool is_off() { return not is_on(); } + bool is_off() const { return not is_on(); } - const char* get_property(const char* key); + const char* get_property(const char* key) const; void set_property(std::string key, std::string value); std::unordered_map* get_properties(); XBT_ATTRIB_DEPRECATED_v323("Please use Host::get_properties()") std::map* getProperties() @@ -108,15 +108,15 @@ public: return res; } - double get_speed(); - double get_available_speed(); - int get_core_count(); - double get_load(); + double get_speed() const; + double get_available_speed() const; + int get_core_count() const; + double get_load() const; - double get_pstate_speed(int pstate_index); + double get_pstate_speed(int pstate_index) const; int get_pstate_count() const; void set_pstate(int pstate_index); - int get_pstate(); + int get_pstate() const; XBT_ATTRIB_DEPRECATED_v323("Please use Host::get_speed() instead.") double getSpeed() { return get_speed(); } XBT_ATTRIB_DEPRECATED_v323("Please use Host::get_pstate_speed() instead.") double getPstateSpeed(int pstate_index) @@ -124,7 +124,7 @@ public: return get_pstate_speed(pstate_index); } - std::vector get_attached_storages(); + std::vector get_attached_storages() const; XBT_ATTRIB_DEPRECATED_v323("Please use Host::get_attached_storages() instead.") void getAttachedStorages( std::vector* storages); @@ -191,7 +191,7 @@ public: } private: - simgrid::xbt::string name_{"noname"}; + simgrid::xbt::string name_ {"noname"}; std::unordered_map* mounts_ = nullptr; // caching public: diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index e321de2074..7aab1cf72c 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -126,7 +126,7 @@ void Host::turn_off() } } -bool Host::is_on() +bool Host::is_on() const { return this->pimpl_cpu->is_on(); } @@ -210,7 +210,7 @@ std::unordered_map* Host::get_properties() } /** Retrieve the property value (or nullptr if not set) */ -const char* Host::get_property(const char* key) +const char* Host::get_property(const char* key) const { return this->pimpl_->get_property(key); } @@ -221,7 +221,7 @@ void Host::set_property(std::string key, std::string value) } /** @brief Get the peak processor speed (in flops/s), at the specified pstate */ -double Host::get_pstate_speed(int pstate_index) +double Host::get_pstate_speed(int pstate_index) const { return simgrid::simix::simcall([this, pstate_index] { return this->pimpl_cpu->get_pstate_peak_speed(pstate_index); }); } @@ -240,14 +240,14 @@ double Host::get_pstate_speed(int pstate_index) * * Finally, executions of priority 2 get twice the amount of flops than executions of priority 1. */ -double Host::get_speed() +double Host::get_speed() const { return this->pimpl_cpu->get_speed(1.0); } /** @brief Returns the current computation load (in flops per second) * The external load (coming from an availability trace) is not taken in account. */ -double Host::get_load() +double Host::get_load() const { return this->pimpl_cpu->get_load(); } @@ -255,13 +255,13 @@ double Host::get_load() * * This accounts for external load (see @ref set_speed_trace()). */ -double Host::get_available_speed() +double Host::get_available_speed() const { return this->pimpl_cpu->get_speed_ratio(); } /** @brief Returns the number of core of the processor. */ -int Host::get_core_count() +int Host::get_core_count() const { return this->pimpl_cpu->get_core_count(); } @@ -272,7 +272,7 @@ void Host::set_pstate(int pstate_index) simgrid::simix::simcall([this, pstate_index] { this->pimpl_cpu->set_pstate(pstate_index); }); } /** @brief Retrieve the pstate at which the host is currently running */ -int Host::get_pstate() +int Host::get_pstate() const { return this->pimpl_cpu->get_pstate(); } @@ -282,7 +282,7 @@ int Host::get_pstate() * \brief Returns the list of storages attached to an host. * \return a vector containing all storages attached to the host */ -std::vector Host::get_attached_storages() +std::vector Host::get_attached_storages() const { return simgrid::simix::simcall([this] { return this->pimpl_->get_attached_storages(); }); }