]> granicus.if.org Git - icinga2/commitdiff
Use initializer lists for arrays and dictionaries 5983/head
authorGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 11 Jan 2018 10:17:38 +0000 (11:17 +0100)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Tue, 16 Jan 2018 11:27:44 +0000 (12:27 +0100)
113 files changed:
lib/base/application.cpp
lib/base/array-script.cpp
lib/base/array.cpp
lib/base/array.hpp
lib/base/boolean-script.cpp
lib/base/configobject-script.cpp
lib/base/configobject.cpp
lib/base/datetime-script.cpp
lib/base/dictionary-script.cpp
lib/base/dictionary.cpp
lib/base/dictionary.hpp
lib/base/filelogger.cpp
lib/base/function-script.cpp
lib/base/json-script.cpp
lib/base/math-script.cpp
lib/base/number-script.cpp
lib/base/object-script.cpp
lib/base/process.cpp
lib/base/scriptglobal.cpp
lib/base/scriptutils.cpp
lib/base/serializer.cpp
lib/base/string-script.cpp
lib/base/sysloglogger.cpp
lib/base/typetype-script.cpp
lib/base/value-operators.cpp
lib/checker/checkercomponent.cpp
lib/cli/consolecommand.cpp
lib/cli/nodeutility.cpp
lib/compat/checkresultreader.cpp
lib/compat/compatlogger.cpp
lib/compat/externalcommandlistener.cpp
lib/compat/statusdatawriter.cpp
lib/config/configitem.cpp
lib/config/configitembuilder.cpp
lib/config/expression.cpp
lib/config/vmops.hpp
lib/db_ido/commanddbobject.cpp
lib/db_ido/dbconnection.cpp
lib/db_ido/dbconnection.ti
lib/db_ido/dbevents.cpp
lib/db_ido/dbobject.cpp
lib/db_ido/endpointdbobject.cpp
lib/db_ido/hostdbobject.cpp
lib/db_ido/hostgroupdbobject.cpp
lib/db_ido/idochecktask.cpp
lib/db_ido/servicedbobject.cpp
lib/db_ido/servicegroupdbobject.cpp
lib/db_ido/timeperioddbobject.cpp
lib/db_ido/userdbobject.cpp
lib/db_ido/usergroupdbobject.cpp
lib/db_ido/zonedbobject.cpp
lib/db_ido_mysql/idomysqlconnection.cpp
lib/db_ido_pgsql/idopgsqlconnection.cpp
lib/icinga/apiactions.cpp
lib/icinga/apievents.cpp
lib/icinga/checkable-check.cpp
lib/icinga/checkable-script.cpp
lib/icinga/clusterevents.cpp
lib/icinga/dependency-apply.cpp
lib/icinga/icingaapplication.cpp
lib/icinga/legacytimeperiod.cpp
lib/icinga/macroprocessor.cpp
lib/icinga/notification-apply.cpp
lib/icinga/pluginutility.cpp
lib/icinga/scheduleddowntime-apply.cpp
lib/icinga/service-apply.cpp
lib/icinga/service.cpp
lib/icinga/timeperiod.cpp
lib/livestatus/commandstable.cpp
lib/livestatus/contactgroupstable.cpp
lib/livestatus/contactstable.cpp
lib/livestatus/hostgroupstable.cpp
lib/livestatus/hoststable.cpp
lib/livestatus/livestatuslistener.cpp
lib/livestatus/livestatusquery.cpp
lib/livestatus/servicegroupstable.cpp
lib/livestatus/servicestable.cpp
lib/livestatus/statustable.cpp
lib/livestatus/zonestable.cpp
lib/methods/clusterzonechecktask.cpp
lib/methods/nullchecktask.cpp
lib/methods/pluginnotificationtask.cpp
lib/methods/randomchecktask.cpp
lib/methods/timeperiodtask.cpp
lib/notification/notificationcomponent.cpp
lib/perfdata/elasticsearchwriter.cpp
lib/perfdata/gelfwriter.cpp
lib/perfdata/graphitewriter.cpp
lib/perfdata/influxdbwriter.cpp
lib/perfdata/influxdbwriter.ti
lib/perfdata/opentsdbwriter.cpp
lib/perfdata/perfdatawriter.cpp
lib/remote/actionshandler.cpp
lib/remote/apilistener-configsync.cpp
lib/remote/apilistener-filesync.cpp
lib/remote/apilistener.cpp
lib/remote/configpackageshandler.cpp
lib/remote/configpackageutility.cpp
lib/remote/configstageshandler.cpp
lib/remote/consolehandler.cpp
lib/remote/createobjecthandler.cpp
lib/remote/deleteobjecthandler.cpp
lib/remote/httpserverconnection.cpp
lib/remote/infohandler.cpp
lib/remote/jsonrpcconnection-heartbeat.cpp
lib/remote/jsonrpcconnection-pki.cpp
lib/remote/modifyobjecthandler.cpp
lib/remote/objectqueryhandler.cpp
lib/remote/pkiutility.cpp
lib/remote/statushandler.cpp
lib/remote/templatequeryhandler.cpp
lib/remote/typequeryhandler.cpp
lib/remote/variablequeryhandler.cpp

index 0c325c728040d84e2d66db539a35a300805a29a6..e1717522c57d1a6187865b1992115374d91c9344 100644 (file)
@@ -400,24 +400,24 @@ pid_t Application::StartReloadProcess()
        Log(LogInformation, "Application", "Got reload command: Starting new instance.");
 
        // prepare arguments
-       Array::Ptr args = new Array();
-       args->Add(GetExePath(m_ArgV[0]));
+       ArrayData args;
+       args.push_back(GetExePath(m_ArgV[0]));
 
        for (int i=1; i < Application::GetArgC(); i++) {
                if (std::string(Application::GetArgV()[i]) != "--reload-internal")
-                       args->Add(Application::GetArgV()[i]);
+                       args.push_back(Application::GetArgV()[i]);
                else
                        i++;     // the next parameter after --reload-internal is the pid, remove that too
        }
 
 #ifndef _WIN32
-       args->Add("--reload-internal");
-       args->Add(Convert::ToString(Utility::GetPid()));
+       args.push_back("--reload-internal");
+       args.push_back(Convert::ToString(Utility::GetPid()));
 #else /* _WIN32 */
-       args->Add("--validate");
+       args.push_back("--validate");
 #endif /* _WIN32 */
 
-       Process::Ptr process = new Process(Process::PrepareCommand(args));
+       Process::Ptr process = new Process(Process::PrepareCommand(new Array(std::move(args))));
        process->SetTimeout(300);
        process->Run(&ReloadProcessCallback);
 
index 9bfec413034468620c1eebc8f06bb02ccaed36b4..3f7278ff6ba9bfe1e018051c2d9f8ed1a4072699 100644 (file)
@@ -147,14 +147,14 @@ static Array::Ptr ArrayMap(const Function::Ptr& function)
        if (vframe->Sandboxed && !function->IsSideEffectFree())
                BOOST_THROW_EXCEPTION(ScriptError("Map function must be side-effect free."));
 
-       Array::Ptr result = new Array();
+       ArrayData result;
 
        ObjectLock olock(self);
        for (const Value& item : self) {
-               result->Add(function->Invoke({ item }));
+               result.push_back(function->Invoke({ item }));
        }
 
-       return result;
+       return new Array(std::move(result));
 }
 
 static Value ArrayReduce(const Function::Ptr& function)
@@ -186,15 +186,15 @@ static Array::Ptr ArrayFilter(const Function::Ptr& function)
        if (vframe->Sandboxed && !function->IsSideEffectFree())
                BOOST_THROW_EXCEPTION(ScriptError("Filter function must be side-effect free."));
 
-       Array::Ptr result = new Array();
+       ArrayData result;
 
        ObjectLock olock(self);
        for (const Value& item : self) {
                if (function->Invoke({ item }))
-                       result->Add(item);
+                       result.push_back(item);
        }
 
-       return result;
+       return new Array(std::move(result));
 }
 
 static bool ArrayAny(const Function::Ptr& function)
@@ -247,28 +247,25 @@ static Array::Ptr ArrayUnique()
 
 Object::Ptr Array::GetPrototype()
 {
-       static Dictionary::Ptr prototype;
-
-       if (!prototype) {
-               prototype = new Dictionary();
-               prototype->Set("len", new Function("Array#len", ArrayLen, {}, true));
-               prototype->Set("set", new Function("Array#set", ArraySet, { "index", "value" }));
-               prototype->Set("get", new Function("Array#get", ArrayGet, { "index" }));
-               prototype->Set("add", new Function("Array#add", ArrayAdd, { "value" }));
-               prototype->Set("remove", new Function("Array#remove", ArrayRemove, { "index" }));
-               prototype->Set("contains", new Function("Array#contains", ArrayContains, { "value" }, true));
-               prototype->Set("clear", new Function("Array#clear", ArrayClear));
-               prototype->Set("sort", new Function("Array#sort", ArraySort, { "less_cmp" }, true));
-               prototype->Set("shallow_clone", new Function("Array#shallow_clone", ArrayShallowClone, {}, true));
-               prototype->Set("join", new Function("Array#join", ArrayJoin, { "separator" }, true));
-               prototype->Set("reverse", new Function("Array#reverse", ArrayReverse, {}, true));
-               prototype->Set("map", new Function("Array#map", ArrayMap, { "func" }, true));
-               prototype->Set("reduce", new Function("Array#reduce", ArrayReduce, { "reduce" }, true));
-               prototype->Set("filter", new Function("Array#filter", ArrayFilter, { "func" }, true));
-               prototype->Set("any", new Function("Array#any", ArrayAny, { "func" }, true));
-               prototype->Set("all", new Function("Array#all", ArrayAll, { "func" }, true));
-               prototype->Set("unique", new Function("Array#unique", ArrayUnique, {}, true));
-       }
+       static Dictionary::Ptr prototype = new Dictionary({
+               { "len", new Function("Array#len", ArrayLen, {}, true) },
+               { "set", new Function("Array#set", ArraySet, { "index", "value" }) },
+               { "get", new Function("Array#get", ArrayGet, { "index" }) },
+               { "add", new Function("Array#add", ArrayAdd, { "value" }) },
+               { "remove", new Function("Array#remove", ArrayRemove, { "index" }) },
+               { "contains", new Function("Array#contains", ArrayContains, { "value" }, true) },
+               { "clear", new Function("Array#clear", ArrayClear) },
+               { "sort", new Function("Array#sort", ArraySort, { "less_cmp" }, true) },
+               { "shallow_clone", new Function("Array#shallow_clone", ArrayShallowClone, {}, true) },
+               { "join", new Function("Array#join", ArrayJoin, { "separator" }, true) },
+               { "reverse", new Function("Array#reverse", ArrayReverse, {}, true) },
+               { "map", new Function("Array#map", ArrayMap, { "func" }, true) },
+               { "reduce", new Function("Array#reduce", ArrayReduce, { "reduce" }, true) },
+               { "filter", new Function("Array#filter", ArrayFilter, { "func" }, true) },
+               { "any", new Function("Array#any", ArrayAny, { "func" }, true) },
+               { "all", new Function("Array#all", ArrayAll, { "func" }, true) },
+               { "unique", new Function("Array#unique", ArrayUnique, {}, true) }
+       });
 
        return prototype;
 }
index 2a00d3b297b927907c60db413778f3b11069aa34..d6e8ee03e11e7d34ec954f47f25680e4e6c51708 100644 (file)
@@ -32,6 +32,14 @@ template class std::vector<Value>;
 
 REGISTER_PRIMITIVE_TYPE(Array, Object, Array::GetPrototype());
 
+Array::Array(const ArrayData& other)
+       : m_Data(other)
+{ }
+
+Array::Array(ArrayData&& other)
+       : m_Data(std::move(other))
+{ }
+
 Array::Array(std::initializer_list<Value> init)
        : m_Data(init)
 { }
@@ -228,14 +236,14 @@ Array::Ptr Array::ShallowClone() const
  */
 Object::Ptr Array::Clone() const
 {
-       Array::Ptr arr = new Array();
+       ArrayData arr;
 
        ObjectLock olock(this);
        for (const Value& val : m_Data) {
-               arr->Add(val.Clone());
+               arr.push_back(val.Clone());
        }
 
-       return arr;
+       return new Array(std::move(arr));
 }
 
 Array::Ptr Array::Reverse() const
@@ -305,4 +313,3 @@ Array::Iterator icinga::end(const Array::Ptr& x)
 {
        return x->End();
 }
-
index 36f4f62f911e501ab7acf33c2ac83d605d4b559f..6fd1abae5a361ef84cc0be66ebb13dffcdb0cec7 100644 (file)
@@ -30,6 +30,8 @@
 namespace icinga
 {
 
+typedef std::vector<Value> ArrayData;
+
 /**
  * An array of Value items.
  *
@@ -48,6 +50,8 @@ public:
        typedef std::vector<Value>::size_type SizeType;
 
        Array() = default;
+       Array(const ArrayData& other);
+       Array(ArrayData&& other);
        Array(std::initializer_list<Value> init);
 
        Value Get(SizeType index) const;
index e0da2e9bc8be4dce01d0d0e3757dabce4737bc36..1116cc2509667780bd92aa0d6762bcb193966eee 100644 (file)
@@ -34,12 +34,9 @@ static String BooleanToString()
 
 Object::Ptr Boolean::GetPrototype()
 {
-       static Dictionary::Ptr prototype;
-
-       if (!prototype) {
-               prototype = new Dictionary();
-               prototype->Set("to_string", new Function("Boolean#to_string", BooleanToString, {}, true));
-       }
+       static Dictionary::Ptr prototype = new Dictionary({
+               { "to_string", new Function("Boolean#to_string", BooleanToString, {}, true) }
+       });
 
        return prototype;
 }
index 7321e3bf55c3129207196287c5812e52862df8bf..d2cdba45b2b265a920e1ab47183e8a092612f174 100644 (file)
@@ -41,13 +41,10 @@ static void ConfigObjectRestoreAttribute(const String& attr)
 
 Object::Ptr ConfigObject::GetPrototype()
 {
-       static Dictionary::Ptr prototype;
-
-       if (!prototype) {
-               prototype = new Dictionary();
-               prototype->Set("modify_attribute", new Function("ConfigObject#modify_attribute", ConfigObjectModifyAttribute, { "attr", "value" }, false));
-               prototype->Set("restore_attribute", new Function("ConfigObject#restore_attribute", ConfigObjectRestoreAttribute, { "attr", "value" }, false));
-       }
+       static Dictionary::Ptr prototype = new Dictionary({
+               { "modify_attribute", new Function("ConfigObject#modify_attribute", ConfigObjectModifyAttribute, { "attr", "value" }, false) },
+               { "restore_attribute", new Function("ConfigObject#restore_attribute", ConfigObjectRestoreAttribute, { "attr", "value" }, false) }
+       });
 
        return prototype;
 }
index 824ec2630302d8b694c536c7ea4433966e2bb156..8fe176b31519ed85adcf9be7d5e24418e6101d20 100644 (file)
@@ -506,17 +506,16 @@ void ConfigObject::DumpObjects(const String& filename, int attributeTypes)
                        continue;
 
                for (const ConfigObject::Ptr& object : dtype->GetObjects()) {
-                       Dictionary::Ptr persistentObject = new Dictionary();
-
-                       persistentObject->Set("type", type->GetName());
-                       persistentObject->Set("name", object->GetName());
-
                        Dictionary::Ptr update = Serialize(object, attributeTypes);
 
                        if (!update)
                                continue;
 
-                       persistentObject->Set("update", update);
+                       Dictionary::Ptr persistentObject = new Dictionary({
+                               { "type", type->GetName() },
+                               { "name", object->GetName() },
+                               { "update", update }
+                       });
 
                        String json = JsonEncode(persistentObject);
 
@@ -717,13 +716,13 @@ Dictionary::Ptr ConfigObject::GetSourceLocation() const
 {
        DebugInfo di = GetDebugInfo();
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("path", di.Path);
-       result->Set("first_line", di.FirstLine);
-       result->Set("first_column", di.FirstColumn);
-       result->Set("last_line", di.LastLine);
-       result->Set("last_column", di.LastColumn);
-       return result;
+       return new Dictionary({
+               { "path", di.Path },
+               { "first_line", di.FirstLine },
+               { "first_column", di.FirstColumn },
+               { "last_line", di.LastLine },
+               { "last_column", di.LastColumn }
+       });
 }
 
 NameComposer::~NameComposer()
index 9c8f422c16067bf2eac33099a3ac30345aee2e0c..4a16a0aa21e52b8f8fd1fbb3708672ae78108384 100644 (file)
@@ -35,12 +35,9 @@ static String DateTimeFormat(const String& format)
 
 Object::Ptr DateTime::GetPrototype()
 {
-       static Dictionary::Ptr prototype;
-
-       if (!prototype) {
-               prototype = new Dictionary();
-               prototype->Set("format", new Function("DateTime#format", DateTimeFormat, { "format" }));
-       }
+       static Dictionary::Ptr prototype = new Dictionary({
+               { "format", new Function("DateTime#format", DateTimeFormat, { "format" }) }
+       });
 
        return prototype;
 }
index ffa256f6b6f48d85fa0ce2f810622dc83988d778..a45afa826260959e94e31f00fa8fb5a25df67fb9 100644 (file)
@@ -71,41 +71,38 @@ static Array::Ptr DictionaryKeys()
 {
        ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
        Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
-       Array::Ptr keys = new Array();
+       ArrayData keys;
        ObjectLock olock(self);
        for (const Dictionary::Pair& kv : self) {
-               keys->Add(kv.first);
+               keys.push_back(kv.first);
        }
-       return keys;
+       return new Array(std::move(keys));
 }
 
 static Array::Ptr DictionaryValues()
 {
        ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
        Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
-       Array::Ptr keys = new Array();
+       ArrayData values;
        ObjectLock olock(self);
        for (const Dictionary::Pair& kv : self) {
-               keys->Add(kv.second);
+               values.push_back(kv.second);
        }
-       return keys;
+       return new Array(std::move(values));
 }
 
 Object::Ptr Dictionary::GetPrototype()
 {
-       static Dictionary::Ptr prototype;
-
-       if (!prototype) {
-               prototype = new Dictionary();
-               prototype->Set("len", new Function("Dictionary#len", DictionaryLen, {}, true));
-               prototype->Set("set", new Function("Dictionary#set", DictionarySet, { "key", "value" }));
-               prototype->Set("get", new Function("Dictionary#get", DictionaryGet, { "key" }));
-               prototype->Set("remove", new Function("Dictionary#remove", DictionaryRemove, { "key" }));
-               prototype->Set("contains", new Function("Dictionary#contains", DictionaryContains, { "key" }, true));
-               prototype->Set("shallow_clone", new Function("Dictionary#shallow_clone", DictionaryShallowClone, {}, true));
-               prototype->Set("keys", new Function("Dictionary#keys", DictionaryKeys, {}, true));
-               prototype->Set("values", new Function("Dictionary#values", DictionaryValues, {}, true));
-       }
+       static Dictionary::Ptr prototype = new Dictionary({
+               { "len", new Function("Dictionary#len", DictionaryLen, {}, true) },
+               { "set", new Function("Dictionary#set", DictionarySet, { "key", "value" }) },
+               { "get", new Function("Dictionary#get", DictionaryGet, { "key" }) },
+               { "remove", new Function("Dictionary#remove", DictionaryRemove, { "key" }) },
+               { "contains", new Function("Dictionary#contains", DictionaryContains, { "key" }, true) },
+               { "shallow_clone", new Function("Dictionary#shallow_clone", DictionaryShallowClone, {}, true) },
+               { "keys", new Function("Dictionary#keys", DictionaryKeys, {}, true) },
+               { "values", new Function("Dictionary#values", DictionaryValues, {}, true) }
+       });
 
        return prototype;
 }
index da80220b18d163bc73b0f9abde290b510c7a00a1..d4ac10b50100abc65403ebb7682116ff134f2c3f 100644 (file)
@@ -29,6 +29,22 @@ template class std::map<String, Value>;
 
 REGISTER_PRIMITIVE_TYPE(Dictionary, Object, Dictionary::GetPrototype());
 
+Dictionary::Dictionary(const DictionaryData& other)
+{
+       for (const auto& kv : other)
+               m_Data.emplace(kv);
+}
+
+Dictionary::Dictionary(DictionaryData&& other)
+{
+       for (auto& kv : other)
+               m_Data.emplace(std::move(kv));
+}
+
+Dictionary::Dictionary(std::initializer_list<Dictionary::Pair> init)
+       : m_Data(init)
+{ }
+
 /**
  * Retrieves a value from a dictionary.
  *
@@ -202,14 +218,19 @@ Dictionary::Ptr Dictionary::ShallowClone() const
  */
 Object::Ptr Dictionary::Clone() const
 {
-       Dictionary::Ptr dict = new Dictionary();
+       DictionaryData dict;
 
-       ObjectLock olock(this);
-       for (const Dictionary::Pair& kv : m_Data) {
-               dict->Set(kv.first, kv.second.Clone());
+       {
+               ObjectLock olock(this);
+
+               dict.reserve(GetLength());
+
+               for (const Dictionary::Pair& kv : m_Data) {
+                       dict.emplace_back(kv.first, kv.second.Clone());
+               }
        }
 
-       return dict;
+       return new Dictionary(std::move(dict));
 }
 
 /**
index c1bd42c6fd84dea150f5325a441c4ceabf8854d1..7854573a6f01a2e474c8ae629ca47c6e278bbf68 100644 (file)
@@ -30,6 +30,8 @@
 namespace icinga
 {
 
+typedef std::vector<std::pair<String, Value> > DictionaryData;
+
 /**
  * A container that holds key-value pairs.
  *
@@ -49,6 +51,11 @@ public:
 
        typedef std::map<String, Value>::value_type Pair;
 
+       Dictionary() = default;
+       Dictionary(const DictionaryData& other);
+       Dictionary(DictionaryData&& other);
+       Dictionary(std::initializer_list<Pair> init);
+
        Value Get(const String& key) const;
        bool Get(const String& key, Value *result) const;
        void Set(const String& key, Value value);
index 3216ae1ec6cc24d3382b4e47a6c8c69d35d82a23..b1c8b0ad10f308df2b06eb1013b9a16730b1f498 100644 (file)
@@ -32,13 +32,13 @@ REGISTER_STATSFUNCTION(FileLogger, &FileLogger::StatsFunc);
 
 void FileLogger::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const FileLogger::Ptr& filelogger : ConfigType::GetObjectsByType<FileLogger>()) {
-               nodes->Set(filelogger->GetName(), 1); //add more stats
+               nodes.emplace_back(filelogger->GetName(), 1); //add more stats
        }
 
-       status->Set("filelogger", nodes);
+       status->Set("filelogger", new Dictionary(std::move(nodes)));
 }
 
 /**
index 7f8a0aeec48a0d5fed9362b241c7b45a44e4cae5..757eb4e2de479ade4448cdbf8d9ef88a33f3e2eb 100644 (file)
@@ -55,13 +55,10 @@ static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args)
 
 Object::Ptr Function::GetPrototype()
 {
-       static Dictionary::Ptr prototype;
-
-       if (!prototype) {
-               prototype = new Dictionary();
-               prototype->Set("call", new Function("Function#call", FunctionCall));
-               prototype->Set("callv", new Function("Function#callv", FunctionCallV));
-       }
+       static Dictionary::Ptr prototype = new Dictionary({
+               { "call", new Function("Function#call", FunctionCall) },
+               { "callv", new Function("Function#callv", FunctionCallV) }
+       });
 
        return prototype;
 }
index cf598490e946b82c6f7f04f6575109ff70641f44..9df6ee783cd5ec88c55bd9e572cbedf4b4f6be26 100644 (file)
@@ -32,11 +32,11 @@ static String JsonEncodeShim(const Value& value)
 }
 
 INITIALIZE_ONCE([]() {
-       Dictionary::Ptr jsonObj = new Dictionary();
-
-       /* Methods */
-       jsonObj->Set("encode", new Function("Json#encode", JsonEncodeShim, { "value" }, true));
-       jsonObj->Set("decode", new Function("Json#decode", JsonDecode, { "value" }, true));
+       Dictionary::Ptr jsonObj = new Dictionary({
+               /* Methods */
+               { "encode", new Function("Json#encode", JsonEncodeShim, { "value" }, true) },
+               { "decode", new Function("Json#decode", JsonDecode, { "value" }, true) }
+       });
 
        ScriptGlobal::Set("Json", jsonObj);
 });
index f6f05ece8f0a68c064170c98ec03e32008e133a0..dab48a5dfbd942091dc3c94f6471770bba158320 100644 (file)
@@ -158,40 +158,40 @@ static double MathSign(double x)
 }
 
 INITIALIZE_ONCE([]() {
-       Dictionary::Ptr mathObj = new Dictionary();
-
-       /* Constants */
-       mathObj->Set("E", 2.71828182845904523536);
-       mathObj->Set("LN2", 0.693147180559945309417);
-       mathObj->Set("LN10", 2.30258509299404568402);
-       mathObj->Set("LOG2E", 1.44269504088896340736);
-       mathObj->Set("LOG10E", 0.434294481903251827651);
-       mathObj->Set("PI", 3.14159265358979323846);
-       mathObj->Set("SQRT1_2", 0.707106781186547524401);
-       mathObj->Set("SQRT2", 1.41421356237309504880);
-
-       /* Methods */
-       mathObj->Set("abs", new Function("Math#abs", MathAbs, { "x" }, true));
-       mathObj->Set("acos", new Function("Math#acos", MathAcos, { "x" }, true));
-       mathObj->Set("asin", new Function("Math#asin", MathAsin, { "x" }, true));
-       mathObj->Set("atan", new Function("Math#atan", MathAtan, { "x" }, true));
-       mathObj->Set("atan2", new Function("Math#atan2", MathAtan2, { "x", "y" }, true));
-       mathObj->Set("ceil", new Function("Math#ceil", MathCeil, { "x" }, true));
-       mathObj->Set("cos", new Function("Math#cos", MathCos, { "x" }, true));
-       mathObj->Set("exp", new Function("Math#exp", MathExp, { "x" }, true));
-       mathObj->Set("floor", new Function("Math#floor", MathFloor, { "x" }, true));
-       mathObj->Set("log", new Function("Math#log", MathLog, { "x" }, true));
-       mathObj->Set("max", new Function("Math#max", MathMax, {}, true));
-       mathObj->Set("min", new Function("Math#min", MathMin, {}, true));
-       mathObj->Set("pow", new Function("Math#pow", MathPow, { "x", "y" }, true));
-       mathObj->Set("random", new Function("Math#random", MathRandom, {}, true));
-       mathObj->Set("round", new Function("Math#round", MathRound, { "x" }, true));
-       mathObj->Set("sin", new Function("Math#sin", MathSin, { "x" }, true));
-       mathObj->Set("sqrt", new Function("Math#sqrt", MathSqrt, { "x" }, true));
-       mathObj->Set("tan", new Function("Math#tan", MathTan, { "x" }, true));
-       mathObj->Set("isnan", new Function("Math#isnan", MathIsnan, { "x" }, true));
-       mathObj->Set("isinf", new Function("Math#isinf", MathIsinf, { "x" }, true));
-       mathObj->Set("sign", new Function("Math#sign", MathSign, { "x" }, true));
+       Dictionary::Ptr mathObj = new Dictionary({
+               /* Constants */
+               { "E", 2.71828182845904523536 },
+               { "LN2", 0.693147180559945309417 },
+               { "LN10", 2.30258509299404568402 },
+               { "LOG2E", 1.44269504088896340736 },
+               { "LOG10E", 0.434294481903251827651 },
+               { "PI", 3.14159265358979323846 },
+               { "SQRT1_2", 0.707106781186547524401 },
+               { "SQRT2", 1.41421356237309504880 },
+
+               /* Methods */
+               { "abs", new Function("Math#abs", MathAbs, { "x" }, true) },
+               { "acos", new Function("Math#acos", MathAcos, { "x" }, true) },
+               { "asin", new Function("Math#asin", MathAsin, { "x" }, true) },
+               { "atan", new Function("Math#atan", MathAtan, { "x" }, true) },
+               { "atan2", new Function("Math#atan2", MathAtan2, { "x", "y" }, true) },
+               { "ceil", new Function("Math#ceil", MathCeil, { "x" }, true) },
+               { "cos", new Function("Math#cos", MathCos, { "x" }, true) },
+               { "exp", new Function("Math#exp", MathExp, { "x" }, true) },
+               { "floor", new Function("Math#floor", MathFloor, { "x" }, true) },
+               { "log", new Function("Math#log", MathLog, { "x" }, true) },
+               { "max", new Function("Math#max", MathMax, {}, true) },
+               { "min", new Function("Math#min", MathMin, {}, true) },
+               { "pow", new Function("Math#pow", MathPow, { "x", "y" }, true) },
+               { "random", new Function("Math#random", MathRandom, {}, true) },
+               { "round", new Function("Math#round", MathRound, { "x" }, true) },
+               { "sin", new Function("Math#sin", MathSin, { "x" }, true) },
+               { "sqrt", new Function("Math#sqrt", MathSqrt, { "x" }, true) },
+               { "tan", new Function("Math#tan", MathTan, { "x" }, true) },
+               { "isnan", new Function("Math#isnan", MathIsnan, { "x" }, true) },
+               { "isinf", new Function("Math#isinf", MathIsinf, { "x" }, true) },
+               { "sign", new Function("Math#sign", MathSign, { "x" }, true) }
+       });
 
        ScriptGlobal::Set("Math", mathObj);
 });
index 8458f8d216b73dca6715356d7cb2572087a87f50..8ec9ae5547cfdf6f8e189de77840e67ee7a37309 100644 (file)
@@ -33,12 +33,9 @@ static String NumberToString()
 
 Object::Ptr Number::GetPrototype()
 {
-       static Dictionary::Ptr prototype;
-
-       if (!prototype) {
-               prototype = new Dictionary();
-               prototype->Set("to_string", new Function("Number#to_string", NumberToString, {}, true));
-       }
+       static Dictionary::Ptr prototype = new Dictionary({
+               { "to_string", new Function("Number#to_string", NumberToString, {}, true) }
+       });
 
        return prototype;
 }
index 3adf20d0020c1df34eea95394fa262b147dd1015..8c42314d6a9169cdbb8e38b6f9abead2c5e7846c 100644 (file)
@@ -48,14 +48,11 @@ static Object::Ptr ObjectClone()
 
 Object::Ptr Object::GetPrototype()
 {
-       static Dictionary::Ptr prototype;
-
-       if (!prototype) {
-               prototype = new Dictionary();
-               prototype->Set("to_string", new Function("Object#to_string", ObjectToString, {}, true));
-               prototype->Set("notify_attribute", new Function("Object#notify_attribute", ObjectNotifyAttribute, { "attribute" }, false));
-               prototype->Set("clone", new Function("Object#clone", ObjectClone, {}, true));
-       }
+       static Dictionary::Ptr prototype = new Dictionary({
+                       { "to_string", new Function("Object#to_string", ObjectToString, {}, true) },
+                       { "notify_attribute", new Function("Object#notify_attribute", ObjectNotifyAttribute, { "attribute" }, false) },
+                       { "clone", new Function("Object#clone", ObjectClone, {}, true) }
+       });
 
        return prototype;
 }
index 4f87ab3b538e564deeabc46d3bb0ba2a41ec3113..d5d3d69d2ccae47e6fecb6cc43ab8e1024cce6fb 100644 (file)
@@ -201,10 +201,11 @@ static Value ProcessSpawnImpl(struct msghdr *msgh, const Dictionary::Ptr& reques
 
        delete[] envp;
 
-       Dictionary::Ptr response = new Dictionary();
-       response->Set("rc", pid);
-       if (errorCode)
-               response->Set("errno", errorCode);
+       Dictionary::Ptr response = new Dictionary({
+               { "rc", pid },
+               { "errno", errorCode }
+       });
+
        return response;
 }
 
@@ -217,8 +218,9 @@ static Value ProcessKillImpl(struct msghdr *msgh, const Dictionary::Ptr& request
        kill(pid, signum);
        int error = errno;
 
-       Dictionary::Ptr response = new Dictionary();
-       response->Set("errno", error);
+       Dictionary::Ptr response = new Dictionary({
+               { "errno", error }
+       });
 
        return response;
 }
