Use std::vector::emplace_back instead of std::vector::push_back

This commit is contained in:
Gunnar Beutner 2017-11-30 08:19:58 +01:00
parent 59fca5d5ac
commit 3c60fbf75d
53 changed files with 201 additions and 268 deletions

View File

@ -77,10 +77,7 @@ static void ArrayClear(void)
static bool ArraySortCmp(const Function::Ptr& cmp, const Value& a, const Value& b) static bool ArraySortCmp(const Function::Ptr& cmp, const Value& a, const Value& b)
{ {
std::vector<Value> args; return cmp->Invoke({ a, b });
args.push_back(a);
args.push_back(b);
return cmp->Invoke(args);
} }
static Array::Ptr ArraySort(const std::vector<Value>& args) static Array::Ptr ArraySort(const std::vector<Value>& args)
@ -154,9 +151,7 @@ static Array::Ptr ArrayMap(const Function::Ptr& function)
ObjectLock olock(self); ObjectLock olock(self);
for (const Value& item : self) { for (const Value& item : self) {
std::vector<Value> args; result->Add(function->Invoke({ item }));
args.push_back(item);
result->Add(function->Invoke(args));
} }
return result; return result;
@ -177,10 +172,7 @@ static Value ArrayReduce(const Function::Ptr& function)
ObjectLock olock(self); ObjectLock olock(self);
for (size_t i = 1; i < self->GetLength(); i++) { for (size_t i = 1; i < self->GetLength(); i++) {
std::vector<Value> args; result = function->Invoke({ result, self->Get(i) });
args.push_back(result);
args.push_back(self->Get(i));
result = function->Invoke(args);
} }
return result; return result;
@ -198,9 +190,7 @@ static Array::Ptr ArrayFilter(const Function::Ptr& function)
ObjectLock olock(self); ObjectLock olock(self);
for (const Value& item : self) { for (const Value& item : self) {
std::vector<Value> args; if (function->Invoke({ item }))
args.push_back(item);
if (function->Invoke(args))
result->Add(item); result->Add(item);
} }
@ -217,9 +207,7 @@ static bool ArrayAny(const Function::Ptr& function)
ObjectLock olock(self); ObjectLock olock(self);
for (const Value& item : self) { for (const Value& item : self) {
std::vector<Value> args; if (function->Invoke({ item }))
args.push_back(item);
if (function->Invoke(args))
return true; return true;
} }
@ -236,9 +224,7 @@ static bool ArrayAll(const Function::Ptr& function)
ObjectLock olock(self); ObjectLock olock(self);
for (const Value& item : self) { for (const Value& item : self) {
std::vector<Value> args; if (!function->Invoke({ item }))
args.push_back(item);
if (!function->Invoke(args))
return false; return false;
} }

View File

