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

Method EmitScope

lib/base/configwriter.cpp:57–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57void ConfigWriter::EmitScope(std::ostream& fp, int indentLevel, const Dictionary::Ptr& val,
58 const Array::Ptr& imports, bool splitDot)
59{
60 fp << "{";
61
62 if (imports && imports->GetLength() > 0) {
63 ObjectLock xlock(imports);
64 for (const Value& import : imports) {
65 fp << "\n";
66 EmitIndent(fp, indentLevel);
67 fp << "import ";
68 EmitString(fp, import.Get<String>());
69 }
70
71 fp << "\n";
72 }
73
74 if (val) {
75 ObjectLock olock(val);
76 for (const Dictionary::Pair& kv : val) {
77 fp << "\n";
78 EmitIndent(fp, indentLevel);
79
80 if (splitDot) {
81 std::vector<String> tokens = kv.first.Split(".");
82
83 // This is reachable from CreateObjectHandler. This check prevents API clients from creating deeply
84 // nested data structures that could overflow the stack later on.
85 if (tokens.size() > ConfigObject::VarDepthLimit) {
86 BOOST_THROW_EXCEPTION(std::invalid_argument("Attribute '" + kv.first +
87 "' exceeds maximum nesting level of " + std::to_string(ConfigObject::VarDepthLimit) + "."));
88 }
89
90 EmitIdentifier(fp, tokens[0], true);
91
92 for (std::vector<String>::size_type i = 1; i < tokens.size(); i++) {
93 fp << "[";
94 EmitString(fp, tokens[i]);
95 fp << "]";
96 }
97 } else
98 EmitIdentifier(fp, kv.first, true);
99
100 fp << " = ";
101 EmitValue(fp, indentLevel + 1, kv.second);
102 }
103 }
104
105 fp << "\n";
106 EmitIndent(fp, indentLevel - 1);
107 fp << "}";
108}
109
110void ConfigWriter::EmitValue(std::ostream& fp, int indentLevel, const Value& val)
111{

Callers

nothing calls this directly

Calls 3

SplitMethod · 0.80
GetLengthMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected