Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix constness of some methods and add a std::hash<Resource>
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 25 Mar 2016 06:35:46 +0000 (07:35 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 25 Mar 2016 06:35:50 +0000 (07:35 +0100)
I'm not sure that the hash thing actually works.
Gabriel, I think I need your help here.

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

index 6373037..732406d 100644 (file)
@@ -604,14 +604,18 @@ void Resource::turnOff()
   }
 }
 
-Model *Resource::getModel() {
+Model *Resource::getModel() const {
   return p_model;
 }
 
-const char *Resource::getName() {
+const char *Resource::getName() const {
   return p_name;
 }
 
+bool Resource::operator==(const Resource &other) const {
+  return strcmp(p_name, other.p_name);
+}
+
 lmm_constraint_t Resource::getConstraint() {
   return p_constraint;
 }
index f51e48b..7efb6aa 100644 (file)
@@ -409,10 +409,12 @@ public:
   virtual ~Resource();
 
   /** @brief Get the Model of the current Resource */
-  Model *getModel();
+  Model *getModel() const ;
 
   /** @brief Get the name of the current Resource */
-  const char *getName();
+  const char *getName() const ;
+
+  bool operator==(const Resource &other) const;
 
   /**
    * @brief Apply an event of external load event to that storage
@@ -440,7 +442,7 @@ private:
   bool m_isOn;
 
 public: /* LMM */
-  /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component */
+  /** @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();
 protected:
   lmm_constraint_t p_constraint = nullptr;
@@ -449,4 +451,15 @@ protected:
 }
 }
 
+namespace std {
+  template <>
+  struct hash<simgrid::surf::Resource>
+  {
+    std::size_t operator()(const simgrid::surf::Resource& r) const
+    {
+      return (std::size_t) xbt_str_hash(r.getName());
+    }
+  };
+}
+
 #endif /* SURF_MODEL_H_ */