@@ -230,9 +232,10 @@ static Value ProcessWaitPIDImpl(struct msghdr *msgh, const Dictionary::Ptr& requ
        int status;
        int rc = waitpid(pid, &status, 0);
 
-       Dictionary::Ptr response = new Dictionary();
-       response->Set("status", status);
-       response->Set("rc", rc);
+       Dictionary::Ptr response = new Dictionary({
+               { "status", status },
+               { "rc", rc }
+       });
 
        return response;
 }
@@ -375,11 +378,12 @@ static void StartSpawnProcessHelper()
 
 static pid_t ProcessSpawn(const std::vector<String>& arguments, const Dictionary::Ptr& extraEnvironment, bool adjustPriority, int fds[3])
 {
-       Dictionary::Ptr request = new Dictionary();
-       request->Set("command", "spawn");
-       request->Set("arguments", Array::FromVector(arguments));
-       request->Set("extraEnvironment", extraEnvironment);
-       request->Set("adjustPriority", adjustPriority);
+       Dictionary::Ptr request = new Dictionary({
+               { "command", "spawn" },
+               { "arguments", Array::FromVector(arguments) },
+               { "extraEnvironment", extraEnvironment },
+               { "adjustPriority", adjustPriority }
+       });
 
        String jrequest = JsonEncode(request);
        size_t length = jrequest.GetLength();
@@ -435,10 +439,11 @@ send_message:
 
 static int ProcessKill(pid_t pid, int signum)
 {
-       Dictionary::Ptr request = new Dictionary();
-       request->Set("command", "kill");
-       request->Set("pid", pid);
-       request->Set("signum", signum);
+       Dictionary::Ptr request = new Dictionary({
+               { "command", "kill" },
+               { "pid", pid },
+               { "signum", signum }
+       });
 
        String jrequest = JsonEncode(request);
        size_t length = jrequest.GetLength();
@@ -467,9 +472,10 @@ send_message:
 
 static int ProcessWaitPID(pid_t pid, int *status)
 {
-       Dictionary::Ptr request = new Dictionary();
-       request->Set("command", "waitpid");
-       request->Set("pid", pid);
+       Dictionary::Ptr request = new Dictionary({
+               { "command", "waitpid" },
+               { "pid", pid }
+       });
 
        String jrequest = JsonEncode(request);
        size_t length = jrequest.GetLength();
index dccaf758c0a1c24b93c7d1648d36625e33523795..dc7bb3296a0b012e75b09a0204f8500e8c78d331 100644 (file)
@@ -105,16 +105,15 @@ void ScriptGlobal::WriteToFile(const String& filename)
 
        ObjectLock olock(m_Globals);
        for (const Dictionary::Pair& kv : m_Globals) {
-               Dictionary::Ptr persistentVariable = new Dictionary();
-
-               persistentVariable->Set("name", kv.first);
-
                Value value = kv.second;
 
                if (value.IsObject())
                        value = Convert::ToString(value);
 
-               persistentVariable->Set("value", value);
+               Dictionary::Ptr persistentVariable = new Dictionary({
+                       { "name", kv.first },
+                       { "value", value }
+               });
 
                String json = JsonEncode(persistentVariable);
 
index 6dd27b4647343e2dba6f66a1fed26daa52126135..cbedd9f975eac53f0a45419a6ba6518632fb1f96 100644 (file)
@@ -267,12 +267,7 @@ Array::Ptr ScriptUtils::Union(const std::vector<Value>& arguments)
                }
        }
 
-       Array::Ptr result = new Array();
-       for (const Value& value : values) {
-               result->Add(value);
-       }
-
-       return result;
+       return Array::FromSet(values);
 }
 
 Array::Ptr ScriptUtils::Intersection(const std::vector<Value>& arguments)
@@ -370,16 +365,16 @@ Array::Ptr ScriptUtils::Range(const std::vector<Value>& arguments)
                        BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid number of arguments for range()"));
        }
 
-       Array::Ptr result = new Array();
+       ArrayData result;
 
        if ((start < end && increment <= 0) ||
                (start > end && increment >= 0))
-               return result;
+               return new Array();
 
        for (double i = start; (increment > 0 ? i < end : i > end); i += increment)
-               result->Add(i);
+               result.push_back(i);
 
-       return result;
+       return new Array(std::move(result));
 }
 
 Type::Ptr ScriptUtils::TypeOf(const Value& value)
@@ -389,16 +384,16 @@ Type::Ptr ScriptUtils::TypeOf(const Value& value)
 
 Array::Ptr ScriptUtils::Keys(const Dictionary::Ptr& dict)
 {
-       Array::Ptr result = new Array();
+       ArrayData result;
 
        if (dict) {
                ObjectLock olock(dict);
                for (const Dictionary::Pair& kv : dict) {
-                       result->Add(kv.first);
+                       result.push_back(kv.first);
                }
        }
 
-       return result;
+       return new Array(std::move(result));
 }
 
 ConfigObject::Ptr ScriptUtils::GetObject(const Value& vtype, const String& name)
@@ -428,12 +423,12 @@ Array::Ptr ScriptUtils::GetObjects(const Type::Ptr& type)
        if (!ctype)
                BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type: Type must inherit from 'ConfigObject'"));
 
-       Array::Ptr result = new Array();
+       ArrayData result;
 
        for (const ConfigObject::Ptr& object : ctype->GetObjects())
-               result->Add(object);
+               result.push_back(object);
 
-       return result;
+       return new Array(std::move(result));
 }
 
 void ScriptUtils::Assert(const Value& arg)
index 73ab6a356592401d72cf3ccb899c413c6386e131..7296ec3ce9da90b65eeb754e625d382462a5e4f8 100644 (file)
@@ -26,28 +26,32 @@ using namespace icinga;
 
 static Array::Ptr SerializeArray(const Array::Ptr& input, int attributeTypes)
 {
-       Array::Ptr result = new Array();
+       ArrayData result;
+
+       result.reserve(input->GetLength());
 
        ObjectLock olock(input);
 
        for (const Value& value : input) {
-               result->Add(Serialize(value, attributeTypes));
+               result.emplace_back(Serialize(value, attributeTypes));
        }
 
-       return result;
+       return new Array(std::move(result));
 }
 
 static Dictionary::Ptr SerializeDictionary(const Dictionary::Ptr& input, int attributeTypes)
 {
-       Dictionary::Ptr result = new Dictionary();
+       DictionaryData result;
+
+       result.reserve(input->GetLength());
 
        ObjectLock olock(input);
 
        for (const Dictionary::Pair& kv : input) {
-               result->Set(kv.first, Serialize(kv.second, attributeTypes));
+               result.emplace_back(kv.first, Serialize(kv.second, attributeTypes));
        }
 
-       return result;
+       return new Dictionary(std::move(result));
 }
 
 static Object::Ptr SerializeObject(const Object::Ptr& input, int attributeTypes)
@@ -57,7 +61,8 @@ static Object::Ptr SerializeObject(const Object::Ptr& input, int attributeTypes)
        if (!type)
                return nullptr;
 
-       Dictionary::Ptr fields = new Dictionary();
+       DictionaryData fields;
+       fields.reserve(type->GetFieldCount() + 1);
 
        for (int i = 0; i < type->GetFieldCount(); i++) {
                Field field = type->GetFieldInfo(i);
@@ -65,38 +70,45 @@ static Object::Ptr SerializeObject(const Object::Ptr& input, int attributeTypes)
                if (attributeTypes != 0 && (field.Attributes & attributeTypes) == 0)
                        continue;
 
-               fields->Set(field.Name, Serialize(input->GetField(i), attributeTypes));
+               if (strcmp(field.Name, "type") == 0)
+                       continue;
+
+               fields.emplace_back(field.Name, Serialize(input->GetField(i), attributeTypes));
        }
 
-       fields->Set("type", type->GetName());
+       fields.emplace_back("type", type->GetName());
 
-       return fields;
+       return new Dictionary(std::move(fields));
 }
 
 static Array::Ptr DeserializeArray(const Array::Ptr& input, bool safe_mode, int attributeTypes)
 {
-       Array::Ptr result = new Array();
+       ArrayData result;
+
+       result.reserve(input->GetLength());
 
        ObjectLock olock(input);
 
        for (const Value& value : input) {
-               result->Add(Deserialize(value, safe_mode, attributeTypes));
+               result.emplace_back(Deserialize(value, safe_mode, attributeTypes));
        }
 
-       return result;
+       return new Array(std::move(result));
 }
 
 static Dictionary::Ptr DeserializeDictionary(const Dictionary::Ptr& input, bool safe_mode, int attributeTypes)
 {
-       Dictionary::Ptr result = new Dictionary();
+       DictionaryData result;
+
+       result.reserve(input->GetLength());
 
        ObjectLock olock(input);
 
        for (const Dictionary::Pair& kv : input) {
-               result->Set(kv.first, Deserialize(kv.second, safe_mode, attributeTypes));
+               result.emplace_back(kv.first, Deserialize(kv.second, safe_mode, attributeTypes));
        }
 
-       return result;
+       return new Dictionary(std::move(result));
 }
 
 static Object::Ptr DeserializeObject(const Object::Ptr& object, const Dictionary::Ptr& input, bool safe_mode, int attributeTypes)
index ee975abff29d29ffe5fe76f12a5ee400338b101b..83cc9c3fa2ba865e2341a49ab7cbd2f6bc8e4d2c 100644 (file)
@@ -78,11 +78,7 @@ static Array::Ptr StringSplit(const String& delims)
        std::vector<String> tokens;
        boost::algorithm::split(tokens, self, boost::is_any_of(delims));
 
-       Array::Ptr result = new Array();
-       for (const String& token : tokens) {
-               result->Add(token);
-       }
-       return result;
+       return Array::FromVector(tokens);
 }
 
 static int StringFind(const std::vector<Value>& args)
@@ -141,22 +137,19 @@ static String StringTrim()
 
 Object::Ptr String::GetPrototype()
 {
-       static Dictionary::Ptr prototype;
-
-       if (!prototype) {
-               prototype = new Dictionary();
-               prototype->Set("len", new Function("String#len", StringLen, {}, true));
-               prototype->Set("to_string", new Function("String#to_string", StringToString, {}, true));
-               prototype->Set("substr", new Function("String#substr", StringSubstr, { "start", "len" }, true));
-               prototype->Set("upper", new Function("String#upper", StringUpper, {}, true));
-               prototype->Set("lower", new Function("String#lower", StringLower, {}, true));
-               prototype->Set("split", new Function("String#split", StringSplit, { "delims" }, true));
-               prototype->Set("find", new Function("String#find", StringFind, { "str", "start" }, true));
-               prototype->Set("contains", new Function("String#contains", StringContains, { "str" }, true));
-               prototype->Set("replace", new Function("String#replace", StringReplace, { "search", "replacement" }, true));
-               prototype->Set("reverse", new Function("String#reverse", StringReverse, {}, true));
-               prototype->Set("trim", new Function("String#trim", StringTrim, {}, true));
-       }
+       static Dictionary::Ptr prototype = new Dictionary({
+               { "len", new Function("String#len", StringLen, {}, true) },
+               { "to_string", new Function("String#to_string", StringToString, {}, true) },
+               { "substr", new Function("String#substr", StringSubstr, { "start", "len" }, true) },
+               { "upper", new Function("String#upper", StringUpper, {}, true) },
+               { "lower", new Function("String#lower", StringLower, {}, true) },
+               { "split", new Function("String#split", StringSplit, { "delims" }, true) },
+               { "find", new Function("String#find", StringFind, { "str", "start" }, true) },
+               { "contains", new Function("String#contains", StringContains, { "str" }, true) },
+               { "replace", new Function("String#replace", StringReplace, { "search", "replacement" }, true) },
+               { "reverse", new Function("String#reverse", StringReverse, {}, true) },
+               { "trim", new Function("String#trim", StringTrim, {}, true) }
+       });
 
        return prototype;
 }
index fb719997cc2afd8c61e681a39c682a8222cf1349..e7e17a92fce6f523bb396d96a8c50b65059c426f 100644 (file)
@@ -80,13 +80,13 @@ void SyslogLogger::StaticInitialize()
 
 void SyslogLogger::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const SyslogLogger::Ptr& sysloglogger : ConfigType::GetObjectsByType<SyslogLogger>()) {
-               nodes->Set(sysloglogger->GetName(), 1); //add more stats
+               nodes.emplace_back(sysloglogger->GetName(), 1); //add more stats
        }
 
-       status->Set("sysloglogger", nodes);
+       status->Set("sysloglogger", new Dictionary(std::move(nodes)));
 }
 
 void SyslogLogger::OnConfigLoaded()
index d47a76f27bc3052e4e7e29ddf4f8e4dfc0a97063..0a6cfbc1dd9fc0613b0a79fea99605ee42ce98cb 100644 (file)
@@ -42,12 +42,9 @@ static void TypeRegisterAttributeHandler(const String& fieldName, const Function
 
 Object::Ptr TypeType::GetPrototype()
 {
-       static Dictionary::Ptr prototype;
-
-       if (!prototype) {
-               prototype = new Dictionary();
-               prototype->Set("register_attribute_handler", new Function("Type#register_attribute_handler", TypeRegisterAttributeHandler, { "field", "callback" }, false));
-       }
+       static Dictionary::Ptr prototype = new Dictionary({
+               { "register_attribute_handler", new Function("Type#register_attribute_handler", TypeRegisterAttributeHandler, { "field", "callback" }, false) }
+       });
 
        return prototype;
 }
index 78fd0757b77a918131130a64854cddfaf8a5b375..9ce5a2d24743dc8817f4452b5ef23be4d85c766b 100644 (file)
@@ -285,7 +285,7 @@ Value icinga::operator-(const Value& lhs, const Value& rhs)
                if (lhs.IsEmpty())
                        return new Array();
 
-               Array::Ptr result = new Array();
+               ArrayData result;
                Array::Ptr left = lhs;
                Array::Ptr right = rhs;
 
@@ -303,10 +303,10 @@ Value icinga::operator-(const Value& lhs, const Value& rhs)
                        if (found)
                                continue;
 
-                       result->Add(lv);
+                       result.push_back(lv);
                }
 
-               return result;
+               return new Array(std::move(result));
        } else
                BOOST_THROW_EXCEPTION(std::invalid_argument("Operator - cannot be applied to values of type '" + lhs.GetTypeName() + "' and '" + rhs.GetTypeName() + "'"));
 }
index bb30b68368b3be1312073602b7d51ec1ea932f25..f2027e9ea7767b36cc7140db0d7f1f1fd82fe5a7 100644 (file)
@@ -39,24 +39,23 @@ REGISTER_STATSFUNCTION(CheckerComponent, &CheckerComponent::StatsFunc);
 
 void CheckerComponent::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const CheckerComponent::Ptr& checker : ConfigType::GetObjectsByType<CheckerComponent>()) {
                unsigned long idle = checker->GetIdleCheckables();
                unsigned long pending = checker->GetPendingCheckables();
 
-               Dictionary::Ptr stats = new Dictionary();
-               stats->Set("idle", idle);
-               stats->Set("pending", pending);
-
-               nodes->Set(checker->GetName(), stats);
+               nodes.emplace_back(checker->GetName(), new Dictionary({
+                       { "idle", idle },
+                       { "pending", pending }
+               }));
 
                String perfdata_prefix = "checkercomponent_" + checker->GetName() + "_";
                perfdata->Add(new PerfdataValue(perfdata_prefix + "idle", Convert::ToDouble(idle)));
                perfdata->Add(new PerfdataValue(perfdata_prefix + "pending", Convert::ToDouble(pending)));
        }
 
-       status->Set("checkercomponent", nodes);
+       status->Set("checkercomponent", new Dictionary(std::move(nodes)));
 }
 
 void CheckerComponent::OnConfigLoaded()
index 9225fd6d2b1235447e1b8caddc6688d587bb3b45..c102452dce8d02c8a707f0c71111f28b5698688b 100644 (file)
@@ -86,8 +86,9 @@ extern "C" void dbg_eval_with_value(const Value& value, const char *text)
 
        try {
                ScriptFrame frame(true);
-               frame.Locals = new Dictionary();
-               frame.Locals->Set("arg", value);
+               frame.Locals = new Dictionary({
+                       { "arg", value }
+               });
                expr = ConfigCompiler::CompileText("<dbg>", text);
                Value result = Serialize(expr->Evaluate(frame), 0);
                dbg_inspect_value(result);
@@ -102,8 +103,9 @@ extern "C" void dbg_eval_with_object(Object *object, const char *text)
 
        try {
                ScriptFrame frame(true);
-               frame.Locals = new Dictionary();
-               frame.Locals->Set("arg", object);
+               frame.Locals = new Dictionary({
+                       { "arg", object }
+               });
                expr = ConfigCompiler::CompileText("<dbg>", text);
                Value result = Serialize(expr->Evaluate(frame), 0);
                dbg_inspect_value(result);
index 1a028f9f12362fe1477e91b47882843052904d3d..0157d6d23fc6463bb2048a4e17446fd1349bda24 100644 (file)
@@ -56,13 +56,11 @@ int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoi
 {
        Array::Ptr my_config = new Array();
 
-       Dictionary::Ptr my_master_zone = new Dictionary();
        Array::Ptr my_master_zone_members = new Array();
 
        String master_zone_name = "master"; //TODO: Find a better name.
 
        for (const std::string& endpoint : endpoints) {
-
                /* extract all --endpoint arguments and store host,port info */
                std::vector<String> tokens;
                boost::algorithm::split(tokens, endpoint, boost::is_any_of(","));
@@ -94,42 +92,33 @@ int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoi
        }
 
        /* add the master zone to the config */
-       my_master_zone->Set("__name", master_zone_name);
-       my_master_zone->Set("__type", "Zone");
-       my_master_zone->Set("endpoints", my_master_zone_members);
-
-       my_config->Add(my_master_zone);
+       my_config->Add(new Dictionary({
+               { "__name", master_zone_name },
+               { "__type", "Zone" },
+               { "endpoints", my_master_zone_members }
+       }));
 
        /* store the local generated node configuration */
-       Dictionary::Ptr my_endpoint = new Dictionary();
-       Dictionary::Ptr my_zone = new Dictionary();
-
-       my_endpoint->Set("__name", new ConfigIdentifier("NodeName"));
-       my_endpoint->Set("__type", "Endpoint");
-
-       Array::Ptr my_zone_members = new Array();
-       my_zone_members->Add(new ConfigIdentifier("NodeName"));
-
-       my_zone->Set("__name", new ConfigIdentifier("ZoneName"));
-       my_zone->Set("__type", "Zone");
-       my_zone->Set("parent", master_zone_name); //set the master zone as parent
-
-       my_zone->Set("endpoints", my_zone_members);
+       my_config->Add(new Dictionary({
+               { "__name", new ConfigIdentifier("NodeName") },
+               { "__type", "Endpoint" }
+       }));
+
+       my_config->Add(new Dictionary({
+               { "__name", new ConfigIdentifier("ZoneName") },
+               { "__type", "Zone" },
+               { "parent", master_zone_name }, //set the master zone as parent
+               { "endpoints", new Array({ new ConfigIdentifier("ZoneName") }) }
+       }));
 
        for (const String& globalzone : globalZones) {
-               Dictionary::Ptr myGlobalZone = new Dictionary();
-
-               myGlobalZone->Set("__name", globalzone);
-               myGlobalZone->Set("__type", "Zone");
-               myGlobalZone->Set("global", true);
-
-               my_config->Add(myGlobalZone);
+               my_config->Add(new Dictionary({
+                       { "__name", globalzone },
+                       { "__type", "Zone" },
+                       { "global", true }
+               }));
        }
 
-       /* store the local config */
-       my_config->Add(my_endpoint);
-       my_config->Add(my_zone);
-
        /* write the newly generated configuration */
        String zones_path = Application::GetSysconfDir() + "/icinga2/zones.conf";
 
@@ -143,32 +132,23 @@ int NodeUtility::GenerateNodeMasterIcingaConfig(const std::vector<String>& globa
        Array::Ptr my_config = new Array();
 
        /* store the local generated node master configuration */
-       Dictionary::Ptr my_master_endpoint = new Dictionary();
-       Dictionary::Ptr my_master_zone = new Dictionary();
-
-       Array::Ptr my_master_zone_members = new Array();
-
-       my_master_endpoint->Set("__name", new ConfigIdentifier("NodeName"));
-       my_master_endpoint->Set("__type", "Endpoint");
+       my_config->Add(new Dictionary({
+               { "__name", new ConfigIdentifier("NodeName") },
+               { "__type", "Endpoint" }
+       }));
 
-       my_master_zone_members->Add(new ConfigIdentifier("NodeName"));
-
-       my_master_zone->Set("__name", new ConfigIdentifier("ZoneName"));
-       my_master_zone->Set("__type", "Zone");
-       my_master_zone->Set("endpoints", my_master_zone_members);
-
-       /* store the local config */
-       my_config->Add(my_master_endpoint);
-       my_config->Add(my_master_zone);
+       my_config->Add(new Dictionary({
+               { "__name", new ConfigIdentifier("ZoneName") },
+               { "__type", "Zone" },
+               { "endpoints", new Array({ new ConfigIdentifier("NodeName") }) }
+       }));
 
        for (const String& globalzone : globalZones) {
-               Dictionary::Ptr myGlobalZone = new Dictionary();
-
-               myGlobalZone->Set("__name", globalzone);
-               myGlobalZone->Set("__type", "Zone");
-               myGlobalZone->Set("global", true);
-
-               my_config->Add(myGlobalZone);
+               my_config->Add(new Dictionary({
+                       { "__name", globalzone },
+                       { "__type", "Zone" },
+                       { "global", true }
+               }));
        }
 
        /* write the newly generated configuration */
index 40bcbad0604bd5ed89811353e222bc60ca8fde81..01e35dbd8fba71faa72fa5bfc00fbd9f66099054 100644 (file)
@@ -42,13 +42,13 @@ REGISTER_STATSFUNCTION(CheckResultReader, &CheckResultReader::StatsFunc);
 
 void CheckResultReader::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const CheckResultReader::Ptr& checkresultreader : ConfigType::GetObjectsByType<CheckResultReader>()) {
-               nodes->Set(checkresultreader->GetName(), 1); //add more stats
+               nodes.emplace_back(checkresultreader->GetName(), 1); //add more stats
        }
 
-       status->Set("checkresultreader", nodes);
+       status->Set("checkresultreader", new Dictionary(std::move(nodes)));
 }
 
 /**
index 253a557e27647a5a42379764745f193366437385..58b97af698665429071ce9608d70a26c31e9365c 100644 (file)
@@ -44,13 +44,13 @@ REGISTER_STATSFUNCTION(CompatLogger, &CompatLogger::StatsFunc);
 
 void CompatLogger::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const CompatLogger::Ptr& compat_logger : ConfigType::GetObjectsByType<CompatLogger>()) {
-               nodes->Set(compat_logger->GetName(), 1); //add more stats
+               nodes.emplace_back(compat_logger->GetName(), 1); // add more stats
        }
 
-       status->Set("compatlogger", nodes);
+       status->Set("compatlogger", new Dictionary(std::move(nodes)));
 }
 
 /**
index 66452c2d44e48eb2f0473df189ab677d73cf9a60..5843bfd32c48694af5ed0795749da6c32e53faec 100644 (file)
@@ -34,13 +34,13 @@ REGISTER_STATSFUNCTION(ExternalCommandListener, &ExternalCommandListener::StatsF
 
 void ExternalCommandListener::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const ExternalCommandListener::Ptr& externalcommandlistener : ConfigType::GetObjectsByType<ExternalCommandListener>()) {
-               nodes->Set(externalcommandlistener->GetName(), 1); //add more stats
+               nodes.emplace_back(externalcommandlistener->GetName(), 1); //add more stats
        }
 
-       status->Set("externalcommandlistener", nodes);
+       status->Set("externalcommandlistener", new Dictionary(std::move(nodes)));
 }
 
 /**
index f81a8d5ef848fb0e88ea30929bdab236ccc96e9b..90b8ef1317ef88406bfbec420b14184d44cce207 100644 (file)
@@ -52,13 +52,13 @@ REGISTER_STATSFUNCTION(StatusDataWriter, &StatusDataWriter::StatsFunc);
 
 void StatusDataWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const StatusDataWriter::Ptr& statusdatawriter : ConfigType::GetObjectsByType<StatusDataWriter>()) {
-               nodes->Set(statusdatawriter->GetName(), 1); //add more stats
+               nodes.emplace_back(statusdatawriter->GetName(), 1); //add more stats
        }
 
-       status->Set("statusdatawriter", nodes);
+       status->Set("statusdatawriter", new Dictionary(std::move(nodes)));
 }
 
 /**
index e1b9da781a72731e31180779dc38292540d79811..1f125be44cf709123a6662b6584421a63749451a 100644 (file)
@@ -288,26 +288,25 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
                throw;
        }
 
-       Dictionary::Ptr persistentItem = new Dictionary();
-
-       persistentItem->Set("type", GetType()->GetName());
-       persistentItem->Set("name", GetName());
-       persistentItem->Set("properties", Serialize(dobj, FAConfig));
-       persistentItem->Set("debug_hints", dhint);
+       Dictionary::Ptr persistentItem = new Dictionary({
+               { "type", GetType()->GetName() },
+               { "name", GetName() },
+               { "properties", Serialize(dobj, FAConfig) },
+               { "debug_hints", dhint },
+               { "debug_info", new Array({
+                       m_DebugInfo.Path,
+                       m_DebugInfo.FirstLine,
+                       m_DebugInfo.FirstColumn,
+                       m_DebugInfo.LastLine,
+                       m_DebugInfo.LastColumn,
+               }) }
+       });
 
-       Array::Ptr di = new Array();
-       di->Add(m_DebugInfo.Path);
-       di->Add(m_DebugInfo.FirstLine);
-       di->Add(m_DebugInfo.FirstColumn);
-       di->Add(m_DebugInfo.LastLine);
-       di->Add(m_DebugInfo.LastColumn);
-       persistentItem->Set("debug_info", di);
+       dhint.reset();
 
        ConfigCompilerContext::GetInstance()->WriteObject(persistentItem);
        persistentItem.reset();
 
-       dhint.reset();
-
        dobj->Register();
 
        m_Object = dobj;
index e37430deae67641c31b546812b8a4599aa13e43a..d81b595d2bd45b2ec1ecd0c8de182ac93c8ae0e7 100644 (file)
@@ -103,8 +103,7 @@ ConfigItem::Ptr ConfigItemBuilder::Compile()
 
        std::vector<std::unique_ptr<Expression> > exprs;
 
-       Array::Ptr templateArray = new Array();
-       templateArray->Add(m_Name);
+       Array::Ptr templateArray = new Array({ m_Name });
 
        exprs.emplace_back(new SetExpression(MakeIndexer(ScopeThis, "templates"), OpSetAdd,
                std::unique_ptr<LiteralExpression>(new LiteralExpression(templateArray)), m_DebugInfo));
index f355509e5497cd71150ec41df4b561db2c683442..938deb69b5ed64cd4c0eed09f54e407c94d49da6 100644 (file)
@@ -461,17 +461,17 @@ ExpressionResult FunctionCallExpression::DoEvaluate(ScriptFrame& frame, DebugHin
 
 ExpressionResult ArrayExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
 {
-       Array::Ptr result = new Array();
-       result->Reserve(m_Expressions.size());
+       ArrayData result;
+       result.reserve(m_Expressions.size());
 
        for (const auto& aexpr : m_Expressions) {
                ExpressionResult element = aexpr->Evaluate(frame);
                CHECK_RESULT(element);
 
-               result->Add(element.GetValue());
+               result.push_back(element.GetValue());
        }
 
-       return result;
+       return new Array(std::move(result));
 }
 
 ExpressionResult DictExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
index 68b4b663b03a773db2079ad2e57e7d0b3257f1eb..50338173000ead3ed3fdcfa70386f0bf77b85716 100644 (file)
@@ -255,17 +255,15 @@ public:
 private:
        static inline Dictionary::Ptr EvaluateClosedVars(ScriptFrame& frame, const std::map<String, std::unique_ptr<Expression> >& closedVars)
        {
-               Dictionary::Ptr locals;
+               if (closedVars.empty())
+                       return nullptr;
 
-               if (!closedVars.empty()) {
-                       locals = new Dictionary();
+               DictionaryData locals;
 
-                       for (const auto& cvar : closedVars) {
-                               locals->Set(cvar.first, cvar.second->Evaluate(frame));
-                       }
-               }
+               for (const auto& cvar : closedVars)
+                       locals.emplace_back(cvar.first, cvar.second->Evaluate(frame));
 
-               return locals;
+               return new Dictionary(std::move(locals));
        }
 };
 
index b770a0b626990653b4df294b1fbfc8da640274a6..b097bed3315935eb84059cb88227f87d6a3c27f5 100644 (file)
@@ -35,12 +35,11 @@ CommandDbObject::CommandDbObject(const DbType::Ptr& type, const String& name1, c
 
 Dictionary::Ptr CommandDbObject::GetConfigFields() const
 {
-       Dictionary::Ptr fields = new Dictionary();
        Command::Ptr command = static_pointer_cast<Command>(GetObject());
 
-       fields->Set("command_line", CompatUtility::GetCommandLine(command));
-
-       return fields;
+       return new Dictionary({
+               { "command_line", CompatUtility::GetCommandLine(command) }
+       });
 }
 
 Dictionary::Ptr CommandDbObject::GetStatusFields() const
index 7202a24472e61662036799eee1e81c2a08a3c94c..79d058614c6692c70c17aa3ffc938cc3c244da3f 100644 (file)
@@ -109,12 +109,14 @@ void DbConnection::Pause()
        query1.IdColumn = "programstatus_id";
        query1.Type = DbQueryUpdate;
        query1.Category = DbCatProgramStatus;
-       query1.WhereCriteria = new Dictionary();
-       query1.WhereCriteria->Set("instance_id", 0);  /* DbConnection class fills in real ID */
+       query1.WhereCriteria = new Dictionary({
+               { "instance_id", 0 }  /* DbConnection class fills in real ID */
+       });
 
-       query1.Fields = new Dictionary();
-       query1.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
-       query1.Fields->Set("program_end_time", DbValue::FromTimestamp(Utility::GetTime()));
+       query1.Fields = new Dictionary({
+               { "instance_id", 0 }, /* DbConnection class fills in real ID */
+               { "program_end_time", DbValue::FromTimestamp(Utility::GetTime()) }
+       });
 
        query1.Priority = PriorityHigh;
 
@@ -137,10 +139,11 @@ void DbConnection::InsertRuntimeVariable(const String& key, const Value& value)
        query.Table = "runtimevariables";
        query.Type = DbQueryInsert;
        query.Category = DbCatProgramStatus;
-       query.Fields = new Dictionary();
-       query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
-       query.Fields->Set("varname", key);
-       query.Fields->Set("varvalue", value);
+       query.Fields = new Dictionary({
+               { "instance_id", 0 }, /* DbConnection class fills in real ID */
+               { "varname", key },
+               { "varvalue", value }
+       });
        DbObject::OnQuery(query);
 }
 
@@ -157,26 +160,30 @@ void DbConnection::UpdateProgramStatus()
        query1.Type = DbQueryInsert | DbQueryUpdate;
        query1.Category = DbCatProgramStatus;
 
-       query1.Fields = new Dictionary();
-       query1.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
-       query1.Fields->Set("program_version", Application::GetAppVersion());
-       query1.Fields->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
-       query1.Fields->Set("program_start_time", DbValue::FromTimestamp(Application::GetStartTime()));
-       query1.Fields->Set("is_currently_running", 1);
-       query1.Fields->Set("endpoint_name", IcingaApplication::GetInstance()->GetNodeName());
-       query1.Fields->Set("process_id", Utility::GetPid());
-       query1.Fields->Set("daemon_mode", 1);
-       query1.Fields->Set("last_command_check", DbValue::FromTimestamp(Utility::GetTime()));
-       query1.Fields->Set("notifications_enabled", (IcingaApplication::GetInstance()->GetEnableNotifications() ? 1 : 0));
-       query1.Fields->Set("active_host_checks_enabled", (IcingaApplication::GetInstance()->GetEnableHostChecks() ? 1 : 0));
-       query1.Fields->Set("passive_host_checks_enabled", 1);
-       query1.Fields->Set("active_service_checks_enabled", (IcingaApplication::GetInstance()->GetEnableServiceChecks() ? 1 : 0));
-       query1.Fields->Set("passive_service_checks_enabled", 1);
-       query1.Fields->Set("event_handlers_enabled", (IcingaApplication::GetInstance()->GetEnableEventHandlers() ? 1 : 0));
-       query1.Fields->Set("flap_detection_enabled", (IcingaApplication::GetInstance()->GetEnableFlapping() ? 1 : 0));
-       query1.Fields->Set("process_performance_data", (IcingaApplication::GetInstance()->GetEnablePerfdata() ? 1 : 0));
-       query1.WhereCriteria = new Dictionary();
-       query1.WhereCriteria->Set("instance_id", 0);  /* DbConnection class fills in real ID */
+       query1.Fields = new Dictionary({
+               { "instance_id", 0 }, /* DbConnection class fills in real ID */
+               { "program_version", Application::GetAppVersion() },
+               { "status_update_time", DbValue::FromTimestamp(Utility::GetTime()) },
+               { "program_start_time", DbValue::FromTimestamp(Application::GetStartTime()) },
+               { "is_currently_running", 1 },
+               { "endpoint_name", IcingaApplication::GetInstance()->GetNodeName() },
+               { "process_id", Utility::GetPid() },
+               { "daemon_mode", 1 },
+               { "last_command_check", DbValue::FromTimestamp(Utility::GetTime()) },
+               { "notifications_enabled", (IcingaApplication::GetInstance()->GetEnableNotifications() ? 1 : 0) },
+               { "active_host_checks_enabled", (IcingaApplication::GetInstance()->GetEnableHostChecks() ? 1 : 0) },
+               { "passive_host_checks_enabled", 1 },
+               { "active_service_checks_enabled", (IcingaApplication::GetInstance()->GetEnableServiceChecks() ? 1 : 0) },
+               { "passive_service_checks_enabled", 1 },
+               { "event_handlers_enabled", (IcingaApplication::GetInstance()->GetEnableEventHandlers() ? 1 : 0) },
+               { "flap_detection_enabled", (IcingaApplication::GetInstance()->GetEnableFlapping() ? 1 : 0) },
+               { "process_performance_data", (IcingaApplication::GetInstance()->GetEnablePerfdata() ? 1 : 0) }
+       });
+
+       query1.WhereCriteria = new Dictionary({
+               { "instance_id", 0 }  /* DbConnection class fills in real ID */
+       });
+
        query1.Priority = PriorityHigh;
        queries.emplace_back(std::move(query1));
 
@@ -190,8 +197,9 @@ void DbConnection::UpdateProgramStatus()
        query3.Table = "runtimevariables";
        query3.Type = DbQueryDelete;
        query3.Category = DbCatProgramStatus;
-       query3.WhereCriteria = new Dictionary();
-       query3.WhereCriteria->Set("instance_id", 0);  /* DbConnection class fills in real ID */
+       query3.WhereCriteria = new Dictionary({
+               { "instance_id", 0 } /* DbConnection class fills in real ID */
+       });
        DbObject::OnQuery(query3);
 
        InsertRuntimeVariable("total_services", ConfigType::Get<Service>()->GetObjectCount());
index 4a2e2f488596694d916af8fadc4f1b23bef0b904..2f6e60d023f946a8532661e460feec91aa3dbf42 100644 (file)
@@ -37,20 +37,19 @@ abstract class DbConnection : ConfigObject
 
        [config] Array::Ptr categories {
                default {{{
-                       Array::Ptr cat = new Array();
-                       cat->Add("DbCatConfig");
-                       cat->Add("DbCatState");
-                       cat->Add("DbCatAcknowledgement");
-                       cat->Add("DbCatComment");
-                       cat->Add("DbCatDowntime");
-                       cat->Add("DbCatEventHandler");
-                       cat->Add("DbCatFlapping");
-                       cat->Add("DbCatNotification");
-                       cat->Add("DbCatProgramStatus");
-                       cat->Add("DbCatRetention");
-                       cat->Add("DbCatStateHistory");
-
-                       return cat;
+                       return new Array({
+                               "DbCatConfig",
+                               "DbCatState",
+                               "DbCatAcknowledgement",
+                               "DbCatComment",
+                               "DbCatDowntime",
+                               "DbCatEventHandler",
+                               "DbCatFlapping",
+                               "DbCatNotification",
+                               "DbCatProgramStatus",
+                               "DbCatRetention",
+                               "DbCatStateHistory"
+                       });
                }}}
        };
        [no_user_view, no_user_modify] int categories_filter_real (CategoryFilter);
index 1e5ec1bd22a8eda599486207f6c5b95b324a26df..97709793be2e3d7681341068c99dfb28b0261f91 100644 (file)
@@ -111,10 +111,9 @@ void DbEvents::NextCheckUpdatedHandler(const Checkable::Ptr& checkable)
        query1.StatusUpdate = true;
        query1.Object = DbObject::GetOrCreateByObject(checkable);
 
-       Dictionary::Ptr fields1 = new Dictionary();
-       fields1->Set("next_check", DbValue::FromTimestamp(checkable->GetNextCheck()));
-
-       query1.Fields = fields1;
+       query1.Fields = new Dictionary({
+               { "next_check", DbValue::FromTimestamp(checkable->GetNextCheck()) }
+       });
 
        DbObject::OnQuery(query1);
 }