@ -90,7 +90,7 @@ void Array::Add(Value&& value)
{ {
ObjectLock olock(this); ObjectLock olock(this);
m_Data.push_back(std::move(value)); m_Data.emplace_back(std::move(value));
} }
/** /**

View File

@ -34,7 +34,7 @@ static Value FunctionCall(const std::vector<Value>& args)
Function::Ptr self = static_cast<Function::Ptr>(vframe->Self); Function::Ptr self = static_cast<Function::Ptr>(vframe->Self);
std::vector<Value> uargs(args.begin() + 1, args.end()); std::vector<Value> uargs(args.begin() + 1, args.end());
return self->Invoke(args[0], uargs); return self->InvokeThis(args[0], uargs);
} }
static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args) static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args)
@ -49,7 +49,7 @@ static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args)
uargs = std::vector<Value>(args->Begin(), args->End()); uargs = std::vector<Value>(args->Begin(), args->End());
} }
return self->Invoke(thisArg, uargs); return self->InvokeThis(thisArg, uargs);
} }

View File

@ -42,7 +42,7 @@ Value Function::Invoke(const std::vector<Value>& arguments)
return m_Callback(arguments); return m_Callback(arguments);
} }
Value Function::Invoke(const Value& otherThis, const std::vector<Value>& arguments) Value Function::InvokeThis(const Value& otherThis, const std::vector<Value>& arguments)
{ {
ScriptFrame frame; ScriptFrame frame;
frame.Self = otherThis; frame.Self = otherThis;

View File

@ -49,7 +49,7 @@ public:
{ } { }
Value Invoke(const std::vector<Value>& arguments = std::vector<Value>()); Value Invoke(const std::vector<Value>& arguments = std::vector<Value>());
Value Invoke(const Value& otherThis, const std::vector<Value>& arguments = std::vector<Value>()); Value InvokeThis(const Value& otherThis, const std::vector<Value>& arguments = std::vector<Value>());
inline bool IsSideEffectFree(void) const inline bool IsSideEffectFree(void) const
{ {

View File

@ -116,7 +116,7 @@ void SocketEventEngineEpoll::ThreadProc(int tid)
event.LifesupportReference = event.Descriptor.LifesupportObject; event.LifesupportReference = event.Descriptor.LifesupportObject;
VERIFY(event.LifesupportReference); VERIFY(event.LifesupportReference);
events.push_back(event); events.emplace_back(std::move(event));
} }
} }

View File

@ -108,7 +108,7 @@ void SocketEventEnginePoll::ThreadProc(int tid)
event.LifesupportReference = event.Descriptor.LifesupportObject; event.LifesupportReference = event.Descriptor.LifesupportObject;
VERIFY(event.LifesupportReference); VERIFY(event.LifesupportReference);
events.push_back(event); events.emplace_back(std::move(event));
} }
} }

View File

@ -212,7 +212,7 @@ bool ThreadPool::Post(const ThreadPool::WorkFunction& callback, SchedulerPolicy
if (policy == LowLatencyScheduler) if (policy == LowLatencyScheduler)
queue.SpawnWorker(m_ThreadGroup); queue.SpawnWorker(m_ThreadGroup);
queue.Items.push_back(wi); queue.Items.emplace_back(std::move(wi));
queue.CV.notify_one(); queue.CV.notify_one();
} }

View File

@ -28,9 +28,7 @@ using namespace icinga;
static void InvokeAttributeHandlerHelper(const Function::Ptr& callback, static void InvokeAttributeHandlerHelper(const Function::Ptr& callback,
const Object::Ptr& object, const Value& cookie) const Object::Ptr& object, const Value& cookie)
{ {
std::vector<Value> arguments; callback->Invoke({ object });
arguments.push_back(object);
callback->Invoke(arguments);
} }
static void TypeRegisterAttributeHandler(const String& fieldName, const Function::Ptr& callback) static void TypeRegisterAttributeHandler(const String& fieldName, const Function::Ptr& callback)

View File

@ -976,31 +976,31 @@ String Utility::FormatDuration(double duration)
if (duration >= 86400) { if (duration >= 86400) {
int days = duration / 86400; int days = duration / 86400;
tokens.push_back(Convert::ToString(days) + (days != 1 ? " days" : " day")); tokens.emplace_back(Convert::ToString(days) + (days != 1 ? " days" : " day"));
duration = static_cast<int>(duration) % 86400; duration = static_cast<int>(duration) % 86400;
} }
if (duration >= 3600) { if (duration >= 3600) {
int hours = duration / 3600; int hours = duration / 3600;
tokens.push_back(Convert::ToString(hours) + (hours != 1 ? " hours" : " hour")); tokens.emplace_back(Convert::ToString(hours) + (hours != 1 ? " hours" : " hour"));
duration = static_cast<int>(duration) % 3600; duration = static_cast<int>(duration) % 3600;
} }
if (duration >= 60) { if (duration >= 60) {
int minutes = duration / 60; int minutes = duration / 60;
tokens.push_back(Convert::ToString(minutes) + (minutes != 1 ? " minutes" : " minute")); tokens.emplace_back(Convert::ToString(minutes) + (minutes != 1 ? " minutes" : " minute"));
duration = static_cast<int>(duration) % 60; duration = static_cast<int>(duration) % 60;
} }
if (duration >= 1) { if (duration >= 1) {
int seconds = duration; int seconds = duration;
tokens.push_back(Convert::ToString(seconds) + (seconds != 1 ? " seconds" : " second")); tokens.emplace_back(Convert::ToString(seconds) + (seconds != 1 ? " seconds" : " second"));
} }
if (tokens.size() == 0) { if (tokens.size() == 0) {
int milliseconds = std::floor(duration * 1000); int milliseconds = std::floor(duration * 1000);
if (milliseconds >= 1) if (milliseconds >= 1)
tokens.push_back(Convert::ToString(milliseconds) + (milliseconds != 1 ? " milliseconds" : " millisecond")); tokens.emplace_back(Convert::ToString(milliseconds) + (milliseconds != 1 ? " milliseconds" : " millisecond"));
else else
tokens.push_back("less than 1 millisecond"); tokens.push_back("less than 1 millisecond");
} }

View File

@ -132,16 +132,7 @@ bool ApiSetupUtility::SetupMasterCertificates(const String& cn)
Utility::CopyFile(ca, target_ca); Utility::CopyFile(ca, target_ca);
/* fix permissions: root -> icinga daemon user */ /* fix permissions: root -> icinga daemon user */
std::vector<String> files; for (const String& file : { ca_path, ca, ca_key, target_ca, key, csr, cert }) {
files.push_back(ca_path);
files.push_back(ca);
files.push_back(ca_key);
files.push_back(target_ca);
files.push_back(key);
files.push_back(csr);
files.push_back(cert);
for (const String& file : files) {
if (!Utility::SetFileOwnership(file, user, group)) { if (!Utility::SetFileOwnership(file, user, group)) {
Log(LogWarning, "cli") Log(LogWarning, "cli")
<< "Cannot set ownership for user '" << user << "' group '" << group << "' on file '" << file << "'."; << "Cannot set ownership for user '" << user << "' group '" << group << "' on file '" << file << "'.";
@ -201,9 +192,7 @@ bool ApiSetupUtility::SetupMasterEnableApi(void)
{ {
Log(LogInformation, "cli", "Enabling the 'api' feature."); Log(LogInformation, "cli", "Enabling the 'api' feature.");
std::vector<std::string> features; FeatureUtility::EnableFeatures({ "api" });
features.push_back("api");
FeatureUtility::EnableFeatures(features);
return true; return true;
} }

View File

@ -444,10 +444,7 @@ bool TroubleshootCommand::PrintFile(InfoLog& log, const String& path)
bool TroubleshootCommand::CheckConfig(void) bool TroubleshootCommand::CheckConfig(void)
{ {
std::vector<std::string> configs; return DaemonUtility::ValidateConfigFiles({ Application::GetSysconfDir() + "/icinga2/icinga2.conf" }, Application::GetObjectsPath());
configs.push_back(Application::GetSysconfDir() + "/icinga2/icinga2.conf");
return DaemonUtility::ValidateConfigFiles(configs, Application::GetObjectsPath());
} }
//print is supposed allow the user to print the object file //print is supposed allow the user to print the object file

View File

@ -634,8 +634,8 @@ void StatusDataWriter::UpdateObjectsCache(void)
for (const Service::Ptr& service : sg->GetMembers()) { for (const Service::Ptr& service : sg->GetMembers()) {
Host::Ptr host = service->GetHost(); Host::Ptr host = service->GetHost();
sglist.push_back(host->GetName()); sglist.emplace_back(host->GetName());
sglist.push_back(service->GetShortName()); sglist.emplace_back(service->GetShortName());
} }
DumpStringList(tempobjectfp, sglist); DumpStringList(tempobjectfp, sglist);
@ -734,15 +734,15 @@ void StatusDataWriter::UpdateObjectsCache(void)
int state_filter = dep->GetStateFilter(); int state_filter = dep->GetStateFilter();
std::vector<String> failure_criteria; std::vector<String> failure_criteria;
if (state_filter & StateFilterOK || state_filter & StateFilterUp) if (state_filter & StateFilterOK || state_filter & StateFilterUp)
failure_criteria.push_back("o"); failure_criteria.emplace_back("o");
if (state_filter & StateFilterWarning) if (state_filter & StateFilterWarning)
failure_criteria.push_back("w"); failure_criteria.emplace_back("w");
if (state_filter & StateFilterCritical) if (state_filter & StateFilterCritical)
failure_criteria.push_back("c"); failure_criteria.emplace_back("c");
if (state_filter & StateFilterUnknown) if (state_filter & StateFilterUnknown)
failure_criteria.push_back("u"); failure_criteria.emplace_back("u");
if (state_filter & StateFilterDown) if (state_filter & StateFilterDown)
failure_criteria.push_back("d"); failure_criteria.emplace_back("d");
String criteria = boost::algorithm::join(failure_criteria, ","); String criteria = boost::algorithm::join(failure_criteria, ",");

View File

@ -328,13 +328,13 @@ lterm_items_inner: lterm %dprec 2
{ {
$$ = new std::vector<std::pair<Expression *, EItemInfo> >(); $$ = new std::vector<std::pair<Expression *, EItemInfo> >();
EItemInfo info = { true, @1 }; EItemInfo info = { true, @1 };
$$->push_back(std::make_pair($1, info)); $$->emplace_back($1, info);
} }
| rterm_no_side_effect | rterm_no_side_effect
{ {
$$ = new std::vector<std::pair<Expression *, EItemInfo> >(); $$ = new std::vector<std::pair<Expression *, EItemInfo> >();
EItemInfo info = { false, @1 }; EItemInfo info = { false, @1 };
$$->push_back(std::make_pair($1, info)); $$->emplace_back($1, info);
} }
| lterm_items_inner sep lterm %dprec 1 | lterm_items_inner sep lterm %dprec 1
{ {
@ -345,7 +345,7 @@ lterm_items_inner: lterm %dprec 2
if ($3) { if ($3) {
EItemInfo info = { true, @3 }; EItemInfo info = { true, @3 };
$$->push_back(std::make_pair($3, info)); $$->emplace_back($3, info);
} }
} }
| lterm_items_inner sep rterm_no_side_effect %dprec 1 | lterm_items_inner sep rterm_no_side_effect %dprec 1
@ -357,7 +357,7 @@ lterm_items_inner: lterm %dprec 2
if ($3) { if ($3) {
EItemInfo info = { false, @3 }; EItemInfo info = { false, @3 };
$$->push_back(std::make_pair($3, info)); $$->emplace_back($3, info);
} }
} }
; ;

View File

@ -404,7 +404,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
if (kv2.second->m_ActivationContext != context) if (kv2.second->m_ActivationContext != context)
continue; continue;
items.push_back(std::make_pair(kv2.second, false)); items.emplace_back(kv2.second, false);
} }
} }
@ -419,7 +419,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
if (item->m_Abstract || item->m_Object) if (item->m_Abstract || item->m_Object)
continue; continue;
items.push_back(std::make_pair(item, true)); items.emplace_back(item, true);
} }
m_UnnamedItems.swap(newUnnamedItems); m_UnnamedItems.swap(newUnnamedItems);

