From 2e87c280ed476dbc28d22955c886a14aa560cffe Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 23 Nov 2017 09:58:05 +0100 Subject: [PATCH] Use initializer lists instead of std::vector::push_back --- lib/base/process.cpp | 5 +---- lib/cli/nodesetupcommand.cpp | 22 ++++----------------- lib/cli/nodewizardcommand.cpp | 22 ++++----------------- lib/icinga/dependency-apply.cpp | 5 +---- lib/icinga/notification-apply.cpp | 5 +---- lib/icinga/scheduleddowntime-apply.cpp | 5 +---- lib/icinga/service-apply.cpp | 4 +--- lib/remote/apiclient.cpp | 27 ++++---------------------- 8 files changed, 17 insertions(+), 78 deletions(-) diff --git a/lib/base/process.cpp b/lib/base/process.cpp index a8f354088..2f8590f78 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -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 } diff --git a/lib/cli/nodesetupcommand.cpp b/lib/cli/nodesetupcommand.cpp index 6d4617a97..ebf4fb81e 100644 --- a/lib/cli/nodesetupcommand.cpp +++ b/lib/cli/nodesetupcommand.cpp @@ -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 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 disable; - disable.push_back("notification"); - FeatureUtility::DisableFeatures(disable); + FeatureUtility::DisableFeatures({ "notification" }); /* enable the ApiListener config */ Log(LogInformation, "cli", "Updating the ApiListener feature."); - std::vector 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 globalZones; - - globalZones.push_back("global-templates"); - globalZones.push_back("director-global"); - - NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as >(), globalZones); + NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as >(), { "global-templates", "director-global" }); /* update constants.conf with NodeName = CN */ if (cn != Utility::GetFQDN()) { diff --git a/lib/cli/nodewizardcommand.cpp b/lib/cli/nodewizardcommand.cpp index 7ab4c2d0b..c3668570d 100644 --- a/lib/cli/nodewizardcommand.cpp +++ b/lib/cli/nodewizardcommand.cpp @@ -457,15 +457,11 @@ wizard_ticket: /* disable the notifications feature on client nodes */ Log(LogInformation, "cli", "Disabling the Notification feature."); - std::vector disable; - disable.push_back("notification"); - FeatureUtility::DisableFeatures(disable); + FeatureUtility::DisableFeatures({ "notification" }); Log(LogInformation, "cli", "Enabling the ApiListener feature."); - std::vector 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 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 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) diff --git a/lib/icinga/dependency-apply.cpp b/lib/icinga/dependency-apply.cpp index 34b0cf93a..b4df4dd7d 100644 --- a/lib/icinga/dependency-apply.cpp +++ b/lib/icinga/dependency-apply.cpp @@ -31,10 +31,7 @@ using namespace icinga; INITIALIZE_ONCE([]() { - std::vector 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) diff --git a/lib/icinga/notification-apply.cpp b/lib/icinga/notification-apply.cpp index bf01d04fd..7f8930f4e 100644 --- a/lib/icinga/notification-apply.cpp +++ b/lib/icinga/notification-apply.cpp @@ -31,10 +31,7 @@ using namespace icinga; INITIALIZE_ONCE([]() { - std::vector 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) diff --git a/lib/icinga/scheduleddowntime-apply.cpp b/lib/icinga/scheduleddowntime-apply.cpp index 60028fe7f..752ba36d7 100644 --- a/lib/icinga/scheduleddowntime-apply.cpp +++ b/lib/icinga/scheduleddowntime-apply.cpp @@ -30,10 +30,7 @@ using namespace icinga; INITIALIZE_ONCE([]() { - std::vector 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) diff --git a/lib/icinga/service-apply.cpp b/lib/icinga/service-apply.cpp index 6c2e594d3..360285f3a 100644 --- a/lib/icinga/service-apply.cpp +++ b/lib/icinga/service-apply.cpp @@ -30,9 +30,7 @@ using namespace icinga; INITIALIZE_ONCE([]() { - std::vector 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) diff --git a/lib/remote/apiclient.cpp b/lib/remote/apiclient.cpp index 5ca690de8..b4cc25813 100644 --- a/lib/remote/apiclient.cpp +++ b/lib/remote/apiclient.cpp @@ -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 path; - path.push_back("v1"); - path.push_back("types"); - url->SetPath(path); + url->SetPath({ "v1", "types" }); try { std::shared_ptr 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 path; - path.push_back("v1"); - path.push_back("objects"); - path.push_back(pluralType); - url->SetPath(path); + url->SetPath({ "v1", "objects", pluralType }); std::map > 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 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 > 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 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 > params; params["session"].push_back(session);