@@ -145,7 +144,11 @@ void DbEvents::FlappingChangedHandler(const Checkable::Ptr& checkable)
        fields1->Set("is_flapping", checkable->IsFlapping());
        fields1->Set("percent_state_change", checkable->GetFlappingCurrent());
 
-       query1.Fields = fields1;
+       query1.Fields = new Dictionary({
+               { "is_flapping", checkable->IsFlapping() },
+               { "percent_state_change", checkable->GetFlappingCurrent() }
+       });
+
        query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
        DbObject::OnQuery(query1);
@@ -176,12 +179,12 @@ void DbEvents::LastNotificationChangedHandler(const Notification::Ptr& notificat
        query1.StatusUpdate = true;
        query1.Object = DbObject::GetOrCreateByObject(checkable);
 
-       Dictionary::Ptr fields1 = new Dictionary();
-       fields1->Set("last_notification", DbValue::FromTimestamp(now_bag.first));
-       fields1->Set("next_notification", DbValue::FromTimestamp(timeBag.first));
-       fields1->Set("current_notification_number", notification->GetNotificationNumber());
+       query1.Fields = new Dictionary({
+               { "last_notification", DbValue::FromTimestamp(now_bag.first) },
+               { "next_notification", DbValue::FromTimestamp(timeBag.first) },
+               { "current_notification_number", notification->GetNotificationNumber() }
+       });
 
-       query1.Fields = fields1;
        query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
        DbObject::OnQuery(query1);
@@ -221,10 +224,10 @@ void DbEvents::ReachabilityChangedHandler(const Checkable::Ptr& checkable, const
                query1.StatusUpdate = true;
                query1.Object = DbObject::GetOrCreateByObject(child);
 
-               Dictionary::Ptr fields1 = new Dictionary();
-               fields1->Set("is_reachable", is_reachable);
+               query1.Fields = new Dictionary({
+                       { "is_reachable", is_reachable }
+               });
 
-               query1.Fields = fields1;
                query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
                DbObject::OnQuery(query1);
@@ -279,10 +282,10 @@ void DbEvents::EnableChangedHandlerInternal(const Checkable::Ptr& checkable, con
        query1.StatusUpdate = true;
        query1.Object = DbObject::GetOrCreateByObject(checkable);
 
-       Dictionary::Ptr fields1 = new Dictionary();
-       fields1->Set(fieldName, enabled);
+       query1.Fields = new Dictionary({
+               { fieldName, enabled }
+       });
 
-       query1.Fields = fields1;
        query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
        DbObject::OnQuery(query1);
@@ -365,10 +368,11 @@ void DbEvents::AddCommentInternal(std::vector<DbQuery>& queries, const Comment::
 
                fields1->Set("session_token", 0); /* DbConnection class fills in real ID */
 
-               query1.WhereCriteria = new Dictionary();
-               query1.WhereCriteria->Set("object_id", checkable);
-               query1.WhereCriteria->Set("name", comment->GetName());
-               query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(timeBag.first));
+               query1.WhereCriteria = new Dictionary({
+                       { "object_id", checkable },
+                       { "name", comment->GetName() },
+                       { "entry_time", DbValue::FromTimestamp(timeBag.first) }
+               });
        } else {
                query1.Table = "commenthistory";
                query1.Type = DbQueryInsert;
@@ -398,10 +402,12 @@ void DbEvents::RemoveCommentInternal(std::vector<DbQuery>& queries, const Commen
        query1.Type = DbQueryDelete;
        query1.Category = DbCatComment;
 
-       query1.WhereCriteria = new Dictionary();
-       query1.WhereCriteria->Set("object_id", checkable);
-       query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(timeBag.first));
-       query1.WhereCriteria->Set("name", comment->GetName());
+       query1.WhereCriteria = new Dictionary({
+               { "object_id", checkable },
+               { "entry_time", DbValue::FromTimestamp(timeBag.first) },
+               { "name", comment->GetName() }
+       });
+
        queries.emplace_back(std::move(query1));
 
        /* History - update deletion time for service/host */
@@ -412,15 +418,16 @@ void DbEvents::RemoveCommentInternal(std::vector<DbQuery>& queries, const Commen
        query2.Type = DbQueryUpdate;
        query2.Category = DbCatComment;
 
-       Dictionary::Ptr fields2 = new Dictionary();
-       fields2->Set("deletion_time", DbValue::FromTimestamp(timeBagNow.first));
-       fields2->Set("deletion_time_usec", timeBagNow.second);
-       query2.Fields = fields2;
+       query2.Fields = new Dictionary({
+               { "deletion_time", DbValue::FromTimestamp(timeBagNow.first) },
+               { "deletion_time_usec", timeBagNow.second }
+       });
 
-       query2.WhereCriteria = new Dictionary();
-       query2.WhereCriteria->Set("object_id", checkable);
-       query2.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(timeBag.first));
-       query2.WhereCriteria->Set("name", comment->GetName());
+       query2.WhereCriteria = new Dictionary({
+               { "object_id", checkable },
+               { "entry_time", DbValue::FromTimestamp(timeBag.first) },
+               { "name", comment->GetName() }
+       });
 
        queries.emplace_back(std::move(query2));
 }
@@ -509,10 +516,11 @@ void DbEvents::AddDowntimeInternal(std::vector<DbQuery>& queries, const Downtime
 
                fields1->Set("session_token", 0); /* DbConnection class fills in real ID */
 
-               query1.WhereCriteria = new Dictionary();
-               query1.WhereCriteria->Set("object_id", checkable);
-               query1.WhereCriteria->Set("name", downtime->GetName());
-               query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()));
+               query1.WhereCriteria = new Dictionary({
+                       { "object_id", checkable },
+                       { "name", downtime->GetName() },
+                       { "entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()) }
+               });
        } else {
                query1.Table = "downtimehistory";
                query1.Type = DbQueryInsert;
@@ -599,13 +607,15 @@ void DbEvents::RemoveDowntimeInternal(std::vector<DbQuery>& queries, const Downt
        fields3->Set("is_in_effect", 0);
        query3.Fields = fields3;
 
-       query3.WhereCriteria = new Dictionary();
-       query3.WhereCriteria->Set("object_id", checkable);
-       query3.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()));
-       query3.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
-       query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
-       query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
-       query3.WhereCriteria->Set("name", downtime->GetName());
+       query3.WhereCriteria = new Dictionary({
+               { "object_id", checkable },
+               { "entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()) },
+               { "instance_id", 0 }, /* DbConnection class fills in real ID */
+               { "scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()) },
+               { "scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()) },
+               { "name", downtime->GetName() }
+       });
+
        queries.emplace_back(std::move(query3));
 
        /* host/service status */
@@ -650,23 +660,24 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime)
        query1.Type = DbQueryUpdate;
        query1.Category = DbCatDowntime;
 
-       Dictionary::Ptr fields1 = new Dictionary();
-       fields1->Set("was_started", 1);
-       fields1->Set("actual_start_time", DbValue::FromTimestamp(timeBag.first));
-       fields1->Set("actual_start_time_usec", timeBag.second);
-       fields1->Set("is_in_effect", (downtime->IsInEffect() ? 1 : 0));
-       fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
-       fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+       query1.Fields = new Dictionary({
+               { "was_started", 1 },
+               { "actual_start_time", DbValue::FromTimestamp(timeBag.first) },
+               { "actual_start_time_usec", timeBag.second },
+               { "is_in_effect", (downtime->IsInEffect() ? 1 : 0) },
+               { "trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()) },
+               { "instance_id", 0 } /* DbConnection class fills in real ID */
+       });
+
+       query1.WhereCriteria = new Dictionary({
+               { "object_id", checkable },
+               { "entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()) },
+               { "instance_id", 0 }, /* DbConnection class fills in real ID */
+               { "scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()) },
+               { "scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()) },
+               { "name", downtime->GetName() }
+       });
 
-       query1.WhereCriteria = new Dictionary();
-       query1.WhereCriteria->Set("object_id", checkable);
-       query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()));
-       query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
-       query1.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
-       query1.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
-       query1.WhereCriteria->Set("name", downtime->GetName());
-
-       query1.Fields = fields1;
        DbObject::OnQuery(query1);
 
        /* History - downtime was started for service (and host in case) */
@@ -675,13 +686,13 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime)
        query3.Type = DbQueryUpdate;
        query3.Category = DbCatDowntime;
 
-       Dictionary::Ptr fields3 = new Dictionary();
-       fields3->Set("was_started", 1);
-       fields3->Set("is_in_effect", 1);
-       fields3->Set("actual_start_time", DbValue::FromTimestamp(timeBag.first));
-       fields3->Set("actual_start_time_usec", timeBag.second);
-       fields3->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
-       query3.Fields = fields3;
+       query3.Fields = new Dictionary({
+               { "was_started", 1 },
+               { "is_in_effect", 1 },
+               { "actual_start_time", DbValue::FromTimestamp(timeBag.first) },
+               { "actual_start_time_usec", timeBag.second },
+               { "trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()) }
+       });
 
        query3.WhereCriteria = query1.WhereCriteria;
 
@@ -708,10 +719,9 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime)
        query4.StatusUpdate = true;
        query4.Object = DbObject::GetOrCreateByObject(checkable);
 
-       Dictionary::Ptr fields4 = new Dictionary();
-       fields4->Set("scheduled_downtime_depth", checkable->GetDowntimeDepth());
-
-       query4.Fields = fields4;
+       query4.Fields = new Dictionary({
+               { "scheduled_downtime_depth", checkable->GetDowntimeDepth() }
+       });
        query4.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
        DbObject::OnQuery(query4);
@@ -801,11 +811,11 @@ void DbEvents::AddAcknowledgementInternal(const Checkable::Ptr& checkable, Ackno
        query1.StatusUpdate = true;
        query1.Object = DbObject::GetOrCreateByObject(checkable);
 
-       Dictionary::Ptr fields1 = new Dictionary();
-       fields1->Set("acknowledgement_type", type);
-       fields1->Set("problem_has_been_acknowledged", add ? 1 : 0);
+       query1.Fields = new Dictionary({
+               { "acknowledgement_type", type },
+               { "problem_has_been_acknowledged", add ? 1 : 0 }
+       });
 
-       query1.Fields = fields1;
        query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
        DbObject::OnQuery(query1);
@@ -873,17 +883,16 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con
                query2.Type = DbQueryInsert;
                query2.Category = DbCatNotification;
 
-               Dictionary::Ptr fields2 = new Dictionary();
-               fields2->Set("contact_object_id", user);
-               fields2->Set("start_time", DbValue::FromTimestamp(timeBag.first));
-               fields2->Set("start_time_usec", timeBag.second);
-               fields2->Set("end_time", DbValue::FromTimestamp(timeBag.first));
-               fields2->Set("end_time_usec", timeBag.second);
-
-               fields2->Set("notification_id", query1.NotificationInsertID);
-               fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */
+               query2.Fields = new Dictionary({
+                       { "contact_object_id", user },
+                       { "start_time", DbValue::FromTimestamp(timeBag.first) },
+                       { "start_time_usec", timeBag.second },
+                       { "end_time", DbValue::FromTimestamp(timeBag.first) },
+                       { "end_time_usec", timeBag.second },
+                       { "notification_id", query1.NotificationInsertID },
+                       { "instance_id", 0 } /* DbConnection class fills in real ID */
+               });
 
-               query2.Fields = fields2;
                queries.emplace_back(std::move(query2));
        }
 
index b9c14d528185c96bf2ad1447624d9e82c54eed69..9ab72ec1d8f4c55965c5bcc2dbd7d166508ae4b8 100644 (file)
@@ -146,8 +146,9 @@ void DbObject::SendConfigUpdateHeavy(const Dictionary::Ptr& configFields)
        query.Fields->Set(GetType()->GetIDColumn(), object);
        query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
        query.Fields->Set("config_type", 1);
-       query.WhereCriteria = new Dictionary();
-       query.WhereCriteria->Set(GetType()->GetIDColumn(), object);
+       query.WhereCriteria = new Dictionary({
+               { GetType()->GetIDColumn(), object }
+       });
        query.Object = this;
        query.ConfigUpdate = true;
        OnQuery(query);
@@ -189,8 +190,9 @@ void DbObject::SendStatusUpdate()
        query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
        query.Fields->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
-       query.WhereCriteria = new Dictionary();
-       query.WhereCriteria->Set(GetType()->GetIDColumn(), GetObject());
+       query.WhereCriteria = new Dictionary({
+               { GetType()->GetIDColumn(), GetObject() }
+       });
        query.Object = this;
        query.StatusUpdate = true;
        OnQuery(query);
@@ -215,16 +217,18 @@ void DbObject::SendVarsConfigUpdateHeavy()
        query1.Table = "customvariables";
        query1.Type = DbQueryDelete;
        query1.Category = DbCatConfig;
-       query1.WhereCriteria = new Dictionary();
-       query1.WhereCriteria->Set("object_id", obj);
+       query1.WhereCriteria = new Dictionary({
+               { "object_id", obj }
+       });
        queries.emplace_back(std::move(query1));
 
        DbQuery query2;
        query2.Table = "customvariablestatus";
        query2.Type = DbQueryDelete;
        query2.Category = DbCatConfig;
-       query2.WhereCriteria = new Dictionary();
-       query2.WhereCriteria->Set("object_id", obj);
+       query2.WhereCriteria = new Dictionary({
+               { "object_id", obj }
+       });
        queries.emplace_back(std::move(query2));
 
        Dictionary::Ptr vars = custom_var_object->GetVars();
@@ -245,19 +249,18 @@ void DbObject::SendVarsConfigUpdateHeavy()
                        } else
                                value = kv.second;
 
-                       Dictionary::Ptr fields = new Dictionary();
-                       fields->Set("varname", kv.first);
-                       fields->Set("varvalue", value);
-                       fields->Set("is_json", is_json);
-                       fields->Set("config_type", 1);
-                       fields->Set("object_id", obj);
-                       fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
                        DbQuery query3;
                        query3.Table = "customvariables";
                        query3.Type = DbQueryInsert;
                        query3.Category = DbCatConfig;
-                       query3.Fields = fields;
+                       query3.Fields = new Dictionary({
+                               { "varname", kv.first },
+                               { "varvalue", value },
+                               { "is_json", is_json },
+                               { "config_type", 1 },
+                               { "object_id", obj },
+                               { "instance_id", 0 } /* DbConnection class fills in real ID */
+                       });
                        queries.emplace_back(std::move(query3));
                }
        }
@@ -293,23 +296,25 @@ void DbObject::SendVarsStatusUpdate()
                        } else
                                value = kv.second;
 
-                       Dictionary::Ptr fields = new Dictionary();
-                       fields->Set("varname", kv.first);
-                       fields->Set("varvalue", value);
-                       fields->Set("is_json", is_json);
-                       fields->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
-                       fields->Set("object_id", obj);
-                       fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
                        DbQuery query;
                        query.Table = "customvariablestatus";
                        query.Type = DbQueryInsert | DbQueryUpdate;
                        query.Category = DbCatState;
-                       query.Fields = fields;
 
-                       query.WhereCriteria = new Dictionary();
-                       query.WhereCriteria->Set("object_id", obj);
-                       query.WhereCriteria->Set("varname", kv.first);
+                       query.Fields = new Dictionary({
+                               { "varname", kv.first },
+                               { "varvalue", value },
+                               { "is_json", is_json },
+                               { "status_update_time", DbValue::FromTimestamp(Utility::GetTime()) },
+                               { "object_id", obj },
+                               { "instance_id", 0 } /* DbConnection class fills in real ID */
+                       });
+
+                       query.WhereCriteria = new Dictionary({
+                               { "object_id", obj },
+                               { "varname", kv.first }
+                       });
+
                        queries.emplace_back(std::move(query));
                }
 
index 2402cadaf005b77cbcb23808286e66dec93872bf..ed9b27fb3b2dbd6313b9ffb8fe75acf333b0ff37 100644 (file)
@@ -46,30 +46,29 @@ EndpointDbObject::EndpointDbObject(const DbType::Ptr& type, const String& name1,
 
 Dictionary::Ptr EndpointDbObject::GetConfigFields() const
 {
-       Dictionary::Ptr fields = new Dictionary();
        Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(GetObject());
 
-       fields->Set("identity", endpoint->GetName());
-       fields->Set("node", IcingaApplication::GetInstance()->GetNodeName());
-       fields->Set("zone_object_id", endpoint->GetZone());
-
-       return fields;
+       return new Dictionary({
+               { "identity", endpoint->GetName() },
+               { "node", IcingaApplication::GetInstance()->GetNodeName() },
+               { "zone_object_id", endpoint->GetZone() }
+       });
 }
 
 Dictionary::Ptr EndpointDbObject::GetStatusFields() const
 {
-       Dictionary::Ptr fields = new Dictionary();
        Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(GetObject());
 
+
        Log(LogDebug, "EndpointDbObject")
                << "update status for endpoint '" << endpoint->GetName() << "'";
 
-       fields->Set("identity", endpoint->GetName());
-       fields->Set("node", IcingaApplication::GetInstance()->GetNodeName());
-       fields->Set("zone_object_id", endpoint->GetZone());
-       fields->Set("is_connected", EndpointIsConnected(endpoint));
-
-       return fields;
+       return new Dictionary({
+               { "identity", endpoint->GetName() },
+               { "node", IcingaApplication::GetInstance()->GetNodeName() },
+               { "zone_object_id", endpoint->GetZone() },
+               { "is_connected", EndpointIsConnected(endpoint) }
+       });
 }
 
 void EndpointDbObject::UpdateConnectedStatus(const Endpoint::Ptr& endpoint)
@@ -84,14 +83,15 @@ void EndpointDbObject::UpdateConnectedStatus(const Endpoint::Ptr& endpoint)
        query1.Type = DbQueryUpdate;
        query1.Category = DbCatState;
 
-       Dictionary::Ptr fields1 = new Dictionary();
-       fields1->Set("is_connected", (connected ? 1 : 0));
-       fields1->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
-       query1.Fields = fields1;
+       query1.Fields = new Dictionary({
+               { "is_connected", (connected ? 1 : 0) },
+               { "status_update_time", DbValue::FromTimestamp(Utility::GetTime()) }
+       });
 
-       query1.WhereCriteria = new Dictionary();
-       query1.WhereCriteria->Set("endpoint_object_id", endpoint);
-       query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
+       query1.WhereCriteria = new Dictionary({
+               { "endpoint_object_id", endpoint },
+               { "instance_id", 0 } /* DbConnection class fills in real ID */
+       });
 
        OnQuery(query1);
 }
index e339b5e702c53afa2a7425a9790b56cb49e0b6c3..3c8c42058241ea1a02f954f0daa154615d33f7ed 100644 (file)
@@ -51,50 +51,42 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const
        /* Compatibility fallback. */
        String displayName = host->GetDisplayName();
 
-       if (!displayName.IsEmpty())
-               fields->Set("alias", displayName);
-       else
-               fields->Set("alias", host->GetName());
-
-       fields->Set("display_name", displayName);
-       fields->Set("address", host->GetAddress());
-       fields->Set("address6", host->GetAddress6());
-       fields->Set("check_command_object_id", host->GetCheckCommand());
-       fields->Set("eventhandler_command_object_id", host->GetEventCommand());
-       fields->Set("check_timeperiod_object_id", host->GetCheckPeriod());
-       fields->Set("check_interval", host->GetCheckInterval() / 60.0);
-       fields->Set("retry_interval", host->GetRetryInterval() / 60.0);
-       fields->Set("max_check_attempts", host->GetMaxCheckAttempts());
-       fields->Set("flap_detection_enabled", host->GetEnableFlapping());
-       fields->Set("low_flap_threshold", host->GetFlappingThresholdLow());
-       fields->Set("high_flap_threshold", host->GetFlappingThresholdLow());
-       fields->Set("process_performance_data", host->GetEnablePerfdata());
-       fields->Set("freshness_checks_enabled", 1);
-       fields->Set("freshness_threshold", Convert::ToLong(host->GetCheckInterval()));
-       fields->Set("event_handler_enabled", host->GetEnableEventHandler());
-       fields->Set("passive_checks_enabled", host->GetEnablePassiveChecks());
-       fields->Set("active_checks_enabled", host->GetEnableActiveChecks());
-       fields->Set("notifications_enabled", host->GetEnableNotifications());
-       fields->Set("notes", host->GetNotes());
-       fields->Set("notes_url", host->GetNotesUrl());
-       fields->Set("action_url", host->GetActionUrl());
-       fields->Set("icon_image", host->GetIconImage());
-       fields->Set("icon_image_alt", host->GetIconImageAlt());
-
-       fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(host));
-
        unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(host);
        unsigned long notificationTypeFilter = CompatUtility::GetCheckableNotificationTypeFilter(host);
 
-       fields->Set("notify_on_down", (notificationStateFilter & ServiceWarning) || (notificationStateFilter && ServiceCritical));
-       fields->Set("notify_on_unreachable", 1); /* We don't have this filter and state, and as such we don't filter such notifications. */
-       fields->Set("notify_on_recovery", notificationTypeFilter & NotificationRecovery);
-       fields->Set("notify_on_flapping", (notificationTypeFilter & NotificationFlappingStart) ||
-               (notificationTypeFilter & NotificationFlappingEnd));
-       fields->Set("notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) ||
-               (notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved));
-
-       return fields;
+       return new Dictionary({
+               { "alias", !displayName.IsEmpty() ? displayName : host->GetName() },
+               { "display_name", displayName },
+               { "address", host->GetAddress() },
+               { "address6", host->GetAddress6() },
+               { "check_command_object_id", host->GetCheckCommand() },
+               { "eventhandler_command_object_id", host->GetEventCommand() },
+               { "check_timeperiod_object_id", host->GetCheckPeriod() },
+               { "check_interval", host->GetCheckInterval() / 60.0 },
+               { "retry_interval", host->GetRetryInterval() / 60.0 },
+               { "max_check_attempts", host->GetMaxCheckAttempts() },
+               { "flap_detection_enabled", host->GetEnableFlapping() },
+               { "low_flap_threshold", host->GetFlappingThresholdLow() },
+               { "high_flap_threshold", host->GetFlappingThresholdLow() },
+               { "process_performance_data", host->GetEnablePerfdata() },
+               { "freshness_checks_enabled", 1 },
+               { "freshness_threshold", Convert::ToLong(host->GetCheckInterval()) },
+               { "event_handler_enabled", host->GetEnableEventHandler() },
+               { "passive_checks_enabled", host->GetEnablePassiveChecks() },
+               { "active_checks_enabled", host->GetEnableActiveChecks() },
+               { "notifications_enabled", host->GetEnableNotifications() },
+               { "notes", host->GetNotes() },
+               { "notes_url", host->GetNotesUrl() },
+               { "action_url", host->GetActionUrl() },
+               { "icon_image", host->GetIconImage() },
+               { "icon_image_alt", host->GetIconImageAlt() },
+               { "notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(host) },
+               { "notify_on_down", (notificationStateFilter & ServiceWarning) || (notificationStateFilter && ServiceCritical) },
+               { "notify_on_unreachable", 1 }, /* We don't have this filter and state, and as such we don't filter such notifications. */
+               { "notify_on_recovery", notificationTypeFilter & NotificationRecovery },
+               { "notify_on_flapping", (notificationTypeFilter & NotificationFlappingStart) || (notificationTypeFilter & NotificationFlappingEnd) },
+               { "notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) || (notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved) }
+       });
 }
 
 Dictionary::Ptr HostDbObject::GetStatusFields() const
@@ -193,14 +185,16 @@ void HostDbObject::OnConfigUpdateHeavy()
                        query2.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
                        query2.Type = DbQueryInsert;
                        query2.Category = DbCatConfig;
-                       query2.Fields = new Dictionary();
-                       query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
-                       query2.Fields->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
-                       query2.Fields->Set("host_object_id", host);
-                       query2.WhereCriteria = new Dictionary();
-                       query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
-                       query2.WhereCriteria->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
-                       query2.WhereCriteria->Set("host_object_id", host);
+                       query2.Fields = new Dictionary({
+                               { "instance_id", 0 }, /* DbConnection class fills in real ID */
+                               { "hostgroup_id", DbValue::FromObjectInsertID(group) },
+                               { "host_object_id", host }
+                       });
+                       query2.WhereCriteria = new Dictionary({
+                               { "instance_id", 0 }, /* DbConnection class fills in real ID */
+                               { "hostgroup_id", DbValue::FromObjectInsertID(group) },
+                               { "host_object_id", host }
+                       });
                        queries.emplace_back(std::move(query2));
                }
        }
@@ -213,8 +207,9 @@ void HostDbObject::OnConfigUpdateHeavy()
        query2.Table = GetType()->GetTable() + "_parenthosts";
        query2.Type = DbQueryDelete;
        query2.Category = DbCatConfig;
-       query2.WhereCriteria = new Dictionary();
-       query2.WhereCriteria->Set(GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject()));
+       query2.WhereCriteria = new Dictionary({
+               { GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject()) }
+       });
        queries.emplace_back(std::move(query2));
 
        /* parents */
@@ -228,16 +223,15 @@ void HostDbObject::OnConfigUpdateHeavy()
                        << "host parents: " << parent->GetName();
 
                /* parents: host_id, parent_host_object_id */
-               Dictionary::Ptr fields1 = new Dictionary();
-               fields1->Set(GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject()));
-               fields1->Set("parent_host_object_id", parent);
-               fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
                DbQuery query1;
                query1.Table = GetType()->GetTable() + "_parenthosts";
                query1.Type = DbQueryInsert;
                query1.Category = DbCatConfig;
-               query1.Fields = fields1;
+               query1.Fields = new Dictionary({
+                       { GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject()) },
+                       { "parent_host_object_id", parent },
+                       { "instance_id", 0 } /* DbConnection class fills in real ID */
+               });
                queries.emplace_back(std::move(query1));
        }
 
@@ -253,8 +247,9 @@ void HostDbObject::OnConfigUpdateHeavy()
        query3.Table = GetType()->GetTable() + "dependencies";
        query3.Type = DbQueryDelete;
        query3.Category = DbCatConfig;
-       query3.WhereCriteria = new Dictionary();
-       query3.WhereCriteria->Set("dependent_host_object_id", host);
+       query3.WhereCriteria = new Dictionary({
+               { "dependent_host_object_id", host }
+       });
        queries.emplace_back(std::move(query3));
 
        for (const Dependency::Ptr& dep : host->GetDependencies()) {
@@ -271,20 +266,19 @@ void HostDbObject::OnConfigUpdateHeavy()
                Log(LogDebug, "HostDbObject")
                        << "parent host: " << parent->GetName();
 
-               Dictionary::Ptr fields2 = new Dictionary();
-               fields2->Set("host_object_id", parent);
-               fields2->Set("dependent_host_object_id", host);
-               fields2->Set("inherits_parent", 1);
-               fields2->Set("timeperiod_object_id", dep->GetPeriod());
-               fields2->Set("fail_on_up", stateFilter & StateFilterUp);
-               fields2->Set("fail_on_down", stateFilter & StateFilterDown);
-               fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
                DbQuery query2;
                query2.Table = GetType()->GetTable() + "dependencies";
                query2.Type = DbQueryInsert;
                query2.Category = DbCatConfig;
-               query2.Fields = fields2;
+               query2.Fields = new Dictionary({
+                       { "host_object_id", parent },
+                       { "dependent_host_object_id", host },
+                       { "inherits_parent", 1 },
+                       { "timeperiod_object_id", dep->GetPeriod() },
+                       { "fail_on_up", stateFilter & StateFilterUp },
+                       { "fail_on_down", stateFilter & StateFilterDown },
+                       { "instance_id", 0 } /* DbConnection class fills in real ID */
+               });
                queries.emplace_back(std::move(query2));
        }
 
@@ -299,24 +293,24 @@ void HostDbObject::OnConfigUpdateHeavy()
        query4.Table = GetType()->GetTable() + "_contacts";
        query4.Type = DbQueryDelete;
        query4.Category = DbCatConfig;
-       query4.WhereCriteria = new Dictionary();
-       query4.WhereCriteria->Set("host_id", DbValue::FromObjectInsertID(host));
+       query4.WhereCriteria = new Dictionary({
+               { "host_id", DbValue::FromObjectInsertID(host) }
+       });
        queries.emplace_back(std::move(query4));
 
        for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(host)) {
                Log(LogDebug, "HostDbObject")
                        << "host contacts: " << user->GetName();
 
-               Dictionary::Ptr fields_contact = new Dictionary();
-               fields_contact->Set("host_id", DbValue::FromObjectInsertID(host));
-               fields_contact->Set("contact_object_id", user);
-               fields_contact->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
                DbQuery query_contact;
                query_contact.Table = GetType()->GetTable() + "_contacts";
                query_contact.Type = DbQueryInsert;
                query_contact.Category = DbCatConfig;
-               query_contact.Fields = fields_contact;
+               query_contact.Fields = new Dictionary({
+                       { "host_id", DbValue::FromObjectInsertID(host) },
+                       { "contact_object_id", user },
+                       { "instance_id", 0 } /* DbConnection class fills in real ID */
+               });
                queries.emplace_back(std::move(query_contact));
        }
 
@@ -331,24 +325,24 @@ void HostDbObject::OnConfigUpdateHeavy()
        query5.Table = GetType()->GetTable() + "_contactgroups";
        query5.Type = DbQueryDelete;
        query5.Category = DbCatConfig;
-       query5.WhereCriteria = new Dictionary();
-       query5.WhereCriteria->Set("host_id", DbValue::FromObjectInsertID(host));
+       query5.WhereCriteria = new Dictionary({
+               { "host_id", DbValue::FromObjectInsertID(host) }
+       });
        queries.emplace_back(std::move(query5));
 
        for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(host)) {
                Log(LogDebug, "HostDbObject")
                        << "host contactgroups: " << usergroup->GetName();
 
-               Dictionary::Ptr fields_contact = new Dictionary();
-               fields_contact->Set("host_id", DbValue::FromObjectInsertID(host));
-               fields_contact->Set("contactgroup_object_id", usergroup);
-               fields_contact->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
                DbQuery query_contact;
                query_contact.Table = GetType()->GetTable() + "_contactgroups";
                query_contact.Type = DbQueryInsert;
                query_contact.Category = DbCatConfig;
-               query_contact.Fields = fields_contact;
+               query_contact.Fields = new Dictionary({
+                       { "host_id", DbValue::FromObjectInsertID(host) },
+                       { "contactgroup_object_id", usergroup },
+                       { "instance_id", 0 } /* DbConnection class fills in real ID */
+               });
                queries.emplace_back(std::move(query_contact));
        }
 
@@ -382,7 +376,7 @@ String HostDbObject::CalculateConfigHash(const Dictionary::Ptr& configFields) co
        if (groups)
                hashData += DbObject::HashValue(groups);
 
-       Array::Ptr parents = new Array();
+       ArrayData parents;
 
        /* parents */
        for (const Checkable::Ptr& checkable : host->GetParents()) {
@@ -391,14 +385,14 @@ String HostDbObject::CalculateConfigHash(const Dictionary::Ptr& configFields) co
                if (!parent)
                        continue;
 
-               parents->Add(parent->GetName());
+               parents.push_back(parent->GetName());
        }
 
-       parents->Sort();
+       std::sort(parents.begin(), parents.end());
 
-       hashData += DbObject::HashValue(parents);
+       hashData += DbObject::HashValue(new Array(std::move(parents)));
 
-       Array::Ptr dependencies = new Array();
+       ArrayData dependencies;
 
        /* dependencies */
        for (const Dependency::Ptr& dep : host->GetDependencies()) {
@@ -407,37 +401,36 @@ String HostDbObject::CalculateConfigHash(const Dictionary::Ptr& configFields) co
                if (!parent)
                        continue;
 
-               Array::Ptr depInfo = new Array();
-               depInfo->Add(parent->GetName());
-               depInfo->Add(dep->GetStateFilter());
-               depInfo->Add(dep->GetPeriodRaw());
-
-               dependencies->Add(depInfo);
+               dependencies.push_back(new Array({
+                       parent->GetName(),
+                       dep->GetStateFilter(),
+                       dep->GetPeriodRaw()
+               }));
        }
 
-       dependencies->Sort();
+       std::sort(dependencies.begin(), dependencies.end());
 
-       hashData += DbObject::HashValue(dependencies);
+       hashData += DbObject::HashValue(new Array(std::move(dependencies)));
 
-       Array::Ptr users = new Array();
+       ArrayData users;
 
        for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(host)) {
-               users->Add(user->GetName());
+               users.push_back(user->GetName());
        }
 
-       users->Sort();
+       std::sort(users.begin(), users.end());
 
-       hashData += DbObject::HashValue(users);
+       hashData += DbObject::HashValue(new Array(std::move(users)));
 
-       Array::Ptr userGroups = new Array();
+       ArrayData userGroups;
 
        for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(host)) {
-               userGroups->Add(usergroup->GetName());
+               userGroups.push_back(usergroup->GetName());
        }
 
-       userGroups->Sort();
+       std::sort(userGroups.begin(), userGroups.end());
 
-       hashData += DbObject::HashValue(userGroups);
+       hashData += DbObject::HashValue(new Array(std::move(userGroups)));
 
        return SHA256(hashData);
 }
index 73996a62830e11a06ad90b40d1594289bdce3639..13ee8278342ec84d8a87fda14d6f8c8178ea7f92 100644 (file)
@@ -34,15 +34,14 @@ HostGroupDbObject::HostGroupDbObject(const DbType::Ptr& type, const String& name
 
 Dictionary::Ptr HostGroupDbObject::GetConfigFields() const
 {
-       Dictionary::Ptr fields = new Dictionary();
        HostGroup::Ptr group = static_pointer_cast<HostGroup>(GetObject());
 
-       fields->Set("alias", group->GetDisplayName());
-       fields->Set("notes", group->GetNotes());
-       fields->Set("notes_url", group->GetNotesUrl());
-       fields->Set("action_url", group->GetActionUrl());
-
-       return fields;
+       return new Dictionary({
+               { "alias", group->GetDisplayName() },
+               { "notes", group->GetNotes() },
+               { "notes_url", group->GetNotesUrl() },
+               { "action_url", group->GetActionUrl() }
+       });
 }
 
 Dictionary::Ptr HostGroupDbObject::GetStatusFields() const
index 7c667474d196dfb51a092a277e2d81eca27299ca..544c2cefb8f5780129a8322d8861d8551782cc3b 100644 (file)
@@ -181,14 +181,13 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
 
        cr->SetOutput(msgbuf.str());
 
-       Array::Ptr perfdata = new Array();
-       perfdata->Add(new PerfdataValue("queries", qps, false, "", queriesWarning, queriesCritical));
-       perfdata->Add(new PerfdataValue("queries_1min", conn->GetQueryCount(60)));
-       perfdata->Add(new PerfdataValue("queries_5mins", conn->GetQueryCount(5 * 60)));
-       perfdata->Add(new PerfdataValue("queries_15mins", conn->GetQueryCount(15 * 60)));
-       perfdata->Add(new PerfdataValue("pending_queries", pendingQueries, false, "", pendingQueriesWarning, pendingQueriesCritical));
-
-       cr->SetPerformanceData(perfdata);
+       cr->SetPerformanceData(new Array({
+               { new PerfdataValue("queries", qps, false, "", queriesWarning, queriesCritical) },
+               { new PerfdataValue("queries_1min", conn->GetQueryCount(60)) },
+               { new PerfdataValue("queries_5mins", conn->GetQueryCount(5 * 60)) },
+               { new PerfdataValue("queries_15mins", conn->GetQueryCount(15 * 60)) },
+               { new PerfdataValue("pending_queries", pendingQueries, false, "", pendingQueriesWarning, pendingQueriesCritical) }
+       }));
 
        checkable->ProcessCheckResult(cr);
 }
index 93a80d199f79524a762329de8b100e2cf7f74c9c..70ea4267e1006d72e845d7e47643e94959e01042 100644 (file)
@@ -50,50 +50,45 @@ ServiceDbObject::ServiceDbObject(const DbType::Ptr& type, const String& name1, c
 
 Dictionary::Ptr ServiceDbObject::GetConfigFields() const
 {
-       Dictionary::Ptr fields = new Dictionary();
        Service::Ptr service = static_pointer_cast<Service>(GetObject());
        Host::Ptr host = service->GetHost();
 
-       fields->Set("host_object_id", host);
-       fields->Set("display_name", service->GetDisplayName());
-       fields->Set("check_command_object_id", service->GetCheckCommand());
-       fields->Set("eventhandler_command_object_id", service->GetEventCommand());
-       fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
-       fields->Set("check_interval", service->GetCheckInterval() / 60.0);
-       fields->Set("retry_interval", service->GetRetryInterval() / 60.0);
-       fields->Set("max_check_attempts", service->GetMaxCheckAttempts());
-       fields->Set("is_volatile", service->GetVolatile());
-       fields->Set("flap_detection_enabled", service->GetEnableFlapping());
-       fields->Set("low_flap_threshold", service->GetFlappingThresholdLow());
-       fields->Set("high_flap_threshold", service->GetFlappingThresholdLow());
-       fields->Set("process_performance_data", service->GetEnablePerfdata());
-       fields->Set("freshness_checks_enabled", 1);
-       fields->Set("freshness_threshold", Convert::ToLong(service->GetCheckInterval()));
-       fields->Set("event_handler_enabled", service->GetEnableEventHandler());
-       fields->Set("passive_checks_enabled", service->GetEnablePassiveChecks());
-       fields->Set("active_checks_enabled", service->GetEnableActiveChecks());
-       fields->Set("notifications_enabled", service->GetEnableNotifications());
-       fields->Set("notes", service->GetNotes());
-       fields->Set("notes_url", service->GetNotesUrl());
-       fields->Set("action_url", service->GetActionUrl());
-       fields->Set("icon_image", service->GetIconImage());
-       fields->Set("icon_image_alt", service->GetIconImageAlt());
-
-       fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(service));
-
        unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(service);
        unsigned long notificationTypeFilter = CompatUtility::GetCheckableNotificationTypeFilter(service);
 
-       fields->Set("notify_on_warning", notificationStateFilter & ServiceWarning);
-       fields->Set("notify_on_unknown", notificationStateFilter & ServiceUnknown);
-       fields->Set("notify_on_critical", notificationStateFilter & ServiceCritical);
-       fields->Set("notify_on_recovery", notificationTypeFilter & NotificationRecovery);
-       fields->Set("notify_on_flapping", (notificationTypeFilter & NotificationFlappingStart) ||
-               (notificationTypeFilter & NotificationFlappingEnd));
-       fields->Set("notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) ||
-               (notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved));
-
-       return fields;
+       return new Dictionary({
+               { "host_object_id", host },
+               { "display_name", service->GetDisplayName() },
+               { "check_command_object_id", service->GetCheckCommand() },
+               { "eventhandler_command_object_id", service->GetEventCommand() },
+               { "check_timeperiod_object_id", service->GetCheckPeriod() },
+               { "check_interval", service->GetCheckInterval() / 60.0 },
+               { "retry_interval", service->GetRetryInterval() / 60.0 },
+               { "max_check_attempts", service->GetMaxCheckAttempts() },
+               { "is_volatile", service->GetVolatile() },
+               { "flap_detection_enabled", service->GetEnableFlapping() },
+               { "low_flap_threshold", service->GetFlappingThresholdLow() },
+               { "high_flap_threshold", service->GetFlappingThresholdLow() },
+               { "process_performance_data", service->GetEnablePerfdata() },
+               { "freshness_checks_enabled", 1 },
+               { "freshness_threshold", Convert::ToLong(service->GetCheckInterval()) },
+               { "event_handler_enabled", service->GetEnableEventHandler() },
+               { "passive_checks_enabled", service->GetEnablePassiveChecks() },
+               { "active_checks_enabled", service->GetEnableActiveChecks() },
+               { "notifications_enabled", service->GetEnableNotifications() },
+               { "notes", service->GetNotes() },
+               { "notes_url", service->GetNotesUrl() },
+               { "action_url", service->GetActionUrl() },
+               { "icon_image", service->GetIconImage() },
+               { "icon_image_alt", service->GetIconImageAlt() },
+               { "notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(service) },
+               { "notify_on_warning", notificationStateFilter & ServiceWarning },
+               { "notify_on_unknown", notificationStateFilter & ServiceUnknown },
+               { "notify_on_critical", notificationStateFilter & ServiceCritical },
+               { "notify_on_recovery", notificationTypeFilter & NotificationRecovery },
+               { "notify_on_flapping", (notificationTypeFilter & NotificationFlappingStart) || (notificationTypeFilter & NotificationFlappingEnd) },
+               { "notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) || (notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved) }
+       });
 }
 
 Dictionary::Ptr ServiceDbObject::GetStatusFields() const
@@ -174,8 +169,9 @@ void ServiceDbObject::OnConfigUpdateHeavy()
        query1.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
        query1.Type = DbQueryDelete;
        query1.Category = DbCatConfig;
-       query1.WhereCriteria = new Dictionary();
-       query1.WhereCriteria->Set("service_object_id", service);
+       query1.WhereCriteria = new Dictionary({
+               { "service_object_id", service }
+       });
        queries.emplace_back(std::move(query1));
 
        if (groups) {
@@ -187,14 +183,16 @@ void ServiceDbObject::OnConfigUpdateHeavy()
                        query2.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
                        query2.Type = DbQueryInsert;
                        query2.Category = DbCatConfig;
-                       query2.Fields = new Dictionary();
-                       query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
-                       query2.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
-                       query2.Fields->Set("service_object_id", service);
-                       query2.WhereCriteria = new Dictionary();
-                       query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
-                       query2.WhereCriteria->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
-                       query2.WhereCriteria->Set("service_object_id", service);
+                       query2.Fields = new Dictionary({
+                               { "instance_id", 0 }, /* DbConnection class fills in real ID */
+                               { "servicegroup_id", DbValue::FromObjectInsertID(group) },
+                               { "service_object_id", service }
+                       });
+                       query2.WhereCriteria = new Dictionary({
+                               { "instance_id", 0 }, /* DbConnection class fills in real ID */
+                               { "servicegroup_id", DbValue::FromObjectInsertID(group) },
+                               { "service_object_id", service }
+                       });
                        queries.emplace_back(std::move(query2));
                }
        }
@@ -211,8 +209,9 @@ void ServiceDbObject::OnConfigUpdateHeavy()
        query2.Table = GetType()->GetTable() + "dependencies";
        query2.Type = DbQueryDelete;
        query2.Category = DbCatConfig;
-       query2.WhereCriteria = new Dictionary();
-       query2.WhereCriteria->Set("dependent_service_object_id", service);
+       query2.WhereCriteria = new Dictionary({
+               { "dependent_service_object_id", service }
+       });
        queries.emplace_back(std::move(query2));
 
        for (const Dependency::Ptr& dep : service->GetDependencies()) {
@@ -230,22 +229,21 @@ void ServiceDbObject::OnConfigUpdateHeavy()
                int stateFilter = dep->GetStateFilter();
 
                /* service dependencies */
-               Dictionary::Ptr fields1 = new Dictionary();
-               fields1->Set("service_object_id", parent);
-               fields1->Set("dependent_service_object_id", service);
-               fields1->Set("inherits_parent", 1);
-               fields1->Set("timeperiod_object_id", dep->GetPeriod());
-               fields1->Set("fail_on_ok", stateFilter & StateFilterOK);
-               fields1->Set("fail_on_warning", stateFilter & StateFilterWarning);
-               fields1->Set("fail_on_critical", stateFilter & StateFilterCritical);
-               fields1->Set("fail_on_unknown", stateFilter & StateFilterUnknown);
-               fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
                DbQuery query1;
                query1.Table = GetType()->GetTable() + "dependencies";
                query1.Type = DbQueryInsert;
                query1.Category = DbCatConfig;
-               query1.Fields = fields1;
+               query1.Fields = new Dictionary({
+                       { "service_object_id", parent },
+                       { "dependent_service_object_id", service },
+                       { "inherits_parent", 1 },
+                       { "timeperiod_object_id", dep->GetPeriod() },
+                       { "fail_on_ok", stateFilter & StateFilterOK },
+                       { "fail_on_warning", stateFilter & StateFilterWarning },
+                       { "fail_on_critical", stateFilter & StateFilterCritical },
+                       { "fail_on_unknown", stateFilter & StateFilterUnknown },
+                       { "instance_id", 0 } /* DbConnection class fills in real ID */
+               });
                queries.emplace_back(std::move(query1));
        }
 
@@ -261,24 +259,25 @@ void ServiceDbObject::OnConfigUpdateHeavy()
        query3.Table = GetType()->GetTable() + "_contacts";
        query3.Type = DbQueryDelete;
        query3.Category = DbCatConfig;
-       query3.WhereCriteria = new Dictionary();
-       query3.WhereCriteria->Set("service_id", DbValue::FromObjectInsertID(service));
+       query3.WhereCriteria = new Dictionary({
+               { "service_id", DbValue::FromObjectInsertID(service) }
+       });
        queries.emplace_back(std::move(query3));
 
        for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(service)) {
                Log(LogDebug, "ServiceDbObject")
                        << "service contacts: " << user->GetName();
 
-               Dictionary::Ptr fields_contact = new Dictionary();
-               fields_contact->Set("service_id", DbValue::FromObjectInsertID(service));
-               fields_contact->Set("contact_object_id", user);
-               fields_contact->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
                DbQuery query_contact;
                query_contact.Table = GetType()->GetTable() + "_contacts";
                query_contact.Type = DbQueryInsert;
                query_contact.Category = DbCatConfig;
-               query_contact.Fields = fields_contact;
+               query_contact.Fields = new Dictionary({
+                       { "service_id", DbValue::FromObjectInsertID(service) },
+                       { "contact_object_id", user },
+                       { "instance_id", 0 } /* DbConnection class fills in real ID */
+
+               });
                queries.emplace_back(std::move(query_contact));
        }
 
@@ -293,24 +292,24 @@ void ServiceDbObject::OnConfigUpdateHeavy()
        query4.Table = GetType()->GetTable() + "_contactgroups";
        query4.Type = DbQueryDelete;
        query4.Category = DbCatConfig;
-       query4.WhereCriteria = new Dictionary();
-       query4.WhereCriteria->Set("service_id", DbValue::FromObjectInsertID(service));
+       query4.WhereCriteria = new Dictionary({
+               { "service_id", DbValue::FromObjectInsertID(service) }
+       });
        queries.emplace_back(std::move(query4));
 
        for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(service)) {
                Log(LogDebug, "ServiceDbObject")
                        << "service contactgroups: " << usergroup->GetName();
 
-               Dictionary::Ptr fields_contact = new Dictionary();
-               fields_contact->Set("service_id", DbValue::FromObjectInsertID(service));
-               fields_contact->Set("contactgroup_object_id", usergroup);
-               fields_contact->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
                DbQuery query_contact;
                query_contact.Table = GetType()->GetTable() + "_contactgroups";
                query_contact.Type = DbQueryInsert;
                query_contact.Category = DbCatConfig;
-               query_contact.Fields = fields_contact;
+               query_contact.Fields = new Dictionary({
+                       { "service_id", DbValue::FromObjectInsertID(service) },
+                       { "contactgroup_object_id", usergroup },
+                       { "instance_id", 0 } /* DbConnection class fills in real ID */
+               });
                queries.emplace_back(std::move(query_contact));
        }
 
@@ -344,7 +343,7 @@ String ServiceDbObject::CalculateConfigHash(const Dictionary::Ptr& configFields)
        if (groups)
                hashData += DbObject::HashValue(groups);
 
-       Array::Ptr dependencies = new Array();
+       ArrayData dependencies;
 
        /* dependencies */
        for (const Dependency::Ptr& dep : service->GetDependencies()) {
@@ -353,37 +352,36 @@ String ServiceDbObject::CalculateConfigHash(const Dictionary::Ptr& configFields)
                if (!parent)
                        continue;
 
-               Array::Ptr depInfo = new Array();
-               depInfo->Add(parent->GetName());
-               depInfo->Add(dep->GetStateFilter());
-               depInfo->Add(dep->GetPeriodRaw());
-
-               dependencies->Add(depInfo);
+               dependencies.push_back(new Array({
+                       parent->GetName(),
+                       dep->GetStateFilter(),
+                       dep->GetPeriodRaw()
+               }));
        }
 
-       dependencies->Sort();
+       std::sort(dependencies.begin(), dependencies.end());
 
-       hashData += DbObject::HashValue(dependencies);
+       hashData += DbObject::HashValue(new Array(std::move(dependencies)));
 
-       Array::Ptr users = new Array();
+       ArrayData users;
 
        for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(service)) {
-               users->Add(user->GetName());
+               users.push_back(user->GetName());
        }
 
-       users->Sort();
+       std::sort(users.begin(), users.end());
 
-       hashData += DbObject::HashValue(users);
+       hashData += DbObject::HashValue(new Array(std::move(users)));
 
-       Array::Ptr userGroups = new Array();
+       ArrayData userGroups;
 
        for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(service)) {
-               userGroups->Add(usergroup->GetName());
+               userGroups.push_back(usergroup->GetName());
        }
 
-       userGroups->Sort();
+       std::sort(userGroups.begin(), userGroups.end());
 
-       hashData += DbObject::HashValue(userGroups);
+       hashData += DbObject::HashValue(new Array(std::move(userGroups)));
 
        return SHA256(hashData);
 }
index 153914b0d4ae76e78abb53f53ac77972522553b5..085e76f7f86041b4eb5f2736c54a55025d70ac15 100644 (file)
@@ -33,15 +33,14 @@ ServiceGroupDbObject::ServiceGroupDbObject(const DbType::Ptr& type, const String
 
 Dictionary::Ptr ServiceGroupDbObject::GetConfigFields() const
 {
-       Dictionary::Ptr fields = new Dictionary();
        ServiceGroup::Ptr group = static_pointer_cast<ServiceGroup>(GetObject());
 
-       fields->Set("alias", group->GetDisplayName());
-       fields->Set("notes", group->GetNotes());
-       fields->Set("notes_url", group->GetNotesUrl());
-       fields->Set("action_url", group->GetActionUrl());
-
-       return fields;
+       return new Dictionary({
+               { "alias", group->GetDisplayName() },
+               { "notes", group->GetNotes() },
+               { "notes_url", group->GetNotesUrl() },
+               { "action_url", group->GetActionUrl() }
+       });
 }
 
 Dictionary::Ptr ServiceGroupDbObject::GetStatusFields() const
index 3bb392be27121a14705fae6b2254a46b3669904a..a53ae5c2af87bd4c1f45c272474730d9f6606164 100644 (file)
@@ -36,12 +36,11 @@ TimePeriodDbObject::TimePeriodDbObject(const DbType::Ptr& type, const String& na
 
 Dictionary::Ptr TimePeriodDbObject::GetConfigFields() const
 {
-       Dictionary::Ptr fields = new Dictionary();
        TimePeriod::Ptr tp = static_pointer_cast<TimePeriod>(GetObject());
 
-       fields->Set("alias", tp->GetDisplayName());
-
-       return fields;
+       return new Dictionary({
+               { "alias", tp->GetDisplayName() }
+       });
 }
 
 Dictionary::Ptr TimePeriodDbObject::GetStatusFields() const
@@ -57,8 +56,9 @@ void TimePeriodDbObject::OnConfigUpdateHeavy()
        query_del1.Table = GetType()->GetTable() + "_timeranges";
        query_del1.Type = DbQueryDelete;
        query_del1.Category = DbCatConfig;
-       query_del1.WhereCriteria = new Dictionary();
-       query_del1.WhereCriteria->Set("timeperiod_id", DbValue::FromObjectInsertID(tp));
+       query_del1.WhereCriteria = new Dictionary({
+               { "timeperiod_id", DbValue::FromObjectInsertID(tp) }
+       });
        OnQuery(query_del1);
 
        Dictionary::Ptr ranges = tp->GetRanges();
@@ -89,12 +89,13 @@ void TimePeriodDbObject::OnConfigUpdateHeavy()
                        query.Table = GetType()->GetTable() + "_timeranges";
                        query.Type = DbQueryInsert;
                        query.Category = DbCatConfig;
-                       query.Fields = new Dictionary();
-                       query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
-                       query.Fields->Set("timeperiod_id", DbValue::FromObjectInsertID(tp));
-                       query.Fields->Set("day", wday);
-                       query.Fields->Set("start_sec", begin % 86400);
-                       query.Fields->Set("end_sec", end % 86400);
+                       query.Fields = new Dictionary({
+                               { "instance_id", 0 }, /* DbConnection class fills in real ID */
+                               { "timeperiod_id", DbValue::FromObjectInsertID(tp) },
+                               { "day", wday },
+                               { "start_sec", begin % 86400 },
+                               { "end_sec", end % 86400 }
+                       });
                        OnQuery(query);
                }
        }
index d369b38c6e0284af26762f8c2ecd2aeafbde104a..f33883e3acabe38665c783124e80537fc9e4f0df 100644 (file)
@@ -37,46 +37,43 @@ UserDbObject::UserDbObject(const DbType::Ptr& type, const String& name1, const S
 
 Dictionary::Ptr UserDbObject::GetConfigFields() const
 {
-       Dictionary::Ptr fields = new Dictionary();
        User::Ptr user = static_pointer_cast<User>(GetObject());
 
-       fields->Set("alias", user->GetDisplayName());
-       fields->Set("email_address", user->GetEmail());
-       fields->Set("pager_address", user->GetPager());
-       fields->Set("host_timeperiod_object_id", user->GetPeriod());
-       fields->Set("service_timeperiod_object_id", user->GetPeriod());
-       fields->Set("host_notifications_enabled", user->GetEnableNotifications());
-       fields->Set("service_notifications_enabled", user->GetEnableNotifications());
-       fields->Set("can_submit_commands", 1);
-
        int typeFilter = user->GetTypeFilter();
        int stateFilter = user->GetStateFilter();
 
-       fields->Set("notify_service_recovery", (typeFilter & NotificationRecovery) != 0);
-       fields->Set("notify_service_warning", (stateFilter & StateFilterWarning) != 0);
-       fields->Set("notify_service_unknown", (stateFilter & StateFilterUnknown) != 0);
-       fields->Set("notify_service_critical", (stateFilter & StateFilterCritical) != 0);
-       fields->Set("notify_service_flapping", (typeFilter & (NotificationFlappingStart | NotificationFlappingEnd)) != 0);
-       fields->Set("notify_service_downtime", (typeFilter & (NotificationDowntimeStart | NotificationDowntimeEnd | NotificationDowntimeRemoved)) != 0);
-       fields->Set("notify_host_recovery", (typeFilter & NotificationRecovery) != 0);
-       fields->Set("notify_host_down", (stateFilter & StateFilterDown) != 0);
-       fields->Set("notify_host_flapping", (typeFilter & (NotificationFlappingStart | NotificationFlappingEnd)) != 0);
-       fields->Set("notify_host_downtime", (typeFilter & (NotificationDowntimeStart | NotificationDowntimeEnd | NotificationDowntimeRemoved)) != 0);
-
-       return fields;
+       return new Dictionary({
+               { "alias", user->GetDisplayName() },
+               { "email_address", user->GetEmail() },
+               { "pager_address", user->GetPager() },
+               { "host_timeperiod_object_id", user->GetPeriod() },
+               { "service_timeperiod_object_id", user->GetPeriod() },
+               { "host_notifications_enabled", user->GetEnableNotifications() },
+               { "service_notifications_enabled", user->GetEnableNotifications() },
+               { "can_submit_commands", 1 },
+               { "notify_service_recovery", (typeFilter & NotificationRecovery) != 0 },
+               { "notify_service_warning", (stateFilter & StateFilterWarning) != 0 },
+               { "notify_service_unknown", (stateFilter & StateFilterUnknown) != 0 },
+               { "notify_service_critical", (stateFilter & StateFilterCritical) != 0 },
+               { "notify_service_flapping", (typeFilter & (NotificationFlappingStart | NotificationFlappingEnd)) != 0 },
+               { "notify_service_downtime", (typeFilter & (NotificationDowntimeStart | NotificationDowntimeEnd | NotificationDowntimeRemoved)) != 0 },
+               { "notify_host_recovery", (typeFilter & NotificationRecovery) != 0 },
+               { "notify_host_down", (stateFilter & StateFilterDown) != 0 },
+               { "notify_host_flapping", (typeFilter & (NotificationFlappingStart | NotificationFlappingEnd)) != 0 },
+               { "notify_host_downtime", (typeFilter & (NotificationDowntimeStart | NotificationDowntimeEnd | NotificationDowntimeRemoved)) != 0 }
+       });
 }
 
 Dictionary::Ptr UserDbObject::GetStatusFields() const
 {
-       Dictionary::Ptr fields = new Dictionary();
        User::Ptr user = static_pointer_cast<User>(GetObject());
 
-       fields->Set("host_notifications_enabled", user->GetEnableNotifications());
-       fields->Set("service_notifications_enabled", user->GetEnableNotifications());
-       fields->Set("last_host_notification", DbValue::FromTimestamp(user->GetLastNotification()));
-       fields->Set("last_service_notification", DbValue::FromTimestamp(user->GetLastNotification()));
-
-       return fields;
+       return new Dictionary({
+               { "host_notifications_enabled", user->GetEnableNotifications() },
+               { "service_notifications_enabled", user->GetEnableNotifications() },
+               { "last_host_notification", DbValue::FromTimestamp(user->GetLastNotification()) },
+               { "last_service_notification", DbValue::FromTimestamp(user->GetLastNotification()) }
+       });
 }
 
 void UserDbObject::OnConfigUpdateHeavy()
@@ -92,8 +89,9 @@ void UserDbObject::OnConfigUpdateHeavy()
        query1.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
        query1.Type = DbQueryDelete;
        query1.Category = DbCatConfig;
-       query1.WhereCriteria = new Dictionary();
-       query1.WhereCriteria->Set("contact_object_id", user);
+       query1.WhereCriteria = new Dictionary({
+               { "contact_object_id", user }
+       });
        queries.emplace_back(std::move(query1));
 
        if (groups) {
@@ -105,14 +103,16 @@ void UserDbObject::OnConfigUpdateHeavy()
                        query2.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
                        query2.Type = DbQueryInsert | DbQueryUpdate;
                        query2.Category = DbCatConfig;
-                       query2.Fields = new Dictionary();
-                       query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
-                       query2.Fields->Set("contactgroup_id", DbValue::FromObjectInsertID(group));
-                       query2.Fields->Set("contact_object_id", user);
-                       query2.WhereCriteria = new Dictionary();
-                       query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
-                       query2.WhereCriteria->Set("contactgroup_id", DbValue::FromObjectInsertID(group));
-                       query2.WhereCriteria->Set("contact_object_id", user);
+                       query2.Fields = new Dictionary({
+                               { "instance_id", 0 }, /* DbConnection class fills in real ID */
+                               { "contactgroup_id", DbValue::FromObjectInsertID(group) },
+                               { "contact_object_id", user }
+                       });
+                       query2.WhereCriteria = new Dictionary({
+                               { "instance_id", 0 }, /* DbConnection class fills in real ID */
+                               { "contactgroup_id", DbValue::FromObjectInsertID(group) },
+                               { "contact_object_id", user }
+                       });
                        queries.emplace_back(std::move(query2));
                }
        }
