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

Method Set

lib/base/scriptglobal.cpp:36–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36void ScriptGlobal::Set(const String& name, const Value& value)
37{
38 std::vector<String> tokens = name.Split(".");
39
40 if (tokens.empty())
41 BOOST_THROW_EXCEPTION(std::invalid_argument("Name must not be empty"));
42
43 {
44 ObjectLock olock(m_Globals);
45
46 Namespace::Ptr parent = m_Globals;
47
48 for (std::vector<String>::size_type i = 0; i < tokens.size(); i++) {
49 const String& token = tokens[i];
50
51 if (i + 1 != tokens.size()) {
52 Value vparent;
53
54 if (!parent->Get(token, &vparent)) {
55 Namespace::Ptr dict = new Namespace();
56 parent->Set(token, dict);
57 parent = dict;
58 } else {
59 parent = vparent;
60 }
61 }
62 }
63
64 parent->Set(tokens[tokens.size() - 1], value);
65 }
66}
67
68void ScriptGlobal::SetConst(const String& name, const Value& value)
69{

Callers 1

SetConstMethod · 0.45

Calls 4

SplitMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected