From f1d8f814d4af21e7e7a2bcba99009ad4bc8f6813 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 25 Mar 2016 07:35:46 +0100 Subject: [PATCH] fix constness of some methods and add a std::hash I'm not sure that the hash thing actually works. Gabriel, I think I need your help here. --- src/surf/surf_interface.cpp | 8 ++++++-- src/surf/surf_interface.hpp | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 6373037916..732406df3e 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -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; } diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index f51e48b690..7efb6aa6da 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -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 + { + std::size_t operator()(const simgrid::surf::Resource& r) const + { + return (std::size_t) xbt_str_hash(r.getName()); + } + }; +} + #endif /* SURF_MODEL_H_ */ -- 2.20.1