@@ -125,16 +125,15 @@ void UserDbObject::OnConfigUpdateHeavy()
        query2.Table = "contact_addresses";
        query2.Type = DbQueryDelete;
        query2.Category = DbCatConfig;
-       query2.WhereCriteria = new Dictionary();
-       query2.WhereCriteria->Set("contact_id", DbValue::FromObjectInsertID(user));
+       query2.WhereCriteria = new Dictionary({
+               { "contact_id", DbValue::FromObjectInsertID(user) }
+       });
        queries.emplace_back(std::move(query2));
 
        Dictionary::Ptr vars = user->GetVars();
 
        if (vars) { /* This is sparta. */
                for (int i = 1; i <= 6; i++) {
-                       Dictionary::Ptr fields = new Dictionary();
-
                        String key = "address" + Convert::ToString(i);
 
                        if (!vars->Contains(key))
@@ -142,16 +141,17 @@ void UserDbObject::OnConfigUpdateHeavy()
 
                        String val = vars->Get(key);
 
-                       fields->Set("contact_id", DbValue::FromObjectInsertID(user));
-                       fields->Set("address_number", i);
-                       fields->Set("address", val);
-                       fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
                        DbQuery query;
                        query.Type = DbQueryInsert;
                        query.Table = "contact_addresses";
                        query.Category = DbCatConfig;
-                       query.Fields = fields;
+                       query.Fields = new Dictionary({
+                               { "contact_id", DbValue::FromObjectInsertID(user) },
+                               { "address_number", i },
+                               { "address", val },
+                               { "instance_id", 0 } /* DbConnection class fills in real ID */
+
+                       });
                        queries.emplace_back(std::move(query));
                }
        }
index f38b8a55b6cc6a00defc6c48e8f54fbae30f28eb..2a8458f946fca7633aa59b467e1cfdc7ec82a062 100644 (file)
@@ -34,12 +34,11 @@ UserGroupDbObject::UserGroupDbObject(const DbType::Ptr& type, const String& name
 
 Dictionary::Ptr UserGroupDbObject::GetConfigFields() const
 {
-       Dictionary::Ptr fields = new Dictionary();
        UserGroup::Ptr group = static_pointer_cast<UserGroup>(GetObject());
 
-       fields->Set("alias", group->GetDisplayName());
-
-       return fields;
+       return new Dictionary({
+               { "alias", group->GetDisplayName() }
+       });
 }
 
 Dictionary::Ptr UserGroupDbObject::GetStatusFields() const
index 252130b9807dac3a2480cccf4ee8a6d780104384..1c462d7e90797896f76e926997ea6c901822dcfc 100644 (file)
@@ -33,13 +33,13 @@ ZoneDbObject::ZoneDbObject(const DbType::Ptr& type, const String& name1, const S
 
 Dictionary::Ptr ZoneDbObject::GetConfigFields() const
 {
-       Dictionary::Ptr fields = new Dictionary();
        Zone::Ptr zone = static_pointer_cast<Zone>(GetObject());
 
-       fields->Set("is_global", zone->IsGlobal() ? 1 : 0);
-       fields->Set("parent_zone_object_id", zone->GetParent());
+       return new Dictionary({
+               { "is_global", zone->IsGlobal() ? 1 : 0 },
+               { "parent_zone_object_id", zone->GetParent() }
 
-       return fields;
+       });
 }
 
 Dictionary::Ptr ZoneDbObject::GetStatusFields() const
@@ -49,8 +49,7 @@ Dictionary::Ptr ZoneDbObject::GetStatusFields() const
        Log(LogDebug, "ZoneDbObject")
                << "update status for zone '" << zone->GetName() << "'";
 
-       Dictionary::Ptr fields = new Dictionary();
-       fields->Set("parent_zone_object_id", zone->GetParent());
-
-       return fields;
+       return new Dictionary({
+               { "parent_zone_object_id", zone->GetParent() }
+       });
 }
index 999d90161cd962da5243e6c3fb96997b29cf7123..70e0196855871d101acfbbbb08024ec9ace0dd91 100644 (file)
@@ -55,20 +55,19 @@ void IdoMysqlConnection::OnConfigLoaded()
 
 void IdoMysqlConnection::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const IdoMysqlConnection::Ptr& idomysqlconnection : ConfigType::GetObjectsByType<IdoMysqlConnection>()) {
                size_t queryQueueItems = idomysqlconnection->m_QueryQueue.GetLength();
                double queryQueueItemRate = idomysqlconnection->m_QueryQueue.GetTaskCount(60) / 60.0;
 
-               Dictionary::Ptr stats = new Dictionary();
-               stats->Set("version", idomysqlconnection->GetSchemaVersion());
-               stats->Set("instance_name", idomysqlconnection->GetInstanceName());
-               stats->Set("connected", idomysqlconnection->GetConnected());
-               stats->Set("query_queue_items", queryQueueItems);
-               stats->Set("query_queue_item_rate", queryQueueItemRate);
-
-               nodes->Set(idomysqlconnection->GetName(), stats);
+               nodes.emplace_back(idomysqlconnection->GetName(), new Dictionary({
+                       { "version", idomysqlconnection->GetSchemaVersion() },
+                       { "instance_name", idomysqlconnection->GetInstanceName() },
+                       { "connected", idomysqlconnection->GetConnected() },
+                       { "query_queue_items", queryQueueItems },
+                       { "query_queue_item_rate", queryQueueItemRate }
+               }));
 
                perfdata->Add(new PerfdataValue("idomysqlconnection_" + idomysqlconnection->GetName() + "_queries_rate", idomysqlconnection->GetQueryCount(60) / 60.0));
                perfdata->Add(new PerfdataValue("idomysqlconnection_" + idomysqlconnection->GetName() + "_queries_1min", idomysqlconnection->GetQueryCount(60)));
@@ -78,7 +77,7 @@ void IdoMysqlConnection::StatsFunc(const Dictionary::Ptr& status, const Array::P
                perfdata->Add(new PerfdataValue("idomysqlconnection_" + idomysqlconnection->GetName() + "_query_queue_item_rate", queryQueueItemRate));
        }
 
-       status->Set("idomysqlconnection", nodes);
+       status->Set("idomysqlconnection", new Dictionary(std::move(nodes)));
 }
 
 void IdoMysqlConnection::Resume()
index dbc8c1732d5357903926f52c77e22f730fab42b5..d9483e7851c91e8c5f6fb67ce4414bb44992685b 100644 (file)
@@ -62,20 +62,19 @@ void IdoPgsqlConnection::OnConfigLoaded()
 
 void IdoPgsqlConnection::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const IdoPgsqlConnection::Ptr& idopgsqlconnection : ConfigType::GetObjectsByType<IdoPgsqlConnection>()) {
                size_t queryQueueItems = idopgsqlconnection->m_QueryQueue.GetLength();
                double queryQueueItemRate = idopgsqlconnection->m_QueryQueue.GetTaskCount(60) / 60.0;
 
-               Dictionary::Ptr stats = new Dictionary();
-               stats->Set("version", idopgsqlconnection->GetSchemaVersion());
-               stats->Set("instance_name", idopgsqlconnection->GetInstanceName());
-               stats->Set("connected", idopgsqlconnection->GetConnected());
-               stats->Set("query_queue_items", queryQueueItems);
-               stats->Set("query_queue_item_rate", queryQueueItemRate);
-
-               nodes->Set(idopgsqlconnection->GetName(), stats);
+               nodes.emplace_back(idopgsqlconnection->GetName(), new Dictionary({
+                       { "version", idopgsqlconnection->GetSchemaVersion() },
+                       { "instance_name", idopgsqlconnection->GetInstanceName() },
+                       { "connected", idopgsqlconnection->GetConnected() },
+                       { "query_queue_items", queryQueueItems },
+                       { "query_queue_item_rate", queryQueueItemRate }
+               }));
 
                perfdata->Add(new PerfdataValue("idopgsqlconnection_" + idopgsqlconnection->GetName() + "_queries_rate", idopgsqlconnection->GetQueryCount(60) / 60.0));
                perfdata->Add(new PerfdataValue("idopgsqlconnection_" + idopgsqlconnection->GetName() + "_queries_1min", idopgsqlconnection->GetQueryCount(60)));
@@ -85,7 +84,7 @@ void IdoPgsqlConnection::StatsFunc(const Dictionary::Ptr& status, const Array::P
                perfdata->Add(new PerfdataValue("idopgsqlconnection_" + idopgsqlconnection->GetName() + "_query_queue_item_rate", queryQueueItemRate));
        }
 
-       status->Set("idopgsqlconnection", nodes);
+       status->Set("idopgsqlconnection", new Dictionary(std::move(nodes)));
 }
 
 void IdoPgsqlConnection::Resume()
