]> granicus.if.org Git - icinga2/commitdiff
Implement the Dictionary#values prototype function
authorGunnar Beutner <gunnar.beutner@icinga.com>
Mon, 15 May 2017 13:54:48 +0000 (15:54 +0200)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Mon, 15 May 2017 13:54:48 +0000 (15:54 +0200)
doc/18-library-reference.md
lib/base/dictionary-script.cpp

index 0a3f912256b4158c7c176f0ec60b6bf7eafb10bf..9d8cbc0ca36677726c9659cace549dc816f5d1a4 100644 (file)
@@ -1220,6 +1220,14 @@ Signature:
 
 Returns a list of keys for all items that are currently in the dictionary.
 
+### <a id="dictionary-keys"></a> Dictionary#values
+
+Signature:
+
+    function values();
+
+Returns a list of values for all items that are currently in the dictionary.
+
 ## <a id="scriptfunction-type"></a> Function type
 
 Inherits methods from the [Object type](18-library-reference.md#object-type).
index 908b719b210f8b249b031e219892bc81c95b8c0c..66aa26cbd7249876c24b1971c115c542cfbe68cc 100644 (file)
@@ -79,6 +79,18 @@ static Array::Ptr DictionaryKeys(void)
        return keys;
 }
 
+static Array::Ptr DictionaryValues(void)
+{
+       ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
+       Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
+       Array::Ptr keys = new Array();
+       ObjectLock olock(self);
+       for (const Dictionary::Pair& kv : self) {
+               keys->Add(kv.second);
+       }
+       return keys;
+}
+
 Object::Ptr Dictionary::GetPrototype(void)
 {
        static Dictionary::Ptr prototype;
@@ -92,6 +104,7 @@ Object::Ptr Dictionary::GetPrototype(void)
                prototype->Set("contains", new Function("Dictionary#contains", WrapFunction(DictionaryContains), { "key" }, true));
                prototype->Set("shallow_clone", new Function("Dictionary#shallow_clone", WrapFunction(DictionaryShallowClone), {}, true));
                prototype->Set("keys", new Function("Dictionary#keys", WrapFunction(DictionaryKeys), {}, true));
+               prototype->Set("values", new Function("Dictionary#values", WrapFunction(DictionaryValues), {}, true));
        }
 
        return prototype;