View File

@ -102,7 +102,7 @@ public:
static inline Value FunctionCall(ScriptFrame& frame, const Value& self, const Function::Ptr& func, const std::vector<Value>& arguments) static inline Value FunctionCall(ScriptFrame& frame, const Value& self, const Function::Ptr& func, const std::vector<Value>& arguments)
{ {
if (!self.IsEmpty() || self.IsString()) if (!self.IsEmpty() || self.IsString())
return func->Invoke(self, arguments); return func->InvokeThis(self, arguments);
else else
return func->Invoke(arguments); return func->Invoke(arguments);

View File

@ -181,13 +181,12 @@ void DbConnection::UpdateProgramStatus(void)
query1.Fields->Set("process_performance_data", (IcingaApplication::GetInstance()->GetEnablePerfdata() ? 1 : 0)); query1.Fields->Set("process_performance_data", (IcingaApplication::GetInstance()->GetEnablePerfdata() ? 1 : 0));
query1.WhereCriteria = new Dictionary(); query1.WhereCriteria = new Dictionary();
query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
query1.Priority = PriorityHigh; query1.Priority = PriorityHigh;
queries.push_back(query1); queries.emplace_back(std::move(query1));
DbQuery query2; DbQuery query2;
query2.Type = DbQueryNewTransaction; query2.Type = DbQueryNewTransaction;
queries.push_back(query2); queries.emplace_back(std::move(query2));
DbObject::OnMultipleQueries(queries); DbObject::OnMultipleQueries(queries);

View File

@ -383,8 +383,7 @@ void DbEvents::AddCommentInternal(std::vector<DbQuery>& queries, const Comment::
} }
query1.Category = DbCatComment; query1.Category = DbCatComment;
query1.Fields = fields1; query1.Fields = fields1;
queries.emplace_back(std::move(query1));
queries.push_back(query1);
} }
void DbEvents::RemoveComment(const Comment::Ptr& comment) void DbEvents::RemoveComment(const Comment::Ptr& comment)
@ -409,7 +408,7 @@ void DbEvents::RemoveCommentInternal(std::vector<DbQuery>& queries, const Commen
query1.WhereCriteria->Set("object_id", checkable); query1.WhereCriteria->Set("object_id", checkable);
query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time)); query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time));
query1.WhereCriteria->Set("name", comment->GetName()); query1.WhereCriteria->Set("name", comment->GetName());
queries.push_back(query1); queries.emplace_back(std::move(query1));
/* History - update deletion time for service/host */ /* History - update deletion time for service/host */
double now = Utility::GetTime(); double now = Utility::GetTime();
@ -429,7 +428,7 @@ void DbEvents::RemoveCommentInternal(std::vector<DbQuery>& queries, const Commen
query2.WhereCriteria->Set("object_id", checkable); query2.WhereCriteria->Set("object_id", checkable);
query2.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time)); query2.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time));
query2.WhereCriteria->Set("name", comment->GetName()); query2.WhereCriteria->Set("name", comment->GetName());
queries.push_back(query2); queries.emplace_back(std::move(query2));
} }
/* downtimes */ /* downtimes */
@ -526,8 +525,7 @@ void DbEvents::AddDowntimeInternal(std::vector<DbQuery>& queries, const Downtime
query1.Category = DbCatDowntime; query1.Category = DbCatDowntime;
query1.Fields = fields1; query1.Fields = fields1;
queries.emplace_back(std::move(query1));
queries.push_back(query1);
/* host/service status */ /* host/service status */
if (!historical) { if (!historical) {
@ -558,8 +556,7 @@ void DbEvents::AddDowntimeInternal(std::vector<DbQuery>& queries, const Downtime
query2.WhereCriteria->Set("host_object_id", host); query2.WhereCriteria->Set("host_object_id", host);
query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
queries.emplace_back(std::move(query2));
queries.push_back(query2);
} }
} }
@ -587,7 +584,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector<DbQuery>& queries, const Downt
query1.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime())); query1.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
query1.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime())); query1.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
query1.WhereCriteria->Set("name", downtime->GetName()); query1.WhereCriteria->Set("name", downtime->GetName());
queries.push_back(query1); queries.emplace_back(std::move(query1));
/* History - update actual_end_time, was_cancelled for service (and host in case) */ /* History - update actual_end_time, was_cancelled for service (and host in case) */
double now = Utility::GetTime(); double now = Utility::GetTime();
@ -616,8 +613,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector<DbQuery>& queries, const Downt
query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime())); query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime())); query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
query3.WhereCriteria->Set("name", downtime->GetName()); query3.WhereCriteria->Set("name", downtime->GetName());
queries.emplace_back(std::move(query3));
queries.push_back(query3);
/* host/service status */ /* host/service status */
Host::Ptr host; Host::Ptr host;
@ -647,8 +643,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector<DbQuery>& queries, const Downt
query4.WhereCriteria->Set("host_object_id", host); query4.WhereCriteria->Set("host_object_id", host);
query4.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ query4.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
queries.emplace_back(std::move(query4));
queries.push_back(query4);
} }
void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime)
@ -908,7 +903,7 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con
fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */ fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */
query2.Fields = fields2; query2.Fields = fields2;
queries.push_back(query2); queries.emplace_back(std::move(query2));
} }
DbObject::OnMultipleQueries(queries); DbObject::OnMultipleQueries(queries);

View File

@ -217,8 +217,7 @@ void DbObject::SendVarsConfigUpdateHeavy(void)
query1.Category = DbCatConfig; query1.Category = DbCatConfig;
query1.WhereCriteria = new Dictionary(); query1.WhereCriteria = new Dictionary();
query1.WhereCriteria->Set("object_id", obj); query1.WhereCriteria->Set("object_id", obj);
queries.emplace_back(std::move(query1));
queries.push_back(query1);
DbQuery query2; DbQuery query2;
query2.Table = "customvariablestatus"; query2.Table = "customvariablestatus";
@ -226,8 +225,7 @@ void DbObject::SendVarsConfigUpdateHeavy(void)
query2.Category = DbCatConfig; query2.Category = DbCatConfig;
query2.WhereCriteria = new Dictionary(); query2.WhereCriteria = new Dictionary();
query2.WhereCriteria->Set("object_id", obj); query2.WhereCriteria->Set("object_id", obj);
queries.emplace_back(std::move(query2));
queries.push_back(query2);
Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(custom_var_object); Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(custom_var_object);
@ -260,8 +258,7 @@ void DbObject::SendVarsConfigUpdateHeavy(void)
query3.Type = DbQueryInsert; query3.Type = DbQueryInsert;
query3.Category = DbCatConfig; query3.Category = DbCatConfig;
query3.Fields = fields; query3.Fields = fields;
queries.emplace_back(std::move(query3));
queries.push_back(query3);
} }
} }
@ -313,8 +310,7 @@ void DbObject::SendVarsStatusUpdate(void)
query.WhereCriteria = new Dictionary(); query.WhereCriteria = new Dictionary();
query.WhereCriteria->Set("object_id", obj); query.WhereCriteria->Set("object_id", obj);
query.WhereCriteria->Set("varname", kv.first); query.WhereCriteria->Set("varname", kv.first);
queries.emplace_back(std::move(query));
queries.push_back(query);
} }
OnMultipleQueries(queries); OnMultipleQueries(queries);

View File