@@ -534,7 +533,7 @@ Dictionary::Ptr IdoPgsqlConnection::FetchRow(const IdoPgsqlResult& result, int r
 
        int columns = m_Pgsql->nfields(result.get());
 
-       Dictionary::Ptr dict = new Dictionary();
+       DictionaryData dict;
 
        for (int column = 0; column < columns; column++) {
                Value value;
@@ -542,10 +541,10 @@ Dictionary::Ptr IdoPgsqlConnection::FetchRow(const IdoPgsqlResult& result, int r
                if (!m_Pgsql->getisnull(result.get(), row, column))
                        value = m_Pgsql->getvalue(result.get(), row, column);
 
-               dict->Set(m_Pgsql->fname(result.get(), column), value);
+               dict.emplace_back(m_Pgsql->fname(result.get(), column), value);
        }
 
-       return dict;
+       return new Dictionary(std::move(dict));
 }
 
 void IdoPgsqlConnection::ActivateObject(const DbObject::Ptr& dbobj)
index 355bfc878f4d7cf24449b0383f373f4164b279af..f916624f08a69a637d45a91e8c451cfd2bafc47a 100644 (file)
@@ -52,9 +52,10 @@ REGISTER_APIACTION(generate_ticket, "", &ApiActions::GenerateTicket);
 Dictionary::Ptr ApiActions::CreateResult(int code, const String& status,
        const Dictionary::Ptr& additional)
 {
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("code", code);
-       result->Set("status", status);
+       Dictionary::Ptr result = new Dictionary({
+               { "code", code },
+               { "status", status }
+       });
 
        if (additional)
                additional->CopyTo(result);
@@ -275,9 +276,10 @@ Dictionary::Ptr ApiActions::AddComment(const ConfigObject::Ptr& object,
 
        Comment::Ptr comment = Comment::GetByName(commentName);
 
-       Dictionary::Ptr additional = new Dictionary();
-       additional->Set("name", commentName);
-       additional->Set("legacy_id", comment->GetLegacyId());
+       Dictionary::Ptr additional = new Dictionary({
+               { "name", commentName },
+               { "legacy_id", comment->GetLegacyId() }
+       });
 
        return ApiActions::CreateResult(200, "Successfully added comment '"
                + commentName + "' for object '" + checkable->GetName()
@@ -350,9 +352,10 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
 
        Downtime::Ptr downtime = Downtime::GetByName(downtimeName);
 
-       Dictionary::Ptr additional = new Dictionary();
-       additional->Set("name", downtimeName);
-       additional->Set("legacy_id", downtime->GetLegacyId());
+       Dictionary::Ptr additional = new Dictionary({
+               { "name", downtimeName },
+               { "legacy_id", downtime->GetLegacyId() }
+       });
 
        /* Schedule downtime for all child objects. */
        int childOptions = 0;
@@ -366,11 +369,11 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
                if (childOptions == 1)
                        triggerName = downtimeName;
 
-               Array::Ptr childDowntimes = new Array();
-
                Log(LogCritical, "ApiActions")
                        << "Processing child options " << childOptions << " for downtime " << downtimeName;
 
+               ArrayData childDowntimes;
+
                for (const Checkable::Ptr& child : checkable->GetAllChildren()) {
                        Log(LogCritical, "ApiActions")
                                << "Scheduling downtime for child object " << child->GetName();
@@ -383,13 +386,13 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
 
                        Downtime::Ptr childDowntime = Downtime::GetByName(childDowntimeName);
 
-                       Dictionary::Ptr additionalChild = new Dictionary();
-                       additionalChild->Set("name", childDowntimeName);
-                       additionalChild->Set("legacy_id", childDowntime->GetLegacyId());
-                       childDowntimes->Add(additionalChild);
+                       childDowntimes.push_back(new Dictionary({
+                               { "name", childDowntimeName },
+                               { "legacy_id", childDowntime->GetLegacyId() }
+                       }));
                }
 
-               additional->Set("child_downtimes", childDowntimes);
+               additional->Set("child_downtimes", new Array(std::move(childDowntimes)));
        }
 
        return ApiActions::CreateResult(200, "Successfully scheduled downtime '" +
@@ -455,8 +458,9 @@ Dictionary::Ptr ApiActions::GenerateTicket(const ConfigObject::Ptr&,
 
        String ticket = PBKDF2_SHA1(cn, salt, 50000);
 
-       Dictionary::Ptr additional = new Dictionary();
-       additional->Set("ticket", ticket);
+       Dictionary::Ptr additional = new Dictionary({
+               { "ticket", ticket }
+       });
 
        return ApiActions::CreateResult(200, "Generated PKI ticket '" + ticket + "' for common name '"
                + cn + "'.", additional);
index 2090bda0c0fa125ca9fc9b4e85ba870d6a0e9369..7041890dff6b73ba48ad82478cdb20d5c84f002b 100644 (file)
@@ -129,13 +129,13 @@ void ApiEvents::NotificationSentToAllUsersHandler(const Notification::Ptr& notif
        if (service)
                result->Set("service", service->GetShortName());
 
-       Array::Ptr userNames = new Array();
+       ArrayData userNames;
 
        for (const User::Ptr& user : users) {
-               userNames->Add(user->GetName());
+               userNames.push_back(user->GetName());
        }
 
-       result->Set("users", userNames);
+       result->Set("users", new Array(std::move(userNames)));
        result->Set("notification_type", Notification::NotificationTypeToString(type));
        result->Set("author", author);
        result->Set("text", text);
@@ -257,11 +257,11 @@ void ApiEvents::CommentAddedHandler(const Comment::Ptr& comment)
 
        Log(LogDebug, "ApiEvents", "Processing event type 'CommentAdded'.");
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("type", "CommentAdded");
-       result->Set("timestamp", Utility::GetTime());
-
-       result->Set("comment", Serialize(comment, FAConfig | FAState));
+       Dictionary::Ptr result = new Dictionary({
+               { "type", "CommentAdded" },
+               { "timestamp", Utility::GetTime() },
+               { "comment", Serialize(comment, FAConfig | FAState) }
+       });
 
        for (const EventQueue::Ptr& queue : queues) {
                queue->ProcessEvent(result);
@@ -277,11 +277,11 @@ void ApiEvents::CommentRemovedHandler(const Comment::Ptr& comment)
 
        Log(LogDebug, "ApiEvents", "Processing event type 'CommentRemoved'.");
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("type", "CommentRemoved");
-       result->Set("timestamp", Utility::GetTime());
-
-       result->Set("comment", Serialize(comment, FAConfig | FAState));
+       Dictionary::Ptr result = new Dictionary({
+               { "type", "CommentRemoved" },
+               { "timestamp", Utility::GetTime() },
+               { "comment", Serialize(comment, FAConfig | FAState) }
+       });
 
        for (const EventQueue::Ptr& queue : queues) {
                queue->ProcessEvent(result);
@@ -297,11 +297,11 @@ void ApiEvents::DowntimeAddedHandler(const Downtime::Ptr& downtime)
 
        Log(LogDebug, "ApiEvents", "Processing event type 'DowntimeAdded'.");
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("type", "DowntimeAdded");
-       result->Set("timestamp", Utility::GetTime());
-
-       result->Set("downtime", Serialize(downtime, FAConfig | FAState));
+       Dictionary::Ptr result = new Dictionary({
+               { "type", "DowntimeAdded" },
+               { "timestamp", Utility::GetTime() },
+               { "downtime", Serialize(downtime, FAConfig | FAState) }
+       });
 
        for (const EventQueue::Ptr& queue : queues) {
                queue->ProcessEvent(result);
@@ -317,11 +317,11 @@ void ApiEvents::DowntimeRemovedHandler(const Downtime::Ptr& downtime)
 
        Log(LogDebug, "ApiEvents", "Processing event type 'DowntimeRemoved'.");
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("type", "DowntimeRemoved");
-       result->Set("timestamp", Utility::GetTime());
-
-       result->Set("downtime", Serialize(downtime, FAConfig | FAState));
+       Dictionary::Ptr result = new Dictionary({
+               { "type", "DowntimeRemoved" },
+               { "timestamp", Utility::GetTime() },
+               { "downtime", Serialize(downtime, FAConfig | FAState) }
+       });
 
        for (const EventQueue::Ptr& queue : queues) {
                queue->ProcessEvent(result);
@@ -337,11 +337,11 @@ void ApiEvents::DowntimeStartedHandler(const Downtime::Ptr& downtime)
 
        Log(LogDebug, "ApiEvents", "Processing event type 'DowntimeStarted'.");
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("type", "DowntimeStarted");
-       result->Set("timestamp", Utility::GetTime());
-
-       result->Set("downtime", Serialize(downtime, FAConfig | FAState));
+       Dictionary::Ptr result = new Dictionary({
+               { "type", "DowntimeStarted" },
+               { "timestamp", Utility::GetTime() },
+               { "downtime", Serialize(downtime, FAConfig | FAState) }
+       });
 
        for (const EventQueue::Ptr& queue : queues) {
                queue->ProcessEvent(result);
@@ -357,11 +357,11 @@ void ApiEvents::DowntimeTriggeredHandler(const Downtime::Ptr& downtime)
 
        Log(LogDebug, "ApiEvents", "Processing event type 'DowntimeTriggered'.");
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("type", "DowntimeTriggered");
-       result->Set("timestamp", Utility::GetTime());
-
-       result->Set("downtime", Serialize(downtime, FAConfig | FAState));
+       Dictionary::Ptr result = new Dictionary({
+               { "type", "DowntimeTriggered" },
+               { "timestamp", Utility::GetTime() },
+               { "downtime", Serialize(downtime, FAConfig | FAState) }
+       });
 
        for (const EventQueue::Ptr& queue : queues) {
                queue->ProcessEvent(result);
index e7ca7728bc8f217167982534f299ae3f85171701..5d658d3b03e4688e0807dafc02be9933a6322116 100644 (file)
@@ -301,11 +301,12 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
        if (remove_acknowledgement_comments)
                RemoveCommentsByType(CommentAcknowledgement);
 
-       Dictionary::Ptr vars_after = new Dictionary();
-       vars_after->Set("state", new_state);
-       vars_after->Set("state_type", GetStateType());
-       vars_after->Set("attempt", GetCheckAttempt());
-       vars_after->Set("reachable", reachable);
+       Dictionary::Ptr vars_after = new Dictionary({
+               { "state", new_state },
+               { "state_type", GetStateType() },
+               { "attempt", GetCheckAttempt() },
+               { "reachable", reachable }
+       });
 
        if (old_cr)
                cr->SetVarsBefore(old_cr->GetVarsAfter());
index 31c7f9eda281ec031fa0867b2cb42dec5ec1aa37..5d969e3f4cb683c282ff484d5da72e434f8c45a7 100644 (file)
@@ -35,12 +35,9 @@ static void CheckableProcessCheckResult(const CheckResult::Ptr& cr)
 
 Object::Ptr Checkable::GetPrototype()
 {
-       static Dictionary::Ptr prototype;
-
-       if (!prototype) {
-               prototype = new Dictionary();
-               prototype->Set("process_check_result", new Function("Checkable#process_check_result", CheckableProcessCheckResult, { "cr" }, false));
-       }
+       static Dictionary::Ptr prototype = new Dictionary({
+               { "process_check_result", new Function("Checkable#process_check_result", CheckableProcessCheckResult, { "cr" }, false) }
+       });
 
        return prototype;
 }
index 2015558dc9675458e0891abd62e1f5ad2878a848..013bae284ffd7286d68a1b936548b5ab5aef8c2b 100644 (file)
@@ -137,7 +137,7 @@ Value ClusterEvents::CheckResultAPIHandler(const MessageOrigin::Ptr& origin, con
        if (!cr)
                return Empty;
 
-       Array::Ptr rperf = new Array();
+       ArrayData rperf;
 
        if (vperf) {
                ObjectLock olock(vperf);
@@ -147,13 +147,13 @@ Value ClusterEvents::CheckResultAPIHandler(const MessageOrigin::Ptr& origin, con
                        if (vp.IsObjectType<Dictionary>()) {
                                PerfdataValue::Ptr val = new PerfdataValue();
                                Deserialize(val, vp, true);
-                               rperf->Add(val);
+                               rperf.push_back(val);
                        } else
-                               rperf->Add(vp);
+                               rperf.push_back(vp);
                }
        }
 
-       cr->SetPerformanceData(rperf);
+       cr->SetPerformanceData(new Array(std::move(rperf)));
 
        Host::Ptr host = Host::GetByName(params->Get("host"));
 
@@ -892,11 +892,11 @@ void ClusterEvents::NotificationSentToAllUsersHandler(const Notification::Ptr& n
                params->Set("service", service->GetShortName());
        params->Set("notification", notification->GetName());
 
-       Array::Ptr ausers = new Array();
+       ArrayData ausers;
        for (const User::Ptr& user : users) {
-               ausers->Add(user->GetName());
+               ausers.push_back(user->GetName());
        }
-       params->Set("users", ausers);
+       params->Set("users", new Array(std::move(ausers)));
 
        params->Set("type", notificationType);
        params->Set("cr", Serialize(cr));
@@ -1003,12 +1003,12 @@ Value ClusterEvents::NotificationSentToAllUsersAPIHandler(const MessageOrigin::P
        notification->SetLastProblemNotification(params->Get("last_problem_notification"));
        notification->SetNoMoreNotifications(params->Get("no_more_notifications"));
 
-       Array::Ptr notifiedProblemUsers = new Array();
+       ArrayData notifiedProblemUsers;
        for (const User::Ptr& user : users) {
-               notifiedProblemUsers->Add(user->GetName());
+               notifiedProblemUsers.push_back(user->GetName());
        }
 
-       notification->SetNotifiedProblemUsers(notifiedProblemUsers);
+       notification->SetNotifiedProblemUsers(new Array(std::move(notifiedProblemUsers)));
 
        Checkable::OnNotificationSentToAllUsers(notification, checkable, users, type, cr, author, text, origin);
 
index d300b8cfeb0417e827bc41ad3e6a7db9a5215f22..cc464aa7dd1324a62e71ef590a3e01018520cabd 100644 (file)
@@ -108,9 +108,7 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR
                        return false;
                }
        } else {
-               Array::Ptr instances = new Array();
-               instances->Add("");
-               vinstances = instances;
+               vinstances = new Array({ "" });
        }
 
        bool match = false;
index 3a32586a4128282b635836faa50f36e24d27f234..90e623a92eeddcbdaca31ac3d51bd235986e1210 100644 (file)
@@ -65,25 +65,24 @@ REGISTER_STATSFUNCTION(IcingaApplication, &IcingaApplication::StatsFunc);
 
 void IcingaApplication::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const IcingaApplication::Ptr& icingaapplication : ConfigType::GetObjectsByType<IcingaApplication>()) {
-               Dictionary::Ptr stats = new Dictionary();
-               stats->Set("node_name", icingaapplication->GetNodeName());
-               stats->Set("enable_notifications", icingaapplication->GetEnableNotifications());
-               stats->Set("enable_event_handlers", icingaapplication->GetEnableEventHandlers());
-               stats->Set("enable_flapping", icingaapplication->GetEnableFlapping());
-               stats->Set("enable_host_checks", icingaapplication->GetEnableHostChecks());
-               stats->Set("enable_service_checks", icingaapplication->GetEnableServiceChecks());
-               stats->Set("enable_perfdata", icingaapplication->GetEnablePerfdata());
-               stats->Set("pid", Utility::GetPid());
-               stats->Set("program_start", Application::GetStartTime());
-               stats->Set("version", Application::GetAppVersion());
-
-               nodes->Set(icingaapplication->GetName(), stats);
+               nodes.emplace_back(icingaapplication->GetName(), new Dictionary({
+                       { "node_name", icingaapplication->GetNodeName() },
+                       { "enable_notifications", icingaapplication->GetEnableNotifications() },
+                       { "enable_event_handlers", icingaapplication->GetEnableEventHandlers() },
+                       { "enable_flapping", icingaapplication->GetEnableFlapping() },
+                       { "enable_host_checks", icingaapplication->GetEnableHostChecks() },
+                       { "enable_service_checks", icingaapplication->GetEnableServiceChecks() },
+                       { "enable_perfdata", icingaapplication->GetEnablePerfdata() },
+                       { "pid", Utility::GetPid() },
+                       { "program_start", Application::GetStartTime() },
+                       { "version", Application::GetAppVersion() }
+               }));
        }
 
-       status->Set("icingaapplication", nodes);
+       status->Set("icingaapplication", new Dictionary(std::move(nodes)));
 }
 
 /**
@@ -129,9 +128,10 @@ static void PersistModAttrHelper(std::fstream& fp, ConfigObject::Ptr& previousOb
 
                ConfigWriter::EmitRaw(fp, "var obj = ");
 
-               Array::Ptr args1 = new Array();
-               args1->Add(object->GetReflectionType()->GetName());
-               args1->Add(object->GetName());
+               Array::Ptr args1 = new Array({
+                       object->GetReflectionType()->GetName(),
+                       object->GetName()
+               });
                ConfigWriter::EmitFunctionCall(fp, "get_object", args1);
 
                ConfigWriter::EmitRaw(fp, "\nif (obj) {\n");
@@ -139,9 +139,10 @@ static void PersistModAttrHelper(std::fstream& fp, ConfigObject::Ptr& previousOb
 
        ConfigWriter::EmitRaw(fp, "\tobj.");
 
-       Array::Ptr args2 = new Array();
-       args2->Add(attr);
-       args2->Add(value);
+       Array::Ptr args2 = new Array({
+               attr,
+               value
+       });
        ConfigWriter::EmitFunctionCall(fp, "modify_attribute", args2);
 
        ConfigWriter::EmitRaw(fp, "\n");
index 14cdd85252db08c5b33ba712d6409246f4136806..2204f4835e745cd2e5b11c73dc7a7e51153be446 100644 (file)
@@ -374,10 +374,10 @@ Dictionary::Ptr LegacyTimePeriod::ProcessTimeRange(const String& timestamp, tm *
 
        ProcessTimeRangeRaw(timestamp, reference, &begin, &end);
 
-       Dictionary::Ptr segment = new Dictionary();
-       segment->Set("begin", (long)mktime(&begin));
-       segment->Set("end", (long)mktime(&end));
-       return segment;
+       return new Dictionary({
+               { "begin", (long)mktime(&begin) },
+               { "end", (long)mktime(&end) }
+       });
 }
 
 void LegacyTimePeriod::ProcessTimeRanges(const String& timeranges, tm *reference, const Array::Ptr& result)
index 9a0e7840f6e241a0e5f02caf6ed1a97abb14a096..7fc150d948b3ee984a44c978b2fadb69e497d52f 100644 (file)
@@ -48,7 +48,7 @@ Value MacroProcessor::ResolveMacros(const Value& str, const ResolverList& resolv
                result = InternalResolveMacros(str, resolvers, cr, missingMacro, escapeFn,
                        resolvedMacros, useResolvedMacros, recursionLevel + 1);
        } else if (str.IsObjectType<Array>()) {
-               Array::Ptr resultArr = new Array();
+               ArrayData resultArr;;
                Array::Ptr arr = str;
 
                ObjectLock olock(arr);
@@ -59,12 +59,12 @@ Value MacroProcessor::ResolveMacros(const Value& str, const ResolverList& resolv
                                EscapeCallback(), resolvedMacros, useResolvedMacros, recursionLevel + 1);
 
                        if (value.IsObjectType<Array>())
-                               resultArr->Add(Utility::Join(value, ';'));
+                               resultArr.push_back(Utility::Join(value, ';'));
                        else
-                               resultArr->Add(value);
+                               resultArr.push_back(value);
                }
 
-               result = resultArr;
+               result = new Array(std::move(resultArr));
        } else if (str.IsObjectType<Dictionary>()) {
                Dictionary::Ptr resultDict = new Dictionary();
                Dictionary::Ptr dict = str;
@@ -275,19 +275,19 @@ Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverLis
                if (recursive_macro) {
                        if (resolved_macro.IsObjectType<Array>()) {
                                Array::Ptr arr = resolved_macro;
-                               Array::Ptr resolved_arr = new Array();
+                               ArrayData resolved_arr;
 
                                ObjectLock olock(arr);
                                for (const Value& value : arr) {
                                        if (value.IsScalar()) {
-                                               resolved_arr->Add(InternalResolveMacros(value,
+                                               resolved_arr.push_back(InternalResolveMacros(value,
                                                        resolvers, cr, missingMacro, EscapeCallback(), nullptr,
                                                        false, recursionLevel + 1));
                                        } else
-                                               resolved_arr->Add(value);
+                                               resolved_arr.push_back(value);
                                }
 
-                               resolved_macro = resolved_arr;
+                               resolved_macro = new Array(std::move(resolved_arr));
                        } else if (resolved_macro.IsString()) {
                                resolved_macro = InternalResolveMacros(resolved_macro,
                                        resolvers, cr, missingMacro, EscapeCallback(), nullptr,
@@ -444,9 +444,7 @@ Value MacroProcessor::ResolveArguments(const Value& command, const Dictionary::P
                resolvedCommand = MacroProcessor::ResolveMacros(command, resolvers, cr, nullptr,
                        EscapeMacroShellArg, resolvedMacros, useResolvedMacros, recursionLevel + 1);
        else {
-               Array::Ptr arr = new Array();
-               arr->Add(command);
-               resolvedCommand = arr;
+               resolvedCommand = new Array({ command });
        }
 
        if (arguments) {
@@ -562,4 +560,3 @@ Value MacroProcessor::ResolveArguments(const Value& command, const Dictionary::P
 
        return resolvedCommand;
 }
-
index 5e05ece3ba6369617f0b11fc03bb389f4c3bf39a..7f8f39dab98b5807dd297b34a88a2cc89b54d5e7 100644 (file)
@@ -107,9 +107,7 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl
                        return false;
                }
        } else {
-               Array::Ptr instances = new Array();
-               instances->Add("");
-               vinstances = instances;
+               vinstances = new Array({ "" });
        }
 
        bool match = false;
index ceffcfc136a343b530a3d9cf847b7283df2a19ce..02eb27896803cc285afc12a441212f05da8e7580 100644 (file)
@@ -145,7 +145,7 @@ std::pair<String, String> PluginUtility::ParseCheckOutput(const String& output)
 
 Array::Ptr PluginUtility::SplitPerfdata(const String& perfdata)
 {
-       Array::Ptr result = new Array();
+       ArrayData result;
 
        size_t begin = 0;
        String multi_prefix;
@@ -182,7 +182,7 @@ Array::Ptr PluginUtility::SplitPerfdata(const String& perfdata)
                else
                        pdv = label + "=" + value;
 
-               result->Add(pdv);
+               result.emplace_back(std::move(pdv));
 
                if (multi_index != String::NPos)
                        multi_prefix = label.SubStr(0, multi_index);
@@ -190,7 +190,7 @@ Array::Ptr PluginUtility::SplitPerfdata(const String& perfdata)
                begin = spq + 1;
        }
 
-       return result;
+       return new Array(std::move(result));
 }
 
 String PluginUtility::FormatPerfdata(const Array::Ptr& perfdata)
index fb44018d05655c0d07f254becd6b171f10fc623a..3909f6fc0a447215b0ddb8e7a6c86d0f93391fb1 100644 (file)
@@ -106,9 +106,7 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const
                        return false;
                }
        } else {
-               Array::Ptr instances = new Array();
-               instances->Add("");
-               vinstances = instances;
+               vinstances = new Array({ "" });
        }
 
        bool match = false;
index 79d9a78fbfb905b0065866d462466e51215f8acf..4e9f78a66f35a5be7f1e506d860ad021de4ad914 100644 (file)
@@ -95,9 +95,7 @@ bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule)
                        return false;
                }
        } else {
-               Array::Ptr instances = new Array();
-               instances->Add("");
-               vinstances = instances;
+               vinstances = new Array({ "" });
        }
 
        bool match = false;
index 3964b3686784a86e09c494910ac38716699ed6b4..e6ca785f24f2a09d5843e91bf50b58443ebb37c8 100644 (file)
@@ -50,11 +50,10 @@ Dictionary::Ptr ServiceNameComposer::ParseName(const String& name) const
        if (tokens.size() < 2)
                BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid Service name."));
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("host_name", tokens[0]);
-       result->Set("name", tokens[1]);
-
-       return result;
+       return new Dictionary({
+               { "host_name", tokens[0] },
+               { "name", tokens[1] }
+       });
 }
 
 void Service::OnAllConfigLoaded()
index 13ee6bcfbabad07e958a36a41bb42c44ce23412d..4953c3ebb5a0acea0f92004af4ebc4373debc3fd 100644 (file)
@@ -98,9 +98,10 @@ void TimePeriod::AddSegment(double begin, double end)
        }
 
        /* Create new segment if we weren't able to merge this into an existing segment. */
-       Dictionary::Ptr segment = new Dictionary();
-       segment->Set("begin", begin);
-       segment->Set("end", end);
+       Dictionary::Ptr segment = new Dictionary({
+               { "begin", begin },
+               { "end", end }
+       });
 
        if (!segments) {
                segments = new Array();
@@ -152,17 +153,15 @@ void TimePeriod::RemoveSegment(double begin, double end)
 
                /* Cut between */
                if (segment->Get("begin") < begin && segment->Get("end") > end) {
-                       Dictionary::Ptr firstsegment = new Dictionary();
-                       firstsegment->Set("begin", segment->Get("begin"));
-                       firstsegment->Set("end", begin);
-
-                       Dictionary::Ptr secondsegment = new Dictionary();
-                       secondsegment->Set("begin", end);
-                       secondsegment->Set("end", segment->Get("end"));
-
-                       newSegments->Add(firstsegment);
-                       newSegments->Add(secondsegment);
-                       continue;
+                       newSegments->Add(new Dictionary({
+                               { "begin", segment->Get("begin") },
+                               { "end", begin }
+                       }));
+
+                       newSegments->Add(new Dictionary({
+                               { "begin", end },
+                               { "end", segment->Get("end") }
+                       }));
                }
 
                /* Adjust the begin/end timestamps so as to not overlap with the specified range. */
index ae5145fc175f1336c6839505cf04667f049dca3a..a26ae91a2acad8b7a74dae701879dcdf1637d2fa 100644 (file)
@@ -101,19 +101,16 @@ Value CommandsTable::CustomVariableNamesAccessor(const Value& row)
 
        Dictionary::Ptr vars = command->GetVars();
 
-       Array::Ptr cv = new Array();
+       ArrayData keys;
 
-       if (!vars)
-               return cv;
-
-       {
+       if (vars) {
                ObjectLock xlock(vars);
                for (const auto& kv : vars) {
-                       cv->Add(kv.first);
+                       keys.push_back(kv.first);
                }
        }
 
-       return cv;
+       return new Array(std::move(keys));
 }
 
 Value CommandsTable::CustomVariableValuesAccessor(const Value& row)
@@ -125,19 +122,16 @@ Value CommandsTable::CustomVariableValuesAccessor(const Value& row)
 
        Dictionary::Ptr vars = command->GetVars();
 
-       Array::Ptr cv = new Array();
-
-       if (!vars)
-               return cv;
+       ArrayData keys;
 
-       {
+       if (vars) {
                ObjectLock xlock(vars);
                for (const auto& kv : vars) {
-                       cv->Add(kv.second);
+                       keys.push_back(kv.second);
                }
        }
 
-       return cv;
+       return new Array(std::move(keys));
 }
 
 Value CommandsTable::CustomVariablesAccessor(const Value& row)
@@ -149,20 +143,17 @@ Value CommandsTable::CustomVariablesAccessor(const Value& row)
 
        Dictionary::Ptr vars = command->GetVars();
 
-       Array::Ptr cv = new Array();
-
-       if (!vars)
-               return cv;
+       ArrayData result;
 
-       {
+       if (vars) {
                ObjectLock xlock(vars);
                for (const auto& kv : vars) {
-                       Array::Ptr key_val = new Array();
-                       key_val->Add(kv.first);
-                       key_val->Add(kv.second);
-                       cv->Add(key_val);
+                       result.push_back(new Array({
+                               kv.first,
+                               kv.second
+                       }));
                }
        }
 
-       return cv;
+       return new Array(std::move(result));
 }
index 93587674a2796dd2416cf2cc3478b3993135f744..2be78ffad2a07ce8ad2768301e23e8354fe2e939 100644 (file)
@@ -81,11 +81,11 @@ Value ContactGroupsTable::MembersAccessor(const Value& row)
        if (!user_group)
                return Empty;
 
-       Array::Ptr members = new Array();
+       ArrayData result;
 
        for (const User::Ptr& user : user_group->GetMembers()) {
-               members->Add(user->GetName());
+               result.push_back(user->GetName());
        }
 
-       return members;
+       return new Array(std::move(result));
 }
index aeca4b04d4d8b6bc5a73730fe6e761448ae0ac14..62030aae6845f4fc2acf1e4a174bcbb192d7cc50 100644 (file)
@@ -205,17 +205,16 @@ Value ContactsTable::CustomVariableNamesAccessor(const Value& row)
 
        Dictionary::Ptr vars = user->GetVars();
 
-       Array::Ptr cv = new Array();
+       ArrayData result;
 
-       if (!vars)
-               return cv;
-
-       ObjectLock olock(vars);
-       for (const Dictionary::Pair& kv : vars) {
-               cv->Add(kv.first);
+       if (vars) {
+               ObjectLock olock(vars);
+               for (const Dictionary::Pair& kv : vars) {
+                       result.push_back(kv.first);
+               }
        }
 
-       return cv;
+       return new Array(std::move(result));
 }
 
 Value ContactsTable::CustomVariableValuesAccessor(const Value& row)
@@ -227,20 +226,19 @@ Value ContactsTable::CustomVariableValuesAccessor(const Value& row)
 
        Dictionary::Ptr vars = user->GetVars();
 
-       Array::Ptr cv = new Array();
+       ArrayData result;
 
-       if (!vars)
-               return cv;
-
-       ObjectLock olock(vars);
-       for (const Dictionary::Pair& kv : vars) {
-               if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
-                       cv->Add(JsonEncode(kv.second));
-               else
-                       cv->Add(kv.second);
+       if (vars) {
+               ObjectLock olock(vars);
+               for (const Dictionary::Pair& kv : vars) {
+                       if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
+                               result.push_back(JsonEncode(kv.second));
+                       else
+                               result.push_back(kv.second);
+               }
        }
 
-       return cv;
+       return new Array(std::move(result));
 }
 
 Value ContactsTable::CustomVariablesAccessor(const Value& row)
@@ -252,25 +250,26 @@ Value ContactsTable::CustomVariablesAccessor(const Value& row)
 
        Dictionary::Ptr vars = user->GetVars();
 
-       Array::Ptr cv = new Array();
+       ArrayData result;
 
-       if (!vars)
-               return cv;
+       if (vars) {
+               ObjectLock olock(vars);
+               for (const Dictionary::Pair& kv : vars) {
+                       Value val;
 
-       ObjectLock olock(vars);
-       for (const Dictionary::Pair& kv : vars) {
-               Array::Ptr key_val = new Array();
-               key_val->Add(kv.first);
-
-               if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
-                       key_val->Add(JsonEncode(kv.second));
-               else
-                       key_val->Add(kv.second);
+                       if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
+                               val = JsonEncode(kv.second);
+                       else
+                               val = kv.second;
 
-               cv->Add(key_val);
+                       result.push_back(new Array({
+                               kv.first,
+                               val
+                       }));
+               }
        }
 
-       return cv;
+       return new Array(std::move(result));
 }
 
 Value ContactsTable::CVIsJsonAccessor(const Value& row)
index 117a84a7d8626a72b6db05212f1190bdd4c20aaf..a4ab713a36c27c57b5b4a8c7637cb628bbf95828 100644 (file)
@@ -135,13 +135,13 @@ Value HostGroupsTable::MembersAccessor(const Value& row)
        if (!hg)
                return Empty;
 
-       Array::Ptr members = new Array();
+       ArrayData members;
 
        for (const Host::Ptr& host : hg->GetMembers()) {
-               members->Add(host->GetName());
+               members.push_back(host->GetName());
        }
 
-       return members;
+       return new Array(std::move(members));
 }
 
 Value HostGroupsTable::MembersWithStateAccessor(const Value& row)
@@ -151,16 +151,16 @@ Value HostGroupsTable::MembersWithStateAccessor(const Value& row)
        if (!hg)
                return Empty;
 
-       Array::Ptr members = new Array();
+       ArrayData members;
 
        for (const Host::Ptr& host : hg->GetMembers()) {
-               Array::Ptr member_state = new Array();
-               member_state->Add(host->GetName());
-               member_state->Add(host->GetState());
-               members->Add(member_state);
+               members.push_back(new Array({
+                       host->GetName(),
+                       host->GetState()
+               }));
        }
 
-       return members;
+       return new Array(std::move(members));
 }
 
 Value HostGroupsTable::WorstHostStateAccessor(const Value& row)
index 795f31b8e8916deb8a0bcd36de01638deb57e554..d46b8853564d338e84104bcac0fcc8c82a39c596 100644 (file)
@@ -912,13 +912,13 @@ Value HostsTable::ContactsAccessor(const Value& row)
        if (!host)
                return Empty;
 
-       Array::Ptr contact_names = new Array();
+       ArrayData result;
 
        for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(host)) {
-               contact_names->Add(user->GetName());
+               result.push_back(user->GetName());
        }
 
-       return contact_names;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::DowntimesAccessor(const Value& row)
@@ -928,16 +928,16 @@ Value HostsTable::DowntimesAccessor(const Value& row)
        if (!host)
                return Empty;
 
-       Array::Ptr results = new Array();
+       ArrayData result;
 
        for (const Downtime::Ptr& downtime : host->GetDowntimes()) {
                if (downtime->IsExpired())
                        continue;
 
-               results->Add(downtime->GetLegacyId());
+               result.push_back(downtime->GetLegacyId());
        }
 
-       return results;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::DowntimesWithInfoAccessor(const Value& row)
@@ -947,20 +947,20 @@ Value HostsTable::DowntimesWithInfoAccessor(const Value& row)
        if (!host)
                return Empty;
 
-       Array::Ptr results = new Array();
+       ArrayData result;
 
        for (const Downtime::Ptr& downtime : host->GetDowntimes()) {
                if (downtime->IsExpired())
                        continue;
 
-               Array::Ptr downtime_info = new Array();
-               downtime_info->Add(downtime->GetLegacyId());
-               downtime_info->Add(downtime->GetAuthor());
-               downtime_info->Add(downtime->GetComment());
-               results->Add(downtime_info);
+               result.push_back(new Array({
+                       downtime->GetLegacyId(),
+                       downtime->GetAuthor(),
+                       downtime->GetComment()
+               }));
        }
 
-       return results;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::CommentsAccessor(const Value& row)
@@ -970,15 +970,16 @@ Value HostsTable::CommentsAccessor(const Value& row)
        if (!host)
                return Empty;
 
-       Array::Ptr results = new Array();
+       ArrayData result;
+
        for (const Comment::Ptr& comment : host->GetComments()) {
                if (comment->IsExpired())
                        continue;
 
-               results->Add(comment->GetLegacyId());
+               result.push_back(comment->GetLegacyId());
        }
 
-       return results;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::CommentsWithInfoAccessor(const Value& row)
@@ -988,20 +989,20 @@ Value HostsTable::CommentsWithInfoAccessor(const Value& row)
        if (!host)
                return Empty;
 
-       Array::Ptr results = new Array();
+       ArrayData result;
 
        for (const Comment::Ptr& comment : host->GetComments()) {
                if (comment->IsExpired())
                        continue;
 
-               Array::Ptr comment_info = new Array();
-               comment_info->Add(comment->GetLegacyId());
-               comment_info->Add(comment->GetAuthor());
-               comment_info->Add(comment->GetText());
-               results->Add(comment_info);
+               result.push_back(new Array({
+                       comment->GetLegacyId(),
+                       comment->GetAuthor(),
+                       comment->GetText()
+               }));
        }
 
-       return results;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::CommentsWithExtraInfoAccessor(const Value& row)
@@ -1011,22 +1012,22 @@ Value HostsTable::CommentsWithExtraInfoAccessor(const Value& row)
        if (!host)
                return Empty;
 
-       Array::Ptr results = new Array();
+       ArrayData result;
 
        for (const Comment::Ptr& comment : host->GetComments()) {
                if (comment->IsExpired())
                        continue;
 
-               Array::Ptr comment_info = new Array();
-               comment_info->Add(comment->GetLegacyId());
-               comment_info->Add(comment->GetAuthor());
-               comment_info->Add(comment->GetText());
-               comment_info->Add(comment->GetEntryType());
-               comment_info->Add(static_cast<int>(comment->GetEntryTime()));
-               results->Add(comment_info);
+               result.push_back(new Array({
+                       comment->GetLegacyId(),
+                       comment->GetAuthor(),
+                       comment->GetText(),
+                       comment->GetEntryType(),
+                       static_cast<int>(comment->GetEntryTime())
+               }));
        }
 
-       return results;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::CustomVariableNamesAccessor(const Value& row)
@@ -1038,17 +1039,16 @@ Value HostsTable::CustomVariableNamesAccessor(const Value& row)
 
        Dictionary::Ptr vars = host->GetVars();
 
-       Array::Ptr cv = new Array();
-
-       if (!vars)
-               return cv;
+       ArrayData result;
 
-       ObjectLock olock(vars);
-       for (const Dictionary::Pair& kv : vars) {
-               cv->Add(kv.first);
+       if (vars) {
+               ObjectLock olock(vars);
+               for (const Dictionary::Pair& kv : vars) {
+                       result.push_back(kv.first);
+               }
        }
 
-       return cv;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::CustomVariableValuesAccessor(const Value& row)
@@ -1060,20 +1060,19 @@ Value HostsTable::CustomVariableValuesAccessor(const Value& row)
 
        Dictionary::Ptr vars = host->GetVars();
 
-       Array::Ptr cv = new Array();
+       ArrayData result;
 
-       if (!vars)
-               return cv;
-
-       ObjectLock olock(vars);
-       for (const Dictionary::Pair& kv : vars) {
-               if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
-                       cv->Add(JsonEncode(kv.second));
-               else
-                       cv->Add(kv.second);
+       if (vars) {
+               ObjectLock olock(vars);
+               for (const Dictionary::Pair& kv : vars) {
+                       if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
+                               result.push_back(JsonEncode(kv.second));
+                       else
+                               result.push_back(kv.second);
+               }
        }
 
-       return cv;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::CustomVariablesAccessor(const Value& row)
@@ -1085,25 +1084,26 @@ Value HostsTable::CustomVariablesAccessor(const Value& row)
 
        Dictionary::Ptr vars = host->GetVars();
 
-       Array::Ptr cv = new Array();
-
-       if (!vars)
-               return cv;
+       ArrayData result;
 
-       ObjectLock olock(vars);
-       for (const Dictionary::Pair& kv : vars) {
-               Array::Ptr key_val = new Array();
-               key_val->Add(kv.first);
+       if (vars) {
+               ObjectLock olock(vars);
+               for (const Dictionary::Pair& kv : vars) {
+                       Value val;
 
-               if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
-                       key_val->Add(JsonEncode(kv.second));
-               else
-                       key_val->Add(kv.second);
+                       if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
+                               val = JsonEncode(kv.second);
+                       else
+                               val = kv.second;
 
-               cv->Add(key_val);
+                       result.push_back(new Array({
+                               kv.first,
+                               val
+                       }));
+               }
        }
 
-       return cv;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::CVIsJsonAccessor(const Value& row)
@@ -1136,7 +1136,7 @@ Value HostsTable::ParentsAccessor(const Value& row)
        if (!host)
                return Empty;
 
-       Array::Ptr parents = new Array();
+       ArrayData result;
 
        for (const Checkable::Ptr& parent : host->GetParents()) {
                Host::Ptr parent_host = dynamic_pointer_cast<Host>(parent);
@@ -1144,10 +1144,10 @@ Value HostsTable::ParentsAccessor(const Value& row)
                if (!parent_host)
                        continue;
 
-               parents->Add(parent_host->GetName());
+               result.push_back(parent_host->GetName());
        }
 
-       return parents;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::ChildsAccessor(const Value& row)
@@ -1157,7 +1157,7 @@ Value HostsTable::ChildsAccessor(const Value& row)
        if (!host)
                return Empty;
 
-       Array::Ptr childs = new Array();
+       ArrayData result;
 
        for (const Checkable::Ptr& child : host->GetChildren()) {
                Host::Ptr child_host = dynamic_pointer_cast<Host>(child);
@@ -1165,10 +1165,10 @@ Value HostsTable::ChildsAccessor(const Value& row)
                if (!child_host)
                        continue;
 
-               childs->Add(child_host->GetName());
+               result.push_back(child_host->GetName());
        }
 
-       return childs;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::NumServicesAccessor(const Value& row)
@@ -1421,13 +1421,13 @@ Value HostsTable::ContactGroupsAccessor(const Value& row)
        if (!host)
                return Empty;
 
-       Array::Ptr contactgroup_names = new Array();
+       ArrayData result;
 
        for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(host)) {
-               contactgroup_names->Add(usergroup->GetName());
+               result.push_back(usergroup->GetName());
        }
 
-       return contactgroup_names;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::ServicesAccessor(const Value& row)
@@ -1439,14 +1439,14 @@ Value HostsTable::ServicesAccessor(const Value& row)
 
        std::vector<Service::Ptr> rservices = host->GetServices();
 
-       Array::Ptr services = new Array();
-       services->Reserve(rservices.size());
+       ArrayData result;
+       result.reserve(rservices.size());
 
        for (const Service::Ptr& service : rservices) {
-               services->Add(service->GetShortName());
+               result.push_back(service->GetShortName());
        }
 
-       return services;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::ServicesWithStateAccessor(const Value& row)
@@ -1458,19 +1458,18 @@ Value HostsTable::ServicesWithStateAccessor(const Value& row)
 
        std::vector<Service::Ptr> rservices = host->GetServices();
 
-       Array::Ptr services = new Array();
-       services->Reserve(rservices.size());
+       ArrayData result;
+       result.reserve(rservices.size());
 
        for (const Service::Ptr& service : rservices) {
-               Array::Ptr svc_add = new Array();
-
-               svc_add->Add(service->GetShortName());
-               svc_add->Add(service->GetState());
-               svc_add->Add(service->HasBeenChecked() ? 1 : 0);
-               services->Add(svc_add);
+               result.push_back(new Array({
+                       service->GetShortName(),
+                       service->GetState(),
+                       service->HasBeenChecked() ? 1 : 0
+               }));
        }
 
-       return services;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::ServicesWithInfoAccessor(const Value& row)
@@ -1482,27 +1481,25 @@ Value HostsTable::ServicesWithInfoAccessor(const Value& row)
 
        std::vector<Service::Ptr> rservices = host->GetServices();
 
-       Array::Ptr services = new Array();
-       services->Reserve(rservices.size());
+       ArrayData result;
+       result.reserve(rservices.size());
 
        for (const Service::Ptr& service : rservices) {
-               Array::Ptr svc_add = new Array();
-
-               svc_add->Add(service->GetShortName());
-               svc_add->Add(service->GetState());
-               svc_add->Add(service->HasBeenChecked() ? 1 : 0);
-
                String output;
                CheckResult::Ptr cr = service->GetLastCheckResult();
 
                if (cr)
                        output = CompatUtility::GetCheckResultOutput(cr);
 
-               svc_add->Add(output);
-               services->Add(svc_add);
+               result.push_back(new Array({
+                       service->GetShortName(),
+                       service->GetState(),
+                       service->HasBeenChecked() ? 1 : 0,
+                       output
+               }));
        }
 
-       return services;
+       return new Array(std::move(result));
 }
 
 Value HostsTable::CheckSourceAccessor(const Value& row)
index 164b44fc1bc553f31e1d00a1bd0890c68a2f15d5..1f7944a397be9865feb7dd1ce6ba1d484639ae58 100644 (file)
@@ -45,18 +45,17 @@ REGISTER_STATSFUNCTION(LivestatusListener, &LivestatusListener::StatsFunc);
 
 void LivestatusListener::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const LivestatusListener::Ptr& livestatuslistener : ConfigType::GetObjectsByType<LivestatusListener>()) {
-               Dictionary::Ptr stats = new Dictionary();
-               stats->Set("connections", l_Connections);
-
-               nodes->Set(livestatuslistener->GetName(), stats);
+               nodes.emplace_back(livestatuslistener->GetName(), new Dictionary({
+                       { "connections", l_Connections }
+               }));
 
                perfdata->Add(new PerfdataValue("livestatuslistener_" + livestatuslistener->GetName() + "_connections", l_Connections));
        }
 
-       status->Set("livestatuslistener", nodes);
+       status->Set("livestatuslistener", new Dictionary(std::move(nodes)));
 }
 
 /**
index a8e7577aa21813933d77ba4ca7656347d6c78030..df3eb2ff1b062be34a30e8ca14016a2590c30887 100644 (file)
@@ -482,8 +482,6 @@ void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream)
        BeginResultSet(result);
 
        if (m_Aggregators.empty()) {
-               Array::Ptr header = new Array();
-
                typedef std::pair<String, Column> ColumnPair;
 
                std::vector<ColumnPair> column_objs;
@@ -492,24 +490,26 @@ void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream)
                for (const String& columnName : columns)
                        column_objs.emplace_back(columnName, table->GetColumn(columnName));
 
+               ArrayData header;
+
                for (const LivestatusRowValue& object : objects) {
-                       Array::Ptr row = new Array();
+                       ArrayData row;
 
-                       row->Reserve(column_objs.size());
+                       row.reserve(column_objs.size());
 
                        for (const ColumnPair& cv : column_objs) {
                                if (m_ColumnHeaders)
-                                       header->Add(cv.first);
+                                       header.push_back(cv.first);
 
-                               row->Add(cv.second.ExtractValue(object.Row, object.GroupByType, object.GroupByObject));
+                               row.push_back(cv.second.ExtractValue(object.Row, object.GroupByType, object.GroupByObject));
                        }
 
                        if (m_ColumnHeaders) {
-                               AppendResultRow(result, header, first_row);
+                               AppendResultRow(result, new Array(std::move(header)), first_row);
                                m_ColumnHeaders = false;
                        }
 
-                       AppendResultRow(result, row, first_row);
+                       AppendResultRow(result, new Array(std::move(row)), first_row);
                }
        } else {
                std::map<std::vector<Value>, std::vector<AggregatorState *> > allStats;
@@ -542,45 +542,47 @@ void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream)
 
                /* add column headers both for raw and aggregated data */
                if (m_ColumnHeaders) {
-                       Array::Ptr header = new Array();
+                       ArrayData header;
 
                        for (const String& columnName : m_Columns) {
-                               header->Add(columnName);
+                               header.push_back(columnName);
                        }
 
                        for (size_t i = 1; i <= m_Aggregators.size(); i++) {
-                               header->Add("stats_" + Convert::ToString(i));
+                               header.push_back("stats_" + Convert::ToString(i));
                        }
 
-                       AppendResultRow(result, header, first_row);
+                       AppendResultRow(result, new Array(std::move(header)), first_row);
                }
 
                for (const auto& kv : allStats) {
-                       Array::Ptr row = new Array();
+                       ArrayData row;
 
-                       row->Reserve(m_Columns.size() + m_Aggregators.size());
+                       row.reserve(m_Columns.size() + m_Aggregators.size());
 
                        for (const Value& keyPart : kv.first) {
-                               row->Add(keyPart);
+                               row.push_back(keyPart);
                        }
 
                        auto& stats = kv.second;
 
                        for (size_t i = 0; i < m_Aggregators.size(); i++)
-                               row->Add(m_Aggregators[i]->GetResultAndFreeState(stats[i]));
+                               row.push_back(m_Aggregators[i]->GetResultAndFreeState(stats[i]));
 
-                       AppendResultRow(result, row, first_row);
+                       AppendResultRow(result, new Array(std::move(row)), first_row);
                }
 
                /* add a bogus zero value if aggregated is empty*/
                if (allStats.empty()) {
-                       Array::Ptr row = new Array();
+                       ArrayData row;
+
+                       row.reserve(m_Aggregators.size());
 
                        for (size_t i = 1; i <= m_Aggregators.size(); i++) {
-                               row->Add(0);
+                               row.push_back(0);
                        }
 
-                       AppendResultRow(result, row, first_row);
+                       AppendResultRow(result, new Array(std::move(row)), first_row);
                }
        }
 
index 09c24db7715a1e6afd8d49de786826f585afe7dc..1d98bfd50ec7ec7dcc63aea6632f7370f262d529 100644 (file)
@@ -126,16 +126,16 @@ Value ServiceGroupsTable::MembersAccessor(const Value& row)
        if (!sg)
                return Empty;
 
-       Array::Ptr members = new Array();
+       ArrayData result;
 
        for (const Service::Ptr& service : sg->GetMembers()) {
-               Array::Ptr host_svc = new Array();
-               host_svc->Add(service->GetHost()->GetName());
-               host_svc->Add(service->GetShortName());
-               members->Add(host_svc);
+               result.push_back(new Array({
+                       service->GetHost()->GetName(),
+                       service->GetShortName()
+               }));
        }
 
-       return members;
+       return new Array(std::move(result));
 }
 
 Value ServiceGroupsTable::MembersWithStateAccessor(const Value& row)
@@ -145,18 +145,18 @@ Value ServiceGroupsTable::MembersWithStateAccessor(const Value& row)
        if (!sg)
                return Empty;
 
-       Array::Ptr members = new Array();
+       ArrayData result;
 
        for (const Service::Ptr& service : sg->GetMembers()) {
-               Array::Ptr host_svc = new Array();
-               host_svc->Add(service->GetHost()->GetName());
-               host_svc->Add(service->GetShortName());
-               host_svc->Add(service->GetHost()->GetState());
-               host_svc->Add(service->GetState());
-               members->Add(host_svc);
+               result.push_back(new Array({
+                       service->GetHost()->GetName(),
+                       service->GetShortName(),
+                       service->GetHost()->GetState(),
+                       service->GetState()
+               }));
        }
 
-       return members;
+       return new Array(std::move(result));
 }
 
 Value ServiceGroupsTable::WorstServiceStateAccessor(const Value& row)
index 3abffb423041b8942c152e4fa29f1ffe5e63576a..dce09bf5768c0364ec00783fedbd7f912e972d20 100644 (file)
@@ -933,13 +933,13 @@ Value ServicesTable::ContactsAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Array::Ptr contact_names = new Array();
+       ArrayData result;
 
        for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(service)) {
-               contact_names->Add(user->GetName());
+               result.push_back(user->GetName());
        }
 
-       return contact_names;
+       return new Array(std::move(result));
 }
 
 Value ServicesTable::DowntimesAccessor(const Value& row)
@@ -949,16 +949,16 @@ Value ServicesTable::DowntimesAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Array::Ptr results = new Array();
+       ArrayData result;
 
        for (const Downtime::Ptr& downtime : service->GetDowntimes()) {
                if (downtime->IsExpired())
                        continue;
 
-               results->Add(downtime->GetLegacyId());
+               result.push_back(downtime->GetLegacyId());
        }
 
-       return results;
+       return new Array(std::move(result));
 }
 
 Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
@@ -968,20 +968,20 @@ Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Array::Ptr results = new Array();
+       ArrayData result;
 
        for (const Downtime::Ptr& downtime : service->GetDowntimes()) {
                if (downtime->IsExpired())
                        continue;
 
-               Array::Ptr downtime_info = new Array();
-               downtime_info->Add(downtime->GetLegacyId());
-               downtime_info->Add(downtime->GetAuthor());
-               downtime_info->Add(downtime->GetComment());
-               results->Add(downtime_info);
+               result.push_back(new Array({
+                       downtime->GetLegacyId(),
+                       downtime->GetAuthor(),
+                       downtime->GetComment()
+               }));
        }
 
-       return results;
+       return new Array(std::move(result));
 }
 
 Value ServicesTable::CommentsAccessor(const Value& row)
@@ -991,16 +991,16 @@ Value ServicesTable::CommentsAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Array::Ptr results = new Array();
+       ArrayData result;
 
        for (const Comment::Ptr& comment : service->GetComments()) {
                if (comment->IsExpired())
                        continue;
 
-               results->Add(comment->GetLegacyId());
+               result.push_back(comment->GetLegacyId());
        }
 
-       return results;
+       return new Array(std::move(result));
 }
 
 Value ServicesTable::CommentsWithInfoAccessor(const Value& row)
@@ -1010,20 +1010,20 @@ Value ServicesTable::CommentsWithInfoAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Array::Ptr results = new Array();
+       ArrayData result;
 
        for (const Comment::Ptr& comment : service->GetComments()) {
                if (comment->IsExpired())
                        continue;
 
-               Array::Ptr comment_info = new Array();
-               comment_info->Add(comment->GetLegacyId());
-               comment_info->Add(comment->GetAuthor());
-               comment_info->Add(comment->GetText());
-               results->Add(comment_info);
+               result.push_back(new Array({
+                       comment->GetLegacyId(),
+                       comment->GetAuthor(),
+                       comment->GetText()
+               }));
        }
 
-       return results;
+       return new Array(std::move(result));
 }
 
 Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row)
@@ -1033,22 +1033,22 @@ Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Array::Ptr results = new Array();
+       ArrayData result;
 
        for (const Comment::Ptr& comment : service->GetComments()) {
                if (comment->IsExpired())
                        continue;
 
-               Array::Ptr comment_info = new Array();
-               comment_info->Add(comment->GetLegacyId());
-               comment_info->Add(comment->GetAuthor());
-               comment_info->Add(comment->GetText());
-               comment_info->Add(comment->GetEntryType());
-               comment_info->Add(static_cast<int>(comment->GetEntryTime()));
-               results->Add(comment_info);
+               result.push_back(new Array({
+                       comment->GetLegacyId(),
+                       comment->GetAuthor(),
+                       comment->GetText(),
+                       comment->GetEntryType(),
+                       static_cast<int>(comment->GetEntryTime())
+               }));
        }
 
-       return results;
+       return new Array(std::move(result));
 }
 
 Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
@@ -1060,17 +1060,16 @@ Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
 
        Dictionary::Ptr vars = service->GetVars();
 
-       Array::Ptr cv = new Array();
+       ArrayData result;
 
-       if (!vars)
-               return cv;
-
-       ObjectLock olock(vars);
-       for (const Dictionary::Pair& kv : vars) {
-               cv->Add(kv.first);
+       if (vars) {
+               ObjectLock olock(vars);
+               for (const Dictionary::Pair& kv : vars) {
+                       result.push_back(kv.first);
+               }
        }
 
-       return cv;
+       return new Array(std::move(result));
 }
 
 Value ServicesTable::CustomVariableValuesAccessor(const Value& row)
@@ -1082,20 +1081,19 @@ Value ServicesTable::CustomVariableValuesAccessor(const Value& row)
 
        Dictionary::Ptr vars = service->GetVars();
 
-       Array::Ptr cv = new Array();
+       ArrayData result;
 
-       if (!vars)
-               return cv;
-
-       ObjectLock olock(vars);
-       for (const Dictionary::Pair& kv : vars) {
-               if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
-                       cv->Add(JsonEncode(kv.second));
-               else
-                       cv->Add(kv.second);
+       if (vars) {
+               ObjectLock olock(vars);
+               for (const Dictionary::Pair& kv : vars) {
+                       if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
+                               result.push_back(JsonEncode(kv.second));
+                       else
+                               result.push_back(kv.second);
+               }
        }
 
-       return cv;
+       return new Array(std::move(result));
 }
 
 Value ServicesTable::CustomVariablesAccessor(const Value& row)
@@ -1107,25 +1105,26 @@ Value ServicesTable::CustomVariablesAccessor(const Value& row)
 
        Dictionary::Ptr vars = service->GetVars();
 
-       Array::Ptr cv = new Array();
-
-       if (!vars)
-               return cv;
+       ArrayData result;
 
