diff options
author | Razvan Becheriu <razvan@isc.org> | 2024-01-12 15:31:50 +0100 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2024-01-22 16:49:59 +0100 |
commit | 1b4d7b0293bca6657d1f798e6e4e65ce95d2dca4 (patch) | |
tree | fc89d85f5dd097dd85a2921ce1382980e012a423 /src/lib/hooks | |
parent | [#3119] replace const auto with auto const (diff) | |
download | kea-1b4d7b0293bca6657d1f798e6e4e65ce95d2dca4.tar.xz kea-1b4d7b0293bca6657d1f798e6e4e65ce95d2dca4.zip |
[#3119] use range based for loop or BOOST_FOREACH
Diffstat (limited to 'src/lib/hooks')
-rw-r--r-- | src/lib/hooks/callout_handle.cc | 10 | ||||
-rw-r--r-- | src/lib/hooks/callout_manager.cc | 15 | ||||
-rw-r--r-- | src/lib/hooks/hooks_config.cc | 27 | ||||
-rw-r--r-- | src/lib/hooks/hooks_parser.cc | 5 | ||||
-rw-r--r-- | src/lib/hooks/libinfo.cc | 9 | ||||
-rw-r--r-- | src/lib/hooks/library_handle.cc | 5 | ||||
-rw-r--r-- | src/lib/hooks/library_manager_collection.cc | 10 | ||||
-rw-r--r-- | src/lib/hooks/server_hooks.cc | 8 |
8 files changed, 38 insertions, 51 deletions
diff --git a/src/lib/hooks/callout_handle.cc b/src/lib/hooks/callout_handle.cc index 6877b65ac6..d5f792f1e9 100644 --- a/src/lib/hooks/callout_handle.cc +++ b/src/lib/hooks/callout_handle.cc @@ -64,9 +64,8 @@ CalloutHandle::~CalloutHandle() { vector<string> CalloutHandle::getArgumentNames() const { vector<string> names; - for (ElementCollection::const_iterator i = arguments_.begin(); - i != arguments_.end(); ++i) { - names.push_back(i->first); + for (auto const& i : arguments_) { + names.push_back(i.first); } return (names); @@ -111,9 +110,8 @@ vector<string> CalloutHandle::getContextNames() const { vector<string> names; const ElementCollection& elements = getContextForLibrary(); - for (ElementCollection::const_iterator i = elements.begin(); - i != elements.end(); ++i) { - names.push_back(i->first); + for (auto const& i : elements) { + names.push_back(i.first); } return (names); diff --git a/src/lib/hooks/callout_manager.cc b/src/lib/hooks/callout_manager.cc index 575d147983..ac95eb45bf 100644 --- a/src/lib/hooks/callout_manager.cc +++ b/src/lib/hooks/callout_manager.cc @@ -149,31 +149,30 @@ CalloutManager::callCallouts(int hook_index, CalloutHandle& callout_handle) { .arg(server_hooks_.getName(callout_handle.getCurrentHook())); // Call all the callouts. - for (CalloutVector::const_iterator i = hook_vector_[hook_index].begin(); - i != hook_vector_[hook_index].end(); ++i) { + for (auto const& i : hook_vector_[hook_index]) { // In case the callout requires access to the context associated // with the library, set the current library index to the index // associated with the library that registered the callout being // called. - callout_handle.setCurrentLibrary(i->first); + callout_handle.setCurrentLibrary(i.first); // Call the callout try { stopwatch.start(); - int status = (*i->second)(callout_handle); + int status = (*i.second)(callout_handle); stopwatch.stop(); if (status == 0) { LOG_DEBUG(callouts_logger, HOOKS_DBG_EXTENDED_CALLS, HOOKS_CALLOUT_CALLED) .arg(callout_handle.getCurrentLibrary()) .arg(server_hooks_.getName(callout_handle.getCurrentHook())) - .arg(PointerConverter(i->second).dlsymPtr()) + .arg(PointerConverter(i.second).dlsymPtr()) .arg(stopwatch.logFormatLastDuration()); } else { LOG_ERROR(callouts_logger, HOOKS_CALLOUT_ERROR) .arg(server_hooks_.getName(callout_handle.getCurrentHook())) .arg(callout_handle.getCurrentLibrary()) - .arg(PointerConverter(i->second).dlsymPtr()) + .arg(PointerConverter(i.second).dlsymPtr()) .arg(stopwatch.logFormatLastDuration()); } } catch (const std::exception& e) { @@ -184,7 +183,7 @@ CalloutManager::callCallouts(int hook_index, CalloutHandle& callout_handle) { LOG_ERROR(callouts_logger, HOOKS_CALLOUT_EXCEPTION) .arg(server_hooks_.getName(callout_handle.getCurrentHook())) .arg(callout_handle.getCurrentLibrary()) - .arg(PointerConverter(i->second).dlsymPtr()) + .arg(PointerConverter(i.second).dlsymPtr()) .arg(e.what()) .arg(stopwatch.logFormatLastDuration()); callout_handle.setStatus(CalloutHandle::NEXT_STEP_DROP); @@ -196,7 +195,7 @@ CalloutManager::callCallouts(int hook_index, CalloutHandle& callout_handle) { LOG_ERROR(callouts_logger, HOOKS_CALLOUT_EXCEPTION) .arg(server_hooks_.getName(callout_handle.getCurrentHook())) .arg(callout_handle.getCurrentLibrary()) - .arg(PointerConverter(i->second).dlsymPtr()) + .arg(PointerConverter(i.second).dlsymPtr()) .arg("Unspecified exception") .arg(stopwatch.logFormatLastDuration()); callout_handle.setStatus(CalloutHandle::NEXT_STEP_DROP); diff --git a/src/lib/hooks/hooks_config.cc b/src/lib/hooks/hooks_config.cc index e8e0f05735..93a509cda7 100644 --- a/src/lib/hooks/hooks_config.cc +++ b/src/lib/hooks/hooks_config.cc @@ -76,22 +76,20 @@ HooksConfig::equal(const HooksConfig& other) const { /// We don't have any libraries that are interacting (or would change their behavior /// depending on the order in which their callouts are executed), so the code is /// ok for now. - for (isc::hooks::HookLibsCollection::const_iterator this_it = libraries_.begin(); - this_it != libraries_.end(); ++this_it) { + for (auto const& this_it : libraries_) { bool match = false; - for (isc::hooks::HookLibsCollection::const_iterator other_it = - other.libraries_.begin(); other_it != other.libraries_.end(); ++other_it) { - if (this_it->first != other_it->first) { + for (auto const& other_it : other.libraries_) { + if (this_it.first != other_it.first) { continue; } - if (isNull(this_it->second) && isNull(other_it->second)) { + if (isNull(this_it.second) && isNull(other_it.second)) { match = true; break; } - if (isNull(this_it->second) || isNull(other_it->second)) { + if (isNull(this_it.second) || isNull(other_it.second)) { continue; } - if (this_it->second->equals(*other_it->second)) { + if (this_it.second->equals(*other_it.second)) { match = true; break; } @@ -109,15 +107,14 @@ HooksConfig::toElement() const { // hooks-libraries is a list of maps ElementPtr result = Element::createList(); // Iterate through libraries - for (HookLibsCollection::const_iterator hl = libraries_.begin(); - hl != libraries_.end(); ++hl) { + for (auto const& hl : libraries_) { // Entries are maps ElementPtr map = Element::createMap(); // Set the library name - map->set("library", Element::create(hl->first)); + map->set("library", Element::create(hl.first)); // Set parameters (not set vs set empty map) - if (!isNull(hl->second)) { - map->set("parameters", hl->second); + if (!isNull(hl.second)) { + map->set("parameters", hl.second); } // Push to the list result->add(map); @@ -125,5 +122,5 @@ HooksConfig::toElement() const { return (result); } -}; -}; +} +} diff --git a/src/lib/hooks/hooks_parser.cc b/src/lib/hooks/hooks_parser.cc index 976f6a0bd0..fc707f80fb 100644 --- a/src/lib/hooks/hooks_parser.cc +++ b/src/lib/hooks/hooks_parser.cc @@ -10,7 +10,6 @@ #include <cc/dhcp_config_error.h> #include <hooks/hooks_parser.h> #include <boost/algorithm/string.hpp> -#include <boost/foreach.hpp> #include <util/strutil.h> #include <vector> @@ -34,7 +33,7 @@ HooksLibrariesParser::parse(HooksConfig& libraries, ConstElementPtr value) { } // This is the new syntax. Iterate through it and get each map. - BOOST_FOREACH(ConstElementPtr library_entry, value->listValue()) { + for (auto const& library_entry : value->listValue()) { ConstElementPtr parameters; // Is it a map? @@ -54,7 +53,7 @@ HooksLibrariesParser::parse(HooksConfig& libraries, ConstElementPtr value) { // values from the previous loop round. parameters.reset(); - BOOST_FOREACH(auto const& entry_item, library_entry->mapValue()) { + for (auto const& entry_item : library_entry->mapValue()) { if (entry_item.first == "library") { if (entry_item.second->getType() != Element::string) { isc_throw(DhcpConfigError, "hooks library configuration" diff --git a/src/lib/hooks/libinfo.cc b/src/lib/hooks/libinfo.cc index 2abf3a1d47..7e13588cf4 100644 --- a/src/lib/hooks/libinfo.cc +++ b/src/lib/hooks/libinfo.cc @@ -19,12 +19,11 @@ std::vector<std::string> extractNames(const isc::hooks::HookLibsCollection& libraries) { std::vector<std::string> names; - for (isc::hooks::HookLibsCollection::const_iterator it = libraries.begin(); - it != libraries.end(); ++it) { - names.push_back(it->first); + for (auto const& it : libraries) { + names.push_back(it.first); } return (names); } -}; -}; +} +} diff --git a/src/lib/hooks/library_handle.cc b/src/lib/hooks/library_handle.cc index 88cda6f3e4..ef94c9ef8d 100644 --- a/src/lib/hooks/library_handle.cc +++ b/src/lib/hooks/library_handle.cc @@ -120,12 +120,11 @@ LibraryHandle::getParameterNames() { return (names); } auto const& map = params->mapValue(); - for (auto elem = map.begin(); elem != map.end(); ++elem) { - names.push_back(elem->first); + for (auto const& elem : map) { + names.push_back(elem.first); } return (names); } - } // namespace util } // namespace isc diff --git a/src/lib/hooks/library_manager_collection.cc b/src/lib/hooks/library_manager_collection.cc index 09b7912f3c..7f6c14127f 100644 --- a/src/lib/hooks/library_manager_collection.cc +++ b/src/lib/hooks/library_manager_collection.cc @@ -10,6 +10,7 @@ #include <hooks/hooks_manager.h> #include <hooks/library_manager.h> #include <hooks/library_manager_collection.h> +#include <boost/range/adaptor/reversed.hpp> namespace isc { namespace hooks { @@ -41,9 +42,8 @@ LibraryManagerCollection::LibraryManagerCollection(const HookLibsCollection& lib : library_info_(libraries) { // We need to split hook libs into library names and library parameters. - for (HookLibsCollection::const_iterator it = libraries.begin(); - it != libraries.end(); ++it) { - library_names_.push_back(it->first); + for (auto const& it : libraries) { + library_names_.push_back(it.first); } } @@ -122,8 +122,8 @@ bool LibraryManagerCollection::prepareUnloadLibraries() { bool result = true; // Iterate on library managers in reverse order. - for (auto lm = lib_managers_.rbegin(); lm != lib_managers_.rend(); ++lm) { - result = (*lm)->prepareUnloadLibrary() && result; + for (auto const& lm : boost::adaptors::reverse(lib_managers_)) { + result = lm->prepareUnloadLibrary() && result; } return (result); } diff --git a/src/lib/hooks/server_hooks.cc b/src/lib/hooks/server_hooks.cc index 5ca1a50596..1c08700414 100644 --- a/src/lib/hooks/server_hooks.cc +++ b/src/lib/hooks/server_hooks.cc @@ -158,11 +158,9 @@ ServerHooks::findIndex(const std::string& name) const { vector<string> ServerHooks::getHookNames() const { - vector<string> names; - HookCollection::const_iterator i; - for (i = hooks_.begin(); i != hooks_.end(); ++i) { - names.push_back(i->first); + for (auto const& i : hooks_) { + names.push_back(i.first); } return (names); @@ -215,7 +213,5 @@ ServerHooks::hookToCommandName(const std::string& hook_name) { return (""); } - - } // namespace hooks } // namespace isc |