@ -191,8 +191,7 @@ void HostDbObject::OnConfigUpdateHeavy(void)
query1.Category = DbCatConfig; query1.Category = DbCatConfig;
query1.WhereCriteria = new Dictionary(); query1.WhereCriteria = new Dictionary();
query1.WhereCriteria->Set("host_object_id", host); query1.WhereCriteria->Set("host_object_id", host);
queries.emplace_back(std::move(query1));
queries.push_back(query1);
if (groups) { if (groups) {
ObjectLock olock(groups); ObjectLock olock(groups);
@ -211,8 +210,7 @@ void HostDbObject::OnConfigUpdateHeavy(void)
query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
query2.WhereCriteria->Set("hostgroup_id", DbValue::FromObjectInsertID(group)); query2.WhereCriteria->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
query2.WhereCriteria->Set("host_object_id", host); query2.WhereCriteria->Set("host_object_id", host);
queries.emplace_back(std::move(query2));
queries.push_back(query2);
} }
} }
@ -226,8 +224,7 @@ void HostDbObject::OnConfigUpdateHeavy(void)
query2.Category = DbCatConfig; query2.Category = DbCatConfig;
query2.WhereCriteria = new Dictionary(); query2.WhereCriteria = new Dictionary();
query2.WhereCriteria->Set(GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject())); query2.WhereCriteria->Set(GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject()));
queries.emplace_back(std::move(query2));
queries.push_back(query2);
/* parents */ /* parents */
for (const Checkable::Ptr& checkable : host->GetParents()) { for (const Checkable::Ptr& checkable : host->GetParents()) {
@ -250,8 +247,7 @@ void HostDbObject::OnConfigUpdateHeavy(void)
query1.Type = DbQueryInsert; query1.Type = DbQueryInsert;
query1.Category = DbCatConfig; query1.Category = DbCatConfig;
query1.Fields = fields1; query1.Fields = fields1;
queries.emplace_back(std::move(query1));
queries.push_back(query1);
} }
DbObject::OnMultipleQueries(queries); DbObject::OnMultipleQueries(queries);
@ -268,8 +264,7 @@ void HostDbObject::OnConfigUpdateHeavy(void)
query3.Category = DbCatConfig; query3.Category = DbCatConfig;
query3.WhereCriteria = new Dictionary(); query3.WhereCriteria = new Dictionary();
query3.WhereCriteria->Set("dependent_host_object_id", host); query3.WhereCriteria->Set("dependent_host_object_id", host);
queries.emplace_back(std::move(query3));
queries.push_back(query3);
for (const Dependency::Ptr& dep : host->GetDependencies()) { for (const Dependency::Ptr& dep : host->GetDependencies()) {
Checkable::Ptr parent = dep->GetParent(); Checkable::Ptr parent = dep->GetParent();
@ -299,8 +294,7 @@ void HostDbObject::OnConfigUpdateHeavy(void)
query2.Type = DbQueryInsert; query2.Type = DbQueryInsert;
query2.Category = DbCatConfig; query2.Category = DbCatConfig;
query2.Fields = fields2; query2.Fields = fields2;
queries.emplace_back(std::move(query2));
queries.push_back(query2);
} }
DbObject::OnMultipleQueries(queries); DbObject::OnMultipleQueries(queries);
@ -316,8 +310,7 @@ void HostDbObject::OnConfigUpdateHeavy(void)
query4.Category = DbCatConfig; query4.Category = DbCatConfig;
query4.WhereCriteria = new Dictionary(); query4.WhereCriteria = new Dictionary();
query4.WhereCriteria->Set("host_id", DbValue::FromObjectInsertID(host)); query4.WhereCriteria->Set("host_id", DbValue::FromObjectInsertID(host));
queries.emplace_back(std::move(query4));
queries.push_back(query4);
for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(host)) { for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(host)) {
Log(LogDebug, "HostDbObject") Log(LogDebug, "HostDbObject")
@ -333,8 +326,7 @@ void HostDbObject::OnConfigUpdateHeavy(void)
query_contact.Type = DbQueryInsert; query_contact.Type = DbQueryInsert;
query_contact.Category = DbCatConfig; query_contact.Category = DbCatConfig;
query_contact.Fields = fields_contact; query_contact.Fields = fields_contact;
queries.emplace_back(std::move(query_contact));
queries.push_back(query_contact);
} }
DbObject::OnMultipleQueries(queries); DbObject::OnMultipleQueries(queries);
@ -350,8 +342,7 @@ void HostDbObject::OnConfigUpdateHeavy(void)
query5.Category = DbCatConfig; query5.Category = DbCatConfig;
query5.WhereCriteria = new Dictionary(); query5.WhereCriteria = new Dictionary();
query5.WhereCriteria->Set("host_id", DbValue::FromObjectInsertID(host)); query5.WhereCriteria->Set("host_id", DbValue::FromObjectInsertID(host));
queries.emplace_back(std::move(query5));
queries.push_back(query5);
for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(host)) { for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(host)) {
Log(LogDebug, "HostDbObject") Log(LogDebug, "HostDbObject")
@ -367,8 +358,7 @@ void HostDbObject::OnConfigUpdateHeavy(void)
query_contact.Type = DbQueryInsert; query_contact.Type = DbQueryInsert;
query_contact.Category = DbCatConfig; query_contact.Category = DbCatConfig;
query_contact.Fields = fields_contact; query_contact.Fields = fields_contact;
queries.emplace_back(std::move(query_contact));
queries.push_back(query_contact);
} }
DbObject::OnMultipleQueries(queries); DbObject::OnMultipleQueries(queries);

View File

