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

Function ArraySort

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

Source from the content-addressed store, hash-verified

67}
68
69static Array::Ptr ArraySort(const std::vector<Value>& args)
70{
71 ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
72 Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
73 REQUIRE_NOT_NULL(self);
74
75 Array::Ptr arr = self->ShallowClone();
76
77 if (args.empty()) {
78 ObjectLock olock(arr);
79 std::sort(arr->Begin(), arr->End());
80 } else {
81 Function::Ptr function = args[0];
82 REQUIRE_NOT_NULL(function);
83
84 if (vframe->Sandboxed && !function->IsSideEffectFree())
85 BOOST_THROW_EXCEPTION(ScriptError("Sort function must be side-effect free."));
86
87 ObjectLock olock(arr);
88 std::sort(arr->Begin(), arr->End(), [&args](const Value& a, const Value& b) -> bool {
89 Function::Ptr cmp = args[0];
90 return cmp->Invoke({ a, b });
91 });
92 }
93
94 return arr;
95}
96
97static Array::Ptr ArrayShallowClone()
98{

Callers

nothing calls this directly

Calls 7

ScriptErrorClass · 0.85
IsSideEffectFreeMethod · 0.80
ShallowCloneMethod · 0.45
emptyMethod · 0.45
BeginMethod · 0.45
EndMethod · 0.45
InvokeMethod · 0.45

Tested by

no test coverage detected