-       ObjectLock olock(vars);
-       for (const Dictionary::Pair& kv : vars) {
-               Array::Ptr key_val = new Array();
-               key_val->Add(kv.first);
+       if (vars) {
+               ObjectLock olock(vars);
+               for (const Dictionary::Pair& kv : vars) {
+                       Value val;
 
-               if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
-                       key_val->Add(JsonEncode(kv.second));
-               else
-                       key_val->Add(kv.second);
+                       if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
+                               val = JsonEncode(kv.second);
+                       else
+                               val = kv.second;
 
-               cv->Add(key_val);
+                       result.push_back(new Array({
+                               kv.first,
+                               val
+                       }));
+               }
        }
 
-       return cv;
+       return new Array(std::move(result));
 }
 
 Value ServicesTable::CVIsJsonAccessor(const Value& row)
@@ -1173,13 +1172,13 @@ Value ServicesTable::ContactGroupsAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Array::Ptr contactgroup_names = new Array();
+       ArrayData result;
 
        for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(service)) {
-               contactgroup_names->Add(usergroup->GetName());
+               result.push_back(usergroup->GetName());
        }
 
-       return contactgroup_names;
+       return new Array(std::move(result));
 }
 
 Value ServicesTable::CheckSourceAccessor(const Value& row)
index 135e15e99878562aef0aec2d0494899ff6413bbd..ec0b6210366f0ec5764742bb62ef1dac7f733c2e 100644 (file)
@@ -233,58 +233,49 @@ Value StatusTable::CustomVariableNamesAccessor(const Value&)
 {
        Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars();
 
-       Array::Ptr cv = new Array();
+       ArrayData result;
 
-       if (!vars)
-               return cv;
-
-       {
+       if (vars) {
                ObjectLock olock(vars);
                for (const auto& kv : vars) {
-                       cv->Add(kv.first);
+                       result.push_back(kv.first);
                }
        }
 
-       return cv;
+       return new Array(std::move(result));
 }
 
 Value StatusTable::CustomVariableValuesAccessor(const Value&)
 {
        Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars();
 
-       Array::Ptr cv = new Array();
-
-       if (!vars)
-               return cv;
+       ArrayData result;
 
-       {
+       if (vars) {
                ObjectLock olock(vars);
                for (const auto& kv : vars) {
-                       cv->Add(kv.second);
+                       result.push_back(kv.second);
                }
        }
 
-       return cv;
+       return new Array(std::move(result));
 }
 
 Value StatusTable::CustomVariablesAccessor(const Value&)
 {
        Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars();
 
-       Array::Ptr cv = new Array();
-
-       if (!vars)
-               return cv;
+       ArrayData result;
 
-       {
+       if (vars) {
                ObjectLock olock(vars);
                for (const auto& kv : vars) {
-                       Array::Ptr key_val = new Array();
-                       key_val->Add(kv.first);
-                       key_val->Add(kv.second);
-                       cv->Add(key_val);
+                       result.push_back(new Array({
+                               kv.first,
+                               kv.second
+                       }));
                }
        }
 
-       return cv;
+       return new Array(std::move(result));
 }
index f94c825ea38204e0788ed3948838b9381f55c5f7..b755862be009591174eddac548804160b05f5a08 100644 (file)
@@ -89,16 +89,13 @@ Value ZonesTable::EndpointsAccessor(const Value& row)
 
        std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints();
 
-       Array::Ptr endpoint_names = new Array();
+       ArrayData result;
 
        for (const Endpoint::Ptr& endpoint : endpoints) {
-               endpoint_names->Add(endpoint->GetName());
+               result.push_back(endpoint->GetName());
        }
 
-       if (!endpoint_names)
-               return Empty;
-
-       return endpoint_names;
+       return new Array(std::move(result));
 }
 
 Value ZonesTable::GlobalAccessor(const Value& row)
index 635f7fc8c3e07cce729647cc7ff00d0a54870ca3..4bb1146907dad64b38aeeb31580c3a9f54147722 100644 (file)
@@ -138,15 +138,15 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
                        + " greater than warning threshold: " + Utility::FormatDuration(lagWarning));
        }
 
-       Array::Ptr perfdata = new Array();
-       perfdata->Add(new PerfdataValue("slave_lag", zoneLag, false, "s", lagWarning, lagCritical));
-       perfdata->Add(new PerfdataValue("last_messages_sent", lastMessageSent));
-       perfdata->Add(new PerfdataValue("last_messages_received", lastMessageReceived));
-       perfdata->Add(new PerfdataValue("sum_messages_sent_per_second", messagesSentPerSecond));
-       perfdata->Add(new PerfdataValue("sum_messages_received_per_second", messagesReceivedPerSecond));
-       perfdata->Add(new PerfdataValue("sum_bytes_sent_per_second", bytesSentPerSecond));
-       perfdata->Add(new PerfdataValue("sum_bytes_received_per_second", bytesReceivedPerSecond));
-       cr->SetPerformanceData(perfdata);
+       cr->SetPerformanceData(new Array({
+               new PerfdataValue("slave_lag", zoneLag, false, "s", lagWarning, lagCritical),
+               new PerfdataValue("last_messages_sent", lastMessageSent),
+               new PerfdataValue("last_messages_received", lastMessageReceived),
+               new PerfdataValue("sum_messages_sent_per_second", messagesSentPerSecond),
+               new PerfdataValue("sum_messages_received_per_second", messagesReceivedPerSecond),
+               new PerfdataValue("sum_bytes_sent_per_second", bytesSentPerSecond),
+               new PerfdataValue("sum_bytes_received_per_second", bytesReceivedPerSecond)
+       }));
 
        checkable->ProcessCheckResult(cr);
 }
index 68d26754916ed27ef98f64c12db4b42f0fd47e01..64d64b03448c5981105593977501926a563a629a 100644 (file)
@@ -41,11 +41,10 @@ void NullCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult:
        String output = "Hello from ";
        output += IcingaApplication::GetInstance()->GetNodeName();
 
-       Array::Ptr perfdata = new Array();
-       perfdata->Add(new PerfdataValue("time", Convert::ToDouble(Utility::GetTime())));
-
        cr->SetOutput(output);
-       cr->SetPerformanceData(perfdata);
+       cr->SetPerformanceData(new Array({
+               new PerfdataValue("time", Convert::ToDouble(Utility::GetTime()))
+       }));
        cr->SetState(ServiceOK);
 
        service->ProcessCheckResult(cr);
index 4fa3ea71fcefd153b6bc5f2917ee18c7bc5b8bf1..4e98aa4fb857d334af4402055910fed01b98d2a5 100644 (file)
@@ -45,10 +45,11 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification,
 
        Checkable::Ptr checkable = notification->GetCheckable();
 
-       Dictionary::Ptr notificationExtra = new Dictionary();
-       notificationExtra->Set("type", Notification::NotificationTypeToString(type));
-       notificationExtra->Set("author", author);
-       notificationExtra->Set("comment", comment);
+       Dictionary::Ptr notificationExtra = new Dictionary({
+               { "type", Notification::NotificationTypeToString(type) },
+               { "author", author },
+               { "comment", comment }
+       });
 
        Host::Ptr host;
        Service::Ptr service;
index b279b1adf2f419f33bf0b2950cfec0659ddf0de3..787a5deaccba90c6a9e9a188f1538b6a9457f905 100644 (file)
@@ -41,11 +41,10 @@ void RandomCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResul
        String output = "Hello from ";
        output += IcingaApplication::GetInstance()->GetNodeName();
 
-       Array::Ptr perfdata = new Array();
-       perfdata->Add(new PerfdataValue("time", Convert::ToDouble(Utility::GetTime())));
-
        cr->SetOutput(output);
-       cr->SetPerformanceData(perfdata);
+       cr->SetPerformanceData(new Array({
+               new PerfdataValue("time", Convert::ToDouble(Utility::GetTime()))
+       }));
        cr->SetState(static_cast<ServiceState>(Utility::Random() % 4));
 
        service->ProcessCheckResult(cr);
index 9d461e8351c8246a8672a7b65ae84068aaa8ecc2..cc4e9b51c1f63e47e786487046dc0ca04d1e6aaf 100644 (file)
@@ -33,17 +33,16 @@ Array::Ptr TimePeriodTask::EmptyTimePeriodUpdate(const TimePeriod::Ptr&, double,
 
 Array::Ptr TimePeriodTask::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr&, double begin, double end)
 {
-       Array::Ptr segments = new Array();
+       ArrayData segments;
 
        for (long t = begin / 60 - 1; t * 60 < end; t++) {
                if ((t % 2) == 0) {
-                       Dictionary::Ptr segment = new Dictionary();
-                       segment->Set("begin", t * 60);
-                       segment->Set("end", (t + 1) * 60);
-
-                       segments->Add(segment);
+                       segments.push_back(new Dictionary({
+                               { "begin", t * 60 },
+                               { "end", (t + 1) * 60 }
+                       }));
                }
        }
 
-       return segments;
+       return new Array(std::move(segments));
 }
index a3bd06797985ef6baaacc295de75d9bf71970439..3f9a83956c047a011b48e9b482118d43a973e9f0 100644 (file)
@@ -36,13 +36,13 @@ REGISTER_STATSFUNCTION(NotificationComponent, &NotificationComponent::StatsFunc)
 
 void NotificationComponent::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const NotificationComponent::Ptr& notification_component : ConfigType::GetObjectsByType<NotificationComponent>()) {
-               nodes->Set(notification_component->GetName(), 1); //add more stats
+               nodes.emplace_back(notification_component->GetName(), 1); //add more stats
        }
 
-       status->Set("notificationcomponent", nodes);
+       status->Set("notificationcomponent", new Dictionary(std::move(nodes)));
 }
 
 /**
index cfea33819485e298744f405c67044b95021ac2d9..708e906705bf1707736b5b10eba6f6b13c8c5db6 100644 (file)
@@ -53,23 +53,22 @@ void ElasticsearchWriter::OnConfigLoaded()
 
 void ElasticsearchWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const ElasticsearchWriter::Ptr& elasticsearchwriter : ConfigType::GetObjectsByType<ElasticsearchWriter>()) {
                size_t workQueueItems = elasticsearchwriter->m_WorkQueue.GetLength();
                double workQueueItemRate = elasticsearchwriter->m_WorkQueue.GetTaskCount(60) / 60.0;
 
-               Dictionary::Ptr stats = new Dictionary();
-               stats->Set("work_queue_items", workQueueItems);
-               stats->Set("work_queue_item_rate", workQueueItemRate);
-
-               nodes->Set(elasticsearchwriter->GetName(), stats);
+               nodes.emplace_back(elasticsearchwriter->GetName(), new Dictionary({
+                       { "work_queue_items", workQueueItems },
+                       { "work_queue_item_rate", workQueueItemRate }
+               }));
 
                perfdata->Add(new PerfdataValue("elasticsearchwriter_" + elasticsearchwriter->GetName() + "_work_queue_items", workQueueItems));
                perfdata->Add(new PerfdataValue("elasticsearchwriter_" + elasticsearchwriter->GetName() + "_work_queue_item_rate", workQueueItemRate));
        }
 
-       status->Set("elasticsearchwriter", nodes);
+       status->Set("elasticsearchwriter", new Dictionary(std::move(nodes)));
 }
 
 void ElasticsearchWriter::Start(bool runtimeCreated)
@@ -312,13 +311,13 @@ void ElasticsearchWriter::NotificationSentToAllUsersHandlerInternal(const Notifi
 
        fields->Set("host", host->GetName());
 
-       Array::Ptr userNames = new Array();
+       ArrayData userNames;
 
        for (const User::Ptr& user : users) {
-               userNames->Add(user->GetName());
+               userNames.push_back(user->GetName());
        }
 
-       fields->Set("users", userNames);
+       fields->Set("users", new Array(std::move(userNames)));
        fields->Set("notification_type", notificationTypeString);
        fields->Set("author", author);
        fields->Set("text", text);
index 0394befa127d0606615860e29662bf4da5f92808..060da2c80d25c9c30de1a40c7d27ad6aa76ffaec 100644 (file)
@@ -55,25 +55,24 @@ void GelfWriter::OnConfigLoaded()
 
 void GelfWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const GelfWriter::Ptr& gelfwriter : ConfigType::GetObjectsByType<GelfWriter>()) {
                size_t workQueueItems = gelfwriter->m_WorkQueue.GetLength();
                double workQueueItemRate = gelfwriter->m_WorkQueue.GetTaskCount(60) / 60.0;
 
-               Dictionary::Ptr stats = new Dictionary();
-               stats->Set("work_queue_items", workQueueItems);
-               stats->Set("work_queue_item_rate", workQueueItemRate);
-               stats->Set("connected", gelfwriter->GetConnected());
-               stats->Set("source", gelfwriter->GetSource());
-
-               nodes->Set(gelfwriter->GetName(), stats);
+               nodes.emplace_back(gelfwriter->GetName(), new Dictionary({
+                       { "work_queue_items", workQueueItems },
+                       { "work_queue_item_rate", workQueueItemRate },
+                       { "connected", gelfwriter->GetConnected() },
+                       { "source", gelfwriter->GetSource() }
+               }));
 
                perfdata->Add(new PerfdataValue("gelfwriter_" + gelfwriter->GetName() + "_work_queue_items", workQueueItems));
                perfdata->Add(new PerfdataValue("gelfwriter_" + gelfwriter->GetName() + "_work_queue_item_rate", workQueueItemRate));
        }
 
-       status->Set("gelfwriter", nodes);
+       status->Set("gelfwriter", new Dictionary(std::move(nodes)));
 }
 
 void GelfWriter::Start(bool runtimeCreated)
index b21c139d69d610f42e6b4c0ff931e11b45e68a96..320c146fe387d1bf56e4d24a00795273e608637b 100644 (file)
@@ -55,24 +55,23 @@ void GraphiteWriter::OnConfigLoaded()
 
 void GraphiteWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const GraphiteWriter::Ptr& graphitewriter : ConfigType::GetObjectsByType<GraphiteWriter>()) {
                size_t workQueueItems = graphitewriter->m_WorkQueue.GetLength();
                double workQueueItemRate = graphitewriter->m_WorkQueue.GetTaskCount(60) / 60.0;
 
-               Dictionary::Ptr stats = new Dictionary();
-               stats->Set("work_queue_items", workQueueItems);
-               stats->Set("work_queue_item_rate", workQueueItemRate);
-               stats->Set("connected", graphitewriter->GetConnected());
-
-               nodes->Set(graphitewriter->GetName(), stats);
+               nodes.emplace_back(graphitewriter->GetName(), new Dictionary({
+                       { "work_queue_items", workQueueItems },
+                       { "work_queue_item_rate", workQueueItemRate },
+                       { "connected", graphitewriter->GetConnected() }
+               }));
 
                perfdata->Add(new PerfdataValue("graphitewriter_" + graphitewriter->GetName() + "_work_queue_items", workQueueItems));
                perfdata->Add(new PerfdataValue("graphitewriter_" + graphitewriter->GetName() + "_work_queue_item_rate", workQueueItemRate));
        }
 
-       status->Set("graphitewriter", nodes);
+       status->Set("graphitewriter", new Dictionary(std::move(nodes)));
 }
 
 void GraphiteWriter::Start(bool runtimeCreated)
@@ -330,14 +329,14 @@ Value GraphiteWriter::EscapeMacroMetric(const Value& value)
 {
        if (value.IsObjectType<Array>()) {
                Array::Ptr arr = value;
-               Array::Ptr result = new Array();
+               ArrayData result;
 
                ObjectLock olock(arr);
                for (const Value& arg : arr) {
-                       result->Add(EscapeMetric(arg));
+                       result.push_back(EscapeMetric(arg));
                }
 
-               return Utility::Join(result, '.');
+               return Utility::Join(new Array(std::move(result)), '.');
        } else
                return EscapeMetric(value);
 }
index a614064500fd2669e7c9ff7a3c17a28eb484d6f4..08f126a80ba7f9d0fead42ebff4c42393b42e10b 100644 (file)
@@ -81,26 +81,25 @@ void InfluxdbWriter::OnConfigLoaded()
 
 void InfluxdbWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const InfluxdbWriter::Ptr& influxdbwriter : ConfigType::GetObjectsByType<InfluxdbWriter>()) {
                size_t workQueueItems = influxdbwriter->m_WorkQueue.GetLength();
                double workQueueItemRate = influxdbwriter->m_WorkQueue.GetTaskCount(60) / 60.0;
                size_t dataBufferItems = influxdbwriter->m_DataBuffer.size();
 
-               Dictionary::Ptr stats = new Dictionary();
-               stats->Set("work_queue_items", workQueueItems);
-               stats->Set("work_queue_item_rate", workQueueItemRate);
-               stats->Set("data_buffer_items", dataBufferItems);
-
-               nodes->Set(influxdbwriter->GetName(), stats);
+               nodes.emplace_back(influxdbwriter->GetName(), new Dictionary({
+                       { "work_queue_items", workQueueItems },
+                       { "work_queue_item_rate", workQueueItemRate },
+                       { "data_buffer_items", dataBufferItems }
+               }));
 
                perfdata->Add(new PerfdataValue("influxdbwriter_" + influxdbwriter->GetName() + "_work_queue_items", workQueueItems));
                perfdata->Add(new PerfdataValue("influxdbwriter_" + influxdbwriter->GetName() + "_work_queue_item_rate", workQueueItemRate));
                perfdata->Add(new PerfdataValue("influxdbwriter_" + influxdbwriter->GetName() + "_data_queue_items", dataBufferItems));
        }
 
-       status->Set("influxdbwriter", nodes);
+       status->Set("influxdbwriter", new Dictionary(std::move(nodes)));
 }
 
 void InfluxdbWriter::Start(bool runtimeCreated)
index c787bc716f82235ad484e33a3f9db71f22257158..f08edf997bd814fa341d30e4e39328a8b8d7a55c 100644 (file)
@@ -55,27 +55,23 @@ class InfluxdbWriter : ConfigObject
        };
        [config, required] Dictionary::Ptr host_template {
                default {{{
-                       Dictionary::Ptr tags = new Dictionary();
-                       tags->Set("hostname", "$host.name$");
-
-                       Dictionary::Ptr tmpl = new Dictionary();
-                       tmpl->Set("measurement", "$host.check_command$");
-                       tmpl->Set("tags", tags);
-
-                       return tmpl;
+                       return new Dictionary({
+                               { "measurement", "$host.check_command$" },
+                               { "tags", new Dictionary({
+                                       { "hostname", "$host.name$" }
+                               }) }
+                       });
                }}}
        };
        [config, required] Dictionary::Ptr service_template {
                default {{{
-                       Dictionary::Ptr tags = new Dictionary();
-                       tags->Set("hostname", "$host.name$");
-                       tags->Set("service", "$service.name$");
-
-                       Dictionary::Ptr tmpl = new Dictionary();
-                       tmpl->Set("measurement", "$service.check_command$");
-                       tmpl->Set("tags", tags);
-
-                       return tmpl;
+                       return new Dictionary({
+                               { "measurement", "$service.check_command$" },
+                               { "tags", new Dictionary({
+                                       { "hostname", "$host.name" },
+                                       { "service", "$service.name$" }
+                               }) }
+                       });
                }}}
        };
        [config] bool enable_send_thresholds {
index 9bbbbfa54bff81928eedd74e8379fc8575660f57..056da782256650594e2b41dacba2e3f79a49cd63 100644 (file)
@@ -48,13 +48,13 @@ REGISTER_STATSFUNCTION(OpenTsdbWriter, &OpenTsdbWriter::StatsFunc);
 
 void OpenTsdbWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const OpenTsdbWriter::Ptr& opentsdbwriter : ConfigType::GetObjectsByType<OpenTsdbWriter>()) {
-               nodes->Set(opentsdbwriter->GetName(), 1); //add more stats
+               nodes.emplace_back(opentsdbwriter->GetName(), 1); //add more stats
        }
 
-       status->Set("opentsdbwriter", nodes);
+       status->Set("opentsdbwriter", new Dictionary(std::move(nodes)));
 }
 
 void OpenTsdbWriter::Start(bool runtimeCreated)
index 9d987c7d8625878961e94b08694e49c6f7bc0f00..79d0108d76fb0e2c5b41de9de89cd30663fda504 100644 (file)
@@ -40,13 +40,13 @@ REGISTER_STATSFUNCTION(PerfdataWriter, &PerfdataWriter::StatsFunc);
 
 void PerfdataWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
 {
-       Dictionary::Ptr nodes = new Dictionary();
+       DictionaryData nodes;
 
        for (const PerfdataWriter::Ptr& perfdatawriter : ConfigType::GetObjectsByType<PerfdataWriter>()) {
-               nodes->Set(perfdatawriter->GetName(), 1); //add more stats
+               nodes.emplace_back(perfdatawriter->GetName(), 1); //add more stats
        }
 
-       status->Set("perfdatawriter", nodes);
+       status->Set("perfdatawriter", new Dictionary(std::move(nodes)));
 }
 
 void PerfdataWriter::Start(bool runtimeCreated)
index 7663d02bed013c24cb2a8fc7b85c6f428ab3999c..4ef93f17dc897676957760746c613c3b6533e474 100644 (file)
@@ -72,30 +72,33 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques
                objs.emplace_back(nullptr);
        }
 
-       Array::Ptr results = new Array();
+       ArrayData results;
 
        Log(LogNotice, "ApiActionHandler")
                << "Running action " << actionName;
 
        for (const ConfigObject::Ptr& obj : objs) {
                try {
-                       results->Add(action->Invoke(obj, params));
+                       results.emplace_back(action->Invoke(obj, params));
                } catch (const std::exception& ex) {
-                       Dictionary::Ptr fail = new Dictionary();
-                       fail->Set("code", 500);
-                       fail->Set("status", "Action execution failed: '" + DiagnosticInformation(ex, false) + "'.");
+                       Dictionary::Ptr fail = new Dictionary({
+                               { "code", 500 },
+                               { "status", "Action execution failed: '" + DiagnosticInformation(ex, false) + "'." }
+                       });
+
                        if (HttpUtility::GetLastParameter(params, "verboseErrors"))
                                fail->Set("diagnostic information", DiagnosticInformation(ex));
-                       results->Add(fail);
+
+                       results.emplace_back(std::move(fail));
                }
        }
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array(std::move(results)) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
 
        return true;
 }
-
index 8107c971ab611fd8ea7e44be8eef3da526946c13..ebdf60c515399dda5578d1f95d8b2b833b382bd9 100644 (file)
@@ -289,11 +289,14 @@ void ApiListener::UpdateConfigObject(const ConfigObject::Ptr& object, const Mess
        if (object->GetPackage() != "_api" && object->GetVersion() == 0)
                return;
 
-       Dictionary::Ptr message = new Dictionary();
-       message->Set("jsonrpc", "2.0");
-       message->Set("method", "config::UpdateObject");
-
        Dictionary::Ptr params = new Dictionary();
+
+       Dictionary::Ptr message = new Dictionary({
+               { "jsonrpc", "2.0" },
+               { "method", "config::UpdateObject" },
+               { "params", params }
+       });
+
        params->Set("name", object->GetName());
        params->Set("type", object->GetReflectionType()->GetName());
        params->Set("version", object->GetVersion());
@@ -311,7 +314,7 @@ void ApiListener::UpdateConfigObject(const ConfigObject::Ptr& object, const Mess
 
        Dictionary::Ptr original_attributes = object->GetOriginalAttributes();
        Dictionary::Ptr modified_attributes = new Dictionary();
-       Array::Ptr newOriginalAttributes = new Array();
+       ArrayData newOriginalAttributes;
 
        if (original_attributes) {
                ObjectLock olock(original_attributes);
@@ -326,16 +329,14 @@ void ApiListener::UpdateConfigObject(const ConfigObject::Ptr& object, const Mess
 
                        modified_attributes->Set(kv.first, value);
 
-                       newOriginalAttributes->Add(kv.first);
+                       newOriginalAttributes.push_back(kv.first);
                }
        }
 
        params->Set("modified_attributes", modified_attributes);
 
        /* only send the original attribute keys */
-       params->Set("original_attributes", newOriginalAttributes);
-
-       message->Set("params", params);
+       params->Set("original_attributes", new Array(std::move(newOriginalAttributes)));
 
 #ifdef I2_DEBUG
        Log(LogDebug, "ApiListener")
@@ -374,16 +375,18 @@ void ApiListener::DeleteConfigObject(const ConfigObject::Ptr& object, const Mess
                }
        }
 
-       Dictionary::Ptr message = new Dictionary();
-       message->Set("jsonrpc", "2.0");
-       message->Set("method", "config::DeleteObject");
-
        Dictionary::Ptr params = new Dictionary();
+
+       Dictionary::Ptr message = new Dictionary({
+               { "jsonrpc", "2.0" },
+               { "method", "config::DeleteObject" },
+               { "params", params }
+       });
+
        params->Set("name", object->GetName());
        params->Set("type", object->GetReflectionType()->GetName());
        params->Set("version", object->GetVersion());
 
-       message->Set("params", params);
 
 #ifdef I2_DEBUG
        Log(LogDebug, "ApiListener")
index 1ce23b102c0844a245232a56a2d5061dd79bc75a..30a79a35fe05d7352895b8cdce529338e6f98a7d 100644 (file)
@@ -260,14 +260,14 @@ void ApiListener::SendConfigUpdate(const JsonRpcConnection::Ptr& aclient)
                configUpdateV2->Set(zone->GetName(), config.UpdateV2);
        }
 
-       Dictionary::Ptr params = new Dictionary();
-       params->Set("update", configUpdateV1);
-       params->Set("update_v2", configUpdateV2);
-
-       Dictionary::Ptr message = new Dictionary();
-       message->Set("jsonrpc", "2.0");
-       message->Set("method", "config::Update");
-       message->Set("params", params);
+       Dictionary::Ptr message = new Dictionary({
+               { "jsonrpc", "2.0" },
+               { "method", "config::Update" },
+               { "params", new Dictionary({
+                       { "update", configUpdateV1 },
+                       { "update_v2", configUpdateV2 }
+               }) }
+       });
 
        aclient->SendMessage(message);
 }
index 65ad4d64c8ba483fc598acb7e0fcd45f428f2699..527036e0a2b1b07af3290a3b6ddf70d7d5d2fd5a 100644 (file)
@@ -503,10 +503,12 @@ void ApiListener::NewClientHandlerInternal(const Socket::Ptr& client, const Stri
        ClientType ctype;
 
        if (role == RoleClient) {
-               Dictionary::Ptr message = new Dictionary();
-               message->Set("jsonrpc", "2.0");
-               message->Set("method", "icinga::Hello");
-               message->Set("params", new Dictionary());
+               Dictionary::Ptr message = new Dictionary({
+                       { "jsonrpc", "2.0" },
+                       { "method", "icinga::Hello" },
+                       { "params", new Dictionary() }
+               });
+
                JsonRpc::SendMessage(tlsStream, message);
                ctype = ClientJsonRpc;
        } else {
@@ -666,13 +668,13 @@ void ApiListener::ApiTimerHandler()
                if (ts == 0)
                        continue;
 
-               Dictionary::Ptr lparams = new Dictionary();
-               lparams->Set("log_position", ts);
-
-               Dictionary::Ptr lmessage = new Dictionary();
-               lmessage->Set("jsonrpc", "2.0");
-               lmessage->Set("method", "log::SetLogPosition");
-               lmessage->Set("params", lparams);
+               Dictionary::Ptr lmessage = new Dictionary({
+                       { "jsonrpc", "2.0" },
+                       { "method", "log::SetLogPosition" },
+                       { "params", new Dictionary({
+                               { "log_position", ts }
+                       }) }
+               });
 
                double maxTs = 0;
 
@@ -1161,13 +1163,13 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
                                if (ts > logpos_ts + 10) {
                                        logpos_ts = ts;
 
-                                       Dictionary::Ptr lparams = new Dictionary();
-                                       lparams->Set("log_position", logpos_ts);
-
-                                       Dictionary::Ptr lmessage = new Dictionary();
-                                       lmessage->Set("jsonrpc", "2.0");
-                                       lmessage->Set("method", "log::SetLogPosition");
-                                       lmessage->Set("params", lparams);
+                                       Dictionary::Ptr lmessage = new Dictionary({
+                                               { "jsonrpc", "2.0" },
+                                               { "method", "log::SetLogPosition" },
+                                               { "params", new Dictionary({
+                                                       { "log_position", logpos_ts }
+                                               }) }
+                                       });
 
                                        size_t bytesSent = JsonRpc::SendMessage(client->GetStream(), lmessage);
                                        endpoint->AddMessageSent(bytesSent);
@@ -1218,11 +1220,9 @@ void ApiListener::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& per
 
 std::pair<Dictionary::Ptr, Dictionary::Ptr> ApiListener::GetStatus()
 {
-       Dictionary::Ptr status = new Dictionary();
        Dictionary::Ptr perfdata = new Dictionary();
 
        /* cluster stats */
-       status->Set("identity", GetIdentity());
 
        double allEndpoints = 0;
        Array::Ptr allNotConnectedEndpoints = new Array();
@@ -1244,10 +1244,10 @@ std::pair<Dictionary::Ptr, Dictionary::Ptr> ApiListener::GetStatus()
                int countZoneEndpoints = 0;
                double zoneLag = 0;
 
-               Array::Ptr zoneEndpoints = new Array();
+               ArrayData zoneEndpoints;
 
                for (const Endpoint::Ptr& endpoint : zone->GetEndpoints()) {
-                       zoneEndpoints->Add(endpoint->GetName());
+                       zoneEndpoints.emplace_back(endpoint->GetName());
 
                        if (endpoint->GetName() == GetIdentity())
                                continue;
@@ -1272,29 +1272,21 @@ std::pair<Dictionary::Ptr, Dictionary::Ptr> ApiListener::GetStatus()
                if (zone->GetEndpoints().size() == 1 && countZoneEndpoints == 0)
                        zoneConnected = true;
 
-               Dictionary::Ptr zoneStats = new Dictionary();
-               zoneStats->Set("connected", zoneConnected);
-               zoneStats->Set("client_log_lag", zoneLag);
-               zoneStats->Set("endpoints", zoneEndpoints);
-
                String parentZoneName;
                Zone::Ptr parentZone = zone->GetParent();
                if (parentZone)
                        parentZoneName = parentZone->GetName();
 
-               zoneStats->Set("parent_zone", parentZoneName);
+               Dictionary::Ptr zoneStats = new Dictionary({
+                       { "connected", zoneConnected },
+                       { "client_log_lag", zoneLag },
+                       { "endpoints", new Array(std::move(zoneEndpoints)) },
+                       { "parent_zone", parentZoneName }
+               });
 
                connectedZones->Set(zone->GetName(), zoneStats);
        }
 
-       status->Set("num_endpoints", allEndpoints);
-       status->Set("num_conn_endpoints", allConnectedEndpoints->GetLength());
-       status->Set("num_not_conn_endpoints", allNotConnectedEndpoints->GetLength());
-       status->Set("conn_endpoints", allConnectedEndpoints);
-       status->Set("not_conn_endpoints", allNotConnectedEndpoints);
-
-       status->Set("zones", connectedZones);
-
        /* connection stats */
        size_t jsonRpcClients = GetAnonymousClients().size();
        size_t httpClients = GetHttpClients().size();
@@ -1306,22 +1298,31 @@ std::pair<Dictionary::Ptr, Dictionary::Ptr> ApiListener::GetStatus()
        double syncQueueItemRate = m_SyncQueue.GetTaskCount(60) / 60.0;
        double relayQueueItemRate = m_RelayQueue.GetTaskCount(60) / 60.0;
 
-       Dictionary::Ptr jsonRpc = new Dictionary();
-       jsonRpc->Set("clients", jsonRpcClients);
-       jsonRpc->Set("work_queue_items", workQueueItems);
-       jsonRpc->Set("work_queue_count", workQueueCount);
-       jsonRpc->Set("sync_queue_items", syncQueueItems);
-       jsonRpc->Set("relay_queue_items", relayQueueItems);
-
-       jsonRpc->Set("work_queue_item_rate", workQueueItemRate);
-       jsonRpc->Set("sync_queue_item_rate", syncQueueItemRate);
-       jsonRpc->Set("relay_queue_item_rate", relayQueueItemRate);
-
-       Dictionary::Ptr http = new Dictionary();
-       http->Set("clients", httpClients);
-
-       status->Set("json_rpc", jsonRpc);
-       status->Set("http", http);
+       Dictionary::Ptr status = new Dictionary({
+               { "identity", GetIdentity() },
+               { "num_endpoints", allEndpoints },
+               { "num_conn_endpoints", allConnectedEndpoints->GetLength() },
+               { "num_not_conn_endpoints", allNotConnectedEndpoints->GetLength() },
+               { "conn_endpoints", allConnectedEndpoints },
+               { "not_conn_endpoints", allNotConnectedEndpoints },
+
+               { "zones", connectedZones },
+
+               { "json_rpc", new Dictionary({
+                       { "clients", jsonRpcClients },
+                       { "work_queue_items", workQueueItems },
+                       { "work_queue_count", workQueueCount },
+                       { "sync_queue_items", syncQueueItems },
+                       { "relay_queue_items", relayQueueItems },
+                       { "work_queue_item_rate", workQueueItemRate },
+                       { "sync_queue_item_rate", syncQueueItemRate },
+                       { "relay_queue_item_rate", relayQueueItemRate }
+               }) },
+
+               { "http", new Dictionary({
+                       { "clients", httpClients }
+               }) }
+       });
 
        /* performance data */
        perfdata->Set("num_endpoints", allEndpoints);
index 68cb5dd9d6cb35efcf1ed13988ea9b0c24307032..2d8be3c2202ffa5fc20c262a48e5fa82b5c5bc0c 100644 (file)
@@ -51,21 +51,22 @@ void ConfigPackagesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& req
 
        std::vector<String> packages = ConfigPackageUtility::GetPackages();
 
-       Array::Ptr results = new Array();
+       ArrayData results;
 
        {
                boost::mutex::scoped_lock lock(ConfigPackageUtility::GetStaticMutex());
                for (const String& package : packages) {
-                       Dictionary::Ptr packageInfo = new Dictionary();
-                       packageInfo->Set("name", package);
-                       packageInfo->Set("stages", Array::FromVector(ConfigPackageUtility::GetStages(package)));
-                       packageInfo->Set("active-stage", ConfigPackageUtility::GetActiveStage(package));
-                       results->Add(packageInfo);
+                       results.emplace_back(new Dictionary({
+                               { "name", package },
+                               { "stages", Array::FromVector(ConfigPackageUtility::GetStages(package)) },
+                               { "active-stage", ConfigPackageUtility::GetActiveStage(package) }
+                       }));
                }
        }
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array(std::move(results)) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
@@ -85,8 +86,6 @@ void ConfigPackagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& re
                return;
        }
 
-       Dictionary::Ptr result1 = new Dictionary();
-
        try {
                boost::mutex::scoped_lock lock(ConfigPackageUtility::GetStaticMutex());
                ConfigPackageUtility::CreatePackage(packageName);
@@ -96,14 +95,14 @@ void ConfigPackagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& re
                return;
        }
 
-       result1->Set("code", 200);
-       result1->Set("status", "Created package.");
-
-       Array::Ptr results = new Array();
-       results->Add(result1);
+       Dictionary::Ptr result1 = new Dictionary({
+               { "code", 200 },
+               { "status", "Created package." }
+       });
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array({ result1 }) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
@@ -125,7 +124,7 @@ void ConfigPackagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest&
 
        int code = 200;
        String status = "Deleted package.";
-       Dictionary::Ptr result1 = new Dictionary();
+       DictionaryData result1;
 
        try {
                ConfigPackageUtility::DeletePackage(packageName);
@@ -133,21 +132,17 @@ void ConfigPackagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest&
                code = 500;
                status = "Failed to delete package.";
                if (HttpUtility::GetLastParameter(params, "verboseErrors"))
-                       result1->Set("diagnostic information", DiagnosticInformation(ex));
+                       result1.emplace_back("diagnostic information", DiagnosticInformation(ex));
        }
 
+       result1.emplace_back("package", packageName);
+       result1.emplace_back("code", code);
+       result1.emplace_back("status", status);
 
-       result1->Set("package", packageName);
-       result1->Set("code", code);
-       result1->Set("status", status);
-
-       Array::Ptr results = new Array();
-       results->Add(result1);
-
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array({ new Dictionary(std::move(result1)) }) }
+       });
 
        response.SetStatus(code, (code == 200) ? "OK" : "Internal Server Error");
        HttpUtility::SendJsonBody(response, params, result);
 }
