mirror of https://github.com/Icinga/icinga2.git
Implement the Dictionary#values prototype function
This commit is contained in:
parent
37f7c7a294
commit
1b77f4b336
|
@ -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).
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue