Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill unused constructors of Resources and other cleanups
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 25 Mar 2016 07:20:25 +0000 (08:20 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 25 Mar 2016 07:30:29 +0000 (08:30 +0100)
+ fix constness and useless checks

src/surf/HostImpl.cpp
src/surf/HostImpl.hpp
src/surf/surf_interface.cpp
src/surf/surf_interface.hpp

index df99dc0..f990c45 100644 (file)
@@ -154,10 +154,10 @@ void HostImpl::attach(simgrid::s4u::Host* host)
   p_host = host;
 }
 
   p_host = host;
 }
 
-bool HostImpl::isOn() {
+bool HostImpl::isOn() const {
   return p_cpu->isOn();
 }
   return p_cpu->isOn();
 }
-bool HostImpl::isOff() {
+bool HostImpl::isOff() const {
   return p_cpu->isOff();
 }
 void HostImpl::turnOn(){
   return p_cpu->isOff();
 }
 void HostImpl::turnOn(){
index 69d0ce6..62e0cbc 100644 (file)
@@ -115,8 +115,8 @@ public:
   }
   void attach(simgrid::s4u::Host* host);
 
   }
   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;
 
   void turnOn() override;
   void turnOff() override;
 
index cb51390..b5c3a80 100644 (file)
@@ -558,50 +558,35 @@ namespace simgrid {
 namespace surf {
 
 Resource::Resource(Model *model, const char *name)
 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)
   : 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)
   : name_(xbt_strdup(name))
   , model_(model)
-  , isOn_(initiallyOn)
+  , constraint_(constraint)
 {}
 
 {}
 
-
 Resource::~Resource() {
   xbt_free((void*)name_);
 }
 
 Resource::~Resource() {
   xbt_free((void*)name_);
 }
 
-bool Resource::isOn() {
+bool Resource::isOn() const {
   return isOn_;
 }
   return isOn_;
 }
-bool Resource::isOff() {
+bool Resource::isOff() const {
   return ! isOn_;
 }
 
 void Resource::turnOn()
 {
   return ! isOn_;
 }
 
 void Resource::turnOn()
 {
-  if (!isOn_) {
-    isOn_ = true;
-  }
+  isOn_ = true;
 }
 
 void Resource::turnOff()
 {
 }
 
 void Resource::turnOff()
 {
-  if (isOn_) {
-    isOn_ = false;
-  }
+  isOn_ = false;
 }
 
 Model *Resource::getModel() const {
 }
 
 Model *Resource::getModel() const {
@@ -616,7 +601,7 @@ bool Resource::operator==(const Resource &other) const {
   return strcmp(name_, other.name_);
 }
 
   return strcmp(name_, other.name_);
 }
 
-lmm_constraint_t Resource::getConstraint() {
+lmm_constraint_t Resource::getConstraint() const {
   return constraint_;
 }
 
   return constraint_;
 }
 
index 12379ff..66ed71d 100644 (file)
@@ -374,7 +374,7 @@ namespace surf {
 
 /** @ingroup SURF_interface
  * @brief SURF resource interface class
 
 /** @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:
  */
 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);
 
-  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 */
   virtual ~Resource();
 
   /** @brief Get the Model of the current Resource */
-  Model *getModel() const ;
+  Model *getModel() const;
 
   /** @brief Get the name of the current Resource */
 
   /** @brief Get the name of the current Resource */
-  const char *getName() const ;
+  const char *getName() const;
 
   bool operator==(const Resource &other) 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 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 */
   /** @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 */
   /** @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_;
 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) */
 
 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;
 };
 protected:
   lmm_constraint_t constraint_ = nullptr;
 };