Use initializer lists instead of std::vector::push_back

This commit is contained in:
Gunnar Beutner 2017-11-23 09:58:05 +01:00
parent ebc11d41a5
commit 2e87c280ed
8 changed files with 17 additions and 78 deletions

View File

@ -574,10 +574,7 @@ Process::Arguments Process::PrepareCommand(const Value& command)
#ifdef _WIN32 #ifdef _WIN32
return command; return command;
#else /* _WIN32 */ #else /* _WIN32 */
args.push_back("sh"); return { "sh", "-c", command };
args.push_back("-c");
args.push_back(command);
return args;
#endif #endif
} }

View File

@ -159,12 +159,7 @@ int NodeSetupCommand::SetupMaster(const boost::program_options::variables_map& v
/* write zones.conf and update with zone + endpoint information */ /* write zones.conf and update with zone + endpoint information */
Log(LogInformation, "cli", "Generating zone and object configuration."); Log(LogInformation, "cli", "Generating zone and object configuration.");
std::vector<String> globalZones; NodeUtility::GenerateNodeMasterIcingaConfig({ "global-templates", "director-global" });
globalZones.push_back("global-templates");
globalZones.push_back("director-global");
NodeUtility::GenerateNodeMasterIcingaConfig(globalZones);
/* update the ApiListener config - SetupMaster() will always enable it */ /* update the ApiListener config - SetupMaster() will always enable it */
Log(LogInformation, "cli", "Updating the APIListener feature."); 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 */ /* disable the notifications feature */
Log(LogInformation, "cli", "Disabling the Notification feature."); Log(LogInformation, "cli", "Disabling the Notification feature.");
std::vector<std::string> disable; FeatureUtility::DisableFeatures({ "notification" });
disable.push_back("notification");
FeatureUtility::DisableFeatures(disable);
/* enable the ApiListener config */ /* enable the ApiListener config */
Log(LogInformation, "cli", "Updating the ApiListener feature."); Log(LogInformation, "cli", "Updating the ApiListener feature.");
std::vector<std::string> enable; FeatureUtility::EnableFeatures({ "api" });
enable.push_back("api");
FeatureUtility::EnableFeatures(enable);
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf"; String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
NodeUtility::CreateBackupFile(apipath); 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."); Log(LogInformation, "cli", "Generating zone and object configuration.");
std::vector<String> globalZones; NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as<std::vector<std::string> >(), { "global-templates", "director-global" });
globalZones.push_back("global-templates");
globalZones.push_back("director-global");
NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as<std::vector<std::string> >(), globalZones);
/* update constants.conf with NodeName = CN */ /* update constants.conf with NodeName = CN */
if (cn != Utility::GetFQDN()) { if (cn != Utility::GetFQDN()) {

View File

@ -457,15 +457,11 @@ wizard_ticket:
/* disable the notifications feature on client nodes */ /* disable the notifications feature on client nodes */
Log(LogInformation, "cli", "Disabling the Notification feature."); Log(LogInformation, "cli", "Disabling the Notification feature.");
std::vector<std::string> disable; FeatureUtility::DisableFeatures({ "notification" });
disable.push_back("notification");
FeatureUtility::DisableFeatures(disable);
Log(LogInformation, "cli", "Enabling the ApiListener feature."); Log(LogInformation, "cli", "Enabling the ApiListener feature.");
std::vector<std::string> enable; FeatureUtility::EnableFeatures({ "api" });
enable.push_back("api");
FeatureUtility::EnableFeatures(enable);
String apiConfPath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf"; String apiConfPath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
NodeUtility::CreateBackupFile(apiConfPath); NodeUtility::CreateBackupFile(apiConfPath);
@ -503,12 +499,7 @@ wizard_ticket:
/* apilistener config */ /* apilistener config */
Log(LogInformation, "cli", "Generating local zones.conf."); Log(LogInformation, "cli", "Generating local zones.conf.");
std::vector<String> globalZones; NodeUtility::GenerateNodeIcingaConfig(endpoints, { "global-templates", "director-global" });
globalZones.push_back("global-templates");
globalZones.push_back("director-global");
NodeUtility::GenerateNodeIcingaConfig(endpoints, globalZones);
if (cn != Utility::GetFQDN()) { if (cn != Utility::GetFQDN()) {
Log(LogWarning, "cli") Log(LogWarning, "cli")
@ -604,12 +595,7 @@ int NodeWizardCommand::MasterSetup(void) const
else else
std::cout << "'api' feature already enabled.\n"; std::cout << "'api' feature already enabled.\n";
std::vector<String> globalZones; NodeUtility::GenerateNodeMasterIcingaConfig({ "global-templates", "director-global" });
globalZones.push_back("global-templates");
globalZones.push_back("director-global");
NodeUtility::GenerateNodeMasterIcingaConfig(globalZones);
/* apilistener config */ /* apilistener config */
std::cout << ConsoleColorTag(Console_Bold) std::cout << ConsoleColorTag(Console_Bold)

View File

@ -31,10 +31,7 @@
using namespace icinga; using namespace icinga;
INITIALIZE_ONCE([]() { INITIALIZE_ONCE([]() {
std::vector<String> targets; ApplyRule::RegisterType("Dependency", { "Host", "Service" });
targets.push_back("Host");
targets.push_back("Service");
ApplyRule::RegisterType("Dependency", targets);
}); });
bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule) bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)

View File

@ -31,10 +31,7 @@
using namespace icinga; using namespace icinga;
INITIALIZE_ONCE([]() { INITIALIZE_ONCE([]() {
std::vector<String> targets; ApplyRule::RegisterType("Notification", { "Host", "Service" });
targets.push_back("Host");
targets.push_back("Service");
ApplyRule::RegisterType("Notification", targets);
}); });
bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule) bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)