@ -46,10 +46,10 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers;
if (service) if (service)
resolvers.push_back(std::make_pair("service", service)); resolvers.emplace_back("service", service);
resolvers.push_back(std::make_pair("host", host)); resolvers.emplace_back("host", host);
resolvers.push_back(std::make_pair("command", commandObj)); resolvers.emplace_back("command", commandObj);
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
String idoType = MacroProcessor::ResolveMacros("$ido_type$", resolvers, checkable->GetLastCheckResult(), String idoType = MacroProcessor::ResolveMacros("$ido_type$", resolvers, checkable->GetLastCheckResult(),
NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);

View File

@ -185,8 +185,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void)
query1.Category = DbCatConfig; query1.Category = DbCatConfig;
query1.WhereCriteria = new Dictionary(); query1.WhereCriteria = new Dictionary();
query1.WhereCriteria->Set("service_object_id", service); query1.WhereCriteria->Set("service_object_id", service);
queries.emplace_back(std::move(query1));
queries.push_back(query1);
if (groups) { if (groups) {
ObjectLock olock(groups); ObjectLock olock(groups);
@ -205,8 +204,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void)
query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
query2.WhereCriteria->Set("servicegroup_id", DbValue::FromObjectInsertID(group)); query2.WhereCriteria->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
query2.WhereCriteria->Set("service_object_id", service); query2.WhereCriteria->Set("service_object_id", service);
queries.emplace_back(std::move(query2));
queries.push_back(query2);
} }
} }
@ -224,8 +222,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void)
query2.Category = DbCatConfig; query2.Category = DbCatConfig;
query2.WhereCriteria = new Dictionary(); query2.WhereCriteria = new Dictionary();
query2.WhereCriteria->Set("dependent_service_object_id", service); query2.WhereCriteria->Set("dependent_service_object_id", service);
queries.emplace_back(std::move(query2));
queries.push_back(query2);
for (const Dependency::Ptr& dep : service->GetDependencies()) { for (const Dependency::Ptr& dep : service->GetDependencies()) {
Checkable::Ptr parent = dep->GetParent(); Checkable::Ptr parent = dep->GetParent();
@ -258,8 +255,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void)
query1.Type = DbQueryInsert; query1.Type = DbQueryInsert;
query1.Category = DbCatConfig; query1.Category = DbCatConfig;
query1.Fields = fields1; query1.Fields = fields1;
queries.emplace_back(std::move(query1));
queries.push_back(query1);
} }
DbObject::OnMultipleQueries(queries); DbObject::OnMultipleQueries(queries);
@ -276,8 +272,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void)
query3.Category = DbCatConfig; query3.Category = DbCatConfig;
query3.WhereCriteria = new Dictionary(); query3.WhereCriteria = new Dictionary();
query3.WhereCriteria->Set("service_id", DbValue::FromObjectInsertID(service)); query3.WhereCriteria->Set("service_id", DbValue::FromObjectInsertID(service));
queries.emplace_back(std::move(query3));
queries.push_back(query3);
for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(service)) { for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(service)) {
Log(LogDebug, "ServiceDbObject") Log(LogDebug, "ServiceDbObject")
@ -293,8 +288,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void)
query_contact.Type = DbQueryInsert; query_contact.Type = DbQueryInsert;
query_contact.Category = DbCatConfig; query_contact.Category = DbCatConfig;
query_contact.Fields = fields_contact; query_contact.Fields = fields_contact;
queries.emplace_back(std::move(query_contact));
queries.push_back(query_contact);
} }
DbObject::OnMultipleQueries(queries); DbObject::OnMultipleQueries(queries);
@ -310,8 +304,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void)
query4.Category = DbCatConfig; query4.Category = DbCatConfig;
query4.WhereCriteria = new Dictionary(); query4.WhereCriteria = new Dictionary();
query4.WhereCriteria->Set("service_id", DbValue::FromObjectInsertID(service)); query4.WhereCriteria->Set("service_id", DbValue::FromObjectInsertID(service));
queries.emplace_back(std::move(query4));
queries.push_back(query4);
for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(service)) { for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(service)) {
Log(LogDebug, "ServiceDbObject") Log(LogDebug, "ServiceDbObject")
@ -327,8 +320,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void)
query_contact.Type = DbQueryInsert; query_contact.Type = DbQueryInsert;
query_contact.Category = DbCatConfig; query_contact.Category = DbCatConfig;
query_contact.Fields = fields_contact; query_contact.Fields = fields_contact;
queries.emplace_back(std::move(query_contact));
queries.push_back(query_contact);
} }
DbObject::OnMultipleQueries(queries); DbObject::OnMultipleQueries(queries);

View File

@ -94,8 +94,7 @@ void UserDbObject::OnConfigUpdateHeavy(void)
query1.Category = DbCatConfig; query1.Category = DbCatConfig;
query1.WhereCriteria = new Dictionary(); query1.WhereCriteria = new Dictionary();
query1.WhereCriteria->Set("contact_object_id", user); query1.WhereCriteria->Set("contact_object_id", user);
queries.emplace_back(std::move(query1));
queries.push_back(query1);
if (groups) { if (groups) {
ObjectLock olock(groups); ObjectLock olock(groups);
@ -114,8 +113,7 @@ void UserDbObject::OnConfigUpdateHeavy(void)
query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
query2.WhereCriteria->Set("contactgroup_id", DbValue::FromObjectInsertID(group)); query2.WhereCriteria->Set("contactgroup_id", DbValue::FromObjectInsertID(group));
query2.WhereCriteria->Set("contact_object_id", user); query2.WhereCriteria->Set("contact_object_id", user);
queries.emplace_back(std::move(query2));
queries.push_back(query2);
} }
} }
@ -129,8 +127,7 @@ void UserDbObject::OnConfigUpdateHeavy(void)
query2.Category = DbCatConfig; query2.Category = DbCatConfig;
query2.WhereCriteria = new Dictionary(); query2.WhereCriteria = new Dictionary();
query2.WhereCriteria->Set("contact_id", DbValue::FromObjectInsertID(user)); query2.WhereCriteria->Set("contact_id", DbValue::FromObjectInsertID(user));
queries.emplace_back(std::move(query2));
queries.push_back(query2);
Dictionary::Ptr vars = user->GetVars(); Dictionary::Ptr vars = user->GetVars();
@ -155,8 +152,7 @@ void UserDbObject::OnConfigUpdateHeavy(void)
query.Table = "contact_addresses"; query.Table = "contact_addresses";
query.Category = DbCatConfig; query.Category = DbCatConfig;
query.Fields = fields; query.Fields = fields;
queries.emplace_back(std::move(query));
queries.push_back(query);
} }
} }

View File

@ -420,7 +420,7 @@ void IdoMysqlConnection::Reconnect(void)
SetObjectActive(dbobj, active); SetObjectActive(dbobj, active);
if (active) if (active)
activeDbObjs.push_back(dbobj); activeDbObjs.emplace_back(std::move(dbobj));
} }
SetIDCacheValid(true); SetIDCacheValid(true);
@ -489,7 +489,7 @@ void IdoMysqlConnection::AsyncQuery(const String& query, const std::function<voi
* See https://github.com/Icinga/icinga2/issues/4603 for details. * See https://github.com/Icinga/icinga2/issues/4603 for details.
*/ */
aq.Callback = callback; aq.Callback = callback;
m_AsyncQueries.push_back(aq); m_AsyncQueries.emplace_back(std::move(aq));
if (m_AsyncQueries.size() > 25000) { if (m_AsyncQueries.size() > 25000) {
FinishAsyncQueries(); FinishAsyncQueries();

View File

@ -28,10 +28,10 @@ REGISTER_TYPE(CheckCommand);
void CheckCommand::Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, void CheckCommand::Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
{ {
std::vector<Value> arguments; GetExecute()->Invoke({
arguments.push_back(checkable); checkable,
arguments.push_back(cr); cr,
arguments.push_back(resolvedMacros); resolvedMacros,
arguments.push_back(useResolvedMacros); useResolvedMacros
GetExecute()->Invoke(arguments); });
} }

View File

@ -27,9 +27,9 @@ REGISTER_TYPE(EventCommand);
void EventCommand::Execute(const Checkable::Ptr& checkable, void EventCommand::Execute(const Checkable::Ptr& checkable,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
{ {
std::vector<Value> arguments; GetExecute()->Invoke({
arguments.push_back(checkable); checkable,
arguments.push_back(resolvedMacros); resolvedMacros,
arguments.push_back(useResolvedMacros); useResolvedMacros
GetExecute()->Invoke(arguments); });
} }

View File

@ -222,8 +222,7 @@ Value MacroProcessor::EvaluateFunction(const Function::Ptr& func, const Resolver
_1, std::cref(resolvers), cr, resolvedMacros, useResolvedMacros, _1, std::cref(resolvers), cr, resolvedMacros, useResolvedMacros,
recursionLevel + 1))); recursionLevel + 1)));
std::vector<Value> args; return func->InvokeThis(resolvers_this);
return func->Invoke(resolvers_this, args);
} }
Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverList& resolvers, Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverList& resolvers,
@ -542,7 +541,7 @@ Value MacroProcessor::ResolveArguments(const Value& command, const Dictionary::P
continue; continue;
} }
args.push_back(arg); args.emplace_back(std::move(arg));
} }
std::sort(args.begin(), args.end()); std::sort(args.begin(), args.end());

