diff options
Diffstat (limited to 'src/linkedmap.h')
-rw-r--r-- | src/linkedmap.h | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/linkedmap.h b/src/linkedmap.h index f09b6d8..0e866d9 100644 --- a/src/linkedmap.h +++ b/src/linkedmap.h @@ -42,19 +42,31 @@ class LinkedMap //! Find an object given the key. //! Returns a pointer to the element if found or nullptr if it is not found. - const T *find(const char *key_) const + const T *find(const std::string &key) const { - std::string key(key_ ? key_ : ""); auto it = m_lookup.find(key); return it!=m_lookup.end() ? it->second : nullptr; } + //! Find an object given the key. + //! Returns a pointer to the element if found or nullptr if it is not found. + const T *find(const char *key) const + { + return find(std::string(key ? key : "")); + } + //! A non-const wrapper for find() const T* find(const char *key) { return const_cast<T*>(static_cast<const LinkedMap&>(*this).find(key)); } + //! A non-const wrapper for find() const + T* find(const std::string &key) + { + return const_cast<T*>(static_cast<const LinkedMap&>(*this).find(key)); + } + //! Adds a new object to the ordered vector if it was not added already. //! Return a non-owning pointer to the newly added object, or to the existing object if //! it was already inserted before under the given key. @@ -171,19 +183,31 @@ class LinkedRefMap //! find an object given the key. //! Returns a pointer to the object if found or nullptr if it is not found. - const T *find(const char *key_) const + const T *find(const std::string &key) const { - std::string key(key_ ? key_ : ""); auto it = m_lookup.find(key); return it!=m_lookup.end() ? it->second : nullptr; } + //! find an object given the key. + //! Returns a pointer to the object if found or nullptr if it is not found. + const T *find(const char *key) const + { + return find(std::string(key ? key : "")); + } + //! non-const wrapper for find() const T* find(const char *key) { return const_cast<T*>(static_cast<const LinkedRefMap&>(*this).find(key)); } + //! non-const wrapper for find() const + T* find(const std::string &key) + { + return const_cast<T*>(static_cast<const LinkedRefMap&>(*this).find(key)); + } + //! Adds an object reference to the ordered vector if it was not added already. //! Return true if the reference was added, and false if an object with the same key //! was already added before |