From becfa8509409046c7f44e78bc5e1ab02812efcab Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 4 Jan 2018 09:14:55 +0100 Subject: [PATCH] Apply clang-tidy fix 'modernize-use-emplace' --- icinga-studio/mainform.cpp | 4 +- lib/base/configwriter.cpp | 74 +++++++++++++++--------------- lib/base/dependencygraph.cpp | 2 +- lib/base/utility.cpp | 10 ++-- lib/config/configitem.cpp | 2 +- lib/icinga/compatutility.cpp | 14 +++--- lib/livestatus/livestatusquery.cpp | 12 ++--- lib/perfdata/influxdbwriter.cpp | 4 +- lib/remote/actionshandler.cpp | 2 +- lib/remote/apiclient.cpp | 6 +-- lib/remote/filterutility.cpp | 2 +- test/base-base64.cpp | 13 +++--- test/icinga-macros.cpp | 4 +- test/livestatus.cpp | 16 +++---- test/remote-url.cpp | 6 +-- tools/mkclass/classcompiler.cpp | 8 ++-- 16 files changed, 89 insertions(+), 90 deletions(-) diff --git a/icinga-studio/mainform.cpp b/icinga-studio/mainform.cpp index ea7218b51..64ec975db 100644 --- a/icinga-studio/mainform.cpp +++ b/icinga-studio/mainform.cpp @@ -111,7 +111,7 @@ void MainForm::OnTypeSelected(wxTreeEvent& event) ApiType::Ptr type = m_Types[typeName.ToStdString()]; std::vector attrs; - attrs.push_back("__name"); + attrs.emplace_back("__name"); m_ApiClient->GetObjects(type->PluralName, std::bind(&MainForm::ObjectsCompletionHandler, this, _1, _2, true), std::vector(), attrs); @@ -170,7 +170,7 @@ void MainForm::OnObjectSelected(wxListEvent& event) return; std::vector names; - names.push_back(objectName); + names.emplace_back(objectName); m_ApiClient->GetObjects(type->PluralName, std::bind(&MainForm::ObjectDetailsCompletionHandler, this, _1, _2, true), names, std::vector(), std::vector(), true); diff --git a/lib/base/configwriter.cpp b/lib/base/configwriter.cpp index 22fafde32..37eef9916 100644 --- a/lib/base/configwriter.cpp +++ b/lib/base/configwriter.cpp @@ -227,43 +227,43 @@ const std::vector& ConfigWriter::GetKeywords() boost::mutex::scoped_lock lock(mutex); if (keywords.empty()) { - keywords.push_back("object"); - keywords.push_back("template"); - keywords.push_back("include"); - keywords.push_back("include_recursive"); - keywords.push_back("include_zones"); - keywords.push_back("library"); - keywords.push_back("null"); - keywords.push_back("true"); - keywords.push_back("false"); - keywords.push_back("const"); - keywords.push_back("var"); - keywords.push_back("this"); - keywords.push_back("globals"); - keywords.push_back("locals"); - keywords.push_back("use"); - keywords.push_back("__using"); - keywords.push_back("default"); - keywords.push_back("ignore_on_error"); - keywords.push_back("current_filename"); - keywords.push_back("current_line"); - keywords.push_back("apply"); - keywords.push_back("to"); - keywords.push_back("where"); - keywords.push_back("import"); - keywords.push_back("assign"); - keywords.push_back("ignore"); - keywords.push_back("function"); - keywords.push_back("return"); - keywords.push_back("break"); - keywords.push_back("continue"); - keywords.push_back("for"); - keywords.push_back("if"); - keywords.push_back("else"); - keywords.push_back("while"); - keywords.push_back("throw"); - keywords.push_back("try"); - keywords.push_back("except"); + keywords.emplace_back("object"); + keywords.emplace_back("template"); + keywords.emplace_back("include"); + keywords.emplace_back("include_recursive"); + keywords.emplace_back("include_zones"); + keywords.emplace_back("library"); + keywords.emplace_back("null"); + keywords.emplace_back("true"); + keywords.emplace_back("false"); + keywords.emplace_back("const"); + keywords.emplace_back("var"); + keywords.emplace_back("this"); + keywords.emplace_back("globals"); + keywords.emplace_back("locals"); + keywords.emplace_back("use"); + keywords.emplace_back("__using"); + keywords.emplace_back("default"); + keywords.emplace_back("ignore_on_error"); + keywords.emplace_back("current_filename"); + keywords.emplace_back("current_line"); + keywords.emplace_back("apply"); + keywords.emplace_back("to"); + keywords.emplace_back("where"); + keywords.emplace_back("import"); + keywords.emplace_back("assign"); + keywords.emplace_back("ignore"); + keywords.emplace_back("function"); + keywords.emplace_back("return"); + keywords.emplace_back("break"); + keywords.emplace_back("continue"); + keywords.emplace_back("for"); + keywords.emplace_back("if"); + keywords.emplace_back("else"); + keywords.emplace_back("while"); + keywords.emplace_back("throw"); + keywords.emplace_back("try"); + keywords.emplace_back("except"); } return keywords; diff --git a/lib/base/dependencygraph.cpp b/lib/base/dependencygraph.cpp index df686470c..8fccef5f3 100644 --- a/lib/base/dependencygraph.cpp +++ b/lib/base/dependencygraph.cpp @@ -59,7 +59,7 @@ std::vector DependencyGraph::GetParents(const Object::Ptr& child) if (it != m_Dependencies.end()) { typedef std::pair kv_pair; for (const kv_pair& kv : it->second) { - objects.push_back(kv.first); + objects.emplace_back(kv.first); } } diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index adf5a7bcd..edbf2e468 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -580,9 +580,9 @@ bool Utility::Glob(const String& pathSpec, const std::function= 1) tokens.emplace_back(Convert::ToString(milliseconds) + (milliseconds != 1 ? " milliseconds" : " millisecond")); else - tokens.push_back("less than 1 millisecond"); + tokens.emplace_back("less than 1 millisecond"); } return NaturalJoin(tokens); @@ -1254,10 +1254,10 @@ int Utility::CompareVersion(const String& v1, const String& v2) boost::algorithm::split(tokensv2, v2, boost::is_any_of(".")); for (std::vector::size_type i = 0; i < tokensv2.size() - tokensv1.size(); i++) - tokensv1.push_back("0"); + tokensv1.emplace_back("0"); for (std::vector::size_type i = 0; i < tokensv1.size() - tokensv2.size(); i++) - tokensv2.push_back("0"); + tokensv2.emplace_back("0"); for (std::vector::size_type i = 0; i < tokensv1.size(); i++) { if (Convert::ToLong(tokensv2[i]) > Convert::ToLong(tokensv1[i])) diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 0bc70f50d..87037e92f 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -327,7 +327,7 @@ void ConfigItem::Register() /* If this is a non-abstract object with a composite name * we register it in m_UnnamedItems instead of m_Items. */ if (!m_Abstract && dynamic_cast(m_Type.get())) - m_UnnamedItems.push_back(this); + m_UnnamedItems.emplace_back(this); else { auto& items = m_Items[m_Type]; diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 3139e0d52..29eef3dd5 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -457,32 +457,32 @@ String CompatUtility::GetCheckableNotificationNotificationOptions(const Checkabl /* notification state filters */ if (service) { if (notification_state_filter & ServiceWarning) { - notification_options.push_back("w"); + notification_options.emplace_back("w"); } if (notification_state_filter & ServiceUnknown) { - notification_options.push_back("u"); + notification_options.emplace_back("u"); } if (notification_state_filter & ServiceCritical) { - notification_options.push_back("c"); + notification_options.emplace_back("c"); } } else { if (notification_state_filter & HostDown) { - notification_options.push_back("d"); + notification_options.emplace_back("d"); } } /* notification type filters */ if (notification_type_filter & NotificationRecovery) { - notification_options.push_back("r"); + notification_options.emplace_back("r"); } if ((notification_type_filter & NotificationFlappingStart) || (notification_type_filter & NotificationFlappingEnd)) { - notification_options.push_back("f"); + notification_options.emplace_back("f"); } if ((notification_type_filter & NotificationDowntimeStart) || (notification_type_filter & NotificationDowntimeEnd) || (notification_type_filter & NotificationDowntimeRemoved)) { - notification_options.push_back("s"); + notification_options.emplace_back("s"); } return boost::algorithm::join(notification_options, ","); diff --git a/lib/livestatus/livestatusquery.cpp b/lib/livestatus/livestatusquery.cpp index ab33f8638..a8e7577aa 100644 --- a/lib/livestatus/livestatusquery.cpp +++ b/lib/livestatus/livestatusquery.cpp @@ -71,10 +71,10 @@ LivestatusQuery::LivestatusQuery(const std::vector& lines, const String& m_CompatLogPath = compat_log_path; /* default separators */ - m_Separators.push_back("\n"); - m_Separators.push_back(";"); - m_Separators.push_back(","); - m_Separators.push_back("|"); + m_Separators.emplace_back("\n"); + m_Separators.emplace_back(";"); + m_Separators.emplace_back(","); + m_Separators.emplace_back("|"); String line = lines[0]; @@ -233,7 +233,7 @@ LivestatusQuery::LivestatusQuery(const std::vector& lines, const String& aggregators.pop_back(); } - deq.push_back(filter); + deq.emplace_back(filter); if (&deq == &stats) { Aggregator::Ptr aggregator = new CountAggregator(); aggregator->SetFilter(filter); @@ -317,7 +317,7 @@ Filter::Ptr LivestatusQuery::ParseFilter(const String& params, unsigned long& fr tokens.emplace_back(std::move(temp_buffer)); if (tokens.size() == 2) - tokens.push_back(""); + tokens.emplace_back(""); if (tokens.size() < 3) return nullptr; diff --git a/lib/perfdata/influxdbwriter.cpp b/lib/perfdata/influxdbwriter.cpp index 5c4913818..3121d2ab9 100644 --- a/lib/perfdata/influxdbwriter.cpp +++ b/lib/perfdata/influxdbwriter.cpp @@ -373,7 +373,7 @@ void InfluxdbWriter::SendMetric(const Dictionary::Ptr& tmpl, const String& label #endif /* I2_DEBUG */ // Buffer the data point - m_DataBuffer.push_back(msgbuf.str()); + m_DataBuffer.emplace_back(msgbuf.str()); // Flush if we've buffered too much to prevent excessive memory use if (static_cast(m_DataBuffer.size()) >= GetFlushThreshold()) { @@ -423,7 +423,7 @@ void InfluxdbWriter::Flush() url->SetPort(GetPort()); std::vector path; - path.push_back("write"); + path.emplace_back("write"); url->SetPath(path); url->AddQueryElement("db", GetDatabase()); diff --git a/lib/remote/actionshandler.cpp b/lib/remote/actionshandler.cpp index fff051e06..8ddeb7a16 100644 --- a/lib/remote/actionshandler.cpp +++ b/lib/remote/actionshandler.cpp @@ -69,7 +69,7 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques } } else { FilterUtility::CheckPermission(user, permission); - objs.push_back(nullptr); + objs.emplace_back(nullptr); } Array::Ptr results = new Array(); diff --git a/lib/remote/apiclient.cpp b/lib/remote/apiclient.cpp index 4b43d5ebc..e5a98fceb 100644 --- a/lib/remote/apiclient.cpp +++ b/lib/remote/apiclient.cpp @@ -122,7 +122,7 @@ void ApiClient::GetObjects(const String& pluralType, const ObjectsCompletionCall params["joins"].push_back(join); } - params["all_joins"].push_back(all_joins ? "1" : "0"); + params["all_joins"].emplace_back(all_joins ? "1" : "0"); url->SetQuery(params); @@ -232,7 +232,7 @@ void ApiClient::ExecuteScript(const String& session, const String& command, bool std::map > params; params["session"].push_back(session); params["command"].push_back(command); - params["sandboxed"].push_back(sandboxed ? "1" : "0"); + params["sandboxed"].emplace_back(sandboxed ? "1" : "0"); url->SetQuery(params); try { @@ -311,7 +311,7 @@ void ApiClient::AutocompleteScript(const String& session, const String& command, std::map > params; params["session"].push_back(session); params["command"].push_back(command); - params["sandboxed"].push_back(sandboxed ? "1" : "0"); + params["sandboxed"].emplace_back(sandboxed ? "1" : "0"); url->SetQuery(params); try { diff --git a/lib/remote/filterutility.cpp b/lib/remote/filterutility.cpp index c24152d5d..fe3d03bda 100644 --- a/lib/remote/filterutility.cpp +++ b/lib/remote/filterutility.cpp @@ -127,7 +127,7 @@ static void FilteredAddTarget(ScriptFrame& permissionFrame, Expression *permissi ScriptFrame& frame, Expression *ufilter, std::vector& result, const String& variableName, const Object::Ptr& target) { if (FilterUtility::EvaluateFilter(permissionFrame, permissionFilter, target, variableName) && FilterUtility::EvaluateFilter(frame, ufilter, target, variableName)) - result.push_back(target); + result.emplace_back(target); } void FilterUtility::CheckPermission(const ApiUser::Ptr& user, const String& permission, Expression **permissionFilter) diff --git a/test/base-base64.cpp b/test/base-base64.cpp index 1426fc747..eb9c2af01 100644 --- a/test/base-base64.cpp +++ b/test/base-base64.cpp @@ -27,13 +27,12 @@ BOOST_AUTO_TEST_SUITE(base_base64) BOOST_AUTO_TEST_CASE(base64) { std::vector clearText; - clearText.push_back(""); - clearText.push_back("1"); - clearText.push_back("12"); - clearText.push_back("123"); - clearText.push_back("1234"); - clearText.push_back( - "VsowLvPqEiAeITDmo-5L_NB-k7fsT3sT2d3K9O4iC2uBk41hvCPAxrgGSxrdeX5s" + clearText.emplace_back(""); + clearText.emplace_back("1"); + clearText.emplace_back("12"); + clearText.emplace_back("123"); + clearText.emplace_back("1234"); + clearText.emplace_back("VsowLvPqEiAeITDmo-5L_NB-k7fsT3sT2d3K9O4iC2uBk41hvCPAxrgGSxrdeX5s" "Zo0Z9b1kxDZlzf8GHQ9ARW6YLeGODMtiZo8cKkUzfSbxyZ_wlE9u6pCTTg9kODCM" "Ve-X_a3jWkOy89RoDkT5ahKBY-8S25L6wlvWt8ZyQ2bLxfplzEzuHgEknTMKKp2K" "jRlwI2p3gF4FYeQM7dx0E5O782Lh1P3IC6jPNqiZgTgWmsRYZbAN8oU2V626bQxD" diff --git a/test/icinga-macros.cpp b/test/icinga-macros.cpp index 420bff993..94f067600 100644 --- a/test/icinga-macros.cpp +++ b/test/icinga-macros.cpp @@ -41,8 +41,8 @@ BOOST_AUTO_TEST_CASE(simple) macrosB->Set("testD", testD); MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("macrosA", macrosA)); - resolvers.push_back(std::make_pair("macrosB", macrosB)); + resolvers.emplace_back("macrosA", macrosA); + resolvers.emplace_back("macrosB", macrosB); BOOST_CHECK(MacroProcessor::ResolveMacros("$macrosA.testB$ $macrosB.testC$", resolvers) == "hello world"); BOOST_CHECK(MacroProcessor::ResolveMacros("$testA$", resolvers) == "7"); diff --git a/test/livestatus.cpp b/test/livestatus.cpp index 11f45c23c..bb74ffc30 100644 --- a/test/livestatus.cpp +++ b/test/livestatus.cpp @@ -67,10 +67,10 @@ BOOST_AUTO_TEST_CASE(hosts) BOOST_TEST_MESSAGE( "Querying Livestatus..."); std::vector lines; - lines.push_back("GET hosts"); - lines.push_back("Columns: host_name address check_command"); - lines.push_back("OutputFormat: json"); - lines.push_back("\n"); + lines.emplace_back("GET hosts"); + lines.emplace_back("Columns: host_name address check_command"); + lines.emplace_back("OutputFormat: json"); + lines.emplace_back("\n"); /* use our query helper */ String output = LivestatusQueryHelper(lines); @@ -97,10 +97,10 @@ BOOST_AUTO_TEST_CASE(services) BOOST_TEST_MESSAGE( "Querying Livestatus..."); std::vector lines; - lines.push_back("GET services"); - lines.push_back("Columns: host_name service_description check_command notes"); - lines.push_back("OutputFormat: json"); - lines.push_back("\n"); + lines.emplace_back("GET services"); + lines.emplace_back("Columns: host_name service_description check_command notes"); + lines.emplace_back("OutputFormat: json"); + lines.emplace_back("\n"); /* use our query helper */ String output = LivestatusQueryHelper(lines); diff --git a/test/remote-url.cpp b/test/remote-url.cpp index 92344b44e..d70751872 100644 --- a/test/remote-url.cpp +++ b/test/remote-url.cpp @@ -34,9 +34,9 @@ BOOST_AUTO_TEST_CASE(id_and_path) BOOST_CHECK(url->GetAuthority() == "icinga.com"); std::vector PathCorrect; - PathCorrect.push_back("foo"); - PathCorrect.push_back("bar"); - PathCorrect.push_back("baz"); + PathCorrect.emplace_back("foo"); + PathCorrect.emplace_back("bar"); + PathCorrect.emplace_back("baz"); BOOST_CHECK(url->GetPath() == PathCorrect); } diff --git a/tools/mkclass/classcompiler.cpp b/tools/mkclass/classcompiler.cpp index 10069f91b..23d3ce1f6 100644 --- a/tools/mkclass/classcompiler.cpp +++ b/tools/mkclass/classcompiler.cpp @@ -290,7 +290,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) for (const Field& field : klass.Fields) { auto hash = static_cast(SDBM(field.Name, hlen)); - jumptable[hash].push_back(std::make_pair(num, field.Name)); + jumptable[hash].emplace_back(num, field.Name); num++; if (jumptable[hash].size() > 1) @@ -403,7 +403,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) << "\t" << "std::vector deps;" << std::endl; for (const std::string& dep : klass.LoadDependencies) - m_Impl << "\t" << "deps.push_back(\"" << dep << "\");" << std::endl; + m_Impl << "\t" << "deps.emplace_back(\"" << dep << "\");" << std::endl; m_Impl << "\t" << "return deps;" << std::endl << "}" << std::endl << std::endl; @@ -1208,7 +1208,7 @@ void ClassCompiler::CodeGenValidator(const std::string& name, const std::string& else subvalidator_prefix = name; - m_Impl << (type_check ? "\t" : "") << (indent ? "\t\t" : "") << "\t\t" << "location.push_back(akey);" << std::endl + m_Impl << (type_check ? "\t" : "") << (indent ? "\t\t" : "") << "\t\t" << "location.emplace_back(akey);" << std::endl << (type_check ? "\t" : "") << (indent ? "\t\t" : "") << "\t\t" << "TIValidate" << subvalidator_prefix << "_" << i << "(object, akey, avalue, location, utils);" << std::endl << (type_check ? "\t" : "") << (indent ? "\t\t" : "") << "\t\t" << "location.pop_back();" << std::endl; @@ -1313,7 +1313,7 @@ void ClassCompiler::HandleValidator(const Validator& validator, const ClassDebug << "{" << std::endl << "\t" << "SimpleValidate" << it.first.second << "(value, utils);" << std::endl << "\t" << "std::vector location;" << std::endl - << "\t" << "location.push_back(\"" << it.second.Name << "\");" << std::endl + << "\t" << "location.emplace_back(\"" << it.second.Name << "\");" << std::endl << "\t" << "TIValidate" << it.first.first << it.first.second << "(this, value, location, utils);" << std::endl << "\t" << "location.pop_back();" << std::endl << "}" << std::endl << std::endl;