View File

@ -29,14 +29,14 @@ Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notificati
const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros, const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros,
bool useResolvedMacros) bool useResolvedMacros)
{ {
std::vector<Value> arguments; return GetExecute()->Invoke({
arguments.push_back(notification); notification,
arguments.push_back(user); user,
arguments.push_back(cr); cr,
arguments.push_back(type); type,
arguments.push_back(author); author,
arguments.push_back(comment); comment,
arguments.push_back(resolvedMacros); resolvedMacros,
arguments.push_back(useResolvedMacros); useResolvedMacros,
return GetExecute()->Invoke(arguments); });
} }

View File

@ -244,12 +244,7 @@ void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting)
return; return;
} }
std::vector<Value> arguments; Array::Ptr segments = GetUpdate()->Invoke({ this, begin, end });
arguments.push_back(this);
arguments.push_back(begin);
arguments.push_back(end);
Array::Ptr segments = GetUpdate()->Invoke(arguments);
{ {
ObjectLock olock(this); ObjectLock olock(this);

View File

@ -323,9 +323,10 @@ Value HostsTable::NotesExpandedAccessor(const Value& row)
if (!host) if (!host)
return Empty; return Empty;
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers {
resolvers.push_back(std::make_pair("host", host)); { "host", host },
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); { "icinga", IcingaApplication::GetInstance() }
};
return MacroProcessor::ResolveMacros(host->GetNotes(), resolvers, CheckResult::Ptr()); return MacroProcessor::ResolveMacros(host->GetNotes(), resolvers, CheckResult::Ptr());
} }
@ -347,9 +348,10 @@ Value HostsTable::NotesUrlExpandedAccessor(const Value& row)
if (!host) if (!host)
return Empty; return Empty;
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers {
resolvers.push_back(std::make_pair("host", host)); { "host", host },
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); { "icinga", IcingaApplication::GetInstance() }
};
return MacroProcessor::ResolveMacros(host->GetNotesUrl(), resolvers); return MacroProcessor::ResolveMacros(host->GetNotesUrl(), resolvers);
} }
@ -371,9 +373,10 @@ Value HostsTable::ActionUrlExpandedAccessor(const Value& row)
if (!host) if (!host)
return Empty; return Empty;
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers {
resolvers.push_back(std::make_pair("host", host)); { "host", host },
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); { "icinga", IcingaApplication::GetInstance() }
};
return MacroProcessor::ResolveMacros(host->GetActionUrl(), resolvers); return MacroProcessor::ResolveMacros(host->GetActionUrl(), resolvers);
} }
@ -427,9 +430,10 @@ Value HostsTable::IconImageExpandedAccessor(const Value& row)
if (!host) if (!host)
return Empty; return Empty;
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers {
resolvers.push_back(std::make_pair("host", host)); { "host", host },
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); { "icinga", IcingaApplication::GetInstance() }
};
return MacroProcessor::ResolveMacros(host->GetIconImage(), resolvers); return MacroProcessor::ResolveMacros(host->GetIconImage(), resolvers);
} }

View File

@ -309,12 +309,12 @@ Filter::Ptr LivestatusQuery::ParseFilter(const String& params, unsigned long& fr
break; break;
} }
tokens.push_back(temp_buffer.SubStr(0, sp_index)); tokens.emplace_back(temp_buffer.SubStr(0, sp_index));
temp_buffer = temp_buffer.SubStr(sp_index + 1); temp_buffer = temp_buffer.SubStr(sp_index + 1);
} }
/* add the rest as value */ /* add the rest as value */
tokens.push_back(temp_buffer); tokens.emplace_back(std::move(temp_buffer));
if (tokens.size() == 2) if (tokens.size() == 2)
tokens.push_back(""); tokens.push_back("");
@ -490,7 +490,7 @@ void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream)
column_objs.reserve(columns.size()); column_objs.reserve(columns.size());
for (const String& columnName : columns) for (const String& columnName : columns)
column_objs.push_back(std::make_pair(columnName, table->GetColumn(columnName))); column_objs.emplace_back(columnName, table->GetColumn(columnName));
for (const LivestatusRowValue& object : objects) { for (const LivestatusRowValue& object : objects) {
Array::Ptr row = new Array(); Array::Ptr row = new Array();
@ -520,7 +520,7 @@ void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream)
for (const String& columnName : m_Columns) { for (const String& columnName : m_Columns) {
Column column = table->GetColumn(columnName); Column column = table->GetColumn(columnName);
statsKey.push_back(column.ExtractValue(object.Row, object.GroupByType, object.GroupByObject)); statsKey.emplace_back(column.ExtractValue(object.Row, object.GroupByType, object.GroupByObject));
} }
auto it = allStats.find(statsKey); auto it = allStats.find(statsKey);

View File

@ -375,10 +375,11 @@ Value ServicesTable::NotesExpandedAccessor(const Value& row)
if (!service) if (!service)
return Empty; return Empty;
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers {
resolvers.push_back(std::make_pair("service", service)); { "service", service },
resolvers.push_back(std::make_pair("host", service->GetHost())); { "host", service->GetHost() },
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); { "icinga", IcingaApplication::GetInstance() }
};
return MacroProcessor::ResolveMacros(service->GetNotes(), resolvers); return MacroProcessor::ResolveMacros(service->GetNotes(), resolvers);
} }
@ -400,10 +401,11 @@ Value ServicesTable::NotesUrlExpandedAccessor(const Value& row)
if (!service) if (!service)
return Empty; return Empty;
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers {
resolvers.push_back(std::make_pair("service", service)); { "service", service },
resolvers.push_back(std::make_pair("host", service->GetHost())); { "host", service->GetHost() },
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); { "icinga", IcingaApplication::GetInstance() }
};
return MacroProcessor::ResolveMacros(service->GetNotesUrl(), resolvers); return MacroProcessor::ResolveMacros(service->GetNotesUrl(), resolvers);
} }
@ -425,10 +427,11 @@ Value ServicesTable::ActionUrlExpandedAccessor(const Value& row)
if (!service) if (!service)
return Empty; return Empty;
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers {
resolvers.push_back(std::make_pair("service", service)); { "service", service },
resolvers.push_back(std::make_pair("host", service->GetHost())); { "host", service->GetHost() },
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); { "icinga", IcingaApplication::GetInstance() }
};
return MacroProcessor::ResolveMacros(service->GetActionUrl(), resolvers); return MacroProcessor::ResolveMacros(service->GetActionUrl(), resolvers);
} }
@ -450,10 +453,11 @@ Value ServicesTable::IconImageExpandedAccessor(const Value& row)
if (!service) if (!service)
return Empty; return Empty;
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers {
resolvers.push_back(std::make_pair("service", service)); { "service", service },
resolvers.push_back(std::make_pair("host", service->GetHost())); { "host", service->GetHost() },
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); { "icinga", IcingaApplication::GetInstance() }
};
return MacroProcessor::ResolveMacros(service->GetIconImage(), resolvers); return MacroProcessor::ResolveMacros(service->GetIconImage(), resolvers);
} }

View File

@ -144,8 +144,7 @@ bool Table::FilteredAddRow(std::vector<LivestatusRowValue>& rs, const Filter::Pt
rval.GroupByType = groupByType; rval.GroupByType = groupByType;
rval.GroupByObject = groupByObject; rval.GroupByObject = groupByObject;
rs.push_back(rval); rs.emplace_back(std::move(rval));
} }
return true; return true;