-
index 889404491074f91652f953658356b0e9d1e7d0cf..9470d4b24c3fdf12a4f5d278e662c6f51101432b 100644 (file)
@@ -208,12 +208,13 @@ void ConfigPackageUtility::AsyncTryActivateStage(const String& packageName, cons
        VERIFY(Application::GetArgC() >= 1);
 
        // prepare arguments
-       Array::Ptr args = new Array();
-       args->Add(Application::GetExePath(Application::GetArgV()[0]));
-       args->Add("daemon");
-       args->Add("--validate");
-       args->Add("--define");
-       args->Add("ActiveStageOverride=" + packageName + ":" + stageName);
+       Array::Ptr args = new Array({
+               Application::GetExePath(Application::GetArgV()[0]),
+               "daemon",
+               "--validate",
+               "--define",
+               "ActiveStageOverride=" + packageName + ":" + stageName
+       });
 
        Process::Ptr process = new Process(Process::PrepareCommand(args));
        process->SetTimeout(300);
index 56110a71ac1a89a9d45903299c507db8f97efb91..ecfc973c24bc253bd1b1210bf30d751a8eaa896e 100644 (file)
@@ -65,22 +65,22 @@ void ConfigStagesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& reque
        if (!ConfigPackageUtility::ValidateName(stageName))
                return HttpUtility::SendJsonError(response, params, 400, "Invalid stage name.");
 
-       Array::Ptr results = new Array();
+       ArrayData results;
 
        std::vector<std::pair<String, bool> > paths = ConfigPackageUtility::GetFiles(packageName, stageName);
 
        String prefixPath = ConfigPackageUtility::GetPackageDir() + "/" + packageName + "/" + stageName + "/";
 
-       typedef std::pair<String, bool> kv_pair;
-       for (const kv_pair& kv : paths) {
-               Dictionary::Ptr stageInfo = new Dictionary();
-               stageInfo->Set("type", (kv.second ? "directory" : "file"));
-               stageInfo->Set("name", kv.first.SubStr(prefixPath.GetLength()));
-               results->Add(stageInfo);
+       for (const auto& kv : paths) {
+               results.push_back(new Dictionary({
+                       { "type", kv.second ? "directory" : "file" },
+                       { "name", kv.first.SubStr(prefixPath.GetLength()) }
+               }));
        }
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array(std::move(results)) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
@@ -121,21 +121,20 @@ void ConfigStagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& requ
                                HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
        }
 
-       Dictionary::Ptr result1 = new Dictionary();
 
        String responseStatus = "Created stage. ";
        responseStatus += (reload ? " Icinga2 will reload." : " Icinga2 reload skipped.");
 
-       result1->Set("package", packageName);
-       result1->Set("stage", stageName);
-       result1->Set("code", 200);
-       result1->Set("status", responseStatus);
+       Dictionary::Ptr result1 = new Dictionary({
+               { "package", packageName },
+               { "stage", stageName },
+               { "code", 200 },
+               { "status", responseStatus }
+       });
 
-       Array::Ptr results = new Array();
-       results->Add(result1);
-
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array({ result1 }) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
@@ -168,16 +167,14 @@ void ConfigStagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& re
                        HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
        }
 
-       Dictionary::Ptr result1 = new Dictionary();
-
-       result1->Set("code", 200);
-       result1->Set("status", "Stage deleted.");
-
-       Array::Ptr results = new Array();
-       results->Add(result1);
+       Dictionary::Ptr result1 = new Dictionary({
+               { "code", 200 },
+               { "status", "Stage deleted." }
+       });
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array({ result1 }) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
index 575db34bdca82033ba9c360ee20135f735d78818..d2cec89e79af6a175f054e47537661cd57932c9c 100644 (file)
@@ -121,8 +121,7 @@ bool ConsoleHandler::ExecuteScriptHelper(HttpRequest& request, HttpResponse& res
 
        lsf.Lines[fileName] = command;
 
-       Array::Ptr results = new Array();
-       Dictionary::Ptr resultInfo = new Dictionary();
+       Dictionary::Ptr resultInfo;
        std::unique_ptr<Expression> expr;
        Value exprResult;
 
@@ -136,9 +135,11 @@ bool ConsoleHandler::ExecuteScriptHelper(HttpRequest& request, HttpResponse& res
 
                exprResult = expr->Evaluate(frame);
 
-               resultInfo->Set("code", 200);
-               resultInfo->Set("status", "Executed successfully.");
-               resultInfo->Set("result", Serialize(exprResult, 0));
+               resultInfo = new Dictionary({
+                       { "code", 200 },
+                       { "status", "Executed successfully." },
+                       { "result", Serialize(exprResult, 0) }
+               });
        } catch (const ScriptError& ex) {
                DebugInfo di = ex.GetDebugInfo();
 
@@ -149,23 +150,23 @@ bool ConsoleHandler::ExecuteScriptHelper(HttpRequest& request, HttpResponse& res
                        << String(di.FirstColumn, ' ') << String(di.LastColumn - di.FirstColumn + 1, '^') << "\n"
                        << ex.what() << "\n";
 
-               resultInfo->Set("code", 500);
-               resultInfo->Set("status", String(msgbuf.str()));
-               resultInfo->Set("incomplete_expression", ex.IsIncompleteExpression());
-
-               Dictionary::Ptr debugInfo = new Dictionary();
-               debugInfo->Set("path", di.Path);
-               debugInfo->Set("first_line", di.FirstLine);
-               debugInfo->Set("first_column", di.FirstColumn);
-               debugInfo->Set("last_line", di.LastLine);
-               debugInfo->Set("last_column", di.LastColumn);
-               resultInfo->Set("debug_info", debugInfo);
+               resultInfo = new Dictionary({
+                       { "code", 500 },
+                       { "status", String(msgbuf.str()) },
+                       { "incomplete_expression", ex.IsIncompleteExpression() },
+                       { "debug_info", new Dictionary({
+                               { "path", di.Path },
+                               { "first_line", di.FirstLine },
+                               { "first_column", di.FirstColumn },
+                               { "last_line", di.LastLine },
+                               { "last_column", di.LastColumn }
+                       }) }
+               });
        }
 
-       results->Add(resultInfo);
-
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array({ resultInfo }) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
@@ -187,22 +188,21 @@ bool ConsoleHandler::AutocompleteScriptHelper(HttpRequest& request, HttpResponse
        if (!lsf.Locals)
                lsf.Locals = new Dictionary();
 
-       Array::Ptr results = new Array();
-       Dictionary::Ptr resultInfo = new Dictionary();
 
        ScriptFrame frame(true);
        frame.Locals = lsf.Locals;
        frame.Self = lsf.Locals;
        frame.Sandboxed = sandboxed;
 
-       resultInfo->Set("code", 200);
-       resultInfo->Set("status", "Auto-completed successfully.");
-       resultInfo->Set("suggestions", Array::FromVector(GetAutocompletionSuggestions(command, frame)));
-
-       results->Add(resultInfo);
+       Dictionary::Ptr result1 = new Dictionary({
+               { "code", 200 },
+               { "status", "Auto-completed successfully." },
+               { "suggestions", Array::FromVector(GetAutocompletionSuggestions(command, frame)) }
+       });
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array({ result1 }) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
index 6455a8af60486ce42f80421a226d2645f7d3bf44..0cf505e2835daa0e384487628eb1b6bf8f9b5653 100644 (file)
@@ -64,8 +64,9 @@ bool CreateObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
                localZoneName = localZone->GetName();
 
                if (!attrs) {
-                       attrs = new Dictionary();
-                       attrs->Set("zone", localZoneName);
+                       attrs = new Dictionary({
+                               { "zone", localZoneName }
+                       });
                } else if (!attrs->Contains("zone")) {
                        attrs->Set("zone", localZoneName);
                }
@@ -80,11 +81,9 @@ bool CreateObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
        if (params->Contains("ignore_on_error"))
                ignoreOnError = HttpUtility::GetLastParameter(params, "ignore_on_error");
 
-       Array::Ptr results = new Array();
-       results->Add(result1);
-
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array({ result1 }) }
+       });
 
        String config;
 
@@ -129,4 +128,3 @@ bool CreateObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
 
        return true;
 }
-
index daa5685e303c8f7099b8b05963da929a4b9864e3..b631b6598934728bc41c9f865b102d0c17b94a6a 100644 (file)
@@ -72,31 +72,36 @@ bool DeleteObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
 
        bool cascade = HttpUtility::GetLastParameter(params, "cascade");
 
-       Array::Ptr results = new Array();
+       ArrayData results;
 
        bool success = true;
 
        for (const ConfigObject::Ptr& obj : objs) {
-               Dictionary::Ptr result1 = new Dictionary();
-               result1->Set("type", type->GetName());
-               result1->Set("name", obj->GetName());
-               results->Add(result1);
-
+               int code;
+               String status;
                Array::Ptr errors = new Array();
 
                if (!ConfigObjectUtility::DeleteObject(obj, cascade, errors)) {
-                       result1->Set("code", 500);
-                       result1->Set("status", "Object could not be deleted.");
-                       result1->Set("errors", errors);
+                       code = 500;
+                       status = "Object could not be deleted.";
                        success = false;
                } else {
-                       result1->Set("code", 200);
-                       result1->Set("status", "Object was deleted.");
+                       code = 200;
+                       status = "Object was deleted.";
                }
+
+               results.push_back(new Dictionary({
+                       { "type", type->GetName() },
+                       { "name", obj->GetName() },
+                       { "code", code },
+                       { "status", status },
+                       { "errors", errors }
+               }));
        }
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array(std::move(results)) }
+       });
 
        if (!success)
                response.SetStatus(500, "One or more objects could not be deleted");
index ce3bcd22cb2775a6cc5505bb7c6c60bfbbc64d85..1b19635a419904c99fc841e077279dda516bcb59 100644 (file)
@@ -226,10 +226,10 @@ void HttpServerConnection::ProcessMessageAsync(HttpRequest& request)
                response.AddHeader("WWW-Authenticate", "Basic realm=\"Icinga 2\"");
 
                if (request.Headers->Get("accept") == "application/json") {
-                       Dictionary::Ptr result = new Dictionary();
-
-                       result->Set("error", 401);
-                       result->Set("status", "Unauthorized. Please check your user credentials.");
+                       Dictionary::Ptr result = new Dictionary({
+                               { "error", 401 },
+                               { "status", "Unauthorized. Please check your user credentials." }
+                       });
 
                        HttpUtility::SendJsonBody(response, nullptr, result);
                } else {
@@ -248,10 +248,10 @@ void HttpServerConnection::ProcessMessageAsync(HttpRequest& request)
                        String errorInfo = DiagnosticInformation(ex);
 
                        if (request.Headers->Get("accept") == "application/json") {
-                               Dictionary::Ptr result = new Dictionary();
-
-                               result->Set("error", 503);
-                               result->Set("status", errorInfo);
+                               Dictionary::Ptr result = new Dictionary({
+                                       { "error", 503 },
+                                       { "status", errorInfo }
+                               });
 
                                HttpUtility::SendJsonBody(response, nullptr, result);
                        } else {
index c365464533f40b7667a8e0fc475c6fb1cfc7190b..5336c84cf1b8075a49f658533ceada7b461c6ba6 100644 (file)
@@ -67,18 +67,16 @@ bool InfoHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request,
        }
 
        if (request.Headers->Get("accept") == "application/json") {
-               Dictionary::Ptr result1 = new Dictionary();
-
-               result1->Set("user", user->GetName());
-               result1->Set("permissions", Array::FromVector(permInfo));
-               result1->Set("version", Application::GetAppVersion());
-               result1->Set("info", "More information about API requests is available in the documentation at https://docs.icinga.com/icinga2/latest.");
-
-               Array::Ptr results = new Array();
-               results->Add(result1);
-
-               Dictionary::Ptr result = new Dictionary();
-               result->Set("results", results);
+               Dictionary::Ptr result1 = new Dictionary({
+                       { "user", user->GetName() },
+                       { "permissions", Array::FromVector(permInfo) },
+                       { "version", Application::GetAppVersion() },
+                       { "info", "More information about API requests is available in the documentation at https://docs.icinga.com/icinga2/latest." }
+               });
+
+               Dictionary::Ptr result = new Dictionary({
+                       { "results", new Array({ result1 }) }
+               });
 
                HttpUtility::SendJsonBody(response, params, result);
        } else {
index 349103a196f31baa1a1fe7c1d254b186368fc583..12b0d0c532dbfc7a30d46a3347c6d80a5e131bf9 100644 (file)
@@ -42,14 +42,13 @@ void JsonRpcConnection::HeartbeatTimerHandler()
                                continue;
                        }
 
-                       Dictionary::Ptr request = new Dictionary();
-                       request->Set("jsonrpc", "2.0");
-                       request->Set("method", "event::Heartbeat");
-
-                       Dictionary::Ptr params = new Dictionary();
-                       params->Set("timeout", 120);
-
-                       request->Set("params", params);
+                       Dictionary::Ptr request = new Dictionary({
+                               { "jsonrpc", "2.0" },
+                               { "method", "event::Heartbeat" },
+                               { "params", new Dictionary({
+                                       { "timeout", 120 }
+                               }) }
+                       });
 
                        client->SendMessage(request);
                }
index 43543466c4346e8e574976e766811ea51a173bfd..31fa9078ac8de49fd6f9171ab616fc9e1d24668e 100644 (file)
@@ -127,10 +127,11 @@ Value RequestCertificateHandler(const MessageOrigin::Ptr& origin, const Dictiona
                        result->Set("cert", certResponse);
                        result->Set("status_code", 0);
 
-                       Dictionary::Ptr message = new Dictionary();
-                       message->Set("jsonrpc", "2.0");
-                       message->Set("method", "pki::UpdateCertificate");
-                       message->Set("params", result);
+                       Dictionary::Ptr message = new Dictionary({
+                               { "jsonrpc", "2.0" },
+                               { "method", "pki::UpdateCertificate" },
+                               { "params", result }
+                       });
                        JsonRpc::SendMessage(client->GetStream(), message);
 
                        return result;
@@ -197,10 +198,11 @@ Value RequestCertificateHandler(const MessageOrigin::Ptr& origin, const Dictiona
 
        result->Set("status_code", 0);
 
-       message = new Dictionary();
-       message->Set("jsonrpc", "2.0");
-       message->Set("method", "pki::UpdateCertificate");
-       message->Set("params", result);
+       message = new Dictionary({
+               { "jsonrpc", "2.0" },
+               { "method", "pki::UpdateCertificate" },
+               { "params", result }
+       });
        JsonRpc::SendMessage(client->GetStream(), message);
 
        return result;
@@ -209,9 +211,10 @@ delayed_request:
        /* Send a delayed certificate signing request. */
        Utility::MkDirP(requestDir, 0700);
 
-       Dictionary::Ptr request = new Dictionary();
-       request->Set("cert_request", CertificateToString(cert));
-       request->Set("ticket", params->Get("ticket"));
+       Dictionary::Ptr request = new Dictionary({
+               { "cert_request", CertificateToString(cert) },
+               { "ticket", params->Get("ticket") }
+       });
 
        Utility::SaveJsonFile(requestPath, 0600, request);
 
index 65e59fcf05e778d9f1be0c782af26fc140a34df9..5e664eca31a197e40d485972ab4166a1e2f85011 100644 (file)
@@ -78,7 +78,7 @@ bool ModifyObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
 
        Dictionary::Ptr attrs = attrsVal;
 
-       Array::Ptr results = new Array();
+       ArrayData results;
 
        for (const ConfigObject::Ptr& obj : objs) {
                Dictionary::Ptr result1 = new Dictionary();
@@ -104,11 +104,12 @@ bool ModifyObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
                        result1->Set("status", "Attribute '" + key + "' could not be set: " + DiagnosticInformation(ex));
                }
 
-               results->Add(result1);
+               results.push_back(std::move(result1));
        }
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array(std::move(results)) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
index 90520a9e62af4cbb7a80bf7653c4bd263c5a3507..8bb434a80809d9f568866cd1a3e3901e447f05b3 100644 (file)
@@ -81,10 +81,10 @@ Dictionary::Ptr ObjectQueryHandler::SerializeObjectAttrs(const Object::Ptr& obje
                }
        }
 
-       Dictionary::Ptr resultAttrs = new Dictionary();
+       DictionaryData resultAttrs;
+       resultAttrs.reserve(fids.size());
 
-       for (int fid : fids)
-       {
+       for (int fid : fids) {
                Field field = type->GetFieldInfo(fid);
 
                Value val = object->GetField(fid);
@@ -98,10 +98,10 @@ Dictionary::Ptr ObjectQueryHandler::SerializeObjectAttrs(const Object::Ptr& obje
                        continue;
 
                Value sval = Serialize(val, FAConfig | FAState);
-               resultAttrs->Set(field.Name, sval);
+               resultAttrs.emplace_back(field.Name, sval);
        }
 
-       return resultAttrs;
+       return new Dictionary(std::move(resultAttrs));
 }
 
 bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response, const Dictionary::Ptr& params)
@@ -170,8 +170,8 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
                return true;
        }
 
-       Array::Ptr results = new Array();
-       results->Reserve(objs.size());
+       ArrayData results;
+       results.reserve(objs.size());
 
        std::set<String> joinAttrs;
        std::set<String> userJoinAttrs;
@@ -196,21 +196,19 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
        }
 
        for (const ConfigObject::Ptr& obj : objs) {
-               Dictionary::Ptr result1 = new Dictionary();
-               results->Add(result1);
+               DictionaryData result1{
+                       { "name", obj->GetName() },
+                       { "type", obj->GetReflectionType()->GetName() }
+               };
 
-               result1->Set("name", obj->GetName());
-               result1->Set("type", obj->GetReflectionType()->GetName());
-
-               Dictionary::Ptr metaAttrs = new Dictionary();
-               result1->Set("meta", metaAttrs);
+               DictionaryData metaAttrs;
 
                if (umetas) {
                        ObjectLock olock(umetas);
                        for (const String& meta : umetas) {
                                if (meta == "used_by") {
                                        Array::Ptr used_by = new Array();
-                                       metaAttrs->Set("used_by", used_by);
+                                       metaAttrs.emplace_back("used_by", used_by);
 
                                        for (const Object::Ptr& pobj : DependencyGraph::GetParents((obj)))
                                        {
@@ -219,20 +217,13 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
                                                if (!configObj)
                                                        continue;
 
-                                               Dictionary::Ptr refInfo = new Dictionary();
-                                               refInfo->Set("type", configObj->GetReflectionType()->GetName());
-                                               refInfo->Set("name", configObj->GetName());
-                                               used_by->Add(refInfo);
+                                               used_by->Add(new Dictionary({
+                                                       { "type", configObj->GetReflectionType()->GetName() },
+                                                       { "name", configObj->GetName() }
+                                               }));
                                        }
                                } else if (meta == "location") {
-                                       DebugInfo di = obj->GetDebugInfo();
-                                       Dictionary::Ptr dinfo = new Dictionary();
-                                       dinfo->Set("path", di.Path);
-                                       dinfo->Set("first_line", di.FirstLine);
-                                       dinfo->Set("first_column", di.FirstColumn);
-                                       dinfo->Set("last_line", di.LastLine);
-                                       dinfo->Set("last_column", di.LastColumn);
-                                       metaAttrs->Set("location", dinfo);
+                                       metaAttrs.emplace_back("location", obj->GetSourceLocation());
                                } else {
                                        HttpUtility::SendJsonError(response, params, 400, "Invalid field specified for meta: " + meta);
                                        return true;
@@ -240,15 +231,16 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
                        }
                }
 
+               result1.emplace_back("meta", new Dictionary(std::move(metaAttrs)));
+
                try {
-                       result1->Set("attrs", SerializeObjectAttrs(obj, String(), uattrs, false, false));
+                       result1.emplace_back("attrs", SerializeObjectAttrs(obj, String(), uattrs, false, false));
                } catch (const ScriptError& ex) {
                        HttpUtility::SendJsonError(response, params, 400, ex.what());
                        return true;
                }
 
-               Dictionary::Ptr joins = new Dictionary();
-               result1->Set("joins", joins);
+               DictionaryData joins;
 
                for (const String& joinAttr : joinAttrs) {
                        Object::Ptr joinedObj;
@@ -274,16 +266,21 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
                        String prefix = field.NavigationName;
 
                        try {
-                               joins->Set(prefix, SerializeObjectAttrs(joinedObj, prefix, ujoins, true, allJoins));
+                               joins.emplace_back(prefix, SerializeObjectAttrs(joinedObj, prefix, ujoins, true, allJoins));
                        } catch (const ScriptError& ex) {
                                HttpUtility::SendJsonError(response, params, 400, ex.what());
                                return true;
                        }
                }
+
+               result1.emplace_back("joins", new Dictionary(std::move(joins)));
+
+               results.push_back(new Dictionary(std::move(result1)));
        }
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array(std::move(results)) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
index 2d3232d2e8d00bac5f29c66b732eb1ca83320183..6b896dab1262652e5102b13ef7dd85909fb1a5a5 100644 (file)
@@ -197,18 +197,18 @@ int PkiUtility::RequestCertificate(const String& host, const String& port, const
                return 1;
        }
 
-       Dictionary::Ptr request = new Dictionary();
+       Dictionary::Ptr params = new Dictionary({
+               { "ticket", String(ticket) }
+       });
 
        String msgid = Utility::NewUniqueID();
 
-       request->Set("jsonrpc", "2.0");
-       request->Set("id", msgid);
-       request->Set("method", "pki::RequestCertificate");
-
-       Dictionary::Ptr params = new Dictionary();
-       params->Set("ticket", String(ticket));
-
-       request->Set("params", params);
+       Dictionary::Ptr request = new Dictionary({
+               { "jsonrpc", "2.0" },
+               { "id", msgid },
+               { "method", "pki::RequestCertificate" },
+               { "params", params }
+       });
 
        JsonRpc::SendMessage(stream, request);
 
index a489a3e259c41e87f135da488d8398619b08395b..e2c85c2b13943dc2b7fb7dcbab67821263d380b6 100644 (file)
@@ -57,17 +57,15 @@ public:
                if (!func)
                        BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid status function name."));
 
-               Dictionary::Ptr result = new Dictionary();
-
                Dictionary::Ptr status = new Dictionary();
                Array::Ptr perfdata = new Array();
                func->Invoke({ status, perfdata });
 
-               result->Set("name", name);
-               result->Set("status", status);
-               result->Set("perfdata", Serialize(perfdata, FAState));
-
-               return result;
+               return new Dictionary({
+                       { "name", name },
+                       { "status", status },
+                       { "perfdata", Serialize(perfdata, FAState) }
+               });
        }
 
        bool IsValidType(const String& type) const override
@@ -110,10 +108,9 @@ bool StatusHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request
                return true;
        }
 
-       Array::Ptr results = Array::FromVector(objs);
-
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array(std::move(objs)) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
index c8d101c1e8062ef3d7d4008973e90d8fb651296d..d0bd359645f509a79c6871f265cdc1fb1f55088d 100644 (file)
@@ -38,20 +38,19 @@ public:
 
        static Dictionary::Ptr GetTargetForTemplate(const ConfigItem::Ptr& item)
        {
-               Dictionary::Ptr target = new Dictionary();
-               target->Set("name", item->GetName());
-               target->Set("type", item->GetType()->GetName());
-
                DebugInfo di = item->GetDebugInfo();
-               Dictionary::Ptr dinfo = new Dictionary();
-               dinfo->Set("path", di.Path);
-               dinfo->Set("first_line", di.FirstLine);
-               dinfo->Set("first_column", di.FirstColumn);
-               dinfo->Set("last_line", di.LastLine);
-               dinfo->Set("last_column", di.LastColumn);
-               target->Set("location", dinfo);
-
-               return target;
+
+               return new Dictionary({
+                       { "name", item->GetName() },
+                       { "type", item->GetType()->GetName() },
+                       { "location", new Dictionary({
+                               { "path", di.Path },
+                               { "first_line", di.FirstLine },
+                               { "first_column", di.FirstColumn },
+                               { "last_line", di.LastLine },
+                               { "last_column", di.LastColumn }
+                       }) }
+               });
        }
 
        void FindTargets(const String& type,
@@ -132,18 +131,12 @@ bool TemplateQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest&
                return true;
        }
 
-       Array::Ptr results = new Array();
-
-       for (const Dictionary::Ptr& obj : objs) {
-               results->Add(obj);
-       }
-
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array(std::move(objs)) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
 
        return true;
 }
-
index 70427c2f260e255d493967ff9f8af12d20abaa88..0f26d998f71e2dc003a76c0749d92d23caf9fcf4 100644 (file)
@@ -96,11 +96,11 @@ bool TypeQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& requ
                return true;
        }
 
-       Array::Ptr results = new Array();
+       ArrayData results;
 
        for (const Type::Ptr& obj : objs) {
                Dictionary::Ptr result1 = new Dictionary();
-               results->Add(result1);
+               results.push_back(result1);
 
                Dictionary::Ptr resultAttrs = new Dictionary();
                result1->Set("name", obj->GetName());
@@ -140,25 +140,24 @@ bool TypeQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& requ
                                fieldInfo->Set("navigation_name", field.NavigationName);
                        fieldInfo->Set("array_rank", field.ArrayRank);
 
-                       Dictionary::Ptr attributeInfo = new Dictionary();
-                       fieldInfo->Set("attributes", attributeInfo);
-
-                       attributeInfo->Set("config", static_cast<bool>(field.Attributes & FAConfig));
-                       attributeInfo->Set("state", static_cast<bool>(field.Attributes & FAState));
-                       attributeInfo->Set("required", static_cast<bool>(field.Attributes & FARequired));
-                       attributeInfo->Set("navigation", static_cast<bool>(field.Attributes & FANavigation));
-                       attributeInfo->Set("no_user_modify", static_cast<bool>(field.Attributes & FANoUserModify));
-                       attributeInfo->Set("no_user_view", static_cast<bool>(field.Attributes & FANoUserView));
-                       attributeInfo->Set("deprecated", static_cast<bool>(field.Attributes & FADeprecated));
+                       fieldInfo->Set("attributes", new Dictionary({
+                               { "config", static_cast<bool>(field.Attributes & FAConfig) },
+                               { "state", static_cast<bool>(field.Attributes & FAState) },
+                               { "required", static_cast<bool>(field.Attributes & FARequired) },
+                               { "navigation", static_cast<bool>(field.Attributes & FANavigation) },
+                               { "no_user_modify", static_cast<bool>(field.Attributes & FANoUserModify) },
+                               { "no_user_view", static_cast<bool>(field.Attributes & FANoUserView) },
+                               { "deprecated", static_cast<bool>(field.Attributes & FADeprecated) }
+                       }));
                }
        }
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array(std::move(results)) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
 
        return true;
 }
-
index 6a601a4c2706abc8388952f0135422a1e2dcb209..512d3925a39c0931479bb71d18d5db79a2dae212 100644 (file)
@@ -38,11 +38,11 @@ public:
 
        static Dictionary::Ptr GetTargetForVar(const String& name, const Value& value)
        {
-               Dictionary::Ptr target = new Dictionary();
-               target->Set("name", name);
-               target->Set("type", value.GetReflectionType()->GetName());
-               target->Set("value", value);
-               return target;
+               return new Dictionary({
+                       { "name", name },
+                       { "type", value.GetReflectionType()->GetName() },
+                       { "value", value }
+               });
        }
 
        void FindTargets(const String& type,
@@ -102,20 +102,19 @@ bool VariableQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest&
                return true;
        }
 
-       Array::Ptr results = new Array();
+       ArrayData results;
 
        for (const Dictionary::Ptr& var : objs) {
-               Dictionary::Ptr result1 = new Dictionary();
-               results->Add(result1);
-
-               Dictionary::Ptr resultAttrs = new Dictionary();
-               result1->Set("name", var->Get("name"));
-               result1->Set("type", var->Get("type"));
-               result1->Set("value", Serialize(var->Get("value"), 0));
+               results.emplace_back(new Dictionary({
+                       { "name", var->Get("name") },
+                       { "type", var->Get("type") },
+                       { "value", Serialize(var->Get("value"), 0) }
+               }));
        }
 
-       Dictionary::Ptr result = new Dictionary();
-       result->Set("results", results);
+       Dictionary::Ptr result = new Dictionary({
+               { "results", new Array(std::move(results)) }
+       });
 
        response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);