]> granicus.if.org Git - icinga2/commitdiff
Use initializer lists instead of std::vector::push_back
authorGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 23 Nov 2017 08:58:05 +0000 (09:58 +0100)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 30 Nov 2017 16:47:09 +0000 (17:47 +0100)
lib/base/process.cpp
lib/cli/nodesetupcommand.cpp
lib/cli/nodewizardcommand.cpp
lib/icinga/dependency-apply.cpp
lib/icinga/notification-apply.cpp
lib/icinga/scheduleddowntime-apply.cpp
lib/icinga/service-apply.cpp
lib/remote/apiclient.cpp

index a8f354088df4aa07cab74631b72473d4cca28684..2f8590f782488f4fd3d41db58465593343d66185 100644 (file)
@@ -574,10 +574,7 @@ Process::Arguments Process::PrepareCommand(const Value& command)
 #ifdef _WIN32
        return command;
 #else /* _WIN32 */
-       args.push_back("sh");
-       args.push_back("-c");
-       args.push_back(command);
-       return args;
+       return { "sh", "-c", command };
 #endif
 }
 
index 6d4617a978c2e2c29654b829f8573c5d8d3cb8b4..ebf4fb81ea2dbc8f5d8abefcaddcae044588da9b 100644 (file)
@@ -159,12 +159,7 @@ int NodeSetupCommand::SetupMaster(const boost::program_options::variables_map& v
        /* write zones.conf and update with zone + endpoint information */
        Log(LogInformation, "cli", "Generating zone and object configuration.");
 
-       std::vector<String> globalZones;
-
-       globalZones.push_back("global-templates");
-       globalZones.push_back("director-global");
-
-       NodeUtility::GenerateNodeMasterIcingaConfig(globalZones);
+       NodeUtility::GenerateNodeMasterIcingaConfig({ "global-templates", "director-global" });
 
        /* update the ApiListener config - SetupMaster() will always enable it */
        Log(LogInformation, "cli", "Updating the APIListener feature.");
@@ -362,17 +357,13 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm,
        /* disable the notifications feature */
        Log(LogInformation, "cli", "Disabling the Notification feature.");
 
-       std::vector<std::string> disable;
-       disable.push_back("notification");
-       FeatureUtility::DisableFeatures(disable);
+       FeatureUtility::DisableFeatures({ "notification" });
 
        /* enable the ApiListener config */
 
        Log(LogInformation, "cli", "Updating the ApiListener feature.");
 
-       std::vector<std::string> enable;
-       enable.push_back("api");
-       FeatureUtility::EnableFeatures(enable);
+       FeatureUtility::EnableFeatures({ "api" });
 
        String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
        NodeUtility::CreateBackupFile(apipath);
@@ -427,12 +418,7 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm,
 
        Log(LogInformation, "cli", "Generating zone and object configuration.");
 
-       std::vector<String> globalZones;
-
-       globalZones.push_back("global-templates");
-       globalZones.push_back("director-global");
-
-       NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as<std::vector<std::string> >(), globalZones);
+       NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as<std::vector<std::string> >(), { "global-templates", "director-global" });
 
        /* update constants.conf with NodeName = CN */
        if (cn != Utility::GetFQDN()) {
index 7ab4c2d0b79a45f3dc86609b46be484e525b4d38..c3668570dd4e0c22d007915535a39026a6f6e842 100644 (file)
@@ -457,15 +457,11 @@ wizard_ticket:
        /* disable the notifications feature on client nodes */
        Log(LogInformation, "cli", "Disabling the Notification feature.");
 
-       std::vector<std::string> disable;
-       disable.push_back("notification");
-       FeatureUtility::DisableFeatures(disable);
+       FeatureUtility::DisableFeatures({ "notification" });
 
        Log(LogInformation, "cli", "Enabling the ApiListener feature.");
 
-       std::vector<std::string> enable;
-       enable.push_back("api");
-       FeatureUtility::EnableFeatures(enable);
+       FeatureUtility::EnableFeatures({ "api" });
 
        String apiConfPath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
        NodeUtility::CreateBackupFile(apiConfPath);
@@ -503,12 +499,7 @@ wizard_ticket:
        /* apilistener config */
        Log(LogInformation, "cli", "Generating local zones.conf.");
 
-       std::vector<String> globalZones;
-
-       globalZones.push_back("global-templates");
-       globalZones.push_back("director-global");
-
-       NodeUtility::GenerateNodeIcingaConfig(endpoints, globalZones);
+       NodeUtility::GenerateNodeIcingaConfig(endpoints, { "global-templates", "director-global" });
 
        if (cn != Utility::GetFQDN()) {
                Log(LogWarning, "cli")
@@ -604,12 +595,7 @@ int NodeWizardCommand::MasterSetup(void) const
        else
                std::cout << "'api' feature already enabled.\n";
 
-       std::vector<String> globalZones;
-
-       globalZones.push_back("global-templates");
-       globalZones.push_back("director-global");
-
-       NodeUtility::GenerateNodeMasterIcingaConfig(globalZones);
+       NodeUtility::GenerateNodeMasterIcingaConfig({ "global-templates", "director-global" });
 
        /* apilistener config */
        std::cout << ConsoleColorTag(Console_Bold)
index 34b0cf93ab6e88fad739934304c78962be2dddff..b4df4dd7d8b50d32d16cebb8ef7ae922ab677240 100644 (file)
 using namespace icinga;
 
 INITIALIZE_ONCE([]() {
-       std::vector<String> targets;
-       targets.push_back("Host");
-       targets.push_back("Service");
-       ApplyRule::RegisterType("Dependency", targets);
+       ApplyRule::RegisterType("Dependency", { "Host", "Service" });
 });
 
 bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)
index bf01d04fd47ce2a559110d3e961d86f1d7122f8d..7f8930f4edac91dc58e676e05078bdea3ad1fc41 100644 (file)
 using namespace icinga;
 
 INITIALIZE_ONCE([]() {
-       std::vector<String> targets;
-       targets.push_back("Host");
-       targets.push_back("Service");
-       ApplyRule::RegisterType("Notification", targets);
+       ApplyRule::RegisterType("Notification", { "Host", "Service" });
 });
 
 bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)