View File

@ -156,10 +156,10 @@ void ClrCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers;
if (service) if (service)
resolvers.push_back(std::make_pair("service", service)); resolvers.emplace_back("service", service);
resolvers.push_back(std::make_pair("host", host)); resolvers.emplace_back("host", host);
resolvers.push_back(std::make_pair("command", commandObj)); resolvers.emplace_back("command", commandObj);
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
Dictionary::Ptr envMacros = new Dictionary(); Dictionary::Ptr envMacros = new Dictionary();

View File

@ -52,10 +52,10 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers;
if (service) if (service)
resolvers.push_back(std::make_pair("service", service)); resolvers.emplace_back("service", service);
resolvers.push_back(std::make_pair("host", host)); resolvers.emplace_back("host", host);
resolvers.push_back(std::make_pair("command", commandObj)); resolvers.emplace_back("command", commandObj);
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
String zoneName = MacroProcessor::ResolveMacros("$cluster_zone$", resolvers, checkable->GetLastCheckResult(), String zoneName = MacroProcessor::ResolveMacros("$cluster_zone$", resolvers, checkable->GetLastCheckResult(),
NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);

View File

@ -44,10 +44,10 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers;
if (service) if (service)
resolvers.push_back(std::make_pair("service", service)); resolvers.emplace_back("service", service);
resolvers.push_back(std::make_pair("host", host)); resolvers.emplace_back("host", host);
resolvers.push_back(std::make_pair("command", commandObj)); resolvers.emplace_back("command", commandObj);
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
int dummyState = MacroProcessor::ResolveMacros("$dummy_state$", resolvers, checkable->GetLastCheckResult(), int dummyState = MacroProcessor::ResolveMacros("$dummy_state$", resolvers, checkable->GetLastCheckResult(),
NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);

View File

@ -46,10 +46,10 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers;
if (service) if (service)
resolvers.push_back(std::make_pair("service", service)); resolvers.emplace_back("service", service);
resolvers.push_back(std::make_pair("host", host)); resolvers.emplace_back("host", host);
resolvers.push_back(std::make_pair("command", commandObj)); resolvers.emplace_back("command", commandObj);
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(),
resolvers, resolvedMacros, useResolvedMacros, resolvers, resolvedMacros, useResolvedMacros,

View File

@ -44,10 +44,10 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable,
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers;
if (service) if (service)
resolvers.push_back(std::make_pair("service", service)); resolvers.emplace_back("service", service);
resolvers.push_back(std::make_pair("host", host)); resolvers.emplace_back("host", host);
resolvers.push_back(std::make_pair("command", commandObj)); resolvers.emplace_back("command", commandObj);
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(),
resolvers, resolvedMacros, useResolvedMacros, resolvers, resolvedMacros, useResolvedMacros,

View File

@ -55,14 +55,14 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification,
tie(host, service) = GetHostService(checkable); tie(host, service) = GetHostService(checkable);
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers;
resolvers.push_back(std::make_pair("user", user)); resolvers.emplace_back("user", user);
resolvers.push_back(std::make_pair("notification", notificationExtra)); resolvers.emplace_back("notification", notificationExtra);
resolvers.push_back(std::make_pair("notification", notification)); resolvers.emplace_back("notification", notification);
if (service) if (service)
resolvers.push_back(std::make_pair("service", service)); resolvers.emplace_back("service", service);
resolvers.push_back(std::make_pair("host", host)); resolvers.emplace_back("host", host);
resolvers.push_back(std::make_pair("command", commandObj)); resolvers.emplace_back("command", commandObj);
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
PluginUtility::ExecuteCommand(commandObj, checkable, cr, resolvers, PluginUtility::ExecuteCommand(commandObj, checkable, cr, resolvers,
resolvedMacros, useResolvedMacros, resolvedMacros, useResolvedMacros,

View File

@ -363,7 +363,7 @@ void ElasticsearchWriter::Enqueue(String type, const Dictionary::Ptr& fields, do
Log(LogDebug, "ElasticsearchWriter") Log(LogDebug, "ElasticsearchWriter")
<< "Add to fields to message list: '" << fieldsBody << "'."; << "Add to fields to message list: '" << fieldsBody << "'.";
m_DataBuffer.push_back(indexBody + fieldsBody); m_DataBuffer.emplace_back(indexBody + fieldsBody);
/* Flush if we've buffered too much to prevent excessive memory use. */ /* Flush if we've buffered too much to prevent excessive memory use. */
if (static_cast<int>(m_DataBuffer.size()) >= GetFlushThreshold()) { if (static_cast<int>(m_DataBuffer.size()) >= GetFlushThreshold()) {
@ -412,10 +412,10 @@ void ElasticsearchWriter::SendRequest(const String& body)
/* Specify the index path. Best practice is a daily rotation. /* Specify the index path. Best practice is a daily rotation.
* Example: http://localhost:9200/icinga2-2017.09.11?pretty=1 * Example: http://localhost:9200/icinga2-2017.09.11?pretty=1
*/ */
path.push_back(GetIndex() + "-" + Utility::FormatDateTime("%Y.%m.%d", Utility::GetTime())); path.emplace_back(GetIndex() + "-" + Utility::FormatDateTime("%Y.%m.%d", Utility::GetTime()));
/* Use the bulk message format. */ /* Use the bulk message format. */
path.push_back("_bulk"); path.emplace_back("_bulk");
url->SetPath(path); url->SetPath(path);

View File

@ -199,9 +199,9 @@ void GraphiteWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable,
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers;
if (service) if (service)
resolvers.push_back(std::make_pair("service", service)); resolvers.emplace_back("service", service);
resolvers.push_back(std::make_pair("host", host)); resolvers.emplace_back("host", host);
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
String prefix; String prefix;

View File

@ -194,9 +194,9 @@ void InfluxdbWriter::InternalCheckResultHandler(const Checkable::Ptr& checkable,
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers;
if (service) if (service)
resolvers.push_back(std::make_pair("service", service)); resolvers.emplace_back("service", service);
resolvers.push_back(std::make_pair("host", host)); resolvers.emplace_back("host", host);
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
String prefix; String prefix;

View File

@ -100,9 +100,9 @@ void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
MacroProcessor::ResolverList resolvers; MacroProcessor::ResolverList resolvers;
if (service) if (service)
resolvers.push_back(std::make_pair("service", service)); resolvers.emplace_back("service", service);
resolvers.push_back(std::make_pair("host", host)); resolvers.emplace_back("host", host);
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
if (service) { if (service) {
String line = MacroProcessor::ResolveMacros(GetServiceFormatTemplate(), resolvers, cr, NULL, &PerfdataWriter::EscapeMacroMetric); String line = MacroProcessor::ResolveMacros(GetServiceFormatTemplate(), resolvers, cr, NULL, &PerfdataWriter::EscapeMacroMetric);

View File

@ -87,7 +87,7 @@ void ApiClient::TypesHttpCompletionCallback(HttpRequest& request, HttpResponse&
type->Name = typeInfo->Get("name"); type->Name = typeInfo->Get("name");
type->PluralName = typeInfo->Get("plural_name"); type->PluralName = typeInfo->Get("plural_name");
// TODO: attributes // TODO: attributes
types.push_back(type); types.emplace_back(std::move(type));
} }
callback(boost::exception_ptr(), types); callback(boost::exception_ptr(), types);
@ -204,7 +204,7 @@ void ApiClient::ObjectsHttpCompletionCallback(HttpRequest& request,
ApiObjectReference ref; ApiObjectReference ref;
ref.Name = refInfo->Get("name"); ref.Name = refInfo->Get("name");
ref.Type = refInfo->Get("type"); ref.Type = refInfo->Get("type");
object->UsedBy.push_back(ref); object->UsedBy.emplace_back(std::move(ref));
} }
} }

View File

@ -758,7 +758,7 @@ void ApiListener::ApiReconnectTimerHandler(void)
std::vector<String> names; std::vector<String> names;
for (const Endpoint::Ptr& endpoint : ConfigType::GetObjectsByType<Endpoint>()) for (const Endpoint::Ptr& endpoint : ConfigType::GetObjectsByType<Endpoint>())
if (endpoint->GetConnected()) if (endpoint->GetConnected())
names.push_back(endpoint->GetName() + " (" + Convert::ToString(endpoint->GetClients().size()) + ")"); names.emplace_back(endpoint->GetName() + " (" + Convert::ToString(endpoint->GetClients().size()) + ")");
Log(LogNotice, "ApiListener") Log(LogNotice, "ApiListener")
<< "Connected endpoints: " << Utility::NaturalJoin(names); << "Connected endpoints: " << Utility::NaturalJoin(names);

View File

@ -66,8 +66,7 @@ std::vector<String> ConfigPackageUtility::GetPackages(void)
void ConfigPackageUtility::CollectDirNames(const String& path, std::vector<String>& dirs) void ConfigPackageUtility::CollectDirNames(const String& path, std::vector<String>& dirs)
{ {
String name = Utility::BaseName(path); dirs.emplace_back(Utility::BaseName(path));
dirs.push_back(name);
} }
bool ConfigPackageUtility::PackageExists(const String& name) bool ConfigPackageUtility::PackageExists(const String& name)
@ -279,7 +278,7 @@ void ConfigPackageUtility::CollectPaths(const String& path, std::vector<std::pai
<< boost::errinfo_errno(errno) << boost::errinfo_errno(errno)
<< boost::errinfo_file_name(path)); << boost::errinfo_file_name(path));
paths.push_back(std::make_pair(path, S_ISDIR(statbuf.st_mode))); paths.emplace_back(path, S_ISDIR(statbuf.st_mode));
#else /* _WIN32 */ #else /* _WIN32 */
struct _stat statbuf; struct _stat statbuf;
int rc = _stat(path.CStr(), &statbuf); int rc = _stat(path.CStr(), &statbuf);
@ -289,7 +288,7 @@ void ConfigPackageUtility::CollectPaths(const String& path, std::vector<std::pai
<< boost::errinfo_errno(errno) << boost::errinfo_errno(errno)
<< boost::errinfo_file_name(path)); << boost::errinfo_file_name(path));
paths.push_back(std::make_pair(path, ((statbuf.st_mode & S_IFMT) == S_IFDIR))); paths.emplace_back(path, ((statbuf.st_mode & S_IFMT) == S_IFDIR));
#endif /* _WIN32 */ #endif /* _WIN32 */
} }

View File

@ -212,7 +212,7 @@ std::vector<Value> FilterUtility::GetFilterTargets(const QueryDescription& qd, c
if (!FilterUtility::EvaluateFilter(permissionFrame, permissionFilter, target, variableName)) if (!FilterUtility::EvaluateFilter(permissionFrame, permissionFilter, target, variableName))
BOOST_THROW_EXCEPTION(ScriptError("Access denied to object '" + name + "' of type '" + type + "'")); BOOST_THROW_EXCEPTION(ScriptError("Access denied to object '" + name + "' of type '" + type + "'"));
result.push_back(target); result.emplace_back(std::move(target));
} }
attr = provider->GetPluralName(type); attr = provider->GetPluralName(type);
@ -228,7 +228,7 @@ std::vector<Value> FilterUtility::GetFilterTargets(const QueryDescription& qd, c
if (!FilterUtility::EvaluateFilter(permissionFrame, permissionFilter, target, variableName)) if (!FilterUtility::EvaluateFilter(permissionFrame, permissionFilter, target, variableName))
BOOST_THROW_EXCEPTION(ScriptError("Access denied to object '" + name + "' of type '" + type + "'")); BOOST_THROW_EXCEPTION(ScriptError("Access denied to object '" + name + "' of type '" + type + "'"));
result.push_back(target); result.emplace_back(std::move(target));
} }
} }
} }

View File

@ -169,7 +169,7 @@ std::shared_ptr<HttpRequest> HttpClientConnection::NewRequest(void)
void HttpClientConnection::SubmitRequest(const std::shared_ptr<HttpRequest>& request, void HttpClientConnection::SubmitRequest(const std::shared_ptr<HttpRequest>& request,
const HttpCompletionCallback& callback) const HttpCompletionCallback& callback)
{ {
m_Requests.push_back(std::make_pair(request, callback)); m_Requests.emplace_back(request, callback);
request->Finish(); request->Finish();
} }

View File

@ -72,7 +72,7 @@ void HttpHandler::ProcessRequest(const ApiUser::Ptr& user, HttpRequest& request,
if (current_handlers) { if (current_handlers) {
ObjectLock olock(current_handlers); ObjectLock olock(current_handlers);
for (const HttpHandler::Ptr current_handler : current_handlers) { for (const HttpHandler::Ptr& current_handler : current_handlers) {
handlers.push_back(current_handler); handlers.push_back(current_handler);
} }
} }

View File

@ -57,7 +57,7 @@ void HttpResponse::SetStatus(int code, const String& message)
void HttpResponse::AddHeader(const String& key, const String& value) void HttpResponse::AddHeader(const String& key, const String& value)
{ {
m_Headers.push_back(key + ": " + value + "\r\n"); m_Headers.emplace_back(key + ": " + value + "\r\n");
} }
void HttpResponse::FinishHeaders(void) void HttpResponse::FinishHeaders(void)

View File

@ -62,7 +62,7 @@ bool InfoHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request,
if (hasFilter) if (hasFilter)
name += " (filtered)"; name += " (filtered)";
permInfo.push_back(name); permInfo.emplace_back(std::move(name));
} }
} }

View File

@ -212,8 +212,7 @@ void Url::AddQueryElement(const String& name, const String& value)
{ {
auto it = m_Query.find(name); auto it = m_Query.find(name);
if (it == m_Query.end()) { if (it == m_Query.end()) {
m_Query[name] = std::vector<String>(); m_Query[name] = std::vector<String> { value };
m_Query[name].push_back(value);
} else } else
m_Query[name].push_back(value); m_Query[name].push_back(value);
} }
@ -363,9 +362,7 @@ bool Url::ParsePath(const String& path)
if (!ValidateToken(token, ACPATHSEGMENT)) if (!ValidateToken(token, ACPATHSEGMENT))
return false; return false;
String decodedToken = Utility::UnescapeString(token); m_Path.emplace_back(Utility::UnescapeString(token));
m_Path.push_back(decodedToken);
} }
return true; return true;
@ -411,11 +408,9 @@ bool Url::ParseQuery(const String& query)
auto it = m_Query.find(key); auto it = m_Query.find(key);
if (it == m_Query.end()) { if (it == m_Query.end()) {
m_Query[key] = std::vector<String>(); m_Query[key] = std::vector<String> { std::move(value) };
m_Query[key].push_back(value);
} else } else
m_Query[key].push_back(value); m_Query[key].emplace_back(std::move(value));
} }
return true; return true;