]> granicus.if.org Git - icinga2/commitdiff
Implement the Dictionary#clear script function 6508/head
authorGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 2 Aug 2018 06:45:19 +0000 (08:45 +0200)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 2 Aug 2018 06:45:19 +0000 (08:45 +0200)
doc/18-library-reference.md
lib/base/dictionary-script.cpp

index 5a3209dfed121f83469c1a7e9509cd1df90d0d93..30277bfdf889e0e78f15ec7de50c954165fa50c0 100644 (file)
@@ -1428,6 +1428,14 @@ Signature:
 Removes the item with the specified `key`. Trying to remove an item which does not exist
 is a no-op.
 
+### Dictionary#clear <a id="dictionary-clear"></a>
+
+Signature:
+
+    function clear();
+
+Removes all items from the dictionary.
+
 ### Dictionary#set <a id="dictionary-set"></a>
 
 Signature:
index d188119e5d39995038bdbea42cb8d5fe95f967d0..7d805a59bfef1de830bdfacb6c379975a4a57a78 100644 (file)
@@ -57,6 +57,14 @@ static void DictionaryRemove(const String& key)
        self->Remove(key);
 }
 
+static void DictionaryClear()
+{
+       ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
+       Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
+       REQUIRE_NOT_NULL(self);
+       self->Clear();
+}
+
 static bool DictionaryContains(const String& key)
 {
        ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
@@ -115,6 +123,7 @@ Object::Ptr Dictionary::GetPrototype()
                { "set", new Function("Dictionary#set", DictionarySet, { "key", "value" }) },
                { "get", new Function("Dictionary#get", DictionaryGet, { "key" }) },
                { "remove", new Function("Dictionary#remove", DictionaryRemove, { "key" }) },
+               { "clear", new Function("Dictionary#clear", DictionaryClear, {}) },
                { "contains", new Function("Dictionary#contains", DictionaryContains, { "key" }, true) },
                { "shallow_clone", new Function("Dictionary#shallow_clone", DictionaryShallowClone, {}, true) },
                { "keys", new Function("Dictionary#keys", DictionaryKeys, {}, true) },