Merge pull request #9658 from Icinga/unfreeze

Dictionary#*(): remove bool overrideFrozen if unused
This commit is contained in:
Julian Brost 2023-02-10 19:42:00 +01:00 committed by GitHub
commit e074e892ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 16 deletions

View File

@ -142,14 +142,13 @@ Dictionary::Iterator Dictionary::End()
* Removes the item specified by the iterator from the dictionary. * Removes the item specified by the iterator from the dictionary.
* *
* @param it The iterator. * @param it The iterator.
* @param overrideFrozen Whether to allow modifying frozen dictionaries.
*/ */
void Dictionary::Remove(Dictionary::Iterator it, bool overrideFrozen) void Dictionary::Remove(Dictionary::Iterator it)
{ {
ASSERT(OwnsLock()); ASSERT(OwnsLock());
std::unique_lock<std::shared_timed_mutex> lock (m_DataMutex); std::unique_lock<std::shared_timed_mutex> lock (m_DataMutex);
if (m_Frozen && !overrideFrozen) if (m_Frozen)
BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionary must not be modified.")); BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionary must not be modified."));
m_Data.erase(it); m_Data.erase(it);
@ -159,14 +158,13 @@ void Dictionary::Remove(Dictionary::Iterator it, bool overrideFrozen)
* Removes the specified key from the dictionary. * Removes the specified key from the dictionary.
* *
* @param key The key. * @param key The key.
* @param overrideFrozen Whether to allow modifying frozen dictionaries.
*/ */
void Dictionary::Remove(const String& key, bool overrideFrozen) void Dictionary::Remove(const String& key)
{ {
ObjectLock olock(this); ObjectLock olock(this);
std::unique_lock<std::shared_timed_mutex> lock (m_DataMutex); std::unique_lock<std::shared_timed_mutex> lock (m_DataMutex);
if (m_Frozen && !overrideFrozen) if (m_Frozen)
BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionary must not be modified.")); BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionary must not be modified."));
Dictionary::Iterator it; Dictionary::Iterator it;
@ -180,15 +178,13 @@ void Dictionary::Remove(const String& key, bool overrideFrozen)
/** /**
* Removes all dictionary items. * Removes all dictionary items.
*
* @param overrideFrozen Whether to allow modifying frozen dictionaries.
*/ */
void Dictionary::Clear(bool overrideFrozen) void Dictionary::Clear()
{ {
ObjectLock olock(this); ObjectLock olock(this);
std::unique_lock<std::shared_timed_mutex> lock (m_DataMutex); std::unique_lock<std::shared_timed_mutex> lock (m_DataMutex);
if (m_Frozen && !overrideFrozen) if (m_Frozen)
BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionary must not be modified.")); BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionary must not be modified."));
m_Data.clear(); m_Data.clear();

View File

@ -50,11 +50,11 @@ public:
size_t GetLength() const; size_t GetLength() const;
void Remove(const String& key, bool overrideFrozen = false); void Remove(const String& key);
void Remove(Iterator it, bool overrideFrozen = false); void Remove(Iterator it);
void Clear(bool overrideFrozen = false); void Clear();
void CopyTo(const Dictionary::Ptr& dest) const; void CopyTo(const Dictionary::Ptr& dest) const;
Dictionary::Ptr ShallowClone() const; Dictionary::Ptr ShallowClone() const;

View File

@ -32,7 +32,7 @@ Value ScriptGlobal::Get(const String& name, const Value *defaultValue)
return result; return result;
} }
void ScriptGlobal::Set(const String& name, const Value& value, bool overrideFrozen) void ScriptGlobal::Set(const String& name, const Value& value)
{ {
std::vector<String> tokens = name.Split("."); std::vector<String> tokens = name.Split(".");
@ -60,7 +60,7 @@ void ScriptGlobal::Set(const String& name, const Value& value, bool overrideFroz
} }
} }
parent->SetFieldByName(tokens[tokens.size() - 1], value, overrideFrozen, DebugInfo()); parent->Set(tokens[tokens.size() - 1], value);
} }
} }

View File

@ -18,7 +18,7 @@ class ScriptGlobal
{ {
public: public:
static Value Get(const String& name, const Value *defaultValue = nullptr); static Value Get(const String& name, const Value *defaultValue = nullptr);
static void Set(const String& name, const Value& value, bool overrideFrozen = false); static void Set(const String& name, const Value& value);
static void SetConst(const String& name, const Value& value); static void SetConst(const String& name, const Value& value);
static bool Exists(const String& name); static bool Exists(const String& name);