index 60028fe7f766d5d271ec4e77473a377a89132a79..752ba36d71e7f58a5686223e7682848bdb811461 100644 (file)
 using namespace icinga;
 
 INITIALIZE_ONCE([]() {
-       std::vector<String> targets;
-       targets.push_back("Host");
-       targets.push_back("Service");
-       ApplyRule::RegisterType("ScheduledDowntime", targets);
+       ApplyRule::RegisterType("ScheduledDowntime", { "Host", "Service" });
 });
 
 bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)
index 6c2e594d3a3a99a9cdf4ea36aa70156dbd139094..360285f3a1d35f4f9ba63ebd158ae7c6d554fc49 100644 (file)
@@ -30,9 +30,7 @@
 using namespace icinga;
 
 INITIALIZE_ONCE([]() {
-       std::vector<String> targets;
-       targets.push_back("Host");
-       ApplyRule::RegisterType("Service", targets);
+       ApplyRule::RegisterType("Service", { "Host" });
 });
 
 bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule)
index 5ca690de81cd45ad33ec2507c7a384bd5d218bec..b4cc25813548e4c55ffdd0cb77f5abb69ab48940 100644 (file)
@@ -39,11 +39,7 @@ void ApiClient::GetTypes(const TypesCompletionCallback& callback) const
        url->SetScheme("https");
        url->SetHost(m_Connection->GetHost());
        url->SetPort(m_Connection->GetPort());
-
-       std::vector<String> path;
-       path.push_back("v1");
-       path.push_back("types");
-       url->SetPath(path);
+       url->SetPath({ "v1", "types" });
 
        try {
                std::shared_ptr<HttpRequest> req = m_Connection->NewRequest();
@@ -110,12 +106,7 @@ void ApiClient::GetObjects(const String& pluralType, const ObjectsCompletionCall
        url->SetScheme("https");
        url->SetHost(m_Connection->GetHost());
        url->SetPort(m_Connection->GetPort());
-
-       std::vector<String> path;
-       path.push_back("v1");
-       path.push_back("objects");
-       path.push_back(pluralType);
-       url->SetPath(path);
+       url->SetPath({ "v1", "objects", pluralType });
 
        std::map<String, std::vector<String> > params;
 
@@ -236,12 +227,7 @@ void ApiClient::ExecuteScript(const String& session, const String& command, bool
        url->SetScheme("https");
        url->SetHost(m_Connection->GetHost());
        url->SetPort(m_Connection->GetPort());
-
-       std::vector<String> path;
-       path.push_back("v1");
-       path.push_back("console");
-       path.push_back("execute-script");
-       url->SetPath(path);
+       url->SetPath({ "v1", "console", "execute-script" });
 
        std::map<String, std::vector<String> > params;
        params["session"].push_back(session);
@@ -320,12 +306,7 @@ void ApiClient::AutocompleteScript(const String& session, const String& command,
        url->SetScheme("https");
        url->SetHost(m_Connection->GetHost());
        url->SetPort(m_Connection->GetPort());
-
-       std::vector<String> path;
-       path.push_back("v1");
-       path.push_back("console");
-       path.push_back("auto-complete-script");
-       url->SetPath(path);
+       url->SetPath({ "v1", "console", "auto-complete-script" });
 
        std::map<String, std::vector<String> > params;
        params["session"].push_back(session);