From: Martin Quinson Date: Fri, 25 Mar 2016 07:20:25 +0000 (+0100) Subject: kill unused constructors of Resources and other cleanups X-Git-Tag: v3_13~291^2~4 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5d618cbecf8b08ed4b0b4fc2373980b8ce4b4344 kill unused constructors of Resources and other cleanups + fix constness and useless checks --- diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index df99dc0545..f990c45ea6 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -154,10 +154,10 @@ void HostImpl::attach(simgrid::s4u::Host* host) p_host = host; } -bool HostImpl::isOn() { +bool HostImpl::isOn() const { return p_cpu->isOn(); } -bool HostImpl::isOff() { +bool HostImpl::isOff() const { return p_cpu->isOff(); } void HostImpl::turnOn(){ diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 69d0ce6a37..62e0cbc5eb 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -115,8 +115,8 @@ public: } void attach(simgrid::s4u::Host* host); - bool isOn() override; - bool isOff() override; + bool isOn() const override; + bool isOff() const override; void turnOn() override; void turnOff() override; diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index cb51390fc2..b5c3a805fe 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -558,50 +558,35 @@ namespace simgrid { namespace surf { Resource::Resource(Model *model, const char *name) - : Resource(model, name, 1/*ON*/) -{} - -Resource::Resource(Model *model, const char *name, lmm_constraint_t constraint) - : Resource(model, name, constraint, 1/*ON*/) -{} - -Resource::Resource(Model *model, const char *name, lmm_constraint_t constraint, int initiallyOn) : name_(xbt_strdup(name)) , model_(model) - , isOn_(initiallyOn) - , constraint_(constraint) {} -Resource::Resource(Model *model, const char *name, int initiallyOn) +Resource::Resource(Model *model, const char *name, lmm_constraint_t constraint) : name_(xbt_strdup(name)) , model_(model) - , isOn_(initiallyOn) + , constraint_(constraint) {} - Resource::~Resource() { xbt_free((void*)name_); } -bool Resource::isOn() { +bool Resource::isOn() const { return isOn_; } -bool Resource::isOff() { +bool Resource::isOff() const { return ! isOn_; } void Resource::turnOn() { - if (!isOn_) { - isOn_ = true; - } + isOn_ = true; } void Resource::turnOff() { - if (isOn_) { - isOn_ = false; - } + isOn_ = false; } Model *Resource::getModel() const { @@ -616,7 +601,7 @@ bool Resource::operator==(const Resource &other) const { return strcmp(name_, other.name_); } -lmm_constraint_t Resource::getConstraint() { +lmm_constraint_t Resource::getConstraint() const { return constraint_; } diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 12379ffc3a..66ed71dd84 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -374,7 +374,7 @@ namespace surf { /** @ingroup SURF_interface * @brief SURF resource interface class - * @details A resource represent an element of a component (e.g.: a link for the network) + * @details This is the ancestor class of every resources in SimGrid, such as links, CPU or storage */ XBT_PUBLIC_CLASS Resource { public: @@ -395,24 +395,13 @@ public: */ Resource(Model *model, const char *name, lmm_constraint_t constraint); - Resource(Model *model, const char *name, lmm_constraint_t constraint, int initiallyOn); - - /** - * @brief Resource constructor - * - * @param model Model associated to this Resource - * @param name The name of the Resource - * @param initiallyOn the initial state of the Resource - */ - Resource(Model *model, const char *name, int initiallyOn); - virtual ~Resource(); /** @brief Get the Model of the current Resource */ - Model *getModel() const ; + Model *getModel() const; /** @brief Get the name of the current Resource */ - const char *getName() const ; + const char *getName() const; bool operator==(const Resource &other) const; @@ -428,9 +417,9 @@ public: virtual bool isUsed()=0; /** @brief Check if the current Resource is active */ - virtual bool isOn(); + virtual bool isOn() const; /** @brief Check if the current Resource is shut down */ - virtual bool isOff(); + virtual bool isOff() const; /** @brief Turn on the current Resource */ virtual void turnOn(); /** @brief Turn off the current Resource */ @@ -439,11 +428,11 @@ public: private: const char *name_; Model *model_; - bool isOn_; + bool isOn_ = true; public: /* LMM */ /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */ - lmm_constraint_t getConstraint(); + lmm_constraint_t getConstraint() const; protected: lmm_constraint_t constraint_ = nullptr; };