View File

@ -30,10 +30,7 @@
using namespace icinga; using namespace icinga;
INITIALIZE_ONCE([]() { INITIALIZE_ONCE([]() {
std::vector<String> targets; ApplyRule::RegisterType("ScheduledDowntime", { "Host", "Service" });
targets.push_back("Host");
targets.push_back("Service");
ApplyRule::RegisterType("ScheduledDowntime", targets);
}); });
bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule) bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)

View File

@ -30,9 +30,7 @@
using namespace icinga; using namespace icinga;
INITIALIZE_ONCE([]() { INITIALIZE_ONCE([]() {
std::vector<String> targets; ApplyRule::RegisterType("Service", { "Host" });
targets.push_back("Host");
ApplyRule::RegisterType("Service", targets);
}); });
bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule) bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule)

View File

@ -39,11 +39,7 @@ void ApiClient::GetTypes(const TypesCompletionCallback& callback) const
url->SetScheme("https"); url->SetScheme("https");
url->SetHost(m_Connection->GetHost()); url->SetHost(m_Connection->GetHost());
url->SetPort(m_Connection->GetPort()); url->SetPort(m_Connection->GetPort());
url->SetPath({ "v1", "types" });
std::vector<String> path;
path.push_back("v1");
path.push_back("types");
url->SetPath(path);
try { try {
std::shared_ptr<HttpRequest> req = m_Connection->NewRequest(); std::shared_ptr<HttpRequest> req = m_Connection->NewRequest();
@ -110,12 +106,7 @@ void ApiClient::GetObjects(const String& pluralType, const ObjectsCompletionCall
url->SetScheme("https"); url->SetScheme("https");
url->SetHost(m_Connection->GetHost()); url->SetHost(m_Connection->GetHost());
url->SetPort(m_Connection->GetPort()); url->SetPort(m_Connection->GetPort());
url->SetPath({ "v1", "objects", pluralType });
std::vector<String> path;
path.push_back("v1");
path.push_back("objects");
path.push_back(pluralType);
url->SetPath(path);
std::map<String, std::vector<String> > params; 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->SetScheme("https");
url->SetHost(m_Connection->GetHost()); url->SetHost(m_Connection->GetHost());
url->SetPort(m_Connection->GetPort()); url->SetPort(m_Connection->GetPort());
url->SetPath({ "v1", "console", "execute-script" });
std::vector<String> path;
path.push_back("v1");
path.push_back("console");
path.push_back("execute-script");
url->SetPath(path);
std::map<String, std::vector<String> > params; std::map<String, std::vector<String> > params;
params["session"].push_back(session); params["session"].push_back(session);
@ -320,12 +306,7 @@ void ApiClient::AutocompleteScript(const String& session, const String& command,
url->SetScheme("https"); url->SetScheme("https");
url->SetHost(m_Connection->GetHost()); url->SetHost(m_Connection->GetHost());
url->SetPort(m_Connection->GetPort()); url->SetPort(m_Connection->GetPort());
url->SetPath({ "v1", "console", "auto-complete-script" });
std::vector<String> path;
path.push_back("v1");
path.push_back("console");
path.push_back("auto-complete-script");
url->SetPath(path);
std::map<String, std::vector<String> > params; std::map<String, std::vector<String> > params;
params["session"].push_back(session); params["session"].push_back(session);