MCPcopy Create free account
hub / github.com/Icinga/icinga2 / ArrayFilter

Function ArrayFilter

lib/base/array-script.cpp:164–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164static Array::Ptr ArrayFilter(const Function::Ptr& function)
165{
166 ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
167 Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
168 REQUIRE_NOT_NULL(self);
169 REQUIRE_NOT_NULL(function);
170
171 if (vframe->Sandboxed && !function->IsSideEffectFree())
172 BOOST_THROW_EXCEPTION(ScriptError("Filter function must be side-effect free."));
173
174 ArrayData result;
175
176 ObjectLock olock(self);
177 for (const Value& item : self) {
178 if (function->Invoke({ item }))
179 result.push_back(item);
180 }
181
182 return new Array(std::move(result));
183}
184
185static bool ArrayAny(const Function::Ptr& function)
186{

Callers

nothing calls this directly

Calls 4

ScriptErrorClass · 0.85
IsSideEffectFreeMethod · 0.80
push_backMethod · 0.80
InvokeMethod · 0.45

Tested by

no test coverage detected