From 5c10bad86fa18a71dc62d0aca740893fc2445fd2 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 30 Aug 2023 16:34:36 +0200 Subject: [PATCH] Introduce Dictionary#GetRef() --- lib/base/dictionary.cpp | 14 ++++++++++++++ lib/base/dictionary.hpp | 1 + 2 files changed, 15 insertions(+) diff --git a/lib/base/dictionary.cpp b/lib/base/dictionary.cpp index 9429af304..8d3f80d1f 100644 --- a/lib/base/dictionary.cpp +++ b/lib/base/dictionary.cpp @@ -67,6 +67,20 @@ bool Dictionary::Get(const String& key, Value *result) const return true; } +/** + * Retrieves a value's address from a dictionary. + * + * @param key The key whose value's address should be retrieved. + * @returns nullptr if the key was not found. + */ +const Value * Dictionary::GetRef(const String& key) const +{ + std::shared_lock lock (m_DataMutex); + auto it (m_Data.find(key)); + + return it == m_Data.end() ? nullptr : &it->second; +} + /** * Sets a value in the dictionary. * diff --git a/lib/base/dictionary.hpp b/lib/base/dictionary.hpp index 352c29ef9..ffccd630f 100644 --- a/lib/base/dictionary.hpp +++ b/lib/base/dictionary.hpp @@ -42,6 +42,7 @@ public: Value Get(const String& key) const; bool Get(const String& key, Value *result) const; + const Value * GetRef(const String& key) const; void Set(const String& key, Value value, bool overrideFrozen = false); bool Contains(const String& key) const;