From: Razvan Becheriu Date: Fri, 12 Jan 2024 14:31:50 +0000 (+0200) Subject: [#3119] use range based for loop or BOOST_FOREACH X-Git-Tag: Kea-2.5.5~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1b4d7b0293bca6657d1f798e6e4e65ce95d2dca4;p=thirdparty%2Fkea.git [#3119] use range based for loop or BOOST_FOREACH --- diff --git a/src/bin/agent/ca_cfg_mgr.cc b/src/bin/agent/ca_cfg_mgr.cc index f2f8caa92a..cda267f78a 100644 --- a/src/bin/agent/ca_cfg_mgr.cc +++ b/src/bin/agent/ca_cfg_mgr.cc @@ -77,8 +77,8 @@ CtrlAgentCfgMgr::getConfigSummary(const uint32_t /*selection*/) { // Finally, print the hook libraries names const isc::hooks::HookLibsCollection libs = ctx->getHooksConfig().get(); s << ", " << libs.size() << " lib(s):"; - for (auto lib = libs.begin(); lib != libs.end(); ++lib) { - s << lib->first << " "; + for (auto const& lib : libs) { + s << lib.first << " "; } return (s.str()); @@ -163,11 +163,11 @@ CtrlAgentCfgContext::setControlSocketInfo(const ConstElementPtr& control_socket, std::string CtrlAgentCfgContext::getControlSocketInfoSummary() const { std::ostringstream s; - for (auto si = ctrl_sockets_.cbegin(); si != ctrl_sockets_.end(); ++si) { + for (auto const& si : ctrl_sockets_) { if (s.tellp() != 0) { s << " "; } - s << si->first; + s << si.first; } if (s.tellp() == 0) { @@ -200,9 +200,9 @@ CtrlAgentCfgContext::toElement() const { ca->set("hooks-libraries", hooks_config_.toElement()); // Set control-sockets ElementPtr control_sockets = Element::createMap(); - for (auto si = ctrl_sockets_.cbegin(); si != ctrl_sockets_.cend(); ++si) { - ConstElementPtr socket = UserContext::toElement(si->second); - control_sockets->set(si->first, socket); + for (auto const& si : ctrl_sockets_) { + ConstElementPtr socket = UserContext::toElement(si.second); + control_sockets->set(si.first, socket); } ca->set("control-sockets", control_sockets); // Set Control-agent diff --git a/src/bin/agent/ca_process.cc b/src/bin/agent/ca_process.cc index 3a3cebae90..1e42503065 100644 --- a/src/bin/agent/ca_process.cc +++ b/src/bin/agent/ca_process.cc @@ -201,9 +201,7 @@ CtrlAgentProcess::garbageCollectListeners(size_t leaving) { // listeners except the most recently added. if (http_listeners_.size() > leaving) { // Stop no longer used listeners. - for (auto l = http_listeners_.begin(); - l != http_listeners_.end() - leaving; - ++l) { + for (auto l = http_listeners_.begin(); l != http_listeners_.end() - leaving; ++l) { (*l)->stop(); } // We have stopped listeners but there may be some pending handlers @@ -215,7 +213,6 @@ CtrlAgentProcess::garbageCollectListeners(size_t leaving) { } } - CtrlAgentCfgMgrPtr CtrlAgentProcess::getCtrlAgentCfgMgr() { return (boost::dynamic_pointer_cast(getCfgMgr())); diff --git a/src/bin/agent/simple_parser.cc b/src/bin/agent/simple_parser.cc index 9c863656d6..b340d46530 100644 --- a/src/bin/agent/simple_parser.cc +++ b/src/bin/agent/simple_parser.cc @@ -12,7 +12,6 @@ #include #include #include -#include using namespace isc::data; @@ -147,8 +146,8 @@ AgentSimpleParser::parse(const CtrlAgentCfgContextPtr& ctx, ConstElementPtr ctrl_sockets = config->get("control-sockets"); if (ctrl_sockets) { auto const& sockets_map = ctrl_sockets->mapValue(); - for (auto cs = sockets_map.cbegin(); cs != sockets_map.cend(); ++cs) { - ctx->setControlSocketInfo(cs->second, cs->first); + for (auto const& cs : sockets_map) { + ctx->setControlSocketInfo(cs.second, cs.first); } } diff --git a/src/bin/agent/tests/ca_command_mgr_unittests.cc b/src/bin/agent/tests/ca_command_mgr_unittests.cc index 939e55f063..6a71a2af81 100644 --- a/src/bin/agent/tests/ca_command_mgr_unittests.cc +++ b/src/bin/agent/tests/ca_command_mgr_unittests.cc @@ -94,14 +94,14 @@ public: std::vector answer_list = answer->listValue(); ASSERT_EQ(expected_codes.size(), answer_list.size()); + size_t count = 0; // Check all answers. - for (auto ans = answer_list.cbegin(); ans != answer_list.cend(); - ++ans) { + for (auto const& ans : answer_list) { ConstElementPtr text; - ASSERT_NO_THROW(text = isc::config::parseAnswer(status_code, *ans)); - EXPECT_EQ(expected_codes[std::distance(answer_list.cbegin(), ans)], - status_code) + ASSERT_NO_THROW(text = isc::config::parseAnswer(status_code, ans)); + EXPECT_EQ(expected_codes[count], status_code) << "answer contains text: " << text->stringValue(); + count++; } } diff --git a/src/bin/d2/tests/d2_cfg_mgr_unittests.cc b/src/bin/d2/tests/d2_cfg_mgr_unittests.cc index e00afae840..aad7e09757 100644 --- a/src/bin/d2/tests/d2_cfg_mgr_unittests.cc +++ b/src/bin/d2/tests/d2_cfg_mgr_unittests.cc @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -583,8 +582,7 @@ TEST_F(D2CfgMgrTest, fullConfig) { // NOTE that since prior tests have validated server parsing, we are are // assuming that the servers did in fact parse correctly if the correct // number of them are there. - DdnsDomainMapPair domain_pair; - BOOST_FOREACH(domain_pair, (*domains)) { + for (auto const& domain_pair : *domains) { DdnsDomainPtr domain = domain_pair.second; DnsServerInfoStoragePtr servers = domain->getServers(); count = servers->size(); @@ -606,7 +604,7 @@ TEST_F(D2CfgMgrTest, fullConfig) { // NOTE that since prior tests have validated server parsing, we are are // assuming that the servers did in fact parse correctly if the correct // number of them are there. - BOOST_FOREACH(domain_pair, (*domains)) { + for (auto const& domain_pair : *domains) { DdnsDomainPtr domain = domain_pair.second; DnsServerInfoStoragePtr servers = domain->getServers(); count = servers->size(); @@ -933,7 +931,7 @@ TEST_F(D2CfgMgrTest, configPermutations) { // 5. submit JSON for parsing isc::data::ConstElementPtr test; ASSERT_TRUE(tests->get("test-list")); - BOOST_FOREACH(test, tests->get("test-list")->listValue()) { + for (auto const& test : tests->get("test-list")->listValue()) { // Grab the description. std::string description = ""; isc::data::ConstElementPtr elem = test->get("description"); diff --git a/src/bin/d2/tests/d2_simple_parser_unittest.cc b/src/bin/d2/tests/d2_simple_parser_unittest.cc index b236469cb9..682908a083 100644 --- a/src/bin/d2/tests/d2_simple_parser_unittest.cc +++ b/src/bin/d2/tests/d2_simple_parser_unittest.cc @@ -277,7 +277,7 @@ TEST_F(D2SimpleParserTest, globalD2Defaults) { EXPECT_EQ(num, 8); // Let's go over all parameters we have defaults for. - BOOST_FOREACH(SimpleDefault deflt, D2SimpleParser::D2_GLOBAL_DEFAULTS) { + for (auto const& deflt : D2SimpleParser::D2_GLOBAL_DEFAULTS) { ConstElementPtr x; ASSERT_NO_THROW(x = empty->get(deflt.name_)); @@ -569,7 +569,7 @@ public: size_t cnt = 0; // We don't use SimpleParser::setListDefaults() as this does // not handle sub-lists or sub-maps - BOOST_FOREACH(ElementPtr domain, config->listValue()) { + for (auto const& domain : config->listValue()) { cnt += D2SimpleParser:: setDdnsDomainDefaults(domain, D2SimpleParser:: DDNS_DOMAIN_DEFAULTS); diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 8edef2d542..f9a7ab61ec 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -65,6 +65,7 @@ #include #include +#include #include #include @@ -402,8 +403,7 @@ Dhcpv4Exchange::setHostIdentifiers(AllocEngine::ClientContext4Ptr context) { // Collect host identifiers. The identifiers are stored in order of preference. // The server will use them in that order to search for host reservations. - BOOST_FOREACH(const Host::IdentifierType& id_type, - cfg->getIdentifierTypes()) { + for (auto const& id_type : cfg->getIdentifierTypes()) { switch (id_type) { case Host::IDENT_HWADDR: if (context->hwaddr_ && !context->hwaddr_->hwaddr_.empty()) { @@ -515,9 +515,8 @@ void Dhcpv4Exchange::setReservedClientClasses(AllocEngine::ClientContext4Ptr context) { if (context->currentHost() && context->query_) { const ClientClasses& classes = context->currentHost()->getClientClasses4(); - for (ClientClasses::const_iterator cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { - context->query_->addClass(*cclass); + for (auto const& cclass : classes) { + context->query_->addClass(cclass); } } } @@ -587,23 +586,22 @@ void Dhcpv4Exchange::evaluateClasses(const Pkt4Ptr& pkt, bool depend_on_known) { const ClientClassDictionaryPtr& dict = CfgMgr::instance().getCurrentCfg()->getClientClassDictionary(); const ClientClassDefListPtr& defs_ptr = dict->getClasses(); - for (ClientClassDefList::const_iterator it = defs_ptr->cbegin(); - it != defs_ptr->cend(); ++it) { + for (auto const& it : *defs_ptr) { // Note second cannot be null - const ExpressionPtr& expr_ptr = (*it)->getMatchExpr(); + const ExpressionPtr& expr_ptr = it->getMatchExpr(); // Nothing to do without an expression to evaluate if (!expr_ptr) { continue; } // Not the right time if only when required - if ((*it)->getRequired()) { + if (it->getRequired()) { continue; } // Not the right pass. - if ((*it)->getDependOnKnown() != depend_on_known) { + if (it->getDependOnKnown() != depend_on_known) { continue; } - (*it)->test(pkt, expr_ptr); + it->test(pkt, expr_ptr); } } @@ -664,9 +662,9 @@ void Dhcpv4Srv::setPacketStatisticsDefaults() { isc::stats::StatsMgr& stats_mgr = isc::stats::StatsMgr::instance(); // Iterate over set of observed statistics - for (auto it = dhcp4_statistics.begin(); it != dhcp4_statistics.end(); ++it) { + for (auto const& it : dhcp4_statistics) { // Initialize them with default value 0 - stats_mgr.setValue((*it), static_cast(0)); + stats_mgr.setValue(it, static_cast(0)); } } @@ -827,7 +825,7 @@ Dhcpv4Srv::selectSubnet4o6(const Pkt4Ptr& query, bool& drop, // Initialize fields specific to relayed messages. if (query6 && !query6->relay_info_.empty()) { - BOOST_REVERSE_FOREACH(Pkt6::RelayInfo relay, query6->relay_info_) { + for (auto const& relay : boost::adaptors::reverse(query6->relay_info_)) { if (!relay.linkaddr_.isV6Zero() && !relay.linkaddr_.isV6LinkLocal()) { selector.first_relay_linkaddr_ = relay.linkaddr_; @@ -966,9 +964,8 @@ Dhcpv4Srv::earlyGHRLookup(const Pkt4Ptr& query, // Add classes from the global reservations. const ClientClasses& classes = global_host->getClientClasses4(); - for (ClientClasses::const_iterator cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { - query->addClass(*cclass); + for (auto const& cclass : classes) { + query->addClass(cclass); } // Evaluate classes before KNOWN. @@ -1845,17 +1842,16 @@ Dhcpv4Srv::buildCfgOptionList(Dhcpv4Exchange& ex) { // Each class in the incoming packet const ClientClasses& classes = ex.getQuery()->getClasses(); - for (ClientClasses::const_iterator cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { + for (auto const& cclass : classes) { // Find the client class definition for this class const ClientClassDefPtr& ccdef = CfgMgr::instance().getCurrentCfg()-> - getClientClassDictionary()->findClass(*cclass); + getClientClassDictionary()->findClass(cclass); if (!ccdef) { // Not found: the class is built-in or not configured - if (!isClientClassBuiltIn(*cclass)) { + if (!isClientClassBuiltIn(cclass)) { LOG_DEBUG(dhcp4_logger, DBG_DHCP4_BASIC, DHCP4_CLASS_UNCONFIGURED) .arg(ex.getQuery()->getLabel()) - .arg(*cclass); + .arg(cclass); } // Skip it continue; @@ -1922,22 +1918,20 @@ Dhcpv4Srv::appendRequestedOptions(Dhcpv4Exchange& ex) { // Get persistent options. const OptionContainerPersistIndex& pidx = opts->get<2>(); const OptionContainerPersistRange& prange = pidx.equal_range(true); - for (OptionContainerPersistIndex::const_iterator desc = prange.first; - desc != prange.second; ++desc) { + BOOST_FOREACH(auto const& desc, prange) { // Add the persistent option code to requested options. - if (desc->option_) { - uint8_t code = static_cast(desc->option_->getType()); + if (desc.option_) { + uint8_t code = static_cast(desc.option_->getType()); static_cast(requested_opts.insert(code)); } } // Get cancelled options. const OptionContainerCancelIndex& cidx = opts->get<5>(); const OptionContainerCancelRange& crange = cidx.equal_range(true); - for (OptionContainerCancelIndex::const_iterator desc = crange.first; - desc != crange.second; ++desc) { + BOOST_FOREACH(auto const& desc, crange) { // Add the cancelled option code to cancelled options. - if (desc->option_) { - uint8_t code = static_cast(desc->option_->getType()); + if (desc.option_) { + uint8_t code = static_cast(desc.option_->getType()); static_cast(cancelled_opts.insert(code)); } } @@ -2024,7 +2018,7 @@ Dhcpv4Srv::appendRequestedOptions(Dhcpv4Exchange& ex) { // Iterate on the configured option list for (auto const& copts : co_list) { for (auto const& desc : copts->getList(DHCP4_OPTION_SPACE, - DHO_VIVSO_SUBOPTIONS)) { + DHO_VIVSO_SUBOPTIONS)) { if (!desc.option_) { continue; } @@ -2153,11 +2147,10 @@ Dhcpv4Srv::appendRequestedVendorOptions(Dhcpv4Exchange& ex) { // Get persistent options. const OptionContainerPersistIndex& pidx = opts->get<2>(); const OptionContainerPersistRange& prange = pidx.equal_range(true); - for (OptionContainerPersistIndex::const_iterator desc = prange.first; - desc != prange.second; ++desc) { + BOOST_FOREACH(auto const& desc, prange) { // Add the persistent option code to requested options. - if (desc->option_) { - uint8_t code = static_cast(desc->option_->getType()); + if (desc.option_) { + uint8_t code = static_cast(desc.option_->getType()); static_cast(requested_opts[vendor_id].insert(code)); } } @@ -2165,11 +2158,10 @@ Dhcpv4Srv::appendRequestedVendorOptions(Dhcpv4Exchange& ex) { // Get cancelled options. const OptionContainerCancelIndex& cidx = opts->get<5>(); const OptionContainerCancelRange& crange = cidx.equal_range(true); - for (OptionContainerCancelIndex::const_iterator desc = crange.first; - desc != crange.second; ++desc) { + BOOST_FOREACH(auto const& desc, crange) { // Add the cancelled option code to cancelled options. - if (desc->option_) { - uint8_t code = static_cast(desc->option_->getType()); + if (desc.option_) { + uint8_t code = static_cast(desc.option_->getType()); static_cast(cancelled_opts.insert(code)); } } @@ -2762,9 +2754,9 @@ Dhcpv4Srv::assignLease(Dhcpv4Exchange& ex) { // Among those returned try to find a lease that belongs to // current shared network. while (s) { - for (auto l = leases_client_id.begin(); l != leases_client_id.end(); ++l) { - if ((*l)->subnet_id_ == s->getID()) { - lease = *l; + for (auto const& l : leases_client_id) { + if (l->subnet_id_ == s->getID()) { + lease = l; break; } } @@ -2790,9 +2782,9 @@ Dhcpv4Srv::assignLease(Dhcpv4Exchange& ex) { // Pick one that belongs to a subnet in this shared network. while (s) { - for (auto l = leases_hwaddr.begin(); l != leases_hwaddr.end(); ++l) { - if ((*l)->subnet_id_ == s->getID()) { - lease = *l; + for (auto const& l : leases_hwaddr) { + if (l->subnet_id_ == s->getID()) { + lease = l; break; } } @@ -3400,10 +3392,13 @@ Dhcpv4Srv::setFixedFields(Dhcpv4Exchange& ex) { string sname; string filename; size_t found_cnt = 0; // How many fields we have found. - for (ClientClasses::const_iterator name = classes.cbegin(); - name != classes.cend() && found_cnt < 3; ++name) { + for (auto const& name : classes) { + + if (found_cnt >= 3) { + break; + } - ClientClassDefPtr cl = dict->findClass(*name); + ClientClassDefPtr cl = dict->findClass(name); if (!cl) { // Let's skip classes that don't have definitions. Currently // these are automatic classes VENDOR_CLASS_something, but there @@ -4365,11 +4360,10 @@ Dhcpv4Srv::acceptServerId(const Pkt4Ptr& query) const { // Check if the server identifier is configured at client class level. const ClientClasses& classes = query->getClasses(); - for (ClientClasses::const_iterator cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { + for (auto const& cclass : classes) { // Find the client class definition for this class const ClientClassDefPtr& ccdef = CfgMgr::instance().getCurrentCfg()-> - getClientClassDictionary()->findClass(*cclass); + getClientClassDictionary()->findClass(cclass); if (!ccdef) { continue; } @@ -4453,17 +4447,15 @@ void Dhcpv4Srv::requiredClassify(Dhcpv4Exchange& ex) { subnet->getSharedNetwork(network); if (network) { const ClientClasses& to_add = network->getRequiredClasses(); - for (ClientClasses::const_iterator cclass = to_add.cbegin(); - cclass != to_add.cend(); ++cclass) { - classes.insert(*cclass); + for (auto const& cclass : to_add) { + classes.insert(cclass); } } // Followed by the subnet const ClientClasses& to_add = subnet->getRequiredClasses(); - for(ClientClasses::const_iterator cclass = to_add.cbegin(); - cclass != to_add.cend(); ++cclass) { - classes.insert(*cclass); + for (auto const& cclass : to_add) { + classes.insert(cclass); } // And finish by the pool @@ -4476,9 +4468,8 @@ void Dhcpv4Srv::requiredClassify(Dhcpv4Exchange& ex) { PoolPtr pool = subnet->getPool(Lease::TYPE_V4, addr, false); if (pool) { const ClientClasses& to_add = pool->getRequiredClasses(); - for (ClientClasses::const_iterator cclass = to_add.cbegin(); - cclass != to_add.cend(); ++cclass) { - classes.insert(*cclass); + for (auto const& cclass : to_add) { + classes.insert(cclass); } } } @@ -4490,19 +4481,18 @@ void Dhcpv4Srv::requiredClassify(Dhcpv4Exchange& ex) { // Note getClientClassDictionary() cannot be null const ClientClassDictionaryPtr& dict = CfgMgr::instance().getCurrentCfg()->getClientClassDictionary(); - for (ClientClasses::const_iterator cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { - const ClientClassDefPtr class_def = dict->findClass(*cclass); + for (auto const& cclass : classes) { + const ClientClassDefPtr class_def = dict->findClass(cclass); if (!class_def) { LOG_DEBUG(dhcp4_logger, DBG_DHCP4_BASIC, DHCP4_CLASS_UNDEFINED) - .arg(*cclass); + .arg(cclass); continue; } const ExpressionPtr& expr_ptr = class_def->getMatchExpr(); // Nothing to do without an expression to evaluate if (!expr_ptr) { LOG_DEBUG(dhcp4_logger, DBG_DHCP4_BASIC, DHCP4_CLASS_UNTESTABLE) - .arg(*cclass); + .arg(cclass); continue; } // Evaluate the expression which can return false (no match), @@ -4511,22 +4501,22 @@ void Dhcpv4Srv::requiredClassify(Dhcpv4Exchange& ex) { bool status = evaluateBool(*expr_ptr, *query); if (status) { LOG_INFO(dhcp4_logger, EVAL_RESULT) - .arg(*cclass) + .arg(cclass) .arg("true"); // Matching: add the class - query->addClass(*cclass); + query->addClass(cclass); } else { LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, EVAL_RESULT) - .arg(*cclass) + .arg(cclass) .arg("false"); } } catch (const Exception& ex) { LOG_ERROR(dhcp4_logger, EVAL_RESULT) - .arg(*cclass) + .arg(cclass) .arg(ex.what()); } catch (...) { LOG_ERROR(dhcp4_logger, EVAL_RESULT) - .arg(*cclass) + .arg(cclass) .arg("get exception?"); } } @@ -4535,16 +4525,15 @@ void Dhcpv4Srv::requiredClassify(Dhcpv4Exchange& ex) { void Dhcpv4Srv::deferredUnpack(Pkt4Ptr& query) { // Iterate on the list of deferred option codes - BOOST_FOREACH(const uint16_t& code, query->getDeferredOptions()) { + for (auto const& code : query->getDeferredOptions()) { OptionDefinitionPtr def; // Iterate on client classes const ClientClasses& classes = query->getClasses(); - for (ClientClasses::const_iterator cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { + for (auto const& cclass : classes) { // Get the client class definition for this class const ClientClassDefPtr& ccdef = CfgMgr::instance().getCurrentCfg()-> - getClientClassDictionary()->findClass(*cclass); + getClientClassDictionary()->findClass(cclass); // If not found skip it if (!ccdef) { continue; diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc index b26cfc4e05..a7bf06954e 100644 --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@ -45,7 +45,6 @@ #include #include -#include #include #include @@ -157,10 +156,10 @@ public: } // Let's go through all the networks one by one - for (auto net = networks->begin(); net != networks->end(); ++net) { + for (auto const& net : *networks) { // For each network go through all the subnets in it. - const Subnet4SimpleCollection* subnets = (*net)->getAllSubnets(); + const Subnet4SimpleCollection* subnets = net->getAllSubnets(); if (!subnets) { // Shared network without subnets it weird, but we decided to // accept such configurations. @@ -168,8 +167,8 @@ public: } // For each subnet, add it to a list of regular subnets. - for (auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) { - dest->add(*subnet); + for (auto const& subnet : *subnets) { + dest->add(subnet); } } } @@ -216,61 +215,61 @@ public: std::set names; // Let's go through all the networks one by one - for (auto net = networks.begin(); net != networks.end(); ++net) { + for (auto const& net : networks) { string txt; // Let's check if all subnets have either the same interface // or don't have the interface specified at all. - bool authoritative = (*net)->getAuthoritative(); - string iface = (*net)->getIface(); + bool authoritative = net->getAuthoritative(); + string iface = net->getIface(); - const Subnet4SimpleCollection* subnets = (*net)->getAllSubnets(); + const Subnet4SimpleCollection* subnets = net->getAllSubnets(); if (subnets) { // For each subnet, add it to a list of regular subnets. - for (auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) { - if ((*subnet)->getAuthoritative() != authoritative) { + for (auto const& subnet : *subnets) { + if (subnet->getAuthoritative() != authoritative) { isc_throw(DhcpConfigError, "Subnet " << boolalpha - << (*subnet)->toText() + << subnet->toText() << " has different authoritative setting " - << (*subnet)->getAuthoritative() + << subnet->getAuthoritative() << " than the shared-network itself: " << authoritative); } if (iface.empty()) { - iface = (*subnet)->getIface(); + iface = subnet->getIface(); continue; } - if ((*subnet)->getIface().empty()) { + if (subnet->getIface().empty()) { continue; } - if ((*subnet)->getIface() != iface) { - isc_throw(DhcpConfigError, "Subnet " << (*subnet)->toText() - << " has specified interface " << (*subnet)->getIface() + if (subnet->getIface() != iface) { + isc_throw(DhcpConfigError, "Subnet " << subnet->toText() + << " has specified interface " << subnet->getIface() << ", but earlier subnet in the same shared-network" << " or the shared-network itself used " << iface); } // Let's collect the subnets in case we later find out the // subnet doesn't have a mandatory name. - txt += (*subnet)->toText() + " "; + txt += subnet->toText() + " "; } } // Next, let's check name of the shared network. - if ((*net)->getName().empty()) { + if (net->getName().empty()) { isc_throw(DhcpConfigError, "Shared-network with subnets " << txt << " is missing mandatory 'name' parameter"); } // Is it unique? - if (names.find((*net)->getName()) != names.end()) { + if (names.find(net->getName()) != names.end()) { isc_throw(DhcpConfigError, "A shared-network with " - "name " << (*net)->getName() << " defined twice."); + "name " << net->getName() << " defined twice."); } - names.insert((*net)->getName()); + names.insert(net->getName()); } } @@ -563,8 +562,8 @@ processDhcp4Config(isc::data::ConstElementPtr config_set) { HostCollection hosts; HostReservationsListParser parser; parser.parse(SUBNET_ID_GLOBAL, reservations, hosts); - for (auto h = hosts.begin(); h != hosts.end(); ++h) { - srv_config->getCfgHosts()->add(*h); + for (auto const& h : hosts) { + srv_config->getCfgHosts()->add(h); } } @@ -607,12 +606,10 @@ processDhcp4Config(isc::data::ConstElementPtr config_set) { } // Make parsers grouping. - ConfigPair config_pair; const std::map& values_map = mutable_cfg->mapValue(); - BOOST_FOREACH(config_pair, values_map) { - + for (auto const& config_pair : values_map) { parameter_name = config_pair.first; // These are converted to SimpleParser and are handled already above. diff --git a/src/bin/dhcp4/tests/callout_library_3.cc b/src/bin/dhcp4/tests/callout_library_3.cc index 6bd0fa3569..07faf51445 100644 --- a/src/bin/dhcp4/tests/callout_library_3.cc +++ b/src/bin/dhcp4/tests/callout_library_3.cc @@ -58,8 +58,8 @@ dhcp4_srv_configured(CalloutHandle& handle) { // Append argument names. std::vector args = handle.getArgumentNames(); - for (auto arg = args.begin(); arg != args.end(); ++arg) { - if (appendArgument(SRV_CONFIG_MARKER_FILE, arg->c_str()) != 0) { + for (auto const& arg : args) { + if (appendArgument(SRV_CONFIG_MARKER_FILE, arg.c_str()) != 0) { return (1); } } diff --git a/src/bin/dhcp4/tests/config_backend_unittest.cc b/src/bin/dhcp4/tests/config_backend_unittest.cc index 5010177871..82fe4545f1 100644 --- a/src/bin/dhcp4/tests/config_backend_unittest.cc +++ b/src/bin/dhcp4/tests/config_backend_unittest.cc @@ -23,7 +23,6 @@ #include #include -#include #include #include diff --git a/src/bin/dhcp4/tests/config_parser_unittest.cc b/src/bin/dhcp4/tests/config_parser_unittest.cc index eb78dbbf76..bd5f2b361f 100644 --- a/src/bin/dhcp4/tests/config_parser_unittest.cc +++ b/src/bin/dhcp4/tests/config_parser_unittest.cc @@ -42,7 +42,6 @@ #include "dhcp4_test_utils.h" #include "get_config_unittest.h" -#include #include #include @@ -438,8 +437,7 @@ public: " \"subnet\": \"192.0.2.0/24\", " " \"option-data\": [ {"; bool first = true; - typedef std::pair ParamPair; - BOOST_FOREACH(ParamPair param, params) { + for (auto const& param : params) { if (!first) { stream << ", "; } else { @@ -2365,18 +2363,16 @@ TEST_F(Dhcp4ParserTest, badSubnetValues) { // Iterate over the list of scenarios. Each should fail to parse with // a specific error message. - for (auto scenario = scenarios.begin(); scenario != scenarios.end(); ++scenario) { - { - SCOPED_TRACE((*scenario).description_); - ConstElementPtr config; - ASSERT_NO_THROW(config = parseDHCP4((*scenario).config_json_)) - << "invalid json, broken test"; - ConstElementPtr status; - EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, config)); - checkResult(status, 1); - ASSERT_TRUE(comment_); - EXPECT_EQ(comment_->stringValue(), (*scenario).exp_error_msg_); - } + for (auto const& scenario : scenarios) { + SCOPED_TRACE(scenario.description_); + ConstElementPtr config; + ASSERT_NO_THROW(config = parseDHCP4(scenario.config_json_)) + << "invalid json, broken test"; + ConstElementPtr status; + EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, config)); + checkResult(status, 1); + ASSERT_TRUE(comment_); + EXPECT_EQ(comment_->stringValue(), scenario.exp_error_msg_); } } diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index 14ffe8d4ff..12f2c3d1f5 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -667,13 +667,16 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelStats) { // preparing the schema which check if all statistics are set to zero std::ostringstream s; s << "{ \"arguments\": { "; - for (auto st = initial_stats.begin(); st != initial_stats.end();) { - s << "\"" << *st << "\": [ [ 0, \""; - s << isc::util::clockToText(StatsMgr::instance().getObservation(*st)->getInteger().second); - s << "\" ] ]"; - if (++st != initial_stats.end()) { + bool first = true; + for (auto const& st : initial_stats) { + if (!first) { s << ", "; + } else { + first = false; } + s << "\"" << st << "\": [ [ 0, \""; + s << isc::util::clockToText(StatsMgr::instance().getObservation(st)->getInteger().second); + s << "\" ] ]"; } s << " }, \"result\": 0 }"; diff --git a/src/bin/dhcp4/tests/dhcp4_client.cc b/src/bin/dhcp4/tests/dhcp4_client.cc index ae466aa97a..75efdcbe7a 100644 --- a/src/bin/dhcp4/tests/dhcp4_client.cc +++ b/src/bin/dhcp4/tests/dhcp4_client.cc @@ -137,9 +137,8 @@ Dhcp4Client::appendPRL() { // has been specified to be requested. OptionUint8ArrayPtr prl(new OptionUint8Array(Option::V4, DHO_DHCP_PARAMETER_REQUEST_LIST)); - for (std::set::const_iterator opt = requested_options_.begin(); - opt != requested_options_.end(); ++opt) { - prl->addValue(*opt); + for (auto const& opt : requested_options_) { + prl->addValue(opt); } context_.query_->addOption(prl); } @@ -235,20 +234,18 @@ void Dhcp4Client::appendExtraOptions() { // If there are any custom options specified, add them all to the message. if (!extra_options_.empty()) { - for (OptionCollection::iterator opt = extra_options_.begin(); - opt != extra_options_.end(); ++opt) { + for (auto const& opt : extra_options_) { // Call base class function so that unittests can add multiple // options with the same code. - context_.query_->Pkt::addOption(opt->second); + context_.query_->Pkt::addOption(opt.second); } } } void Dhcp4Client::appendClasses() { - for (ClientClasses::const_iterator cclass = classes_.cbegin(); - cclass != classes_.cend(); ++cclass) { - context_.query_->addClass(*cclass); + for (auto const& cclass : classes_) { + context_.query_->addClass(cclass); } } @@ -556,9 +553,8 @@ Dhcp4Client::sendMsg(const Pkt4Ptr& msg) { msg_copy->setIndex(iface_index_); // Copy classes const ClientClasses& classes = msg->getClasses(); - for (ClientClasses::const_iterator cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { - msg_copy->addClass(*cclass); + for (auto const& cclass : classes) { + msg_copy->addClass(cclass); } srv_->fakeReceive(msg_copy); diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc index 28d150b343..78aa950096 100644 --- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc @@ -2898,7 +2898,7 @@ Dhcpv4SrvTest::loadConfigFile(const string& path) { removeTlsParameters(hosts); hosts = dhcp4->get("hosts-databases"); if (hosts) { - for (auto& host : hosts->listValue()) { + for (auto const& host : hosts->listValue()) { removeTlsParameters(host); } } @@ -2991,7 +2991,7 @@ Dhcpv4SrvTest::checkConfigFiles() { "with-ddns.json", }; vector files; - for (const string& example : examples) { + for (auto const& example : examples) { string file = path + "/" + example; files.push_back(file); } diff --git a/src/bin/dhcp4/tests/hooks_unittest.cc b/src/bin/dhcp4/tests/hooks_unittest.cc index 8ee1a8a3dc..b30b7d5682 100644 --- a/src/bin/dhcp4/tests/hooks_unittest.cc +++ b/src/bin/dhcp4/tests/hooks_unittest.cc @@ -3371,7 +3371,7 @@ TEST_F(LoadUnloadDhcpv4SrvTest, failLoadIncompatibleLibraries) { // Checks if callouts installed on the dhcp4_srv_configured ared indeed called // and all the necessary parameters are passed. TEST_F(LoadUnloadDhcpv4SrvTest, Dhcpv4SrvConfigured) { - for (const string& parameters : vector{ + for (auto const& parameters : vector{ "", R"(, "parameters": { "mode": "fail-without-error" } )", R"(, "parameters": { "mode": "fail-with-error" } )"}) { diff --git a/src/bin/dhcp4/tests/shared_network_unittest.cc b/src/bin/dhcp4/tests/shared_network_unittest.cc index bf5964dc1e..6cda3aabf2 100644 --- a/src/bin/dhcp4/tests/shared_network_unittest.cc +++ b/src/bin/dhcp4/tests/shared_network_unittest.cc @@ -1165,10 +1165,9 @@ public: Subnet4Ptr getConfiguredSubnet(const IOAddress& address) { CfgSubnets4Ptr cfg = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4(); const Subnet4Collection* subnets = cfg->getAll(); - for (auto subnet_it = subnets->cbegin(); subnet_it != subnets->cend(); - ++subnet_it) { - if ((*subnet_it)->inRange(address)) { - return (*subnet_it); + for (auto const& subnet_it : *subnets) { + if (subnet_it->inRange(address)) { + return (subnet_it); } } return (Subnet4Ptr()); diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index a7e7379581..b415ed596f 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -63,8 +63,8 @@ #endif #include -#include #include +#include #include #include #include @@ -261,9 +261,9 @@ void Dhcpv6Srv::setPacketStatisticsDefaults() { isc::stats::StatsMgr& stats_mgr = isc::stats::StatsMgr::instance(); // Iterate over set of observed statistics - for (auto it = dhcp6_statistics.begin(); it != dhcp6_statistics.end(); ++it) { + for (auto const& it : dhcp6_statistics) { // Initialize them with default value 0 - stats_mgr.setValue((*it), static_cast(0)); + stats_mgr.setValue(it, static_cast(0)); } } @@ -364,8 +364,7 @@ void Dhcpv6Srv::setHostIdentifiers(AllocEngine::ClientContext6& ctx) { const ConstCfgHostOperationsPtr cfg = CfgMgr::instance().getCurrentCfg()->getCfgHostOperations6(); - BOOST_FOREACH(const Host::IdentifierType& id_type, - cfg->getIdentifierTypes()) { + for (auto const& id_type : cfg->getIdentifierTypes()) { switch (id_type) { case Host::IDENT_DUID: if (ctx.duid_) { @@ -455,9 +454,8 @@ Dhcpv6Srv::earlyGHRLookup(const Pkt6Ptr& query, // Add classes from the global reservations. const ClientClasses& classes = global_host->getClientClasses6(); - for (ClientClasses::const_iterator cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { - query->addClass(*cclass); + for (auto const& cclass : classes) { + query->addClass(cclass); } // Evaluate classes before KNOWN. @@ -1378,11 +1376,11 @@ Dhcpv6Srv::duidToString(const OptionPtr& opt) { OptionBuffer data = opt->getData(); bool colon = false; - for (OptionBufferConstIter it = data.begin(); it != data.end(); ++it) { + for (auto const& it : data) { if (colon) { tmp << ":"; } - tmp << hex << setw(2) << setfill('0') << static_cast(*it); + tmp << hex << setw(2) << setfill('0') << static_cast(it); if (!colon) { colon = true; } @@ -1452,17 +1450,16 @@ Dhcpv6Srv::buildCfgOptionList(const Pkt6Ptr& question, // Each class in the incoming packet const ClientClasses& classes = question->getClasses(); - for (ClientClasses::const_iterator cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { + for (auto const& cclass : classes) { // Find the client class definition for this class const ClientClassDefPtr& ccdef = CfgMgr::instance().getCurrentCfg()-> - getClientClassDictionary()->findClass(*cclass); + getClientClassDictionary()->findClass(cclass); if (!ccdef) { // Not found: the class is built-in or not configured - if (!isClientClassBuiltIn(*cclass)) { + if (!isClientClassBuiltIn(cclass)) { LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_UNCONFIGURED) .arg(question->getLabel()) - .arg(*cclass); + .arg(cclass); } // Skip it continue; @@ -1516,22 +1513,20 @@ Dhcpv6Srv::appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer, // Get persistent options. const OptionContainerPersistIndex& pidx = opts->get<2>(); const OptionContainerPersistRange& prange = pidx.equal_range(true); - for (OptionContainerPersistIndex::const_iterator desc = prange.first; - desc != prange.second; ++desc) { + BOOST_FOREACH(auto const& desc, prange) { // Add the persistent option code to requested options. - if (desc->option_) { - uint16_t code = desc->option_->getType(); + if (desc.option_) { + uint16_t code = desc.option_->getType(); static_cast(requested_opts.insert(code)); } } // Get cancelled options. const OptionContainerCancelIndex& cidx = opts->get<5>(); const OptionContainerCancelRange& crange = cidx.equal_range(true); - for (OptionContainerCancelIndex::const_iterator desc = crange.first; - desc != crange.second; ++desc) { + BOOST_FOREACH(auto const& desc, crange) { // Add the cancelled option code to the cancelled options. - if (desc->option_) { - uint16_t code = desc->option_->getType(); + if (desc.option_) { + uint16_t code = desc.option_->getType(); static_cast(cancelled_opts.insert(code)); } } @@ -1741,25 +1736,23 @@ Dhcpv6Srv::appendRequestedVendorOptions(const Pkt6Ptr& question, // Get persistent options. const OptionContainerPersistIndex& pidx = opts->get<2>(); const OptionContainerPersistRange& prange = pidx.equal_range(true); - for (OptionContainerPersistIndex::const_iterator desc = prange.first; - desc != prange.second; ++desc) { - if (!desc->option_) { + BOOST_FOREACH(auto const& desc, prange) { + if (!desc.option_) { continue; } // Add the persistent option code to requested options - uint16_t code = desc->option_->getType(); + uint16_t code = desc.option_->getType(); static_cast(requested_opts[vendor_id].insert(code)); } // Get cancelled options. const OptionContainerCancelIndex& cidx = opts->get<5>(); const OptionContainerCancelRange& crange = cidx.equal_range(true); - for (OptionContainerCancelIndex::const_iterator desc = crange.first; - desc != crange.second; ++desc) { - if (!desc->option_) { + BOOST_FOREACH(auto const& desc, crange) { + if (!desc.option_) { continue; } // Add the cancelled option code to cancelled options - uint16_t code = desc->option_->getType(); + uint16_t code = desc.option_->getType(); static_cast(cancelled_opts[vendor_id].insert(code)); } } @@ -2254,22 +2247,21 @@ Dhcpv6Srv::createNameChangeRequests(const Pkt6Ptr& answer, // to determine if the changes included changes to the FQDN. If so // then we may need to do a CHG_REMOVE. bool extended_only = false; - for (Lease6Collection::const_iterator l = ctx.currentIA().changed_leases_.begin(); - l != ctx.currentIA().changed_leases_.end(); ++l) { + for (auto const& l : ctx.currentIA().changed_leases_) { - if ((*l)->addr_ == iaaddr->getAddress()) { + if (l->addr_ == iaaddr->getAddress()) { // The address is the same so this must be renewal. If we're not // always updating on renew, then we only renew if DNS info has // changed. if (!ctx.getDdnsParams()->getUpdateOnRenew() && - ((*l)->hostname_ == opt_fqdn->getDomainName() && - (*l)->fqdn_fwd_ == do_fwd && (*l)->fqdn_rev_ == do_rev)) { + (l->hostname_ == opt_fqdn->getDomainName() && + l->fqdn_fwd_ == do_fwd && l->fqdn_rev_ == do_rev)) { extended_only = true; } else { // Queue a CHG_REMOVE of the old data. // NCR will only be created if the lease hostname is not // empty and at least one of the direction flags is true - queueNCR(CHG_REMOVE, *l); + queueNCR(CHG_REMOVE, l); } break; @@ -2317,9 +2309,8 @@ Dhcpv6Srv::getMAC(const Pkt6Ptr& pkt) { CfgMACSources mac_sources = CfgMgr::instance().getCurrentCfg()-> getMACSources().get(); HWAddrPtr hwaddr; - for (CfgMACSources::const_iterator it = mac_sources.begin(); - it != mac_sources.end(); ++it) { - hwaddr = pkt->getMAC(*it); + for (auto const& it : mac_sources) { + hwaddr = pkt->getMAC(it); if (hwaddr) { return (hwaddr); } @@ -2537,57 +2528,56 @@ Dhcpv6Srv::assignIA_PD(const Pkt6Ptr& query, uint32_t min_preferred_lft = (*leases.begin())->preferred_lft_; const bool pd_exclude_requested = requestedInORO(query, D6O_PD_EXCLUDE); - for (Lease6Collection::iterator l = leases.begin(); - l != leases.end(); ++l) { + for (auto const& l : leases) { // We have a lease! Let's wrap its content into IA_PD option // with IAADDR suboption. if (ctx.fake_allocation_) { LOG_INFO(lease6_logger, DHCP6_PD_LEASE_ADVERT) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) - .arg(static_cast((*l)->prefixlen_)) + .arg(l->addr_.toText()) + .arg(static_cast(l->prefixlen_)) .arg(ia->getIAID()); - } else if ((*l)->reuseable_valid_lft_ == 0) { + } else if (l->reuseable_valid_lft_ == 0) { LOG_INFO(lease6_logger, DHCP6_PD_LEASE_ALLOC) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) - .arg(static_cast((*l)->prefixlen_)) + .arg(l->addr_.toText()) + .arg(static_cast(l->prefixlen_)) .arg(ia->getIAID()) - .arg(Lease::lifetimeToText((*l)->valid_lft_)); + .arg(Lease::lifetimeToText(l->valid_lft_)); } else { - (*l)->valid_lft_ = (*l)->reuseable_valid_lft_; - (*l)->preferred_lft_ = (*l)->reuseable_preferred_lft_; + l->valid_lft_ = l->reuseable_valid_lft_; + l->preferred_lft_ = l->reuseable_preferred_lft_; LOG_INFO(lease6_logger, DHCP6_PD_LEASE_REUSE) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) - .arg(static_cast((*l)->prefixlen_)) + .arg(l->addr_.toText()) + .arg(static_cast(l->prefixlen_)) .arg(ia->getIAID()) - .arg(Lease::lifetimeToText((*l)->valid_lft_)); + .arg(Lease::lifetimeToText(l->valid_lft_)); // Increment the reuse statistics. StatsMgr::instance().addValue("v6-ia-pd-lease-reuses", int64_t(1)); - StatsMgr::instance().addValue(StatsMgr::generateName("subnet", (*l)->subnet_id_, + StatsMgr::instance().addValue(StatsMgr::generateName("subnet", l->subnet_id_, "v6-ia-pd-lease-reuses"), int64_t(1)); } // Check for new minimum lease time - if (((*l)->preferred_lft_ > 0) && (min_preferred_lft > (*l)->preferred_lft_)) { - min_preferred_lft = (*l)->preferred_lft_; + if ((l->preferred_lft_ > 0) && (min_preferred_lft > l->preferred_lft_)) { + min_preferred_lft = l->preferred_lft_; } boost::shared_ptr - addr(new Option6IAPrefix(D6O_IAPREFIX, (*l)->addr_, - (*l)->prefixlen_, (*l)->preferred_lft_, - (*l)->valid_lft_)); + addr(new Option6IAPrefix(D6O_IAPREFIX, l->addr_, + l->prefixlen_, l->preferred_lft_, + l->valid_lft_)); ia_rsp->addOption(addr); if (pd_exclude_requested) { // PD exclude option has been requested via ORO, thus we need to // include it if the pool configuration specifies this option. Pool6Ptr pool = boost::dynamic_pointer_cast< - Pool6>(subnet->getPool(Lease::TYPE_PD, (*l)->addr_)); + Pool6>(subnet->getPool(Lease::TYPE_PD, l->addr_)); if (pool) { Option6PDExcludePtr pd_exclude_option = pool->getPrefixExcludeOption(); if (pd_exclude_option) { @@ -2660,12 +2650,11 @@ Dhcpv6Srv::extendIA_NA(const Pkt6Ptr& query, // Extract the addresses that the client is trying to obtain. OptionCollection addrs = ia->getOptions(); - for (OptionCollection::const_iterator it = addrs.begin(); - it != addrs.end(); ++it) { - if (it->second->getType() != D6O_IAADDR) { + for (auto const& it : addrs) { + if (it.second->getType() != D6O_IAADDR) { continue; } - Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast(it->second); + Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast(it.second); if (!iaaddr) { // That's weird. Option code was ok, but the object type was not. // This should never happen. The only case would be with badly @@ -2695,82 +2684,80 @@ Dhcpv6Srv::extendIA_NA(const Pkt6Ptr& query, uint32_t min_preferred_lft = std::numeric_limits::max(); // For all leases we have now, add the IAADDR with non-zero lifetimes. - for (Lease6Collection::iterator l = leases.begin(); l != leases.end(); ++l) { - if ((*l)->reuseable_valid_lft_ == 0) { + for (auto const& l : leases) { + if (l->reuseable_valid_lft_ == 0) { LOG_INFO(lease6_logger, DHCP6_LEASE_RENEW) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) + .arg(l->addr_.toText()) .arg(ia->getIAID()); } else { - (*l)->valid_lft_ = (*l)->reuseable_valid_lft_; - (*l)->preferred_lft_ = (*l)->reuseable_preferred_lft_; + l->valid_lft_ = l->reuseable_valid_lft_; + l->preferred_lft_ = l->reuseable_preferred_lft_; LOG_INFO(lease6_logger, DHCP6_LEASE_REUSE) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) + .arg(l->addr_.toText()) .arg(ia->getIAID()) - .arg(Lease::lifetimeToText((*l)->valid_lft_)); + .arg(Lease::lifetimeToText(l->valid_lft_)); // Increment the reuse statistics. StatsMgr::instance().addValue("v6-ia-na-lease-reuses", int64_t(1)); - StatsMgr::instance().addValue(StatsMgr::generateName("subnet", (*l)->subnet_id_, + StatsMgr::instance().addValue(StatsMgr::generateName("subnet", l->subnet_id_, "v6-ia-na-lease-reuses"), int64_t(1)); } Option6IAAddrPtr iaaddr(new Option6IAAddr(D6O_IAADDR, - (*l)->addr_, (*l)->preferred_lft_, (*l)->valid_lft_)); + l->addr_, l->preferred_lft_, l->valid_lft_)); ia_rsp->addOption(iaaddr); // Check for new minimum lease time - if (((*l)->preferred_lft_ > 0) && (min_preferred_lft > (*l)->preferred_lft_)) { - min_preferred_lft = (*l)->preferred_lft_; + if ((l->preferred_lft_ > 0) && (min_preferred_lft > l->preferred_lft_)) { + min_preferred_lft = l->preferred_lft_; } // Now remove this address from the hints list. - AllocEngine::Resource hint_type((*l)->addr_); + AllocEngine::Resource hint_type(l->addr_); hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end()); } // For the leases that we just retired, send the addresses with 0 lifetimes. - for (Lease6Collection::iterator l = ctx.currentIA().old_leases_.begin(); - l != ctx.currentIA().old_leases_.end(); ++l) { + for (auto const& l : ctx.currentIA().old_leases_) { // Send an address with zero lifetimes only when this lease belonged to // this client. Do not send it when we're reusing an old lease that belonged // to someone else. - if (equalValues(query->getClientId(), (*l)->duid_)) { + if (equalValues(query->getClientId(), l->duid_)) { Option6IAAddrPtr iaaddr(new Option6IAAddr(D6O_IAADDR, - (*l)->addr_, 0, 0)); + l->addr_, 0, 0)); ia_rsp->addOption(iaaddr); } // Now remove this address from the hints list. - AllocEngine::Resource hint_type((*l)->addr_); + AllocEngine::Resource hint_type(l->addr_); hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end()); // If the new FQDN settings have changed for the lease, we need to // delete any existing FQDN records for this lease. - if (((*l)->hostname_ != ctx.hostname_) || ((*l)->fqdn_fwd_ != ctx.fwd_dns_update_) || - ((*l)->fqdn_rev_ != ctx.rev_dns_update_)) { + if ((l->hostname_ != ctx.hostname_) || (l->fqdn_fwd_ != ctx.fwd_dns_update_) || + (l->fqdn_rev_ != ctx.rev_dns_update_)) { LOG_DEBUG(ddns6_logger, DBG_DHCP6_DETAIL, DHCP6_DDNS_REMOVE_OLD_LEASE_FQDN) .arg(query->getLabel()) - .arg((*l)->toText()) + .arg(l->toText()) .arg(ctx.hostname_) .arg(ctx.rev_dns_update_ ? "true" : "false") .arg(ctx.fwd_dns_update_ ? "true" : "false"); - queueNCR(CHG_REMOVE, *l); + queueNCR(CHG_REMOVE, l); } } // Finally, if there are any addresses requested that we haven't dealt with // already, inform the client that he can't have them. - for (AllocEngine::HintContainer::const_iterator hint = hints.begin(); - hint != hints.end(); ++hint) { + for (auto const& hint : hints) { Option6IAAddrPtr iaaddr(new Option6IAAddr(D6O_IAADDR, - hint->getAddress(), 0, 0)); + hint.getAddress(), 0, 0)); ia_rsp->addOption(iaaddr); } @@ -2848,12 +2835,11 @@ Dhcpv6Srv::extendIA_PD(const Pkt6Ptr& query, // Extract prefixes that the client is trying to renew. OptionCollection addrs = ia->getOptions(); - for (OptionCollection::const_iterator it = addrs.begin(); - it != addrs.end(); ++it) { - if (it->second->getType() != D6O_IAPREFIX) { + for (auto const& it : addrs) { + if (it.second->getType() != D6O_IAPREFIX) { continue; } - Option6IAPrefixPtr prf = boost::dynamic_pointer_cast(it->second); + Option6IAPrefixPtr prf = boost::dynamic_pointer_cast(it.second); if (!prf) { // That's weird. Option code was ok, but the object type was not. // This should never happen. The only case would be with badly @@ -2889,40 +2875,40 @@ Dhcpv6Srv::extendIA_PD(const Pkt6Ptr& query, // for calculating T1 and T2. uint32_t min_preferred_lft = std::numeric_limits::max(); - for (Lease6Collection::iterator l = leases.begin(); l != leases.end(); ++l) { - if ((*l)->reuseable_valid_lft_ == 0) { + for (auto const& l : leases) { + if (l->reuseable_valid_lft_ == 0) { LOG_INFO(lease6_logger, DHCP6_PD_LEASE_RENEW) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) - .arg(static_cast((*l)->prefixlen_)) + .arg(l->addr_.toText()) + .arg(static_cast(l->prefixlen_)) .arg(ia->getIAID()); } else { - (*l)->valid_lft_ = (*l)->reuseable_valid_lft_; - (*l)->preferred_lft_ = (*l)->reuseable_preferred_lft_; + l->valid_lft_ = l->reuseable_valid_lft_; + l->preferred_lft_ = l->reuseable_preferred_lft_; LOG_INFO(lease6_logger, DHCP6_PD_LEASE_REUSE) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) - .arg(static_cast((*l)->prefixlen_)) + .arg(l->addr_.toText()) + .arg(static_cast(l->prefixlen_)) .arg(ia->getIAID()) - .arg(Lease::lifetimeToText((*l)->valid_lft_)); + .arg(Lease::lifetimeToText(l->valid_lft_)); // Increment the reuse statistics. StatsMgr::instance().addValue("v6-ia-pd-lease-reuses", int64_t(1)); - StatsMgr::instance().addValue(StatsMgr::generateName("subnet", (*l)->subnet_id_, + StatsMgr::instance().addValue(StatsMgr::generateName("subnet", l->subnet_id_, "v6-ia-pd-lease-reuses"), int64_t(1)); } Option6IAPrefixPtr prf(new Option6IAPrefix(D6O_IAPREFIX, - (*l)->addr_, (*l)->prefixlen_, - (*l)->preferred_lft_, (*l)->valid_lft_)); + l->addr_, l->prefixlen_, + l->preferred_lft_, l->valid_lft_)); ia_rsp->addOption(prf); if (pd_exclude_requested) { // PD exclude option has been requested via ORO, thus we need to // include it if the pool configuration specifies this option. Pool6Ptr pool = boost::dynamic_pointer_cast< - Pool6>(subnet->getPool(Lease::TYPE_PD, (*l)->addr_)); + Pool6>(subnet->getPool(Lease::TYPE_PD, l->addr_)); if (pool) { Option6PDExcludePtr pd_exclude_option = pool->getPrefixExcludeOption(); @@ -2933,46 +2919,44 @@ Dhcpv6Srv::extendIA_PD(const Pkt6Ptr& query, } // Check for new minimum lease time - if (((*l)->preferred_lft_ > 0) && ((*l)->preferred_lft_ < min_preferred_lft)) { - min_preferred_lft = (*l)->preferred_lft_; + if ((l->preferred_lft_ > 0) && (l->preferred_lft_ < min_preferred_lft)) { + min_preferred_lft = l->preferred_lft_; } // Now remove this prefix from the hints list. - AllocEngine::Resource hint_type((*l)->addr_, (*l)->prefixlen_); + AllocEngine::Resource hint_type(l->addr_, l->prefixlen_); hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end()); } /// For the leases that we just retired, send the prefixes with 0 lifetimes. - for (Lease6Collection::iterator l = ctx.currentIA().old_leases_.begin(); - l != ctx.currentIA().old_leases_.end(); ++l) { + for (auto const& l : ctx.currentIA().old_leases_) { // Send a prefix with zero lifetimes only when this lease belonged to // this client. Do not send it when we're reusing an old lease that belonged // to someone else. - if (equalValues(query->getClientId(), (*l)->duid_)) { - Option6IAPrefixPtr prefix(new Option6IAPrefix(D6O_IAPREFIX, (*l)->addr_, - (*l)->prefixlen_, 0, 0)); + if (equalValues(query->getClientId(), l->duid_)) { + Option6IAPrefixPtr prefix(new Option6IAPrefix(D6O_IAPREFIX, l->addr_, + l->prefixlen_, 0, 0)); ia_rsp->addOption(prefix); } // Now remove this prefix from the hints list. - AllocEngine::Resource hint_type((*l)->addr_, (*l)->prefixlen_); + AllocEngine::Resource hint_type(l->addr_, l->prefixlen_); hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end()); } // Finally, if there are any prefixes requested that we haven't dealt with // already, inform the client that he can't have them. - for (AllocEngine::HintContainer::const_iterator prefix = hints.begin(); - prefix != hints.end(); ++prefix) { + for (auto const& prefix : hints) { // Send the prefix with the zero lifetimes only if the prefix // contains non-zero value. A zero value indicates that the hint was // for the prefix length. - if (!prefix->getAddress().isV6Zero()) { + if (!prefix.getAddress().isV6Zero()) { OptionPtr prefix_opt(new Option6IAPrefix(D6O_IAPREFIX, - prefix->getAddress(), - prefix->getPrefixLength(), + prefix.getAddress(), + prefix.getPrefixLength(), 0, 0)); ia_rsp->addOption(prefix_opt); } @@ -3741,16 +3725,14 @@ Dhcpv6Srv::processConfirm(AllocEngine::ClientContext6& ctx) { // over the IA_NA options to check if they hold any addresses. If there // are no, the Confirm is discarded. // Check addresses in IA_NA options and make sure they are appropriate. - for (OptionCollection::const_iterator ia = ias.begin(); - ia != ias.end(); ++ia) { - const OptionCollection& opts = ia->second->getOptions(); - for (OptionCollection::const_iterator opt = opts.begin(); - opt != opts.end(); ++opt) { + for (auto const& ia : ias) { + const OptionCollection& opts = ia.second->getOptions(); + for (auto const& opt : opts) { // Ignore options other than IAAddr. - if (opt->second->getType() == D6O_IAADDR) { + if (opt.second->getType() == D6O_IAADDR) { // Check that the address is in range in the subnet selected. Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast< - Option6IAAddr>(opt->second); + Option6IAAddr>(opt.second); // If there is subnet selected and the address has been included // in IA_NA, mark it verified and verify that it belongs to the // subnet. @@ -3927,16 +3909,15 @@ Dhcpv6Srv::declineIA(const Pkt6Ptr& decline, const DuidPtr& duid, const OptionCollection& opts = ia->getOptions(); int total_addrs = 0; // Let's count the total number of addresses. - for (OptionCollection::const_iterator opt = opts.begin(); opt != opts.end(); - ++opt) { + for (auto const& opt : opts) { // Let's ignore nested options other than IAADDR (there shouldn't be anything // else in IA_NA in Decline message, but let's be on the safe side). - if (opt->second->getType() != D6O_IAADDR) { + if (opt.second->getType() != D6O_IAADDR) { continue; } Option6IAAddrPtr decline_addr = boost::dynamic_pointer_cast - (opt->second); + (opt.second); if (!decline_addr) { continue; } @@ -4243,23 +4224,22 @@ void Dhcpv6Srv::evaluateClasses(const Pkt6Ptr& pkt, bool depend_on_known) { const ClientClassDictionaryPtr& dict = CfgMgr::instance().getCurrentCfg()->getClientClassDictionary(); const ClientClassDefListPtr& defs_ptr = dict->getClasses(); - for (ClientClassDefList::const_iterator it = defs_ptr->cbegin(); - it != defs_ptr->cend(); ++it) { + for (auto const& it : *defs_ptr) { // Note second cannot be null - const ExpressionPtr& expr_ptr = (*it)->getMatchExpr(); + const ExpressionPtr& expr_ptr = it->getMatchExpr(); // Nothing to do without an expression to evaluate if (!expr_ptr) { continue; } // Not the right time if only when required - if ((*it)->getRequired()) { + if (it->getRequired()) { continue; } // Not the right pass. - if ((*it)->getDependOnKnown() != depend_on_known) { + if (it->getDependOnKnown() != depend_on_known) { continue; } - (*it)->test(pkt, expr_ptr); + it->test(pkt, expr_ptr); } } @@ -4283,9 +4263,8 @@ Dhcpv6Srv::setReservedClientClasses(const Pkt6Ptr& pkt, const AllocEngine::ClientContext6& ctx) { if (ctx.currentHost() && pkt) { const ClientClasses& classes = ctx.currentHost()->getClientClasses6(); - for (ClientClasses::const_iterator cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { - pkt->addClass(*cclass); + for (auto const& cclass : classes) { + pkt->addClass(cclass); } } } @@ -4317,17 +4296,15 @@ Dhcpv6Srv::requiredClassify(const Pkt6Ptr& pkt, AllocEngine::ClientContext6& ctx subnet->getSharedNetwork(network); if (network) { const ClientClasses& to_add = network->getRequiredClasses(); - for (ClientClasses::const_iterator cclass = to_add.cbegin(); - cclass != to_add.cend(); ++cclass) { - classes.insert(*cclass); + for (auto const& cclass : to_add) { + classes.insert(cclass); } } // Followed by the subnet const ClientClasses& to_add = subnet->getRequiredClasses(); - for (ClientClasses::const_iterator cclass = to_add.cbegin(); - cclass != to_add.cend(); ++cclass) { - classes.insert(*cclass); + for (auto const& cclass : to_add) { + classes.insert(cclass); } // And finish by pools @@ -4339,9 +4316,8 @@ Dhcpv6Srv::requiredClassify(const Pkt6Ptr& pkt, AllocEngine::ClientContext6& ctx false); if (pool) { const ClientClasses& to_add = pool->getRequiredClasses(); - for (ClientClasses::const_iterator cclass = to_add.cbegin(); - cclass != to_add.cend(); ++cclass) { - classes.insert(*cclass); + for (auto const& cclass : to_add) { + classes.insert(cclass); } } } @@ -4353,19 +4329,18 @@ Dhcpv6Srv::requiredClassify(const Pkt6Ptr& pkt, AllocEngine::ClientContext6& ctx // Note getClientClassDictionary() cannot be null const ClientClassDictionaryPtr& dict = CfgMgr::instance().getCurrentCfg()->getClientClassDictionary(); - for (ClientClasses::const_iterator cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { - const ClientClassDefPtr class_def = dict->findClass(*cclass); + for (auto const& cclass : classes) { + const ClientClassDefPtr class_def = dict->findClass(cclass); if (!class_def) { LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_UNDEFINED) - .arg(*cclass); + .arg(cclass); continue; } const ExpressionPtr& expr_ptr = class_def->getMatchExpr(); // Nothing to do without an expression to evaluate if (!expr_ptr) { LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_UNTESTABLE) - .arg(*cclass); + .arg(cclass); continue; } // Evaluate the expression which can return false (no match), @@ -4374,22 +4349,22 @@ Dhcpv6Srv::requiredClassify(const Pkt6Ptr& pkt, AllocEngine::ClientContext6& ctx bool status = evaluateBool(*expr_ptr, *pkt); if (status) { LOG_INFO(dhcp6_logger, EVAL_RESULT) - .arg(*cclass) + .arg(cclass) .arg("true"); // Matching: add the class - pkt->addClass(*cclass); + pkt->addClass(cclass); } else { LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, EVAL_RESULT) - .arg(*cclass) + .arg(cclass) .arg("false"); } } catch (const Exception& ex) { LOG_ERROR(dhcp6_logger, EVAL_RESULT) - .arg(*cclass) + .arg(cclass) .arg(ex.what()); } catch (...) { LOG_ERROR(dhcp6_logger, EVAL_RESULT) - .arg(*cclass) + .arg(cclass) .arg("get exception?"); } } @@ -4593,14 +4568,13 @@ void Dhcpv6Srv::processRSOO(const Pkt6Ptr& query, const Pkt6Ptr& rsp) { // and if it's RSOO-enabled and there's no such option provided yet, // copy it to the server's response const OptionCollection& rsoo = rsoo_container->getOptions(); - for (OptionCollection::const_iterator opt = rsoo.begin(); - opt != rsoo.end(); ++opt) { + for (auto const& opt : rsoo) { // Echo option if it is RSOO enabled option and there is no such // option added yet. - if (cfg_rsoo->enabled(opt->second->getType()) && - !rsp->getOption(opt->second->getType())) { - rsp->addOption(opt->second); + if (cfg_rsoo->enabled(opt.second->getType()) && + !rsp->getOption(opt.second->getType())) { + rsp->addOption(opt.second); } } } @@ -4802,13 +4776,12 @@ Dhcpv6Srv::checkDynamicSubnetChange(const Pkt6Ptr& question, Pkt6Ptr& answer, ((prev_hostname != ctx.hostname_) || (prev_fwd_dns_update != ctx.fwd_dns_update_) || (prev_rev_dns_update != ctx.rev_dns_update_))) { - for (Lease6Collection::const_iterator l = ctx.new_leases_.begin(); - l != ctx.new_leases_.end(); ++l) { - (*l)->hostname_ = ctx.hostname_; - (*l)->fqdn_fwd_ = ctx.fwd_dns_update_; - (*l)->fqdn_rev_ = ctx.rev_dns_update_; - (*l)->reuseable_valid_lft_ = 0; - LeaseMgrFactory::instance().updateLease6(*l); + for (auto const& l : ctx.new_leases_) { + l->hostname_ = ctx.hostname_; + l->fqdn_fwd_ = ctx.fwd_dns_update_; + l->fqdn_rev_ = ctx.rev_dns_update_; + l->reuseable_valid_lft_ = 0; + LeaseMgrFactory::instance().updateLease6(l); } } } diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index 47a8f3f100..e39163fe6f 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -49,7 +49,6 @@ #include #include -#include #include #include #include @@ -109,7 +108,7 @@ public: /// @param cfg server configuration (RSOO will be stored here) void parse(const SrvConfigPtr& cfg, const isc::data::ConstElementPtr& value) { try { - BOOST_FOREACH(ConstElementPtr source_elem, value->listValue()) { + for (auto const& source_elem : value->listValue()) { std::string option_str = source_elem->stringValue(); // This option can be either code (integer) or name. Let's try code first int64_t code = 0; @@ -245,10 +244,10 @@ public: } // Let's go through all the networks one by one - for (auto net = networks->begin(); net != networks->end(); ++net) { + for (auto const& net : *networks) { // For each network go through all the subnets in it. - const Subnet6SimpleCollection* subnets = (*net)->getAllSubnets(); + const Subnet6SimpleCollection* subnets = net->getAllSubnets(); if (!subnets) { // Shared network without subnets it weird, but we decided to // accept such configurations. @@ -256,8 +255,8 @@ public: } // For each subnet, add it to a list of regular subnets. - for (auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) { - dest->add(*subnet); + for (auto const& subnet : *subnets) { + dest->add(subnet); } } } @@ -305,75 +304,74 @@ public: std::set names; // Let's go through all the networks one by one - for (auto net = networks.begin(); net != networks.end(); ++net) { + for (auto const& net : networks) { string txt; // Let's check if all subnets have either the same interface // or don't have the interface specified at all. - string iface = (*net)->getIface(); + string iface = net->getIface(); - const Subnet6SimpleCollection* subnets = (*net)->getAllSubnets(); + const Subnet6SimpleCollection* subnets = net->getAllSubnets(); if (subnets) { bool rapid_commit = false; - // For each subnet, add it to a list of regular subnets. - for (auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) { + // Rapid commit must either be enabled or disabled in all subnets + // in the shared network. + if (subnets->size()) { + // If this is the first subnet, remember the value. + rapid_commit = (*subnets->begin())->getRapidCommit(); + } - // Rapid commit must either be enabled or disabled in all subnets - // in the shared network. - if (subnet == subnets->begin()) { - // If this is the first subnet, remember the value. - rapid_commit = (*subnet)->getRapidCommit(); - } else { - // Ok, this is the second or following subnets. The value - // must match what was set in the first subnet. - if (rapid_commit != (*subnet)->getRapidCommit()) { - isc_throw(DhcpConfigError, "All subnets in a shared network " - "must have the same rapid-commit value. Subnet " - << (*subnet)->toText() - << " has specified rapid-commit " - << ( (*subnet)->getRapidCommit() ? "true" : "false") - << ", but earlier subnet in the same shared-network" - << " or the shared-network itself used rapid-commit " - << (rapid_commit ? "true" : "false")); - } + // For each subnet, add it to a list of regular subnets. + for (auto const& subnet : *subnets) { + // Ok, this is the second or following subnets. The value + // must match what was set in the first subnet. + if (rapid_commit != subnet->getRapidCommit()) { + isc_throw(DhcpConfigError, "All subnets in a shared network " + "must have the same rapid-commit value. Subnet " + << subnet->toText() + << " has specified rapid-commit " + << (subnet->getRapidCommit() ? "true" : "false") + << ", but earlier subnet in the same shared-network" + << " or the shared-network itself used rapid-commit " + << (rapid_commit ? "true" : "false")); } if (iface.empty()) { - iface = (*subnet)->getIface(); + iface = subnet->getIface(); continue; } - if ((*subnet)->getIface().empty()) { + if (subnet->getIface().empty()) { continue; } - if ((*subnet)->getIface() != iface) { - isc_throw(DhcpConfigError, "Subnet " << (*subnet)->toText() - << " has specified interface " << (*subnet)->getIface() + if (subnet->getIface() != iface) { + isc_throw(DhcpConfigError, "Subnet " << subnet->toText() + << " has specified interface " << subnet->getIface() << ", but earlier subnet in the same shared-network" << " or the shared-network itself used " << iface); } // Let's collect the subnets in case we later find out the // subnet doesn't have a mandatory name. - txt += (*subnet)->toText() + " "; + txt += subnet->toText() + " "; } } // Next, let's check name of the shared network. - if ((*net)->getName().empty()) { + if (net->getName().empty()) { isc_throw(DhcpConfigError, "Shared-network with subnets " << txt << " is missing mandatory 'name' parameter"); } // Is it unique? - if (names.find((*net)->getName()) != names.end()) { + if (names.find(net->getName()) != names.end()) { isc_throw(DhcpConfigError, "A shared-network with " - "name " << (*net)->getName() << " defined twice."); + "name " << net->getName() << " defined twice."); } - names.insert((*net)->getName()); + names.insert(net->getName()); } } @@ -689,8 +687,8 @@ processDhcp6Config(isc::data::ConstElementPtr config_set) { HostCollection hosts; HostReservationsListParser parser; parser.parse(SUBNET_ID_GLOBAL, reservations, hosts); - for (auto h = hosts.begin(); h != hosts.end(); ++h) { - srv_config->getCfgHosts()->add(*h); + for (auto const& h : hosts) { + srv_config->getCfgHosts()->add(h); } } @@ -731,12 +729,10 @@ processDhcp6Config(isc::data::ConstElementPtr config_set) { } // Make parsers grouping. - ConfigPair config_pair; const std::map& values_map = mutable_cfg->mapValue(); - BOOST_FOREACH(config_pair, values_map) { - + for (auto const& config_pair : values_map) { parameter_name = config_pair.first; // These are converted to SimpleParser and are handled already above. diff --git a/src/bin/dhcp6/tests/callout_library_3.cc b/src/bin/dhcp6/tests/callout_library_3.cc index c8e212eac0..7465809d2b 100644 --- a/src/bin/dhcp6/tests/callout_library_3.cc +++ b/src/bin/dhcp6/tests/callout_library_3.cc @@ -56,8 +56,8 @@ dhcp6_srv_configured(CalloutHandle& handle) { // Append argument names. std::vector args = handle.getArgumentNames(); - for (auto arg = args.begin(); arg != args.end(); ++arg) { - if (appendArgument(SRV_CONFIG_MARKER_FILE, arg->c_str()) != 0) { + for (auto const& arg : args) { + if (appendArgument(SRV_CONFIG_MARKER_FILE, arg.c_str()) != 0) { return (1); } } diff --git a/src/bin/dhcp6/tests/config_backend_unittest.cc b/src/bin/dhcp6/tests/config_backend_unittest.cc index f1427ce5f8..52fae459b5 100644 --- a/src/bin/dhcp6/tests/config_backend_unittest.cc +++ b/src/bin/dhcp6/tests/config_backend_unittest.cc @@ -25,7 +25,6 @@ #include #include -#include #include #include diff --git a/src/bin/dhcp6/tests/config_parser_unittest.cc b/src/bin/dhcp6/tests/config_parser_unittest.cc index ef08dbdd24..6f571d52ab 100644 --- a/src/bin/dhcp6/tests/config_parser_unittest.cc +++ b/src/bin/dhcp6/tests/config_parser_unittest.cc @@ -41,9 +41,9 @@ #include "dhcp6_test_utils.h" #include "get_config_unittest.h" -#include #include +#include #include #include #include @@ -595,8 +595,7 @@ public: " \"subnet\": \"2001:db8:1::/64\", " " \"option-data\": [ {"; bool first = true; - typedef std::pair ParamPair; - BOOST_FOREACH(ParamPair param, params) { + for (auto const& param : params) { if (!first) { stream << ", "; } else { @@ -2092,16 +2091,14 @@ TEST_F(Dhcp6ParserTest, badSubnetValues) { // Iterate over the list of scenarios. Each should fail to parse with // a specific error message. for (auto const& scenario : scenarios) { - { - SCOPED_TRACE(scenario.description_); - ConstElementPtr config; - ASSERT_NO_THROW(config = parseDHCP6(scenario.config_json_)) - << "invalid json, broken test"; - ConstElementPtr status; - EXPECT_NO_THROW(status = Dhcpv6SrvTest::configure(srv_, config)); - checkResult(status, 1); - EXPECT_EQ(comment_->stringValue(), scenario.exp_error_msg_); - } + SCOPED_TRACE(scenario.description_); + ConstElementPtr config; + ASSERT_NO_THROW(config = parseDHCP6(scenario.config_json_)) + << "invalid json, broken test"; + ConstElementPtr status; + EXPECT_NO_THROW(status = Dhcpv6SrvTest::configure(srv_, config)); + checkResult(status, 1); + EXPECT_EQ(comment_->stringValue(), scenario.exp_error_msg_); } } @@ -5424,9 +5421,8 @@ TEST_F(Dhcp6ParserTest, invalidD2ClientConfig) { /// @param range Range of reservations returned by the @c Host object /// in which the reservation will be searched. bool reservationExists(const IPv6Resrv& resrv, const IPv6ResrvRange& range) { - for (IPv6ResrvIterator it = range.first; it != range.second; - ++it) { - if (resrv == it->second) { + BOOST_FOREACH(auto const& it, range) { + if (resrv == it.second) { return (true); } } diff --git a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc index 421cf13ccf..67c3b192b9 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -1426,14 +1426,17 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelStats) { }; std::ostringstream s; + bool first = true; s << "{ \"arguments\": { "; - for (auto st = initial_stats.begin(); st != initial_stats.end();) { - s << "\"" << *st << "\": [ [ 0, \""; - s << isc::util::clockToText(StatsMgr::instance().getObservation(*st)->getInteger().second); - s << "\" ] ]"; - if (++st != initial_stats.end()) { + for (auto const& st : initial_stats) { + if (!first) { s << ", "; + } else { + first = false; } + s << "\"" << st << "\": [ [ 0, \""; + s << isc::util::clockToText(StatsMgr::instance().getObservation(st)->getInteger().second); + s << "\" ] ]"; } s << " }, \"result\": 0 }"; diff --git a/src/bin/dhcp6/tests/dhcp6_client.cc b/src/bin/dhcp6/tests/dhcp6_client.cc index a797a9745d..a1d085769d 100644 --- a/src/bin/dhcp6/tests/dhcp6_client.cc +++ b/src/bin/dhcp6/tests/dhcp6_client.cc @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -258,13 +257,12 @@ Dhcp6Client::appendFQDN() { void Dhcp6Client::appendRequestedIAs(const Pkt6Ptr& query) const { - BOOST_FOREACH(const ClientIA& ia, client_ias_) { + for (auto const& ia : client_ias_) { OptionCollection options = query->getOptions(ia.type_ == Lease::TYPE_NA ? D6O_IA_NA : D6O_IA_PD); - std::pair option_pair; Option6IAPtr existing_ia; - BOOST_FOREACH(option_pair, options) { + for (auto const& option_pair : options) { Option6IAPtr ia_opt = boost::dynamic_pointer_cast(option_pair.second); // This shouldn't happen. @@ -287,7 +285,7 @@ Dhcp6Client::appendRequestedIAs(const Pkt6Ptr& query) const { if ((ia.type_ == Lease::TYPE_NA) && !ia.prefix_.isV6Zero()) { Option6IAAddrPtr ia_addr(new Option6IAAddr(D6O_IAADDR, ia.prefix_, 0, 0)); - BOOST_FOREACH(option_pair, existing_ia->getOptions()) { + for (auto const& option_pair : existing_ia->getOptions()) { Option6IAAddrPtr existing_addr = boost::dynamic_pointer_cast< Option6IAAddr>(option_pair.second); if (existing_addr && @@ -306,7 +304,7 @@ Dhcp6Client::appendRequestedIAs(const Pkt6Ptr& query) const { ia.prefix_, ia.prefix_len_, 0, 0)); - BOOST_FOREACH(option_pair, existing_ia->getOptions()) { + for (auto const& option_pair : existing_ia->getOptions()) { Option6IAPrefixPtr existing_prefix = boost::dynamic_pointer_cast(option_pair.second); if (existing_prefix && @@ -328,19 +326,19 @@ Dhcp6Client::copyIAs(const Pkt6Ptr& source, const Pkt6Ptr& dest) { typedef OptionCollection Opts; // Copy IA_NAs. Opts opts = source->getOptions(D6O_IA_NA); - for (Opts::const_iterator opt = opts.begin(); opt != opts.end(); ++opt) { + for (auto const& opt : opts) { // Only copy the entire IA_NA if there is at lease one IA Address option. - if (opt->second->getOption(D6O_IAADDR)) { - dest->addOption(opt->second); + if (opt.second->getOption(D6O_IAADDR)) { + dest->addOption(opt.second); } } // Copy IA_PDs. opts = source->getOptions(D6O_IA_PD); - for (Opts::const_iterator opt = opts.begin(); opt != opts.end(); ++opt) { + for (auto const& opt : opts) { // Only copy the entire IA_PD if there is at least one IA Prefix option // in it. - if (opt->second->getOption(D6O_IAPREFIX)) { - dest->addOption(opt->second); + if (opt.second->getOption(D6O_IAPREFIX)) { + dest->addOption(opt.second); } } } @@ -350,32 +348,28 @@ Dhcp6Client::copyIAsFromLeases(const Pkt6Ptr& dest) const { // Go over leases and create IA_NA and IA_PD options from them. // Create one IA per lease. std::set iaids = getIAIDs(); - for (std::set::const_iterator iaid = iaids.begin(); - iaid != iaids.end(); ++iaid) { - std::vector leases = getLeasesByIAID(*iaid); + for (auto const& iaid : iaids) { + std::vector leases = getLeasesByIAID(iaid); // Only a valid lease should be included. Do not copy a // lease which have been marked by the server as invalid. if (leases[0].valid_lft_ == 0) { continue; } Option6IAPtr opt(new Option6IA(leases[0].type_ == Lease::TYPE_NA ? - D6O_IA_NA : D6O_IA_PD, *iaid)); - for (std::vector::const_iterator lease = leases.begin(); - lease != leases.end(); ++lease) { - if ((lease->preferred_lft_ != 0) && (lease->valid_lft_ != 0)) { - if (lease->type_ == Lease::TYPE_NA) { - opt->addOption(Option6IAAddrPtr(new Option6IAAddr( - D6O_IAADDR, - lease->addr_, - lease->preferred_lft_, - lease->valid_lft_))); - } else if (lease->type_ == Lease::TYPE_PD) { - opt->addOption(Option6IAAddrPtr(new Option6IAPrefix( - D6O_IAPREFIX, - lease->addr_, - lease->prefixlen_, - lease->preferred_lft_, - lease->valid_lft_))); + D6O_IA_NA : D6O_IA_PD, iaid)); + for (auto const& lease : leases) { + if ((lease.preferred_lft_ != 0) && (lease.valid_lft_ != 0)) { + if (lease.type_ == Lease::TYPE_NA) { + opt->addOption(Option6IAAddrPtr(new Option6IAAddr(D6O_IAADDR, + lease.addr_, + lease.preferred_lft_, + lease.valid_lft_))); + } else if (lease.type_ == Lease::TYPE_PD) { + opt->addOption(Option6IAAddrPtr(new Option6IAPrefix(D6O_IAPREFIX, + lease.addr_, + lease.prefixlen_, + lease.preferred_lft_, + lease.valid_lft_))); } } } @@ -414,16 +408,14 @@ Dhcp6Client::createMsg(const uint8_t msg_type) { // If there are any custom options specified, add them all to the message. if (!extra_options_.empty()) { - for (OptionCollection::iterator opt = extra_options_.begin(); - opt != extra_options_.end(); ++opt) { - msg->addOption(opt->second); + for (auto const& opt : extra_options_) { + msg->addOption(opt.second); } } // Add classes. - for (ClientClasses::const_iterator cclass = classes_.cbegin(); - cclass != classes_.cend(); ++cclass) { - msg->addClass(*cclass); + for (auto const& cclass : classes_) { + msg->addClass(cclass); } return (msg); @@ -621,17 +613,18 @@ Dhcp6Client::generateIAFromLeases(const Pkt6Ptr& query, const bool include_address) { /// @todo: add support for IAPREFIX here. - for (std::vector::const_iterator lease = config_.leases_.begin(); - lease != config_.leases_.end(); ++lease) { - if (lease->type_ != Lease::TYPE_NA) { + for (auto const& lease : config_.leases_) { + if (lease.type_ != Lease::TYPE_NA) { continue; } - Option6IAPtr ia(new Option6IA(D6O_IA_NA, lease->iaid_)); + Option6IAPtr ia(new Option6IA(D6O_IA_NA, lease.iaid_)); if (include_address) { ia->addOption(OptionPtr(new Option6IAAddr(D6O_IAADDR, - lease->addr_, lease->preferred_lft_, lease->valid_lft_))); + lease.addr_, + lease.preferred_lft_, + lease.valid_lft_))); } query->addOption(ia); } @@ -681,9 +674,8 @@ Dhcp6Client::getClientId() const { std::set Dhcp6Client::getIAIDs() const { std::set iaids; - for (std::vector::const_iterator lease = config_.leases_.begin(); - lease != config_.leases_.end(); ++lease) { - iaids.insert(lease->iaid_); + for (auto const& lease : config_.leases_) { + iaids.insert(lease.iaid_); } return (iaids); } @@ -759,7 +751,7 @@ bool Dhcp6Client::hasLeaseForAddress(const asiolink::IOAddress& address, const IAID& iaid) const { std::vector leases = getLeasesByAddress(address); - BOOST_FOREACH(const Lease6& lease, leases) { + for (auto const& lease : leases) { if (lease.iaid_ == iaid) { return (true); } @@ -777,7 +769,7 @@ Dhcp6Client::hasLeaseForAddressRange(const asiolink::IOAddress& first, bool Dhcp6Client::hasLeaseWithZeroLifetimeForAddress(const asiolink::IOAddress& address) const { std::vector leases = getLeasesByAddress(address); - BOOST_FOREACH(const Lease6& lease, leases) { + for (auto const& lease : leases) { if ((lease.preferred_lft_ == 0) && (lease.valid_lft_ == 0)) { return (true); } @@ -790,7 +782,7 @@ bool Dhcp6Client::hasLeaseForPrefix(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const { std::vector leases = getLeasesByAddress(prefix); - BOOST_FOREACH(const Lease6& lease, leases) { + for (auto const& lease : leases) { if (lease.prefixlen_ == prefix_len) { return (true); } @@ -803,7 +795,7 @@ Dhcp6Client::hasLeaseForPrefix(const asiolink::IOAddress& prefix, const uint8_t prefix_len, const IAID& iaid) const { std::vector leases = getLeasesByAddress(prefix); - BOOST_FOREACH(const Lease6& lease, leases) { + for (auto const& lease : leases) { if ((lease.prefixlen_ == prefix_len) && (lease.iaid_ == iaid)) { return (true); @@ -825,7 +817,7 @@ bool Dhcp6Client::hasLeaseWithZeroLifetimeForPrefix(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const { std::vector leases = getLeasesByAddress(prefix); - BOOST_FOREACH(const Lease6& lease, leases) { + for (auto const& lease : leases) { if ((lease.prefixlen_ == prefix_len) && (lease.preferred_lft_ == 0) && (lease.valid_lft_ == 0)) { return (true); @@ -965,9 +957,8 @@ Dhcp6Client::sendMsg(const Pkt6Ptr& msg) { // Copy classes const ClientClasses& classes = msg->getClasses(); - for (ClientClasses::const_iterator cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { - msg_copy->addClass(*cclass); + for (auto const& cclass : classes) { + msg_copy->addClass(cclass); } srv_->fakeReceive(msg_copy); diff --git a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc index 656711af22..697e4f07a7 100644 --- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc @@ -267,7 +267,7 @@ Dhcpv6SrvTest::loadConfigFile(const string& path) { removeTlsParameters(hosts); hosts = dhcp6->get("hosts-databases"); if (hosts) { - for (auto& host : hosts->listValue()) { + for (auto const& host : hosts->listValue()) { removeTlsParameters(host); } } @@ -362,7 +362,7 @@ Dhcpv6SrvTest::checkConfigFiles() { "with-ddns.json", }; vector files; - for (const string& example : examples) { + for (auto const& example : examples) { string file = path + "/" + example; files.push_back(file); } @@ -3365,15 +3365,14 @@ TEST_F(Dhcpv6SrvTest, rsoo2relays) { int count120 = 0; // Let's count how many times option 120 was echoed back int count130 = 0; // Let's count how many times option 130 was echoed back OptionPtr opt120; - for (OptionCollection::const_iterator it = client.config_.options_.begin(); - it != client.config_.options_.end(); ++it) { - switch (it->second->getType()) { + for (auto const& it : client.config_.options_) { + switch (it.second->getType()) { case 110: count110++; break; case 120: count120++; - opt120 = it->second; + opt120 = it.second; break; case 130: count130++; diff --git a/src/bin/dhcp6/tests/dhcp6_test_utils.cc b/src/bin/dhcp6/tests/dhcp6_test_utils.cc index a2f9acff61..de4dec633c 100644 --- a/src/bin/dhcp6/tests/dhcp6_test_utils.cc +++ b/src/bin/dhcp6/tests/dhcp6_test_utils.cc @@ -1146,14 +1146,13 @@ NakedDhcpv6SrvTest::checkIA_NAStatusCode( // it will return it with zeroed lifetimes. if (check_addr) { dhcp::OptionCollection options = ia->getOptions(); - for (isc::dhcp::OptionCollection::iterator opt = options.begin(); - opt != options.end(); ++opt) { - if (opt->second->getType() != D6O_IAADDR) { + for (auto const& opt : options) { + if (opt.second->getType() != D6O_IAADDR) { continue; } dhcp::Option6IAAddrPtr addr = - boost::dynamic_pointer_cast(opt->second); + boost::dynamic_pointer_cast(opt.second); ASSERT_TRUE(addr); EXPECT_EQ(0, addr->getPreferred()); diff --git a/src/bin/dhcp6/tests/hooks_unittest.cc b/src/bin/dhcp6/tests/hooks_unittest.cc index d87896eab3..0fb81725f3 100644 --- a/src/bin/dhcp6/tests/hooks_unittest.cc +++ b/src/bin/dhcp6/tests/hooks_unittest.cc @@ -5589,7 +5589,7 @@ TEST_F(LoadUnloadDhcpv6SrvTest, failLoadIncompatibleLibraries) { // Checks if callouts installed on the dhcp6_srv_configured ared indeed called // and all the necessary parameters are passed. TEST_F(LoadUnloadDhcpv6SrvTest, Dhcpv6SrvConfigured) { - for (const string& parameters : vector{ + for (auto const& parameters : vector{ "", R"(, "parameters": { "mode": "fail-without-error" } )", R"(, "parameters": { "mode": "fail-with-error" } )"}) { diff --git a/src/bin/dhcp6/tests/shared_network_unittest.cc b/src/bin/dhcp6/tests/shared_network_unittest.cc index 02a8283e74..fa9651e4f3 100644 --- a/src/bin/dhcp6/tests/shared_network_unittest.cc +++ b/src/bin/dhcp6/tests/shared_network_unittest.cc @@ -1279,9 +1279,9 @@ public: Subnet6Ptr getConfiguredSubnet(const Lease::Type& type, const IOAddress& resource) const { CfgSubnets6Ptr cfg = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6(); const Subnet6Collection* subnets = cfg->getAll(); - for (auto subnet_it = subnets->cbegin(); subnet_it != subnets->cend(); ++subnet_it) { - if ((*subnet_it)->inPool(type, resource)) { - return (*subnet_it); + for (auto const& subnet_it : *subnets) { + if (subnet_it->inPool(type, resource)) { + return (subnet_it); } } @@ -1380,13 +1380,13 @@ public: bool hasLeaseForAddressRange(Dhcp6Client& client, const IOAddress& first, const IOAddress& last, const LeaseOnServer& lease_on_server = LeaseOnServer::MUST_EXIST) { std::vector leases = client.getLeasesByAddressRange(first, last); - for (auto lease_it = leases.cbegin(); lease_it != leases.cend(); ++lease_it) { + for (auto const& lease_it : leases) { // Take into account only valid leases. - if (lease_it->valid_lft_ == 0) { + if (lease_it.valid_lft_ == 0) { continue; } - Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, lease_it->addr_); + Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, lease_it.addr_); if ((lease && (lease_on_server == LeaseOnServer::MUST_NOT_EXIST)) || (!lease && (lease_on_server == LeaseOnServer::MUST_EXIST))) { return (false); @@ -1415,13 +1415,13 @@ public: const LeaseOnServer& lease_on_server = LeaseOnServer::MUST_EXIST) { std::vector leases = client.getLeasesByPrefixPool(prefix, prefix_len, delegated_len); - for (auto lease_it = leases.cbegin(); lease_it != leases.cend(); ++lease_it) { + for (auto const& lease_it : leases) { // Take into account only valid leases. - if (lease_it->valid_lft_ == 0) { + if (lease_it.valid_lft_ == 0) { continue; } - Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, lease_it->addr_); + Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, lease_it.addr_); if ((lease && (lease->prefixlen_ == lease->prefixlen_) && (lease_on_server == LeaseOnServer::MUST_NOT_EXIST)) || (!lease && (lease_on_server == LeaseOnServer::MUST_EXIST))) { diff --git a/src/bin/perfdhcp/pkt_transform.cc b/src/bin/perfdhcp/pkt_transform.cc index 7aaf9c6c41..d189161c5c 100644 --- a/src/bin/perfdhcp/pkt_transform.cc +++ b/src/bin/perfdhcp/pkt_transform.cc @@ -116,11 +116,10 @@ PktTransform::packOptions(const OptionBuffer& in_buffer, // If there are any options on the list, we will use provided // options offsets to override them in the output buffer // with new contents. - for (OptionCollection::const_iterator it = options.begin(); - it != options.end(); ++it) { + for (auto const& it : options) { // Get options with their position (offset). boost::shared_ptr option = - boost::dynamic_pointer_cast(it->second); + boost::dynamic_pointer_cast(it.second); if (option == NULL) { isc_throw(isc::BadValue, "option is null"); } @@ -146,8 +145,7 @@ PktTransform::packOptions(const OptionBuffer& in_buffer, out_buffer.writeUint8At(buf_data[i], offset + i); } } - } - catch (const Exception&) { + } catch (const Exception&) { isc_throw(isc::BadValue, "failed to pack options into buffer."); } } @@ -155,11 +153,10 @@ PktTransform::packOptions(const OptionBuffer& in_buffer, void PktTransform::unpackOptions(const OptionBuffer& in_buffer, const OptionCollection& options) { - for (OptionCollection::const_iterator it = options.begin(); - it != options.end(); ++it) { + for (auto const& it : options) { boost::shared_ptr option = - boost::dynamic_pointer_cast(it->second); + boost::dynamic_pointer_cast(it.second); if (option == NULL) { isc_throw(isc::BadValue, "option is null"); } diff --git a/src/bin/perfdhcp/stats_mgr.cc b/src/bin/perfdhcp/stats_mgr.cc index 1563588f65..1bb655b791 100644 --- a/src/bin/perfdhcp/stats_mgr.cc +++ b/src/bin/perfdhcp/stats_mgr.cc @@ -14,6 +14,7 @@ #include #include #include +#include using isc::dhcp::DHO_DHCP_CLIENT_IDENTIFIER; using isc::dhcp::DUID; @@ -313,21 +314,16 @@ ExchangeStats::printTimestamps() { using namespace boost::posix_time; // Iterate through all received packets. - for (PktListIterator it = rcvd_packets_.begin(); - it != rcvd_packets_.end(); - ++it) { - PktPtr rcvd_packet = *it; + for (auto const& it : rcvd_packets_) { + PktPtr rcvd_packet = it; PktListTransidHashIndex& idx = archived_packets_.template get<1>(); std::pair p = idx.equal_range(hashTransid(rcvd_packet)); - for (PktListTransidHashIterator it_archived = p.first; - it_archived != p.second; - ++it_archived) { - if ((*it_archived)->getTransid() == - rcvd_packet->getTransid()) { - PktPtr sent_packet = *it_archived; + BOOST_FOREACH(auto const& it_archived, p) { + if (it_archived->getTransid() == rcvd_packet->getTransid()) { + PktPtr sent_packet = it_archived; // Get sent and received packet times. ptime sent_time = sent_packet->getTimestamp(); ptime rcvd_time = rcvd_packet->getTimestamp(); diff --git a/src/bin/perfdhcp/stats_mgr.h b/src/bin/perfdhcp/stats_mgr.h index 39718e9b79..e5a3619351 100644 --- a/src/bin/perfdhcp/stats_mgr.h +++ b/src/bin/perfdhcp/stats_mgr.h @@ -209,10 +209,8 @@ public: /// \code /// PktList packets_collection(); /// ... # Add elements to the container - /// for (PktListIterator it = packets_collection.begin(); - /// it != packets_collection.end(); - /// ++it) { - /// boost::shared_ptr pkt = *it; + /// for (auto const& it : packets_collection) { + /// boost::shared_ptr pkt = it; /// # Do something with packet; /// } /// \endcode @@ -778,10 +776,8 @@ public: /// // \return true, if packet drops occurred. bool droppedPackets() const { - for (ExchangesMapIterator it = exchanges_.begin(); - it != exchanges_.end(); - ++it) { - if (it->second->getDroppedPacketsNum() > 0) { + for (auto const& it : exchanges_) { + if (it.second->getDroppedPacketsNum() > 0) { return (true); } } @@ -1098,11 +1094,9 @@ public: isc_throw(isc::InvalidOperation, "no exchange type added for tracking"); } - for (ExchangesMapIterator it = exchanges_.begin(); - it != exchanges_.end(); - ++it) { - ExchangeStatsPtr xchg_stats = it->second; - std::cout << "***Statistics for: " << it->first + for (auto const& it : exchanges_) { + ExchangeStatsPtr xchg_stats = it.second; + std::cout << "***Statistics for: " << it.first << "***" << std::endl; xchg_stats->printMainStats(); std::cout << std::endl; @@ -1126,35 +1120,36 @@ public: std::ostringstream stream_drops; std::ostringstream stream_reject; std::string sep(""); - for (ExchangesMapIterator it = exchanges_.begin(); - it != exchanges_.end(); ++it) { - - if (it != exchanges_.begin()) { + bool first = true; + for (auto const& it : exchanges_) { + if (!first) { if (clean_report) { sep = clean_sep; } else { sep = "/"; } + } else { + first = false; } - stream_sent << sep << it->second->getSentPacketsNum(); - stream_rcvd << sep << it->second->getRcvdPacketsNum(); - stream_drops << sep << it->second->getDroppedPacketsNum(); - stream_reject << sep << it->second->getRejLeasesNum(); + stream_sent << sep << it.second->getSentPacketsNum(); + stream_rcvd << sep << it.second->getRcvdPacketsNum(); + stream_drops << sep << it.second->getDroppedPacketsNum(); + stream_reject << sep << it.second->getRejLeasesNum(); } if (clean_report) { - std::cout << stream_sent.str() - << clean_sep << stream_rcvd.str() - << clean_sep << stream_drops.str() - << clean_sep << stream_reject.str() - << std::endl; + std::cout << stream_sent.str() + << clean_sep << stream_rcvd.str() + << clean_sep << stream_drops.str() + << clean_sep << stream_reject.str() + << std::endl; } else { - std::cout << "sent: " << stream_sent.str() - << "; received: " << stream_rcvd.str() - << "; drops: " << stream_drops.str() - << "; rejected: " << stream_reject.str() - << std::endl; + std::cout << "sent: " << stream_sent.str() + << "; received: " << stream_rcvd.str() + << "; drops: " << stream_drops.str() + << "; rejected: " << stream_reject.str() + << std::endl; } } @@ -1174,12 +1169,10 @@ public: isc_throw(isc::InvalidOperation, "no exchange type added for tracking"); } - for (ExchangesMapIterator it = exchanges_.begin(); - it != exchanges_.end(); - ++it) { - ExchangeStatsPtr xchg_stats = it->second; + for (auto const& it : exchanges_) { + ExchangeStatsPtr xchg_stats = it.second; std::cout << "***Timestamps for packets: " - << it->first + << it.first << "***" << std::endl; xchg_stats->printTimestamps(); std::cout << std::endl; @@ -1199,19 +1192,19 @@ public: if (custom_counters_.empty()) { isc_throw(isc::InvalidOperation, "no custom counters specified"); } - for (CustomCountersMapIterator it = custom_counters_.begin(); - it != custom_counters_.end(); - ++it) { - CustomCounterPtr counter = it->second; + for (auto const& it : custom_counters_) { + CustomCounterPtr counter = it.second; std::cout << counter->getName() << ": " << counter->getValue() << std::endl; } } - std::tuple getSentPackets(const ExchangeType xchg_type) const { + std::tuple + getSentPackets(const ExchangeType xchg_type) const { ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type); - std::tuple sent_packets_its = xchg_stats->getSentPackets(); - return(sent_packets_its); + std::tuple sent_packets_its = + xchg_stats->getSentPackets(); + return (sent_packets_its); } private: diff --git a/src/bin/perfdhcp/test_control.cc b/src/bin/perfdhcp/test_control.cc index 29ef5a87f3..9d33be86aa 100644 --- a/src/bin/perfdhcp/test_control.cc +++ b/src/bin/perfdhcp/test_control.cc @@ -549,9 +549,8 @@ TestControl::initPacketTemplates() { template_packets_v6_.clear(); template_buffers_.clear(); std::vector template_files = options_.getTemplateFiles(); - for (std::vector::const_iterator it = template_files.begin(); - it != template_files.end(); ++it) { - readPacketTemplate(*it); + for (auto const& it : template_files) { + readPacketTemplate(it); } } @@ -750,13 +749,13 @@ std::string TestControl::vector2Hex(const std::vector& vec, const std::string& separator /* = "" */) { std::ostringstream stream; - for (std::vector::const_iterator it = vec.begin(); - it != vec.end(); - ++it) { - if (it == vec.begin()) { - stream << byte2Hex(*it); + bool first = true; + for (auto const& it : vec) { + if (first) { + stream << byte2Hex(it); + first = false; } else { - stream << separator << byte2Hex(*it); + stream << separator << byte2Hex(it); } } return (stream.str()); diff --git a/src/bin/perfdhcp/test_control.h b/src/bin/perfdhcp/test_control.h index 17700cebf2..2ec4e44cec 100644 --- a/src/bin/perfdhcp/test_control.h +++ b/src/bin/perfdhcp/test_control.h @@ -615,10 +615,9 @@ protected: void addUniqeAddr(const std::set& current, ExchangeType xchg_type) { switch(xchg_type) { case ExchangeType::SA: { - for (auto current_it = current.begin(); - current_it != current.end(); ++current_it) { + for (auto const& current_it : current) { // addresses should be unique cross packets - auto ret = unique_address_.emplace(*current_it); + auto ret = unique_address_.emplace(current_it); if (!ret.second) { stats_mgr_.updateNonUniqueAddrNum(ExchangeType::SA); } @@ -626,10 +625,9 @@ protected: break; } case ExchangeType::RR: { - for (auto current_it = current.begin(); - current_it != current.end(); ++current_it) { + for (auto const& current_it : current) { // addresses should be unique cross packets - auto ret = unique_reply_address_.emplace(*current_it); + auto ret = unique_reply_address_.emplace(current_it); if (!ret.second) { stats_mgr_.updateNonUniqueAddrNum(ExchangeType::RR); } @@ -642,10 +640,9 @@ protected: break; } case ExchangeType::DO: { - for (auto current_it = current.begin(); - current_it != current.end(); ++current_it) { + for (auto const& current_it : current) { // addresses should be unique cross packets - auto ret = unique_address_.emplace(*current_it); + auto ret = unique_address_.emplace(current_it); if (!ret.second) { stats_mgr_.updateNonUniqueAddrNum(ExchangeType::DO); } @@ -653,10 +650,9 @@ protected: break; } case ExchangeType::RA: { - for (auto current_it = current.begin(); - current_it != current.end(); ++current_it) { + for (auto const& current_it : current) { // addresses should be unique cross packets - auto ret = unique_reply_address_.emplace(*current_it); + auto ret = unique_reply_address_.emplace(current_it); if (!ret.second) { stats_mgr_.updateNonUniqueAddrNum(ExchangeType::RA); } @@ -677,13 +673,13 @@ protected: /// /// \param addr holding value of unique address. void removeUniqueAddr(const std::set& addr) { - for (auto addr_it = addr.begin(); addr_it != addr.end(); ++addr_it) { - auto it = unique_address_.find(*addr_it); + for (auto const& addr_it : addr) { + auto it = unique_address_.find(addr_it); if (it != unique_address_.end()) { unique_address_.erase(it); } - auto it2 = unique_reply_address_.find(*addr_it); + auto it2 = unique_reply_address_.find(addr_it); if (it2 != unique_reply_address_.end()) { unique_reply_address_.erase(it2); } diff --git a/src/bin/perfdhcp/tests/avalanche_scen_unittest.cc b/src/bin/perfdhcp/tests/avalanche_scen_unittest.cc index d2e119a094..614ca03380 100644 --- a/src/bin/perfdhcp/tests/avalanche_scen_unittest.cc +++ b/src/bin/perfdhcp/tests/avalanche_scen_unittest.cc @@ -18,7 +18,6 @@ #include #include -#include #include #include diff --git a/src/bin/perfdhcp/tests/basic_scen_unittest.cc b/src/bin/perfdhcp/tests/basic_scen_unittest.cc index 5240293339..431e8326fc 100644 --- a/src/bin/perfdhcp/tests/basic_scen_unittest.cc +++ b/src/bin/perfdhcp/tests/basic_scen_unittest.cc @@ -17,7 +17,6 @@ #include #include #include -#include #include #include diff --git a/src/bin/perfdhcp/tests/perf_socket_unittest.cc b/src/bin/perfdhcp/tests/perf_socket_unittest.cc index 39a2db99e9..e0d5f1ce2e 100644 --- a/src/bin/perfdhcp/tests/perf_socket_unittest.cc +++ b/src/bin/perfdhcp/tests/perf_socket_unittest.cc @@ -6,8 +6,8 @@ #include -#include "command_options_helper.h" -#include "../perf_socket.h" +#include +#include #include #include @@ -16,7 +16,6 @@ #include #include -#include #include #include diff --git a/src/bin/perfdhcp/tests/test_control_unittest.cc b/src/bin/perfdhcp/tests/test_control_unittest.cc index 1838a7b1db..f31f25a844 100644 --- a/src/bin/perfdhcp/tests/test_control_unittest.cc +++ b/src/bin/perfdhcp/tests/test_control_unittest.cc @@ -6,8 +6,8 @@ #include -#include "command_options_helper.h" -#include "../test_control.h" +#include +#include #include #include @@ -19,7 +19,6 @@ #include #include -#include #include #include diff --git a/src/hooks/dhcp/high_availability/command_creator.cc b/src/hooks/dhcp/high_availability/command_creator.cc index 725f9f185a..a2f25195a8 100644 --- a/src/hooks/dhcp/high_availability/command_creator.cc +++ b/src/hooks/dhcp/high_availability/command_creator.cc @@ -141,17 +141,15 @@ ConstElementPtr CommandCreator::createLease6BulkApply(const Lease6CollectionPtr& leases, const Lease6CollectionPtr& deleted_leases) { ElementPtr deleted_leases_list = Element::createList(); - for (auto lease = deleted_leases->begin(); lease != deleted_leases->end(); - ++lease) { - ElementPtr lease_as_json = (*lease)->toElement(); + for (auto const& lease : *deleted_leases) { + ElementPtr lease_as_json = lease->toElement(); insertLeaseExpireTime(lease_as_json); deleted_leases_list->add(lease_as_json); } ElementPtr leases_list = Element::createList(); - for (auto lease = leases->begin(); lease != leases->end(); - ++lease) { - ElementPtr lease_as_json = (*lease)->toElement(); + for (auto const& lease : *leases) { + ElementPtr lease_as_json = lease->toElement(); insertLeaseExpireTime(lease_as_json); leases_list->add(lease_as_json); } diff --git a/src/hooks/dhcp/high_availability/ha_config.cc b/src/hooks/dhcp/high_availability/ha_config.cc index bc31fde230..8cfa685833 100644 --- a/src/hooks/dhcp/high_availability/ha_config.cc +++ b/src/hooks/dhcp/high_availability/ha_config.cc @@ -257,9 +257,9 @@ HAConfig::getPeerConfig(const std::string& name) const { HAConfig::PeerConfigPtr HAConfig::getFailoverPeerConfig() const { PeerConfigMap servers = getOtherServersConfig(); - for (auto peer = servers.begin(); peer != servers.end(); ++peer) { - if (peer->second->getRole() != HAConfig::PeerConfig::BACKUP) { - return (peer->second); + for (auto const& peer : servers) { + if (peer.second->getRole() != HAConfig::PeerConfig::BACKUP) { + return (peer.second); } } @@ -289,28 +289,28 @@ HAConfig::validate() { // Gather all the roles and see how many occurrences of each role we get. std::map peers_cnt; - for (auto p = peers_.begin(); p != peers_.end(); ++p) { - if (!p->second->getUrl().isValid()) { + for (auto const& p : peers_) { + if (!p.second->getUrl().isValid()) { isc_throw(HAConfigValidationError, "invalid URL: " - << p->second->getUrl().getErrorMessage() - << " for server " << p->second->getName()); + << p.second->getUrl().getErrorMessage() + << " for server " << p.second->getName()); } // The hostname must be an address, not a name. IOAddress addr("::"); try { - addr = IOAddress(p->second->getUrl().getStrippedHostname()); + addr = IOAddress(p.second->getUrl().getStrippedHostname()); } catch (const IOError& ex) { isc_throw(HAConfigValidationError, "bad url '" - << p->second->getUrl().toText() + << p.second->getUrl().toText() << "': " << ex.what() - << " for server " << p->second->getName()); + << " for server " << p.second->getName()); } // Check TLS setup. - Optional ca = p->second->getTrustAnchor(); - Optional cert = p->second->getCertFile(); - Optional key = p->second->getKeyFile(); + Optional ca = p.second->getTrustAnchor(); + Optional cert = p.second->getCertFile(); + Optional key = p.second->getKeyFile(); // When not configured get the value from the global level. if (ca.unspecified()) { ca = trust_anchor_; @@ -346,11 +346,11 @@ HAConfig::validate() { TlsRole tls_role = TlsRole::CLIENT; bool cert_required = true; // The peer entry for myself will be used for the server side. - if (p->second->getName() == getThisServerName()) { + if (p.second->getName() == getThisServerName()) { tls_role = TlsRole::SERVER; cert_required = getRequireClientCerts(); } - TlsContext::configure(p->second->tls_context_, + TlsContext::configure(p.second->tls_context_, tls_role, ca.get(), cert.get(), @@ -358,20 +358,20 @@ HAConfig::validate() { cert_required); } catch (const isc::Exception& ex) { isc_throw(HAConfigValidationError, "bad TLS config for server " - << p->second->getName() << ": " << ex.what()); + << p.second->getName() << ": " << ex.what()); } } else { // Refuse HTTPS scheme when TLS is not enabled. - if (p->second->getUrl().getScheme() == Url::HTTPS) { + if (p.second->getUrl().getScheme() == Url::HTTPS) { isc_throw(HAConfigValidationError, "bad url '" - << p->second->getUrl().toText() + << p.second->getUrl().toText() << "': https scheme is not supported" - << " for server " << p->second->getName() + << " for server " << p.second->getName() << " where TLS is disabled"); } } - ++peers_cnt[p->second->getRole()]; + ++peers_cnt[p.second->getRole()]; } // Only one primary server allowed. diff --git a/src/hooks/dhcp/high_availability/ha_config_parser.cc b/src/hooks/dhcp/high_availability/ha_config_parser.cc index 79f0c305b2..1d66aae93e 100644 --- a/src/hooks/dhcp/high_availability/ha_config_parser.cc +++ b/src/hooks/dhcp/high_availability/ha_config_parser.cc @@ -261,57 +261,57 @@ HAConfigParser::parseOne(const HAConfigMapperPtr& config_storage, auto const& peers_vec = peers->listValue(); // Go over configuration of each peer. - for (auto p = peers_vec.begin(); p != peers_vec.end(); ++p) { + for (auto const& p : peers_vec) { // Peer configuration is held in a map. - if ((*p)->getType() != Element::map) { + if (p->getType() != Element::map) { isc_throw(ConfigError, "peer configuration must be a map"); } - setDefaults(*p, HA_CONFIG_PEER_DEFAULTS); + setDefaults(p, HA_CONFIG_PEER_DEFAULTS); // Server name. - auto cfg = rel_config->selectNextPeerConfig(getString(*p, "name")); + auto cfg = rel_config->selectNextPeerConfig(getString(p, "name")); // URL. - cfg->setUrl(Url(getString((*p), "url"))); + cfg->setUrl(Url(getString(p, "url"))); // Optional trust anchor. - if ((*p)->contains("trust-anchor")) { - cfg->setTrustAnchor(getString(*p, ("trust-anchor"))); + if (p->contains("trust-anchor")) { + cfg->setTrustAnchor(getString(p, ("trust-anchor"))); } // Optional certificate file. - if ((*p)->contains("cert-file")) { - cfg->setCertFile(getString(*p, ("cert-file"))); + if (p->contains("cert-file")) { + cfg->setCertFile(getString(p, ("cert-file"))); } // Optional private key file. - if ((*p)->contains("key-file")) { - cfg->setKeyFile(getString(*p, ("key-file"))); + if (p->contains("key-file")) { + cfg->setKeyFile(getString(p, ("key-file"))); } // Role. - cfg->setRole(getString(*p, "role")); + cfg->setRole(getString(p, "role")); // Auto failover configuration. - cfg->setAutoFailover(getBoolean(*p, "auto-failover")); + cfg->setAutoFailover(getBoolean(p, "auto-failover")); // Basic HTTP authentication password. std::string password; - if ((*p)->contains("basic-auth-password")) { - if ((*p)->contains("basic-auth-password-file")) { + if (p->contains("basic-auth-password")) { + if (p->contains("basic-auth-password-file")) { isc_throw(dhcp::DhcpConfigError, "only one of " << "basic-auth-password and " << "basic-auth-password-file parameter can be " << "configured in peer '" << cfg->getName() << "'"); } - password = getString((*p), "basic-auth-password"); + password = getString(p, "basic-auth-password"); } - if ((*p)->contains("basic-auth-password-file")) { + if (p->contains("basic-auth-password-file")) { std::string password_file = - getString((*p), "basic-auth-password-file"); + getString(p, "basic-auth-password-file"); try { password = util::file::getContent(password_file); } catch (const std::exception& ex) { @@ -321,8 +321,8 @@ HAConfigParser::parseOne(const HAConfigMapperPtr& config_storage, } // Basic HTTP authentication user. - if ((*p)->contains("basic-auth-user")) { - std::string user = getString((*p), "basic-auth-user"); + if (p->contains("basic-auth-user")) { + std::string user = getString(p, "basic-auth-user"); BasicHttpAuthPtr& auth = cfg->getBasicAuth(); try { if (!user.empty()) { @@ -343,17 +343,17 @@ HAConfigParser::parseOne(const HAConfigMapperPtr& config_storage, std::set configured_states; // Go over per state configurations. - for (auto s = states_vec.begin(); s != states_vec.end(); ++s) { + for (auto const& s : states_vec) { // State configuration is held in map. - if ((*s)->getType() != Element::map) { + if (s->getType() != Element::map) { isc_throw(ConfigError, "state configuration must be a map"); } - setDefaults(*s, HA_CONFIG_STATE_DEFAULTS); + setDefaults(s, HA_CONFIG_STATE_DEFAULTS); // Get state name and set per state configuration. - std::string state_name = getString(*s, "state"); + std::string state_name = getString(s, "state"); int state = stringToState(state_name); // Check that this configuration doesn't duplicate existing configuration. @@ -364,7 +364,7 @@ HAConfigParser::parseOne(const HAConfigMapperPtr& config_storage, configured_states.insert(state); rel_config->getStateMachineConfig()-> - getStateConfig(state)->setPausing(getString(*s, "pause")); + getStateConfig(state)->setPausing(getString(s, "pause")); } } diff --git a/src/hooks/dhcp/high_availability/ha_service.cc b/src/hooks/dhcp/high_availability/ha_service.cc index 1d34b0e889..3843f61dad 100644 --- a/src/hooks/dhcp/high_availability/ha_service.cc +++ b/src/hooks/dhcp/high_availability/ha_service.cc @@ -1198,21 +1198,21 @@ HAService::asyncSendLeaseUpdates(const dhcp::Pkt4Ptr& query, size_t sent_num = 0; // Schedule sending lease updates to each peer. - for (auto p = peers_configs.begin(); p != peers_configs.end(); ++p) { - HAConfig::PeerConfigPtr conf = p->second; + for (auto const& p : peers_configs) { + HAConfig::PeerConfigPtr conf = p.second; // Check if the lease updates should be queued. This is the case when the // server is in the communication-recovery state. Queued lease updates may // be sent when the communication is re-established. if (shouldQueueLeaseUpdates(conf)) { // Lease updates for deleted leases. - for (auto l = deleted_leases->begin(); l != deleted_leases->end(); ++l) { - lease_update_backlog_.push(LeaseUpdateBacklog::DELETE, *l); + for (auto const& l : *deleted_leases) { + lease_update_backlog_.push(LeaseUpdateBacklog::DELETE, l); } // Lease updates for new allocations and updated leases. - for (auto l = leases->begin(); l != leases->end(); ++l) { - lease_update_backlog_.push(LeaseUpdateBacklog::ADD, *l); + for (auto const& l : *leases) { + lease_update_backlog_.push(LeaseUpdateBacklog::ADD, l); } continue; @@ -1233,14 +1233,14 @@ HAService::asyncSendLeaseUpdates(const dhcp::Pkt4Ptr& query, } // Lease updates for deleted leases. - for (auto l = deleted_leases->begin(); l != deleted_leases->end(); ++l) { - asyncSendLeaseUpdate(query, conf, CommandCreator::createLease4Delete(**l), + for (auto const& l : *deleted_leases) { + asyncSendLeaseUpdate(query, conf, CommandCreator::createLease4Delete(*l), parking_lot); } // Lease updates for new allocations and updated leases. - for (auto l = leases->begin(); l != leases->end(); ++l) { - asyncSendLeaseUpdate(query, conf, CommandCreator::createLease4Update(**l), + for (auto const& l : *leases) { + asyncSendLeaseUpdate(query, conf, CommandCreator::createLease4Update(*l), parking_lot); } @@ -1278,20 +1278,20 @@ HAService::asyncSendLeaseUpdates(const dhcp::Pkt6Ptr& query, size_t sent_num = 0; // Schedule sending lease updates to each peer. - for (auto p = peers_configs.begin(); p != peers_configs.end(); ++p) { - HAConfig::PeerConfigPtr conf = p->second; + for (auto const& p : peers_configs) { + HAConfig::PeerConfigPtr conf = p.second; // Check if the lease updates should be queued. This is the case when the // server is in the communication-recovery state. Queued lease updates may // be sent when the communication is re-established. if (shouldQueueLeaseUpdates(conf)) { - for (auto l = deleted_leases->begin(); l != deleted_leases->end(); ++l) { - lease_update_backlog_.push(LeaseUpdateBacklog::DELETE, *l); + for (auto const& l : *deleted_leases) { + lease_update_backlog_.push(LeaseUpdateBacklog::DELETE, l); } // Lease updates for new allocations and updated leases. - for (auto l = leases->begin(); l != leases->end(); ++l) { - lease_update_backlog_.push(LeaseUpdateBacklog::ADD, *l); + for (auto const& l : *leases) { + lease_update_backlog_.push(LeaseUpdateBacklog::ADD, l); } continue; @@ -1658,7 +1658,7 @@ HAService::processStatusGet() const { } std::set scopes = query_filter_.getServedScopes(); ElementPtr list = Element::createList(); - for (const std::string& scope : scopes) { + for (auto const& scope : scopes) { list->add(Element::create(scope)); } local->set("scopes", list); diff --git a/src/hooks/dhcp/high_availability/lease_sync_filter.cc b/src/hooks/dhcp/high_availability/lease_sync_filter.cc index 7cdee015a7..99c2327beb 100644 --- a/src/hooks/dhcp/high_availability/lease_sync_filter.cc +++ b/src/hooks/dhcp/high_availability/lease_sync_filter.cc @@ -24,11 +24,11 @@ void LeaseSyncFilter::apply() { subnet_ids_.clear(); if (server_type_ == HAServerType::DHCPv4) { - for (auto subnet : *CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll()) { + for (auto const& subnet : *CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll()) { conditionallyApplySubnetFilter(subnet); } } else { - for (auto subnet : *CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll()) { + for (auto const& subnet : *CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll()) { conditionallyApplySubnetFilter(subnet); } } @@ -44,7 +44,7 @@ LeaseSyncFilter::conditionallyApplySubnetFilter(const SubnetPtr& subnet) { try { auto server_name = HAConfig::getSubnetServerName(subnet); if (!server_name.empty()) { - for (auto peer : config_->getAllServersConfig()) { + for (auto const& peer : config_->getAllServersConfig()) { if (peer.first == server_name) { subnet_ids_.insert(subnet->getID()); return; diff --git a/src/hooks/dhcp/high_availability/query_filter.cc b/src/hooks/dhcp/high_availability/query_filter.cc index 5efda93f96..6cf2a9d2dd 100644 --- a/src/hooks/dhcp/high_availability/query_filter.cc +++ b/src/hooks/dhcp/high_availability/query_filter.cc @@ -132,8 +132,8 @@ QueryFilter::QueryFilter(const HAConfigPtr& config) // The returned configurations are not ordered. Let's iterate over them // and put them in the desired order. - for (auto peer_pair = peers_map.begin(); peer_pair != peers_map.end(); ++peer_pair) { - auto peer = peer_pair->second; + for (auto const& peer_pair : peers_map) { + auto peer = peer_pair.second; // The primary server is always first on the list. if (peer->getRole() == HAConfig::PeerConfig::PRIMARY) { peers_.insert(peers_.begin(), peer); @@ -275,16 +275,16 @@ QueryFilter::serveFailoverScopesInternal() { // Iterate over the roles of all servers to see which scope should // be enabled. - for (auto peer = peers_.begin(); peer != peers_.end(); ++peer) { + for (auto const& peer : peers_) { // The scope of the primary server must always be served. If we're // doing load balancing, the scope of the secondary server also // has to be served. Regardless if I am primary or secondary, // I will start serving queries from both scopes. If I am a // standby server, I will start serving the scope of the primary // server. - if (((*peer)->getRole() == HAConfig::PeerConfig::PRIMARY) || - ((*peer)->getRole() == HAConfig::PeerConfig::SECONDARY)) { - serveScopeInternal((*peer)->getName()); + if ((peer->getRole() == HAConfig::PeerConfig::PRIMARY) || + (peer->getRole() == HAConfig::PeerConfig::SECONDARY)) { + serveScopeInternal(peer->getName()); } } } @@ -304,8 +304,8 @@ QueryFilter::serveNoScopesInternal() { scopes_.clear(); // Disable scope for each peer in the configuration. - for (auto peer = peers_.begin(); peer != peers_.end(); ++peer) { - scopes_[(*peer)->getName()] = false; + for (auto const& peer : peers_) { + scopes_[peer->getName()] = false; } } diff --git a/src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc b/src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc index 52d1780b3f..fbf22735e8 100644 --- a/src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc @@ -954,7 +954,7 @@ CommunicationStateTest::getRejectedLeaseUpdatesCountFromContainerTest() { // expiring in the future. Even entries have lifetimes expiring in // the past. Entries entries; - for (auto i = 0; i < 1000; i++) { + for (auto i = 0; i < 1000; ++i) { entries.insert({i, time(NULL) + (i % 2 ? 100 + i : -1 - i)}); } // Get the count of valid entries. It should remove the expiring diff --git a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc index 800d31a2cd..5a783117be 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc @@ -122,8 +122,8 @@ void generateTestLeases(std::vector& leases) { template ConstElementPtr getLeasesAsJson(const LeasesVec& leases) { ElementPtr leases_json = Element::createList(); - for (auto l = leases.begin(); l != leases.end(); ++l) { - leases_json->add((*l)->toElement()); + for (auto const& l : leases) { + leases_json->add(l->toElement()); } return (leases_json); } @@ -258,13 +258,13 @@ public: findRequest(const std::string& str1, const std::string& str2, const std::string& str3 = "") { std::lock_guard lk(mutex_); - for (auto r = requests_.begin(); r < requests_.end(); ++r) { - std::string request_as_string = (*r)->toString(); + for (auto const& r : requests_) { + std::string request_as_string = r->toString(); if (request_as_string.find(str1) != std::string::npos) { if (request_as_string.find(str2) != std::string::npos) { if (str3.empty() || (request_as_string.find(str3) != std::string::npos)) - return (*r); + return (r); } } } diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds.cc b/src/hooks/dhcp/lease_cmds/lease_cmds.cc index 243c6382ea..7e344bba33 100644 --- a/src/hooks/dhcp/lease_cmds/lease_cmds.cc +++ b/src/hooks/dhcp/lease_cmds/lease_cmds.cc @@ -1319,23 +1319,21 @@ LeaseCmdsImpl::leaseGetAllHandler(CalloutHandle& handle) { } const std::vector& subnet_ids = subnets->listValue(); - for (auto subnet_id = subnet_ids.begin(); - subnet_id != subnet_ids.end(); - ++subnet_id) { - if ((*subnet_id)->getType() != Element::integer) { + for (auto const& subnet_id : subnet_ids) { + if (subnet_id->getType() != Element::integer) { isc_throw(BadValue, "listed subnet identifiers must be numbers"); } if (v4) { Lease4Collection leases = - LeaseMgrFactory::instance().getLeases4((*subnet_id)->intValue()); + LeaseMgrFactory::instance().getLeases4(subnet_id->intValue()); for (auto const& lease : leases) { ElementPtr lease_json = lease->toElement(); leases_json->add(lease_json); } } else { Lease6Collection leases = - LeaseMgrFactory::instance().getLeases6((*subnet_id)->intValue()); + LeaseMgrFactory::instance().getLeases6(subnet_id->intValue()); for (auto const& lease : leases) { ElementPtr lease_json = lease->toElement(); leases_json->add(lease_json); diff --git a/src/hooks/dhcp/lease_cmds/tests/lease_cmds4_unittest.cc b/src/hooks/dhcp/lease_cmds/tests/lease_cmds4_unittest.cc index c01874563d..7caa51d737 100644 --- a/src/hooks/dhcp/lease_cmds/tests/lease_cmds4_unittest.cc +++ b/src/hooks/dhcp/lease_cmds/tests/lease_cmds4_unittest.cc @@ -67,10 +67,10 @@ public: // we're interested in. if (l->getType() == isc::data::Element::list) { std::vector e = l->listValue(); - for (auto it = e.begin(); it != e.end(); ++it) { - isc::data::ConstElementPtr ip_address = (*it)->get("ip-address"); + for (auto const& it : e) { + isc::data::ConstElementPtr ip_address = it->get("ip-address"); if (ip_address && ip_address->stringValue() == ip) { - l = (*it); + l = it; break; } } diff --git a/src/hooks/dhcp/lease_cmds/tests/lease_cmds6_unittest.cc b/src/hooks/dhcp/lease_cmds/tests/lease_cmds6_unittest.cc index bc5e953fa5..1ff38c6e33 100644 --- a/src/hooks/dhcp/lease_cmds/tests/lease_cmds6_unittest.cc +++ b/src/hooks/dhcp/lease_cmds/tests/lease_cmds6_unittest.cc @@ -68,10 +68,10 @@ public: // we're interested in. if (l->getType() == isc::data::Element::list) { std::vector e = l->listValue(); - for (auto it = e.begin(); it != e.end(); ++it) { - isc::data::ConstElementPtr ip_address = (*it)->get("ip-address"); + for (auto const& it : e) { + isc::data::ConstElementPtr ip_address = it->get("ip-address"); if (ip_address && ip_address->stringValue() == ip) { - l = (*it); + l = it; break; } } diff --git a/src/hooks/dhcp/lease_cmds/tests/lease_cmds_unittest.h b/src/hooks/dhcp/lease_cmds/tests/lease_cmds_unittest.h index 57720f4665..4f3be11376 100644 --- a/src/hooks/dhcp/lease_cmds/tests/lease_cmds_unittest.h +++ b/src/hooks/dhcp/lease_cmds/tests/lease_cmds_unittest.h @@ -177,24 +177,23 @@ public: /// @param cms a vector of string with command names void testCommands(const std::vector cmds) { // The commands should not be registered yet. - for (auto cmd = cmds.begin(); cmd != cmds.end(); ++cmd) { - checkCommandRegistered(*cmd, false); + for (auto const& cmd : cmds) { + checkCommandRegistered(cmd, false); } loadLib(); // The commands should be available after library was loaded. - for (auto cmd = cmds.begin(); cmd != cmds.end(); ++cmd) { - checkCommandRegistered(*cmd, true); + for (auto const& cmd : cmds) { + checkCommandRegistered(cmd, true); } unloadLibs(); // and the commands should be gone now. - for (auto cmd = cmds.begin(); cmd != cmds.end(); ++cmd) { - checkCommandRegistered(*cmd, false); + for (auto const& cmd : cmds) { + checkCommandRegistered(cmd, false); } - } // Check that the library can be loaded and unloaded multiple times. diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index 53b67998a7..dc4ffca856 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -1036,10 +1036,8 @@ public: // Create JSON list of required classes. ElementPtr required_classes_element = Element::createList(); auto const& required_classes = subnet->getRequiredClasses(); - for (auto required_class = required_classes.cbegin(); - required_class != required_classes.cend(); - ++required_class) { - required_classes_element->add(Element::create(*required_class)); + for (auto const& required_class : required_classes) { + required_classes_element->add(Element::create(required_class)); } // Create binding for DDNS replace client name mode. @@ -1170,8 +1168,8 @@ public: auto option_spaces = subnet->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = subnet->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption4(server_selector, subnet->getID(), desc_copy, true); @@ -1205,8 +1203,8 @@ public: auto option_spaces = pool->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = pool->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption4(server_selector, pool_id, desc_copy, true); } @@ -1800,8 +1798,8 @@ public: auto option_spaces = shared_network->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = shared_network->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption4(server_selector, shared_network->getName(), desc_copy, true); @@ -2749,8 +2747,8 @@ public: auto option_spaces = option_defs.getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionDefContainerPtr defs = option_defs.getItems(option_space); - for (auto def = defs->begin(); def != defs->end(); ++def) { - createUpdateOptionDef4(server_selector, *def, client_class->getName()); + for (auto const& def : *defs) { + createUpdateOptionDef4(server_selector, def, client_class->getName()); } } } @@ -2759,8 +2757,8 @@ public: auto option_spaces = client_class->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = client_class->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption4(server_selector, client_class, desc_copy); } diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc index 1ab8655f99..90368c8f8d 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc @@ -1278,10 +1278,8 @@ public: // Create JSON list of required classes. ElementPtr required_classes_element = Element::createList(); auto const& required_classes = subnet->getRequiredClasses(); - for (auto required_class = required_classes.cbegin(); - required_class != required_classes.cend(); - ++required_class) { - required_classes_element->add(Element::create(*required_class)); + for (auto const& required_class : required_classes) { + required_classes_element->add(Element::create(required_class)); } // Create binding for DDNS replace client name mode. @@ -1427,8 +1425,8 @@ public: auto option_spaces = subnet->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = subnet->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption6(server_selector, subnet->getID(), desc_copy, true); @@ -1463,8 +1461,8 @@ public: auto option_spaces = pool->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = pool->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption6(server_selector, Lease::TYPE_NA, pool_id, desc_copy, true); @@ -1514,8 +1512,8 @@ public: auto option_spaces = pd_pool->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = pd_pool->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption6(server_selector, Lease::TYPE_PD, pd_pool_id, desc_copy, true); @@ -2139,8 +2137,8 @@ public: auto option_spaces = shared_network->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = shared_network->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption6(server_selector, shared_network->getName(), desc_copy, true); @@ -3176,8 +3174,8 @@ public: auto option_spaces = option_defs.getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionDefContainerPtr defs = option_defs.getItems(option_space); - for (auto def = defs->begin(); def != defs->end(); ++def) { - createUpdateOptionDef6(server_selector, *def, client_class->getName()); + for (auto const& def : *defs) { + createUpdateOptionDef6(server_selector, def, client_class->getName()); } } } @@ -3186,8 +3184,8 @@ public: auto option_spaces = client_class->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = client_class->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption6(server_selector, client_class, desc_copy); } diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h index c4f84da36c..fa032b9aa4 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h @@ -634,10 +634,8 @@ public: // Create JSON list of required classes. data::ElementPtr required_classes_element = data::Element::createList(); auto const& required_classes = object->getRequiredClasses(); - for (auto required_class = required_classes.cbegin(); - required_class != required_classes.cend(); - ++required_class) { - required_classes_element->add(data::Element::create(*required_class)); + for (auto const& required_class : required_classes) { + required_classes_element->add(data::Element::create(required_class)); } return (required_classes_element ? diff --git a/src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp4.cc b/src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp4.cc index 9b99b31a0d..31badd2ca5 100644 --- a/src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp4.cc +++ b/src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp4.cc @@ -1010,8 +1010,8 @@ public: auto option_spaces = subnet->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = subnet->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption4(server_selector, subnet->getID(), desc_copy, true); @@ -1050,8 +1050,8 @@ public: auto option_spaces = pool->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = pool->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption4(server_selector, pool_id, desc_copy, true); } @@ -1576,8 +1576,8 @@ public: auto option_spaces = shared_network->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = shared_network->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption4(server_selector, shared_network->getName(), desc_copy, true); @@ -2550,8 +2550,8 @@ public: auto option_spaces = option_defs.getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionDefContainerPtr defs = option_defs.getItems(option_space); - for (auto def = defs->begin(); def != defs->end(); ++def) { - createUpdateOptionDef4(server_selector, *def, client_class->getName()); + for (auto const& def : *defs) { + createUpdateOptionDef4(server_selector, def, client_class->getName()); } } } @@ -2560,8 +2560,8 @@ public: auto option_spaces = client_class->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = client_class->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption4(server_selector, client_class, desc_copy); } diff --git a/src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp6.cc b/src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp6.cc index 4595a0a5b9..f7e1accc95 100644 --- a/src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp6.cc +++ b/src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp6.cc @@ -1185,8 +1185,8 @@ public: auto option_spaces = subnet->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = subnet->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption6(server_selector, subnet->getID(), desc_copy, true); @@ -1225,8 +1225,8 @@ public: auto option_spaces = pool->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = pool->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption6(server_selector, Lease::TYPE_NA, pool_id, desc_copy, true); @@ -1279,8 +1279,8 @@ public: auto option_spaces = pd_pool->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = pd_pool->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption6(server_selector, Lease::TYPE_PD, pd_pool_id, desc_copy, true); @@ -1813,8 +1813,8 @@ public: auto option_spaces = shared_network->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = shared_network->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption6(server_selector, shared_network->getName(), desc_copy, true); @@ -2872,8 +2872,8 @@ public: auto option_spaces = option_defs.getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionDefContainerPtr defs = option_defs.getItems(option_space); - for (auto def = defs->begin(); def != defs->end(); ++def) { - createUpdateOptionDef6(server_selector, *def, client_class->getName()); + for (auto const& def : *defs) { + createUpdateOptionDef6(server_selector, def, client_class->getName()); } } } @@ -2882,8 +2882,8 @@ public: auto option_spaces = client_class->getCfgOption()->getOptionSpaceNames(); for (auto const& option_space : option_spaces) { OptionContainerPtr options = client_class->getCfgOption()->getAll(option_space); - for (auto desc = options->begin(); desc != options->end(); ++desc) { - OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc); + for (auto const& desc : *options) { + OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc); desc_copy->space_name_ = option_space; createUpdateOption6(server_selector, client_class, desc_copy); } diff --git a/src/hooks/dhcp/pgsql_cb/pgsql_cb_impl.h b/src/hooks/dhcp/pgsql_cb/pgsql_cb_impl.h index a5cefeea17..5eb707d28a 100644 --- a/src/hooks/dhcp/pgsql_cb/pgsql_cb_impl.h +++ b/src/hooks/dhcp/pgsql_cb/pgsql_cb_impl.h @@ -601,10 +601,8 @@ public: // Create JSON list of required classes. data::ElementPtr required_classes_element = data::Element::createList(); auto const& required_classes = object->getRequiredClasses(); - for (auto required_class = required_classes.cbegin(); - required_class != required_classes.cend(); - ++required_class) { - required_classes_element->add(data::Element::create(*required_class)); + for (auto const& required_class : required_classes) { + required_classes_element->add(data::Element::create(required_class)); } bindings.add(required_classes_element); diff --git a/src/hooks/dhcp/stat_cmds/stat_cmds.cc b/src/hooks/dhcp/stat_cmds/stat_cmds.cc index 4e17695d20..6ba4a13004 100644 --- a/src/hooks/dhcp/stat_cmds/stat_cmds.cc +++ b/src/hooks/dhcp/stat_cmds/stat_cmds.cc @@ -676,8 +676,8 @@ LeaseStatCmdsImpl::createResultSet(const ElementPtr &result_wrapper, // Create the list of column names and add it to the result set. ElementPtr columns = Element::createList(); - for (auto label = column_labels.begin(); label != column_labels.end(); ++label) { - columns->add(Element::create(*label)); + for (auto const& label : column_labels) { + columns->add(Element::create(label)); } result_set->set("columns", columns); diff --git a/src/hooks/dhcp/stat_cmds/tests/stat_cmds_unittest.cc b/src/hooks/dhcp/stat_cmds/tests/stat_cmds_unittest.cc index 8037209726..cd62dec3c1 100644 --- a/src/hooks/dhcp/stat_cmds/tests/stat_cmds_unittest.cc +++ b/src/hooks/dhcp/stat_cmds/tests/stat_cmds_unittest.cc @@ -249,22 +249,22 @@ public: void testCommands(const std::vector cmds) { // The commands should not be registered yet. - for (auto cmd = cmds.begin(); cmd != cmds.end(); ++cmd) { - checkCommandRegistered(*cmd, false); + for (auto const& cmd : cmds) { + checkCommandRegistered(cmd, false); } loadLib(); // The commands should be available after library was loaded. - for (auto cmd = cmds.begin(); cmd != cmds.end(); ++cmd) { - checkCommandRegistered(*cmd, true); + for (auto const& cmd : cmds) { + checkCommandRegistered(cmd, true); } unloadLibs(); // and the commands should be gone now. - for (auto cmd = cmds.begin(); cmd != cmds.end(); ++cmd) { - checkCommandRegistered(*cmd, false); + for (auto const& cmd : cmds) { + checkCommandRegistered(cmd, false); } } @@ -630,7 +630,7 @@ struct TestScenario { std::string description_; std::string command_txt_; std::string exp_response_; - std::string exp_result_json; + std::string exp_result_json_; }; // Verifies detection of invalid v4 input parameters. @@ -792,11 +792,9 @@ TEST_F(StatCmdsTest, StatLease4GetBadParams) { } }; - for (auto test = tests.begin(); test != tests.end(); ++test) { - { - SCOPED_TRACE((*test).description_); - testCommand((*test).command_txt_, CONTROL_RESULT_ERROR,(*test).exp_response_); - } + for (auto const& test : tests) { + SCOPED_TRACE(test.description_); + testCommand(test.command_txt_, CONTROL_RESULT_ERROR, test.exp_response_); } } @@ -990,14 +988,11 @@ TEST_F(StatCmdsTest, statLease4GetValid) { } }; - for (auto test = tests.begin(); test != tests.end(); ++test) { - { - SCOPED_TRACE((*test).description_); - testCommand((*test).command_txt_, CONTROL_RESULT_SUCCESS, - (*test).exp_response_, (*test).exp_result_json); - } + for (auto const& test : tests) { + SCOPED_TRACE(test.description_); + testCommand(test.command_txt_, CONTROL_RESULT_SUCCESS, + test.exp_response_, test.exp_result_json_); } - } // Verifies result content for valid v4 statistic commands that @@ -1052,14 +1047,11 @@ TEST_F(StatCmdsTest, statLease4GetSubnetsNotFound) { } }; - for (auto test = tests.begin(); test != tests.end(); ++test) { - { - SCOPED_TRACE((*test).description_); - testCommand((*test).command_txt_, CONTROL_RESULT_EMPTY, - (*test).exp_response_, (*test).exp_result_json); + for (auto const& test : tests) { + SCOPED_TRACE(test.description_); + testCommand(test.command_txt_, CONTROL_RESULT_EMPTY, + test.exp_response_, test.exp_result_json_); } - } - } // Verifies detection of invalid v6 input parameters. @@ -1221,11 +1213,9 @@ TEST_F(StatCmdsTest, StatLease6GetBadParams) { } }; - for (auto test = tests.begin(); test != tests.end(); ++test) { - { - SCOPED_TRACE((*test).description_); - testCommand((*test).command_txt_, CONTROL_RESULT_ERROR,(*test).exp_response_); - } + for (auto const& test : tests) { + SCOPED_TRACE(test.description_); + testCommand(test.command_txt_, CONTROL_RESULT_ERROR, test.exp_response_); } } @@ -1426,12 +1416,10 @@ TEST_F(StatCmdsTest, statLease6GetValid) { } }; - for (auto test = tests.begin(); test != tests.end(); ++test) { - { - SCOPED_TRACE((*test).description_); - testCommand((*test).command_txt_, CONTROL_RESULT_SUCCESS, - (*test).exp_response_, (*test).exp_result_json); - } + for (auto const& test : tests) { + SCOPED_TRACE(test.description_); + testCommand(test.command_txt_, CONTROL_RESULT_SUCCESS, + test.exp_response_, test.exp_result_json_); } } @@ -1488,12 +1476,10 @@ TEST_F(StatCmdsTest, statLease6GetSubnetsNotFound) { } }; - for (auto test = tests.begin(); test != tests.end(); ++test) { - { - SCOPED_TRACE((*test).description_); - testCommand((*test).command_txt_, CONTROL_RESULT_EMPTY, - (*test).exp_response_, (*test).exp_result_json); - } + for (auto const& test : tests) { + SCOPED_TRACE(test.description_); + testCommand(test.command_txt_, CONTROL_RESULT_EMPTY, + test.exp_response_, test.exp_result_json_); } } @@ -1540,12 +1526,10 @@ TEST_F(StatCmdsTest, statLease4OrphanedStats) { } }; - for (auto test = tests.begin(); test != tests.end(); ++test) { - { - SCOPED_TRACE((*test).description_); - testCommand((*test).command_txt_, CONTROL_RESULT_SUCCESS, - (*test).exp_response_, (*test).exp_result_json); - } + for (auto const& test : tests) { + SCOPED_TRACE(test.description_); + testCommand(test.command_txt_, CONTROL_RESULT_SUCCESS, + test.exp_response_, test.exp_result_json_); } } @@ -1593,12 +1577,10 @@ TEST_F(StatCmdsTest, statLease6OrphanedStats) { } }; - for (auto test = tests.begin(); test != tests.end(); ++test) { - { - SCOPED_TRACE((*test).description_); - testCommand((*test).command_txt_, CONTROL_RESULT_SUCCESS, - (*test).exp_response_, (*test).exp_result_json); - } + for (auto const& test : tests) { + SCOPED_TRACE(test.description_); + testCommand(test.command_txt_, CONTROL_RESULT_SUCCESS, + test.exp_response_, test.exp_result_json_); } } diff --git a/src/hooks/dhcp/user_chk/user.cc b/src/hooks/dhcp/user_chk/user.cc index 531a486d23..09c6c8a573 100644 --- a/src/hooks/dhcp/user_chk/user.cc +++ b/src/hooks/dhcp/user_chk/user.cc @@ -85,14 +85,13 @@ UserId::toText(char delim_char) const { std::stringstream tmp; tmp << std::hex; bool delim = false; - for (std::vector::const_iterator it = id_.begin(); - it != id_.end(); ++it) { + for (auto const& it : id_) { if (delim_char && delim) { tmp << delim_char; } tmp << std::setw(2) << std::setfill('0') - << static_cast(*it); + << static_cast(it); delim = true; } diff --git a/src/hooks/dhcp/user_chk/user_file.cc b/src/hooks/dhcp/user_chk/user_file.cc index 4f493cf04a..25dc6890c7 100644 --- a/src/hooks/dhcp/user_chk/user_file.cc +++ b/src/hooks/dhcp/user_chk/user_file.cc @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -87,7 +86,7 @@ UserFile::makeUser(const std::string& user_string) { // respective locals. Anything else is assumed to be an option so // add it to the local property map. std::pair element_pair; - BOOST_FOREACH (element_pair, elements->mapValue()) { + for (auto const& element_pair : elements->mapValue()) { // Get the element's label. std::string label = element_pair.first; diff --git a/src/lib/asiolink/tests/io_address_unittest.cc b/src/lib/asiolink/tests/io_address_unittest.cc index b1139402df..58239989d5 100644 --- a/src/lib/asiolink/tests/io_address_unittest.cc +++ b/src/lib/asiolink/tests/io_address_unittest.cc @@ -22,7 +22,7 @@ using namespace isc::asiolink; TEST(IOAddressHashTest, hashIPv4) { IOAddress::Hash hash; std::unordered_set results; - for (uint32_t i = 0; i < 10; i++) { + for (uint32_t i = 0; i < 10; ++i) { IOAddress address(i); auto result = hash(address); results.insert(result); @@ -35,7 +35,7 @@ TEST(IOAddressHashTest, hashIPv4) { TEST(IOAddressHashTest, hashIPv6) { IOAddress::Hash hash; std::unordered_set results; - for (auto i = 0; i < 10; i++) { + for (auto i = 0; i < 10; ++i) { std::ostringstream s; s << "2001:db8:" << i << "::ffff"; IOAddress address(s.str()); diff --git a/src/lib/asiolink/testutils/test_server_unix_socket.cc b/src/lib/asiolink/testutils/test_server_unix_socket.cc index c0bd45ac5f..e17e1e671a 100644 --- a/src/lib/asiolink/testutils/test_server_unix_socket.cc +++ b/src/lib/asiolink/testutils/test_server_unix_socket.cc @@ -193,9 +193,8 @@ public: /// @brief Stops all connections. void stopAll() { - for (auto conn = connections_.begin(); conn != connections_.end(); - ++conn) { - (*conn)->stop(); + for (auto const& conn : connections_) { + conn->stop(); } connections_.clear(); } diff --git a/src/lib/cc/command_interpreter.cc b/src/lib/cc/command_interpreter.cc index ebef7d7d54..7910625137 100644 --- a/src/lib/cc/command_interpreter.cc +++ b/src/lib/cc/command_interpreter.cc @@ -298,17 +298,17 @@ combineCommandsLists(const ConstElementPtr& response1, // Storing command names in a set guarantees that the non-unique // command names are aggregated. std::set combined_set; - for (auto v = vec1.cbegin(); v != vec1.cend(); ++v) { - combined_set.insert((*v)->stringValue()); + for (auto const& v : vec1) { + combined_set.insert(v->stringValue()); } - for (auto v = vec2.cbegin(); v != vec2.cend(); ++v) { - combined_set.insert((*v)->stringValue()); + for (auto const& v : vec2) { + combined_set.insert(v->stringValue()); } // Create a combined list of commands. ElementPtr combined_list = Element::createList(); - for (auto s = combined_set.cbegin(); s != combined_set.cend(); ++s) { - combined_list->add(Element::create(*s)); + for (auto const& s : combined_set) { + combined_list->add(Element::create(s)); } return (createAnswer(CONTROL_RESULT_SUCCESS, combined_list)); } diff --git a/src/lib/cc/data.cc b/src/lib/cc/data.cc index abcb0fbc4f..6e18926087 100644 --- a/src/lib/cc/data.cc +++ b/src/lib/cc/data.cc @@ -923,11 +923,14 @@ ListElement::toJSON(std::ostream& ss) const { ss << "[ "; const std::vector& v = listValue(); - for (auto it = v.begin(); it != v.end(); ++it) { - if (it != v.begin()) { + bool first = true; + for (auto const& it : v) { + if (!first) { ss << ", "; + } else { + first = false; } - (*it)->toJSON(ss); + it->toJSON(ss); } ss << " ]"; } @@ -936,13 +939,16 @@ void MapElement::toJSON(std::ostream& ss) const { ss << "{ "; - for (auto it = m.begin(); it != m.end(); ++it) { - if (it != m.begin()) { + bool first = true; + for (auto const& it : m) { + if (!first) { ss << ", "; + } else { + first = false; } - ss << "\"" << (*it).first << "\": "; - if ((*it).second) { - (*it).second->toJSON(ss); + ss << "\"" << it.first << "\": "; + if (it.second) { + it.second->toJSON(ss); } else { ss << "None"; } @@ -1218,14 +1224,14 @@ mergeDiffAdd(ElementPtr& element, ElementPtr& other, // Store new elements in a separate container so we don't overwrite // options as we add them (if there are duplicates). ElementPtr new_elements = Element::createList(); - for (auto& right : other->listValue()) { + for (auto const& right : other->listValue()) { // Check if we have any description of the key in the configuration // hierarchy. auto f = hierarchy[idx].find(key); if (f != hierarchy[idx].end()) { bool found = false; ElementPtr mutable_right = boost::const_pointer_cast(right); - for (auto& left : element->listValue()) { + for (auto const& left : element->listValue()) { ElementPtr mutable_left = boost::const_pointer_cast(left); // Check if the elements refer to the same configuration // entity. @@ -1242,7 +1248,7 @@ mergeDiffAdd(ElementPtr& element, ElementPtr& other, } } // Finally add the new elements. - for (auto& right : new_elements->listValue()) { + for (auto const& right : new_elements->listValue()) { element->add(right); } return; @@ -1367,13 +1373,13 @@ extend(const std::string& container, const std::string& extension, } if (element->getType() == Element::list) { - for (auto& right : other->listValue()) { + for (auto const& right : other->listValue()) { // Check if we have any description of the key in the configuration // hierarchy. auto f = hierarchy[idx].find(key); if (f != hierarchy[idx].end()) { ElementPtr mutable_right = boost::const_pointer_cast(right); - for (auto& left : element->listValue()) { + for (auto const& left : element->listValue()) { ElementPtr mutable_left = boost::const_pointer_cast(left); if (container == key) { alter = true; @@ -1566,17 +1572,20 @@ prettyPrint(ConstElementPtr element, std::ostream& out, // iterate on items auto const& l = element->listValue(); - for (auto it = l.begin(); it != l.end(); ++it) { + bool first = true; + for (auto const& it : l) { // add the separator if not the first item - if (it != l.begin()) { + if (!first) { out << separator; + } else { + first = false; } // add indentation if (complex) { out << std::string(indent + step, ' '); } // recursive call - prettyPrint(*it, out, indent + step, step); + prettyPrint(it, out, indent + step, step); } // close the list @@ -1599,7 +1608,7 @@ prettyPrint(ConstElementPtr element, std::ostream& out, // iterate on keyword: value auto const& m = element->mapValue(); bool first = true; - for (auto it = m.begin(); it != m.end(); ++it) { + for (auto const& it : m) { // add the separator if not the first item if (first) { first = false; @@ -1609,9 +1618,9 @@ prettyPrint(ConstElementPtr element, std::ostream& out, // add indentation out << std::string(indent + step, ' '); // add keyword: - out << "\"" << it->first << "\": "; + out << "\"" << it.first << "\": "; // recursive call - prettyPrint(it->second, out, indent + step, step); + prettyPrint(it.second, out, indent + step, step); } // close the map diff --git a/src/lib/cc/simple_parser.cc b/src/lib/cc/simple_parser.cc index 314d2888c3..7506d69d94 100644 --- a/src/lib/cc/simple_parser.cc +++ b/src/lib/cc/simple_parser.cc @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -178,7 +177,7 @@ size_t SimpleParser::setDefaults(ElementPtr scope, const Element::Position pos("", 0, 0); // Let's go over all parameters we have defaults for. - BOOST_FOREACH(SimpleDefault def_value, default_values) { + for (auto const& def_value : default_values) { // Try if such a parameter is there. If it is, let's // skip it, because user knows best *cough*. @@ -245,7 +244,7 @@ size_t SimpleParser::setListDefaults(ConstElementPtr list, const SimpleDefaults& default_values) { size_t cnt = 0; - BOOST_FOREACH(ElementPtr entry, list->listValue()) { + for (auto const& entry : list->listValue()) { cnt += setDefaults(entry, default_values); } return (cnt); @@ -261,7 +260,7 @@ SimpleParser::deriveParams(ConstElementPtr parent, } size_t cnt = 0; - BOOST_FOREACH(string param, params) { + for (auto const& param : params) { ConstElementPtr x = parent->get(param); if (!x) { // Parent doesn't define this parameter, so there's diff --git a/src/lib/config/base_command_mgr.cc b/src/lib/config/base_command_mgr.cc index ff1d2d86c0..74bfa0585d 100644 --- a/src/lib/config/base_command_mgr.cc +++ b/src/lib/config/base_command_mgr.cc @@ -183,9 +183,8 @@ BaseCommandMgr::listCommandsHandler(const std::string& /* name */, const isc::data::ConstElementPtr& ) { using namespace isc::data; ElementPtr commands = Element::createList(); - for (HandlerContainer::const_iterator it = handlers_.begin(); - it != handlers_.end(); ++it) { - commands->add(Element::create(it->first)); + for (auto const& it : handlers_) { + commands->add(Element::create(it.first)); } return (createAnswer(CONTROL_RESULT_SUCCESS, commands)); } diff --git a/src/lib/config/command_mgr.cc b/src/lib/config/command_mgr.cc index 831d56e78c..cd42f1c3ad 100644 --- a/src/lib/config/command_mgr.cc +++ b/src/lib/config/command_mgr.cc @@ -262,9 +262,8 @@ public: /// @brief Stops all connections which are allowed to stop. void stopAll() { - for (auto conn = connections_.begin(); conn != connections_.end(); - ++conn) { - (*conn)->stop(); + for (auto const& conn : connections_) { + conn->stop(); } connections_.clear(); } diff --git a/src/lib/config/hooked_command_mgr.cc b/src/lib/config/hooked_command_mgr.cc index 4674080483..2a1c71e39f 100644 --- a/src/lib/config/hooked_command_mgr.cc +++ b/src/lib/config/hooked_command_mgr.cc @@ -99,13 +99,13 @@ HookedCommandMgr::handleCommand(const std::string& cmd_name, // Only update the response if there are any hooks present. if (!hooks.empty()) { ElementPtr hooks_commands = Element::createList(); - for (auto h = hooks.cbegin(); h != hooks.end(); ++h) { + for (auto const& h : hooks) { // Try to convert hook name to command name. If non-empty // string is returned it means that the hook point may have // command handlers associated with it. Otherwise, it means that // existing hook points are not for command handlers but for // regular callouts. - std::string command_name = ServerHooks::hookToCommandName(*h); + std::string command_name = ServerHooks::hookToCommandName(h); if (!command_name.empty()) { // Final check: are command handlers registered for this // hook point? If there are no command handlers associated, diff --git a/src/lib/config/tests/command_mgr_unittests.cc b/src/lib/config/tests/command_mgr_unittests.cc index e558ce3944..e589349819 100644 --- a/src/lib/config/tests/command_mgr_unittests.cc +++ b/src/lib/config/tests/command_mgr_unittests.cc @@ -80,8 +80,8 @@ public: // Iterate over existing hook points and for each of them remove // callouts registered. std::vector hooks = ServerHooks::getServerHooksPtr()->getHookNames(); - for (auto h = hooks.cbegin(); h != hooks.cend(); ++h) { - HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts(*h); + for (auto const& h : hooks) { + HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts(h); } } @@ -418,9 +418,8 @@ TEST_F(CommandMgrTest, delegateListCommands) { const std::vector& commands_list = answer_arg->listValue(); ASSERT_EQ(3, commands_list.size()); std::vector command_names_list; - for (auto cmd = commands_list.cbegin(); cmd != commands_list.cend(); - ++cmd) { - command_names_list.push_back((*cmd)->stringValue()); + for (auto const& cmd : commands_list) { + command_names_list.push_back(cmd->stringValue()); } std::sort(command_names_list.begin(), command_names_list.end()); EXPECT_EQ("list-commands", command_names_list[0]); diff --git a/src/lib/d2srv/d2_cfg_mgr.cc b/src/lib/d2srv/d2_cfg_mgr.cc index 17ac59b231..48a84c9776 100644 --- a/src/lib/d2srv/d2_cfg_mgr.cc +++ b/src/lib/d2srv/d2_cfg_mgr.cc @@ -12,8 +12,7 @@ #include #include #include - -#include +#include using namespace isc::asiolink; using namespace isc::config; @@ -95,9 +94,8 @@ D2CfgContext::toElement() const { d2->set("reverse-ddns", reverse_ddns); // Set tsig-keys ElementPtr tsig_keys = Element::createList(); - for (TSIGKeyInfoMap::const_iterator key = keys_->begin(); - key != keys_->end(); ++key) { - tsig_keys->add(key->second->toElement()); + for (auto const& key : *keys_) { + tsig_keys->add(key.second->toElement()); } d2->set("tsig-keys", tsig_keys); // Set control-socket (skip if null as empty is not legal) @@ -198,16 +196,8 @@ D2CfgMgr::reverseV4Address(const isc::asiolink::IOAddress& ioaddr) { // Walk backwards through vector outputting each octet and a dot. std::ostringstream stream; - // We have to set the following variable to get - // const_reverse_iterator type of rend(), otherwise Solaris GCC - // complains on operator!= by trying to use the non-const variant. - const ByteAddress::const_reverse_iterator end = bytes.rend(); - - for (ByteAddress::const_reverse_iterator rit = bytes.rbegin(); - rit != end; - ++rit) - { - stream << static_cast(*rit) << "."; + for (auto const& rit : boost::adaptors::reverse(bytes)) { + stream << static_cast(rit) << "."; } // Tack on the suffix and we're done. @@ -228,16 +218,8 @@ D2CfgMgr::reverseV6Address(const isc::asiolink::IOAddress& ioaddr) { // Walk backwards through string outputting each digits and a dot. std::ostringstream stream; - // We have to set the following variable to get - // const_reverse_iterator type of rend(), otherwise Solaris GCC - // complains on operator!= by trying to use the non-const variant. - const std::string::const_reverse_iterator end = digits.rend(); - - for (std::string::const_reverse_iterator rit = digits.rbegin(); - rit != end; - ++rit) - { - stream << static_cast(*rit) << "."; + for (auto const& rit : boost::adaptors::reverse(digits)) { + stream << static_cast(rit) << "."; } // Tack on the suffix and we're done. diff --git a/src/lib/d2srv/d2_config.cc b/src/lib/d2srv/d2_config.cc index c75281b5f6..ff41645941 100644 --- a/src/lib/d2srv/d2_config.cc +++ b/src/lib/d2srv/d2_config.cc @@ -12,7 +12,6 @@ #include #include -#include #include #include @@ -270,9 +269,8 @@ DdnsDomain::toElement() const { result->set("name", Element::create(name_)); // Set servers ElementPtr servers = Element::createList(); - for (DnsServerInfoStorage::const_iterator server = servers_->begin(); - server != servers_->end(); ++server) { - ElementPtr dns_server = (*server)->toElement(); + for (auto const& server : *servers_) { + ElementPtr dns_server = server->toElement(); servers->add(dns_server); } // the dns server list may not be empty @@ -330,9 +328,8 @@ DdnsDomainListMgr::matchDomain(const std::string& fqdn, DdnsDomainPtr& domain) { size_t req_len = fqdn.size(); size_t match_len = 0; - DdnsDomainMapPair map_pair; DdnsDomainPtr best_match; - BOOST_FOREACH (map_pair, *domains_) { + for (auto const& map_pair : *domains_) { std::string domain_name = map_pair.first; size_t dom_len = domain_name.size(); @@ -386,9 +383,8 @@ ElementPtr DdnsDomainListMgr::toElement() const { ElementPtr result = Element::createList(); // Iterate on ddns domains - for (DdnsDomainMap::const_iterator domain = domains_->begin(); - domain != domains_->end(); ++domain) { - ElementPtr ddns_domain = domain->second->toElement(); + for (auto const& domain : *domains_) { + ElementPtr ddns_domain = domain.second->toElement(); result->add(ddns_domain); } @@ -457,9 +453,8 @@ TSIGKeyInfoParser::parse(ConstElementPtr key_config) { TSIGKeyInfoMapPtr TSIGKeyInfoListParser::parse(ConstElementPtr key_list) { TSIGKeyInfoMapPtr keys(new TSIGKeyInfoMap()); - ConstElementPtr key_config; TSIGKeyInfoParser key_parser; - BOOST_FOREACH(key_config, key_list->listValue()) { + for (auto const& key_config : key_list->listValue()) { TSIGKeyInfoPtr key = key_parser.parse(key_config); // Duplicates are not allowed and should be flagged as an error. @@ -574,9 +569,8 @@ DnsServerInfoListParser::parse(ConstElementPtr server_list, ConstElementPtr domain_config, const TSIGKeyInfoMapPtr keys) { DnsServerInfoStoragePtr servers(new DnsServerInfoStorage()); - ConstElementPtr server_config; DnsServerInfoParser parser; - BOOST_FOREACH(server_config, server_list->listValue()) { + for (auto const& server_config : server_list->listValue()) { DnsServerInfoPtr server = parser.parse(server_config, domain_config, keys); servers->push_back(server); @@ -627,8 +621,7 @@ DdnsDomainMapPtr DdnsDomainListParser::parse(ConstElementPtr domain_list, const TSIGKeyInfoMapPtr keys) { DdnsDomainMapPtr domains(new DdnsDomainMap()); DdnsDomainParser parser; - ConstElementPtr domain_config; - BOOST_FOREACH(domain_config, domain_list->listValue()) { + for (auto const& domain_config : domain_list->listValue()) { DdnsDomainPtr domain = parser.parse(domain_config, keys); // Duplicates are not allowed diff --git a/src/lib/d2srv/d2_config.h b/src/lib/d2srv/d2_config.h index cb141ad6b7..56d1a332b5 100644 --- a/src/lib/d2srv/d2_config.h +++ b/src/lib/d2srv/d2_config.h @@ -17,8 +17,6 @@ #include #include -#include - #include #include diff --git a/src/lib/d2srv/d2_simple_parser.cc b/src/lib/d2srv/d2_simple_parser.cc index 8be6376272..b158188031 100644 --- a/src/lib/d2srv/d2_simple_parser.cc +++ b/src/lib/d2srv/d2_simple_parser.cc @@ -11,7 +11,6 @@ #include #include #include -#include using namespace isc::data; using namespace isc::d2; @@ -185,7 +184,7 @@ D2SimpleParser::setManagerDefaults(ElementPtr global, // manager is disabled. if (mgr->find("ddns-domains")) { ConstElementPtr domains = mgr->get("ddns-domains"); - BOOST_FOREACH(ElementPtr domain, domains->listValue()) { + for (auto const& domain : domains->listValue()) { // Set the domain's defaults. We can't use setListDefaults() // as this does not handle sub-lists or maps, like server list. cnt += setDdnsDomainDefaults(domain, DDNS_DOMAIN_DEFAULTS); diff --git a/src/lib/database/database_connection.cc b/src/lib/database/database_connection.cc index 8da9bca1bc..03c450a60f 100644 --- a/src/lib/database/database_connection.cc +++ b/src/lib/database/database_connection.cc @@ -15,7 +15,6 @@ #include #include -#include #include using namespace isc::asiolink; @@ -80,7 +79,7 @@ DatabaseConnection::parse(const std::string& dbaccess) { // /usr/include/c++/4.4/bits/stl_algo.h:2178 "array subscript is above // array bounds" boost::split(tokens, dba, boost::is_any_of(string("\t "))); - BOOST_FOREACH(std::string token, tokens) { + for (auto const& token : tokens) { size_t pos = token.find("="); if (pos != string::npos) { string name = token.substr(0, pos); @@ -106,8 +105,7 @@ DatabaseConnection::redactedAccessString(const ParameterMap& parameters) { // Reconstruct the access string: start of with an empty string, then // work through all the parameters in the original string and add them. std::string access; - for (DatabaseConnection::ParameterMap::const_iterator i = parameters.begin(); - i != parameters.end(); ++i) { + for (auto const& i : parameters) { // Separate second and subsequent tokens are preceded by a space. if (!access.empty()) { @@ -115,15 +113,15 @@ DatabaseConnection::redactedAccessString(const ParameterMap& parameters) { } // Append name of parameter... - access += i->first; + access += i.first; access += "="; // ... and the value, except in the case of the password, where a // redacted value is appended. - if (i->first == std::string("password")) { + if (i.first == std::string("password")) { access += "*****"; } else { - access += i->second; + access += i.second; } } diff --git a/src/lib/database/tests/dbaccess_parser_unittest.cc b/src/lib/database/tests/dbaccess_parser_unittest.cc index 29322e0727..a288e0216f 100644 --- a/src/lib/database/tests/dbaccess_parser_unittest.cc +++ b/src/lib/database/tests/dbaccess_parser_unittest.cc @@ -142,16 +142,15 @@ public: // Check that the keywords and keyword values are the same: loop // through the keywords in the database access string. - for (DatabaseConnection::ParameterMap::const_iterator actual = parameters.begin(); - actual != parameters.end(); ++actual) { + for (auto const& actual : parameters) { // Does the keyword exist in the set of expected keywords? std::map::iterator corresponding = - expected.find(actual->first); + expected.find(actual.first); ASSERT_TRUE(corresponding != expected.end()); // Keyword exists, is the value the same? - EXPECT_EQ(corresponding->second, actual->second); + EXPECT_EQ(corresponding->second, actual.second); } } diff --git a/src/lib/dhcp/classify.cc b/src/lib/dhcp/classify.cc index 9f1461604e..2ff5a08084 100644 --- a/src/lib/dhcp/classify.cc +++ b/src/lib/dhcp/classify.cc @@ -54,11 +54,14 @@ ClientClasses::contains(const ClientClass& x) const { std::string ClientClasses::toText(const std::string& separator) const { std::stringstream s; - for (const_iterator class_it = cbegin(); class_it != cend(); ++class_it) { - if (class_it != cbegin()) { + bool first = true; + for (auto const& class_it : *this) { + if (!first) { s << separator; + } else { + first = false; } - s << *class_it; + s << class_it; } return (s.str()); } @@ -66,7 +69,7 @@ ClientClasses::toText(const std::string& separator) const { ElementPtr ClientClasses::toElement() const { ElementPtr result(Element::createList()); - for (const ClientClass& c : container_) { + for (auto const& c : container_) { result->add(Element::create(c)); } return (result); diff --git a/src/lib/dhcp/duid.h b/src/lib/dhcp/duid.h index 6f72cccb3a..a9f9172d4f 100644 --- a/src/lib/dhcp/duid.h +++ b/src/lib/dhcp/duid.h @@ -85,7 +85,7 @@ public: std::stringstream tmp; tmp << std::hex; bool delim = false; - for (auto const data : data_) { + for (auto const& data : data_) { if (delim) { tmp << ":"; } diff --git a/src/lib/dhcp/duid_factory.cc b/src/lib/dhcp/duid_factory.cc index 6303e9ea1f..d5019736f0 100644 --- a/src/lib/dhcp/duid_factory.cc +++ b/src/lib/dhcp/duid_factory.cc @@ -244,7 +244,7 @@ void DUIDFactory::createLinkLayerId(std::vector& identifier, uint16_t& htype) const { // Let's find suitable interface. - for (const IfacePtr& iface : IfaceMgr::instance().getIfaces()) { + for (auto const& iface : IfaceMgr::instance().getIfaces()) { // All the following checks could be merged into one multi-condition // statement, but let's keep them separated as perhaps one day // we will grow knobs to selectively turn them on or off. Also, diff --git a/src/lib/dhcp/hwaddr.cc b/src/lib/dhcp/hwaddr.cc index 9416f2d412..6f26e08164 100644 --- a/src/lib/dhcp/hwaddr.cc +++ b/src/lib/dhcp/hwaddr.cc @@ -55,12 +55,11 @@ std::string HWAddr::toText(bool include_htype) const { } tmp << std::hex; bool delim = false; - for (std::vector::const_iterator it = hwaddr_.begin(); - it != hwaddr_.end(); ++it) { + for (auto const& it : hwaddr_) { if (delim) { tmp << ":"; } - tmp << std::setw(2) << std::setfill('0') << static_cast(*it); + tmp << std::setw(2) << std::setfill('0') << static_cast(it); delim = true; } return (tmp.str()); diff --git a/src/lib/dhcp/iface_mgr_bsd.cc b/src/lib/dhcp/iface_mgr_bsd.cc index 4ae0f0e85b..e74f96080f 100644 --- a/src/lib/dhcp/iface_mgr_bsd.cc +++ b/src/lib/dhcp/iface_mgr_bsd.cc @@ -114,14 +114,13 @@ IfaceMgr::detectIfaces(bool update_only) { freeifaddrs(iflist); // Interfaces registering - for (IfaceLst::const_iterator iface_iter = ifaces.begin(); - iface_iter != ifaces.end(); ++iface_iter) { + for (auto const& iface_iter : ifaces) { IfacePtr iface; if (update_only) { - iface = getIface(iface_iter->first); + iface = getIface(iface_iter.first); } if (!iface) { - addInterface(iface_iter->second); + addInterface(iface_iter.second); } } } diff --git a/src/lib/dhcp/iface_mgr_linux.cc b/src/lib/dhcp/iface_mgr_linux.cc index 1fb2aaf712..55092388ff 100644 --- a/src/lib/dhcp/iface_mgr_linux.cc +++ b/src/lib/dhcp/iface_mgr_linux.cc @@ -279,9 +279,8 @@ void Netlink::ipaddrs_get(Iface& iface, NetlinkMessages& addr_info) { uint8_t addr[V6ADDRESS_LEN]; RTattribPtrs rta_tb; - for (NetlinkMessages::const_iterator msg = addr_info.begin(); - msg != addr_info.end(); ++msg) { - ifaddrmsg* ifa = static_cast(NLMSG_DATA(*msg)); + for (auto const& msg : addr_info) { + ifaddrmsg* ifa = static_cast(NLMSG_DATA(msg)); // These are not the addresses you are looking for if (ifa->ifa_index != iface.getIndex()) { @@ -290,7 +289,7 @@ void Netlink::ipaddrs_get(Iface& iface, NetlinkMessages& addr_info) { if ((ifa->ifa_family == AF_INET6) || (ifa->ifa_family == AF_INET)) { std::fill(rta_tb.begin(), rta_tb.end(), static_cast(NULL)); - parse_rtattr(rta_tb, IFA_RTA(ifa), (*msg)->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa))); + parse_rtattr(rta_tb, IFA_RTA(ifa), msg->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa))); if (!rta_tb[IFA_LOCAL]) { rta_tb[IFA_LOCAL] = rta_tb[IFA_ADDRESS]; } @@ -396,8 +395,8 @@ void Netlink::rtnl_process_reply(NetlinkMessages& info) { /// @param messages Set of messages to be freed. void Netlink::release_list(NetlinkMessages& messages) { // let's free local copies of stored messages - for (NetlinkMessages::iterator msg = messages.begin(); msg != messages.end(); ++msg) { - delete[] (*msg); + for (auto const& msg : messages) { + delete[] msg; } // and get rid of the message pointers as well @@ -462,11 +461,10 @@ void IfaceMgr::detectIfaces(bool update_only) { nl.rtnl_process_reply(addr_info); // Now build list with interface names - for (Netlink::NetlinkMessages::iterator msg = link_info.begin(); - msg != link_info.end(); ++msg) { + for (auto const& msg : link_info) { // Required to display information about interface - struct ifinfomsg* interface_info = static_cast(NLMSG_DATA(*msg)); - int len = (*msg)->nlmsg_len; + struct ifinfomsg* interface_info = static_cast(NLMSG_DATA(msg)); + int len = msg->nlmsg_len; len -= NLMSG_LENGTH(sizeof(*interface_info)); nl.parse_rtattr(attribs_table, IFLA_RTA(interface_info), len); diff --git a/src/lib/dhcp/iface_mgr_sun.cc b/src/lib/dhcp/iface_mgr_sun.cc index f8ab65cb63..94dcbd7503 100644 --- a/src/lib/dhcp/iface_mgr_sun.cc +++ b/src/lib/dhcp/iface_mgr_sun.cc @@ -114,14 +114,13 @@ IfaceMgr::detectIfaces(bool update_only) { freeifaddrs(iflist); // Interfaces registering - for (IfaceLst::const_iterator iface_iter = ifaces.begin(); - iface_iter != ifaces.end(); ++iface_iter) { + for (auto const& iface_iter : ifaces) { IfacePtr iface; if (update_only) { - iface = getIface(iface_iter->first); + iface = getIface(iface_iter.first); } if (!iface) { - addInterface(iface_iter->second); + addInterface(iface_iter.second); } } } diff --git a/src/lib/dhcp/libdhcp++.cc b/src/lib/dhcp/libdhcp++.cc index 760765bc45..db2347633d 100644 --- a/src/lib/dhcp/libdhcp++.cc +++ b/src/lib/dhcp/libdhcp++.cc @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -694,9 +695,9 @@ extendVivco(OptionCollection& options) { typedef vector TuplesCollection; map vendors_tuples; auto const& range = options.equal_range(DHO_VIVCO_SUBOPTIONS); - for (auto it = range.first; it != range.second; ++it) { + BOOST_FOREACH(auto const& it, range) { uint32_t offset = 0; - auto const& data = it->second->getData(); + auto const& data = it.second->getData(); size_t size; while ((size = data.size() - offset) != 0) { if (size < sizeof(uint32_t)) { @@ -753,9 +754,9 @@ void extendVivso(OptionCollection& options) { map vendors_data; auto const& range = options.equal_range(DHO_VIVSO_SUBOPTIONS); - for (auto it = range.first; it != range.second; ++it) { + BOOST_FOREACH(auto const& it, range) { uint32_t offset = 0; - auto const& data = it->second->getData(); + auto const& data = it.second->getData(); size_t size; while ((size = data.size() - offset) != 0) { if (size < sizeof(uint32_t)) { diff --git a/src/lib/dhcp/option4_addrlst.cc b/src/lib/dhcp/option4_addrlst.cc index 33e00495a7..23717f1766 100644 --- a/src/lib/dhcp/option4_addrlst.cc +++ b/src/lib/dhcp/option4_addrlst.cc @@ -93,9 +93,8 @@ void Option4AddrLst::setAddresses(const AddressContainer& addrs) { // Do not copy it as a whole. addAddress() does sanity checks. // i.e. throw if someone tries to set IPv6 address. addrs_.clear(); - for (AddressContainer::const_iterator addr = addrs.begin(); - addr != addrs.end(); ++addr) { - addAddress(*addr); + for (auto const& addr : addrs) { + addAddress(addr); } } @@ -116,9 +115,8 @@ std::string Option4AddrLst::toText(int indent) const { std::stringstream output; output << headerToText(indent) << ":"; - for (AddressContainer::const_iterator addr = addrs_.begin(); - addr != addrs_.end(); ++addr) { - output << " " << (*addr); + for (auto const& addr : addrs_) { + output << " " << addr; } return (output.str()); diff --git a/src/lib/dhcp/option6_addrlst.cc b/src/lib/dhcp/option6_addrlst.cc index a219d7c59b..980097b2ff 100644 --- a/src/lib/dhcp/option6_addrlst.cc +++ b/src/lib/dhcp/option6_addrlst.cc @@ -68,15 +68,14 @@ void Option6AddrLst::pack(isc::util::OutputBuffer& buf, bool) const { // len field contains length without 4-byte option header buf.writeUint16(len() - getHeaderLen()); - for (AddressContainer::const_iterator addr=addrs_.begin(); - addr!=addrs_.end(); ++addr) { - if (!addr->isV6()) { - isc_throw(isc::BadValue, addr->toText() + for (auto const& addr : addrs_) { + if (!addr.isV6()) { + isc_throw(isc::BadValue, addr.toText() << " is not an IPv6 address"); } // If an address is IPv6 address it should have assumed // length of V6ADDRESS_LEN. - buf.writeData(&addr->toBytes()[0], V6ADDRESS_LEN); + buf.writeData(&addr.toBytes()[0], V6ADDRESS_LEN); } } @@ -97,9 +96,8 @@ std::string Option6AddrLst::toText(int indent) const { stringstream output; output << headerToText(indent) << ":"; - for (AddressContainer::const_iterator addr = addrs_.begin(); - addr != addrs_.end(); ++addr) { - output << " " << *addr; + for (auto const& addr : addrs_) { + output << " " << addr; } return (output.str()); } diff --git a/src/lib/dhcp/option6_ia.cc b/src/lib/dhcp/option6_ia.cc index 2b414903da..831834525b 100644 --- a/src/lib/dhcp/option6_ia.cc +++ b/src/lib/dhcp/option6_ia.cc @@ -108,10 +108,8 @@ uint16_t Option6IA::len() const { OPTION6_IA_LEN /* option content (12) */; // length of all suboptions - for (OptionCollection::const_iterator it = options_.begin(); - it != options_.end(); - ++it) { - length += (*it).second->len(); + for (auto const& it : options_) { + length += it.second->len(); } return (length); } diff --git a/src/lib/dhcp/option6_iaaddr.cc b/src/lib/dhcp/option6_iaaddr.cc index 1737cd1f79..9112e29f73 100644 --- a/src/lib/dhcp/option6_iaaddr.cc +++ b/src/lib/dhcp/option6_iaaddr.cc @@ -105,10 +105,8 @@ uint16_t Option6IAAddr::len() const { // length of all suboptions // TODO implement: // protected: unsigned short Option::lenHelper(int header_size); - for (OptionCollection::const_iterator it = options_.begin(); - it != options_.end(); - ++it) { - length += (*it).second->len(); + for (auto const& it : options_) { + length += it.second->len(); } return (length); } diff --git a/src/lib/dhcp/option6_iaprefix.cc b/src/lib/dhcp/option6_iaprefix.cc index fcca8b0594..7a5e2ab5f1 100644 --- a/src/lib/dhcp/option6_iaprefix.cc +++ b/src/lib/dhcp/option6_iaprefix.cc @@ -112,9 +112,8 @@ uint16_t Option6IAPrefix::len() const { uint16_t length = OPTION6_HDR_LEN + OPTION6_IAPREFIX_LEN; // length of all suboptions - for (OptionCollection::const_iterator it = options_.begin(); - it != options_.end(); ++it) { - length += (*it).second->len(); + for (auto const& it : options_) { + length += it.second->len(); } return (length); } diff --git a/src/lib/dhcp/option_classless_static_route.cc b/src/lib/dhcp/option_classless_static_route.cc index 6b22b7ca2a..2f2da8229a 100644 --- a/src/lib/dhcp/option_classless_static_route.cc +++ b/src/lib/dhcp/option_classless_static_route.cc @@ -34,7 +34,7 @@ void OptionClasslessStaticRoute::pack(isc::util::OutputBuffer& buf, bool check) const { // Header = option code and length. packHeader(buf, check); - for (const auto& route : static_routes_) { + for (auto const& route : static_routes_) { // 1-5 octets of destination descriptor auto dest = encodeDestinationDescriptor(route); buf.writeData(&dest[0], dest.size()); @@ -76,7 +76,7 @@ OptionClasslessStaticRoute::toText(int indent) const { stream << in << "type=" << type_ << "(CLASSLESS_STATIC_ROUTE), " << "len=" << (len() - getHeaderLen()); int i = 0; - for (const auto& route : static_routes_) { + for (auto const& route : static_routes_) { stream << ", Route " << ++i << " (subnet " << std::get<0>(route).toText() << "/" << static_cast(std::get<1>(route)) << ", router IP " << std::get<2>(route).toText() << ")"; @@ -119,7 +119,7 @@ OptionClasslessStaticRoute::calcSignificantOctets(const uint8_t& mask_width) { void OptionClasslessStaticRoute::calcDataLen() { uint16_t len = 0; - for (const auto& route : static_routes_) { + for (auto const& route : static_routes_) { // 1-5 octets of destination descriptor len += calcSignificantOctets(std::get<1>(route)) + 1; // IP address of the router @@ -200,7 +200,7 @@ void OptionClasslessStaticRoute::parseConfigData(const std::string& config_txt) { // this option allows more than one static route, so let's separate them using comma std::vector tokens = str::tokens(config_txt, std::string(",")); - for (const auto& route_str : tokens) { + for (auto const& route_str : tokens) { std::vector parts = str::tokens(str::trim(route_str), std::string("-")); if (parts.size() != 2) { isc_throw(BadValue, "DHCPv4 OptionClasslessStaticRoute " diff --git a/src/lib/dhcp/option_custom.cc b/src/lib/dhcp/option_custom.cc index 1da78fddb0..fdc8f1936d 100644 --- a/src/lib/dhcp/option_custom.cc +++ b/src/lib/dhcp/option_custom.cc @@ -180,10 +180,9 @@ OptionCustom::createBuffers() { const OptionDefinition::RecordFieldsCollection fields = definition_.getRecordFields(); - for (OptionDefinition::RecordFieldsConstIter field = fields.begin(); - field != fields.end(); ++field) { + for (auto const& field : fields) { OptionBuffer buf; - createBuffer(buf, *field); + createBuffer(buf, field); // We have the buffer with default value prepared so we // add it to the set of buffers. buffers.push_back(buf); @@ -291,9 +290,8 @@ OptionCustom::createBuffers(const OptionBuffer& data_buf) { definition_.getRecordFields(); // Go over all data fields within a record. - for (OptionDefinition::RecordFieldsConstIter field = fields.begin(); - field != fields.end(); ++field) { - size_t data_size = bufferLength(*field, false, + for (auto const& field : fields) { + size_t data_size = bufferLength(field, false, data, data_buf.end()); // Our data field requires that there is a certain chunk of @@ -458,13 +456,12 @@ OptionCustom::pack(isc::util::OutputBuffer& buf, bool check) const { packHeader(buf, check); // Write data from buffers. - for (std::vector::const_iterator it = buffers_.begin(); - it != buffers_.end(); ++it) { + for (auto const& it : buffers_) { // In theory the createBuffers function should have taken // care that there are no empty buffers added to the // collection but it is almost always good to make sure. - if (!it->empty()) { - buf.writeData(&(*it)[0], it->size()); + if (!it.empty()) { + buf.writeData(&it[0], it.size()); } } @@ -662,16 +659,13 @@ OptionCustom::len() const { size_t length = getHeaderLen(); // ... lengths of all buffers that hold option data ... - for (std::vector::const_iterator buf = buffers_.begin(); - buf != buffers_.end(); ++buf) { - length += buf->size(); + for (auto const& buf : buffers_) { + length += buf.size(); } // ... and lengths of all suboptions - for (OptionCollection::const_iterator it = options_.begin(); - it != options_.end(); - ++it) { - length += (*it).second->len(); + for (auto const& it : options_) { + length += it.second->len(); } return (static_cast(length)); @@ -699,10 +693,10 @@ std::string OptionCustom::toText(int indent) const { // For record types we iterate over fields defined in // option definition and match the appropriate buffer // with them. - for (OptionDefinition::RecordFieldsConstIter field = fields.begin(); - field != fields.end(); ++field) { - output << " " << dataFieldToText(*field, std::distance(fields.begin(), - field)); + size_t j = 0; + for (auto const& field : fields) { + output << " " << dataFieldToText(field, j); + j++; } // If the last record field is an array iterate on extra buffers diff --git a/src/lib/dhcp/option_int.h b/src/lib/dhcp/option_int.h index 10a4cc6d32..13d5db6076 100644 --- a/src/lib/dhcp/option_int.h +++ b/src/lib/dhcp/option_int.h @@ -201,10 +201,8 @@ public: // The data length is equal to size of T. length += sizeof(T);; // length of all suboptions - for (OptionCollection::const_iterator it = options_.begin(); - it != options_.end(); - ++it) { - length += (*it).second->len(); + for (auto const& it : options_) { + length += it.second->len(); } return (length); } diff --git a/src/lib/dhcp/option_int_array.h b/src/lib/dhcp/option_int_array.h index 70803d7cec..2b9bd68f45 100644 --- a/src/lib/dhcp/option_int_array.h +++ b/src/lib/dhcp/option_int_array.h @@ -244,10 +244,8 @@ public: uint16_t length = (getUniverse() == Option::V4) ? OPTION4_HDR_LEN : OPTION6_HDR_LEN; length += values_.size() * sizeof(T); // length of all suboptions - for (OptionCollection::const_iterator it = options_.begin(); - it != options_.end(); - ++it) { - length += (*it).second->len(); + for (auto const& it : options_) { + length += it.second->len(); } return (length); } @@ -263,18 +261,17 @@ public: output << headerToText(indent) << ":"; std::string data_type = OptionDataTypeUtil::getDataTypeName(OptionDataTypeTraits::type); - for (typename std::vector::const_iterator value = values_.begin(); - value != values_.end(); ++value) { + for (auto const& value : values_) { output << " "; // For 1 byte long data types we need to cast to the integer // because they are usually implemented as "char" types, in // which case the character rather than number would be printed. if (OptionDataTypeTraits::len == 1) { - output << static_cast(*value); + output << static_cast(value); } else { - output << *value; + output << value; } // Append data type. diff --git a/src/lib/dhcp/option_opaque_data_tuples.cc b/src/lib/dhcp/option_opaque_data_tuples.cc index ea8fa7c91a..ad63b13eb5 100644 --- a/src/lib/dhcp/option_opaque_data_tuples.cc +++ b/src/lib/dhcp/option_opaque_data_tuples.cc @@ -44,9 +44,8 @@ void OptionOpaqueDataTuples::pack(isc::util::OutputBuffer& buf, bool check) const { packHeader(buf, check); - for (TuplesCollection::const_iterator it = tuples_.begin(); - it != tuples_.end(); ++it) { - it->pack(buf); + for (auto const& it : tuples_) { + it.pack(buf); } // That's it. We don't pack any sub-options here, because this option // must not contain sub-options. @@ -113,9 +112,8 @@ bool OptionOpaqueDataTuples::hasTuple(const std::string& tuple_str) const { // Iterate over existing tuples (there shouldn't be many of them), // and try to match the searched one. - for (TuplesCollection::const_iterator it = tuples_.begin(); - it != tuples_.end(); ++it) { - if (*it == tuple_str) { + for (auto const& it : tuples_) { + if (it == tuple_str) { return (true); } } @@ -127,9 +125,8 @@ OptionOpaqueDataTuples::len() const { // The option starts with the header. uint16_t length = getHeaderLen(); // Now iterate over existing tuples and add their size. - for (TuplesCollection::const_iterator it = tuples_.begin(); - it != tuples_.end(); ++it) { - length += it->getTotalLength(); + for (auto const& it : tuples_) { + length += it.getTotalLength(); } return (length); diff --git a/src/lib/dhcp/option_vendor_class.cc b/src/lib/dhcp/option_vendor_class.cc index df4cf1cb34..70d0976df4 100644 --- a/src/lib/dhcp/option_vendor_class.cc +++ b/src/lib/dhcp/option_vendor_class.cc @@ -40,14 +40,15 @@ OptionVendorClass::pack(isc::util::OutputBuffer& buf, bool check) const { buf.writeUint32(getVendorId()); - for (TuplesCollection::const_iterator it = tuples_.begin(); - it != tuples_.end(); ++it) { + bool first = true; + for (auto const& it : tuples_) { // For DHCPv4 V-I Vendor Class option, there is enterprise id before // every tuple. - if ((getUniverse() == V4) && (it != tuples_.begin())) { + if ((getUniverse() == V4) && (!first)) { buf.writeUint32(getVendorId()); } - it->pack(buf); + first = false; + it.pack(buf); } // That's it. We don't pack any sub-options here, because this option @@ -146,9 +147,8 @@ bool OptionVendorClass::hasTuple(const std::string& tuple_str) const { // Iterate over existing tuples (there shouldn't be many of them), // and try to match the searched one. - for (TuplesCollection::const_iterator it = tuples_.begin(); - it != tuples_.end(); ++it) { - if (*it == tuple_str) { + for (auto const& it : tuples_) { + if (it == tuple_str) { return (true); } } @@ -161,14 +161,15 @@ OptionVendorClass::len() const { // The option starts with the header and enterprise id. uint16_t length = getHeaderLen() + sizeof(uint32_t); // Now iterate over existing tuples and add their size. - for (TuplesCollection::const_iterator it = tuples_.begin(); - it != tuples_.end(); ++it) { + bool first = true; + for (auto const& it : tuples_) { // For DHCPv4 V-I Vendor Class option, there is enterprise id before // every tuple. - if ((getUniverse() == V4) && (it != tuples_.begin())) { + if ((getUniverse() == V4) && (!first)) { length += sizeof(uint32_t); } - length += it->getTotalLength(); + first = false; + length += it.getTotalLength(); } diff --git a/src/lib/dhcp/pkt.cc b/src/lib/dhcp/pkt.cc index 2484d974ff..abfd7b4632 100644 --- a/src/lib/dhcp/pkt.cc +++ b/src/lib/dhcp/pkt.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace isc { @@ -90,10 +91,9 @@ Pkt::getOptions(const uint16_t opt_type) { // matching options, copy them and replace the original ones with new // instances. if (copy_retrieved_options_) { - for (OptionCollection::iterator opt_it = range.first; - opt_it != range.second; ++opt_it) { - OptionPtr option_copy = opt_it->second->clone(); - opt_it->second = option_copy; + BOOST_FOREACH(auto& opt_it, range) { + OptionPtr option_copy = opt_it.second->clone(); + opt_it.second = option_copy; } } // Finally, return updated options. This can also be empty in some cases. diff --git a/src/lib/dhcp/pkt6.cc b/src/lib/dhcp/pkt6.cc index aba14c691e..a2b93cf374 100644 --- a/src/lib/dhcp/pkt6.cc +++ b/src/lib/dhcp/pkt6.cc @@ -18,7 +18,7 @@ #include #include #include - +#include #include #include #include @@ -227,10 +227,9 @@ Pkt6::getAllRelayOptions(const uint16_t option_code, // matching options, copy them and replace the original ones with new // instances. if (copy_retrieved_options_) { - for (OptionCollection::iterator opt_it = range.first; - opt_it != range.second; ++opt_it) { - OptionPtr option_copy = opt_it->second->clone(); - opt_it->second = option_copy; + BOOST_FOREACH(auto& opt_it, range) { + OptionPtr option_copy = opt_it.second->clone(); + opt_it.second = option_copy; } } opts.insert(range.first, range.second); @@ -312,10 +311,9 @@ Pkt6::getRelayOptions(const uint16_t opt_type, // matching options, copy them and replace the original ones with new // instances. if (copy_retrieved_options_) { - for (OptionCollection::iterator opt_it = range.first; - opt_it != range.second; ++opt_it) { - OptionPtr option_copy = opt_it->second->clone(); - opt_it->second = option_copy; + BOOST_FOREACH(auto& opt_it, range) { + OptionPtr option_copy = opt_it.second->clone(); + opt_it.second = option_copy; } } // Finally, return updated options. This can also be empty in some cases. @@ -406,15 +404,14 @@ Pkt6::packUDP() { calculateRelaySizes(); // Now for each relay, we need to... - for (vector::iterator relay = relay_info_.begin(); - relay != relay_info_.end(); ++relay) { + for (auto const& relay : relay_info_) { // build relay-forw/relay-repl header (see RFC 8415, section 9) - buffer_out_.writeUint8(relay->msg_type_); - buffer_out_.writeUint8(relay->hop_count_); - buffer_out_.writeData(&(relay->linkaddr_.toBytes()[0]), + buffer_out_.writeUint8(relay.msg_type_); + buffer_out_.writeUint8(relay.hop_count_); + buffer_out_.writeData(&(relay.linkaddr_.toBytes()[0]), isc::asiolink::V6ADDRESS_LEN); - buffer_out_.writeData(&relay->peeraddr_.toBytes()[0], + buffer_out_.writeData(&relay.peeraddr_.toBytes()[0], isc::asiolink::V6ADDRESS_LEN); // store every option in this relay scope. Usually that will be @@ -422,7 +419,7 @@ Pkt6::packUDP() { // present here as well (vendor-opts for Cable modems, // subscriber-id, remote-id, options echoed back from Echo // Request Option, etc.) - for (auto const& opt : relay->options_) { + for (auto const& opt : relay.options_) { (opt.second)->pack(buffer_out_); } @@ -431,7 +428,7 @@ Pkt6::packUDP() { // or outside the loop (if there are no more relays and the // payload is a direct message) buffer_out_.writeUint16(D6O_RELAY_MSG); - buffer_out_.writeUint16(relay->relay_msg_len_); + buffer_out_.writeUint16(relay.relay_msg_len_); } } diff --git a/src/lib/dhcp/tests/classify_unittest.cc b/src/lib/dhcp/tests/classify_unittest.cc index abc73dd025..c0602d27e5 100644 --- a/src/lib/dhcp/tests/classify_unittest.cc +++ b/src/lib/dhcp/tests/classify_unittest.cc @@ -86,19 +86,18 @@ TEST(ClassifyTest, ClientClassesIterator) { bool seenbeta = false; bool seengamma = false; bool seendelta = false; - for (ClientClasses::const_iterator it = classes.cbegin(); - it != classes.cend(); ++it) { + for (auto const& it : classes) { ++count; - if (*it == "alpha") { + if (it == "alpha") { seenalpha = true; - } else if (*it == "beta") { + } else if (it == "beta") { seenbeta = true; - } else if (*it == "gamma") { + } else if (it == "gamma") { seengamma = true; - } else if (*it == "delta") { + } else if (it == "delta") { seendelta = true; } else { - ADD_FAILURE() << "Got unexpected " << *it; + ADD_FAILURE() << "Got unexpected " << it; } } EXPECT_EQ(count, classes.size()); diff --git a/src/lib/dhcp/tests/iface_mgr_unittest.cc b/src/lib/dhcp/tests/iface_mgr_unittest.cc index a0a7a28f01..3271b9b68b 100644 --- a/src/lib/dhcp/tests/iface_mgr_unittest.cc +++ b/src/lib/dhcp/tests/iface_mgr_unittest.cc @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -167,11 +166,10 @@ public: // Check if there is any other socket bound to the specified address // and port on this interface. const Iface::SocketCollection& sockets = iface.getSockets(); - for (Iface::SocketCollection::const_iterator socket = sockets.begin(); - socket != sockets.end(); ++socket) { - if (((socket->addr_ == addr) || - ((socket->addr_ == IOAddress("::")) && join_multicast)) && - socket->port_ == port) { + for (auto const& socket : sockets) { + if (((socket.addr_ == addr) || + ((socket.addr_ == IOAddress("::")) && join_multicast)) && + socket.port_ == port) { isc_throw(SocketConfigError, "test socket bind error"); } } @@ -308,14 +306,13 @@ public: return (false); } const Iface::SocketCollection& sockets = iface->getSockets(); - for (Iface::SocketCollection::const_iterator sock = sockets.begin(); - sock != sockets.end(); ++sock) { - if (sock->addr_ == IOAddress(addr)) { + for (auto const& sock : sockets) { + if (sock.addr_ == IOAddress(addr)) { return (true); - } else if ((sock->addr_ == IOAddress("::")) && + } else if ((sock.addr_ == IOAddress("::")) && (IOAddress(addr).isV6LinkLocal())) { - BOOST_FOREACH(Iface::Address a, iface->getAddresses()) { + for (auto const& a : iface->getAddresses()) { if (a.get() == IOAddress(addr)) { return (true); } @@ -336,7 +333,7 @@ public: const bool up, const bool running, const bool inactive4, const bool inactive6) { - for (const IfacePtr& iface : ifaces_) { + for (auto const& iface : ifaces_) { if (iface->getName() == name) { iface->flag_loopback_ = loopback; iface->flag_up_ = up; @@ -410,10 +407,9 @@ public: // Loop through sockets and try to find the ones which match the // specified type. int sockets_count = 0; - for (Iface::SocketCollection::const_iterator sock = sockets.begin(); - sock != sockets.end(); ++sock) { + for (auto const& sock : sockets) { // Match found, increase the counter. - if (sock->family_ == family) { + if (sock.family_ == family) { ++sockets_count; } } @@ -432,10 +428,9 @@ public: const isc::dhcp::SocketInfo* getSocketByAddr(const isc::dhcp::Iface::SocketCollection& sockets, const IOAddress& addr) { - for (isc::dhcp::Iface::SocketCollection::const_iterator s = - sockets.begin(); s != sockets.end(); ++s) { - if (s->addr_ == addr) { - return (&(*s)); + for (auto const& s : sockets) { + if (s.addr_ == addr) { + return (&s); } } return (NULL); @@ -1121,7 +1116,7 @@ TEST_F(IfaceMgrTest, getIface) { cout << "There are " << ifacemgr->getIfacesLst().size() << " interfaces." << endl; - for (const IfacePtr& iface : ifacemgr->getIfacesLst()) { + for (auto const& iface : ifacemgr->getIfacesLst()) { cout << " " << iface->getFullName() << endl; } @@ -2894,7 +2889,7 @@ checkIfAddrs(const Iface & iface, struct ifaddrs *& ifptr) { IOAddress addrv4 = IOAddress::fromBytes(AF_INET, p); - BOOST_FOREACH(Iface::Address a, iface.getAddresses()) { + for (auto const& a :iface.getAddresses()) { if(a.get().isV4() && (a.get()) == addrv4) { return (true); } @@ -2909,7 +2904,7 @@ checkIfAddrs(const Iface & iface, struct ifaddrs *& ifptr) { IOAddress addrv6 = IOAddress::fromBytes(AF_INET6, p); - BOOST_FOREACH(Iface::Address a, iface.getAddresses()) { + for (auto const& a : iface.getAddresses()) { if (a.get().isV6() && (a.get() == addrv6)) { return (true); } diff --git a/src/lib/dhcp/tests/libdhcp++_unittest.cc b/src/lib/dhcp/tests/libdhcp++_unittest.cc index 3c6262c063..c9d0d32207 100644 --- a/src/lib/dhcp/tests/libdhcp++_unittest.cc +++ b/src/lib/dhcp/tests/libdhcp++_unittest.cc @@ -1603,7 +1603,8 @@ TEST_F(LibDhcpTest, fuseLongOptionWithLongSuboption) { ASSERT_EQ(1, col.size()); ASSERT_EQ(1, col.begin()->second->getOptions().size()); uint8_t index = 0; - for (auto const& option : col.begin()->second->getOptions()) { + auto const& options = col.begin()->second->getOptions(); + for (auto const& option : options) { for (auto const& value : option.second->getData()) { ASSERT_EQ(index, value); index++; @@ -3217,12 +3218,11 @@ TEST_F(LibDhcpTest, getOptionDefByName6) { // Get all definitions. const OptionDefContainerPtr defs = LibDHCP::getOptionDefs(DHCP6_OPTION_SPACE); // For each definition try to find it using option name. - for (OptionDefContainer::const_iterator def = defs->begin(); - def != defs->end(); ++def) { + for (auto const& def : *defs) { OptionDefinitionPtr def_by_name = - LibDHCP::getOptionDef(DHCP6_OPTION_SPACE, (*def)->getName()); + LibDHCP::getOptionDef(DHCP6_OPTION_SPACE, def->getName()); ASSERT_TRUE(def_by_name); - ASSERT_TRUE(**def == *def_by_name); + ASSERT_TRUE(*def == *def_by_name); } } @@ -3232,12 +3232,11 @@ TEST_F(LibDhcpTest, getOptionDefByName4) { // Get all definitions. const OptionDefContainerPtr defs = LibDHCP::getOptionDefs(DHCP4_OPTION_SPACE); // For each definition try to find it using option name. - for (OptionDefContainer::const_iterator def = defs->begin(); - def != defs->end(); ++def) { + for (auto const& def : *defs) { OptionDefinitionPtr def_by_name = - LibDHCP::getOptionDef(DHCP4_OPTION_SPACE, (*def)->getName()); + LibDHCP::getOptionDef(DHCP4_OPTION_SPACE, def->getName()); ASSERT_TRUE(def_by_name); - ASSERT_TRUE(**def == *def_by_name); + ASSERT_TRUE(*def == *def_by_name); } } @@ -3247,13 +3246,12 @@ TEST_F(LibDhcpTest, getVendorOptionDefByName6) { const OptionDefContainerPtr& defs = LibDHCP::getVendorOptionDefs(Option::V6, VENDOR_ID_CABLE_LABS); ASSERT_TRUE(defs); - for (OptionDefContainer::const_iterator def = defs->begin(); - def != defs->end(); ++def) { + for (auto const& def : *defs) { OptionDefinitionPtr def_by_name = LibDHCP::getVendorOptionDef(Option::V6, VENDOR_ID_CABLE_LABS, - (*def)->getName()); + def->getName()); ASSERT_TRUE(def_by_name); - ASSERT_TRUE(**def == *def_by_name); + ASSERT_TRUE(*def == *def_by_name); } } @@ -3263,13 +3261,12 @@ TEST_F(LibDhcpTest, getVendorOptionDefByName4) { const OptionDefContainerPtr& defs = LibDHCP::getVendorOptionDefs(Option::V4, VENDOR_ID_CABLE_LABS); ASSERT_TRUE(defs); - for (OptionDefContainer::const_iterator def = defs->begin(); - def != defs->end(); ++def) { + for (auto const& def : *defs) { OptionDefinitionPtr def_by_name = LibDHCP::getVendorOptionDef(Option::V4, VENDOR_ID_CABLE_LABS, - (*def)->getName()); + def->getName()); ASSERT_TRUE(def_by_name); - ASSERT_TRUE(**def == *def_by_name); + ASSERT_TRUE(*def == *def_by_name); } } diff --git a/src/lib/dhcp/tests/option_copy_unittest.cc b/src/lib/dhcp/tests/option_copy_unittest.cc index 9d7a3850da..0adfdc17a9 100644 --- a/src/lib/dhcp/tests/option_copy_unittest.cc +++ b/src/lib/dhcp/tests/option_copy_unittest.cc @@ -128,17 +128,17 @@ void testCopyAssign(const OpType& op_type, // Iterate over source options. OptionCollection::const_iterator it_copy = option_copy_subs.begin(); - for (OptionCollection::const_iterator it = option_subs.begin(); - it != option_subs.end(); ++it, ++it_copy) { + for (auto const& it : option_subs) { // The option codes should be equal in both containers. - EXPECT_EQ(it->first, it_copy->first); + EXPECT_EQ(it.first, it_copy->first); // Pointers must be unequal because the expectation is that options // are copied, rather than pointers. - EXPECT_NE(it->second, it_copy->second); - Option* opt_ptr = it->second.get(); + EXPECT_NE(it.second, it_copy->second); + Option* opt_ptr = it.second.get(); Option* opt_copy_ptr = it_copy->second.get(); // The C++ types must match. EXPECT_TRUE(typeid(*opt_ptr) == typeid(*opt_copy_ptr)); + ++it_copy; } // Final check is to compare their binary representations. diff --git a/src/lib/dhcp/tests/option_definition_unittest.cc b/src/lib/dhcp/tests/option_definition_unittest.cc index f1f51add06..0d01b13700 100644 --- a/src/lib/dhcp/tests/option_definition_unittest.cc +++ b/src/lib/dhcp/tests/option_definition_unittest.cc @@ -551,9 +551,8 @@ TEST_F(OptionDefinitionTest, ipv6AddressArrayTokenized) { // Create a vector of strings representing addresses given above. std::vector addrs_str; - for (std::vector::const_iterator it = addrs.begin(); - it != addrs.end(); ++it) { - addrs_str.push_back(it->toText()); + for (auto const& it : addrs) { + addrs_str.push_back(it.toText()); } // Create DHCPv6 option using the list of IPv6 addresses given in the @@ -650,9 +649,8 @@ TEST_F(OptionDefinitionTest, ipv4AddressArrayTokenized) { // Create a vector of strings representing addresses given above. std::vector addrs_str; - for (std::vector::const_iterator it = addrs.begin(); - it != addrs.end(); ++it) { - addrs_str.push_back(it->toText()); + for (auto const& it : addrs) { + addrs_str.push_back(it.toText()); } // Create DHCPv4 option using the list of IPv4 addresses given in the diff --git a/src/lib/dhcp/tests/pkt4_unittest.cc b/src/lib/dhcp/tests/pkt4_unittest.cc index 8232b8f387..87d97f2a58 100644 --- a/src/lib/dhcp/tests/pkt4_unittest.cc +++ b/src/lib/dhcp/tests/pkt4_unittest.cc @@ -676,9 +676,8 @@ TEST_F(Pkt4Test, getOptions) { // in the packet. pkt->setCopyRetrievedOptions(false); OptionCollection options_modified = pkt->getOptions(1); - for (OptionCollection::const_iterator opt_it_modified = options_modified.begin(); - opt_it_modified != options_modified.end(); ++opt_it_modified) { - opt_it = std::find(options.begin(), options.end(), *opt_it_modified); + for (auto const& opt_it_modified : options_modified) { + opt_it = std::find(options.begin(), options.end(), opt_it_modified); ASSERT_TRUE(opt_it != options.end()); } diff --git a/src/lib/dhcp/tests/pkt6_unittest.cc b/src/lib/dhcp/tests/pkt6_unittest.cc index caee2d2fdb..40c6c6af27 100644 --- a/src/lib/dhcp/tests/pkt6_unittest.cc +++ b/src/lib/dhcp/tests/pkt6_unittest.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -452,9 +453,8 @@ TEST_F(Pkt6Test, addGetDelOptions) { // Both options must be of type 2 and there must not be // any other type returned - for (OptionCollection::const_iterator x= options.begin(); - x != options.end(); ++x) { - EXPECT_EQ(2, x->second->getType()); + for (auto const& x : options) { + EXPECT_EQ(2, x.second->getType()); } // Try to get a single option. Normally for singular options @@ -552,9 +552,8 @@ TEST_F(Pkt6Test, getOptions) { // that copies of the options were used to replace original options // in the packet. OptionCollection options_modified = pkt.getNonCopiedOptions(1); - for (OptionCollection::const_iterator opt_it_modified = options_modified.begin(); - opt_it_modified != options_modified.end(); ++opt_it_modified) { - opt_it = std::find(options.begin(), options.end(), *opt_it_modified); + for (auto const& opt_it_modified : options_modified) { + opt_it = std::find(options.begin(), options.end(), opt_it_modified); ASSERT_TRUE(opt_it != options.end()); } @@ -1064,9 +1063,10 @@ TEST_F(Pkt6Test, getAnyRelayOption) { // Check reverse order. vector ropts; - for (auto it = opts.rbegin(); it != opts.rend(); ++it) { - ropts.push_back(it->second); + for (auto const& it : boost::adaptors::reverse(opts)) { + ropts.push_back(it.second); } + EXPECT_TRUE(lopts0 == ropts); // We just want option from the first relay (closest to the client) diff --git a/src/lib/dhcp/tests/pkt_filter6_test_utils.cc b/src/lib/dhcp/tests/pkt_filter6_test_utils.cc index 83afc1c1e2..b7142a057b 100644 --- a/src/lib/dhcp/tests/pkt_filter6_test_utils.cc +++ b/src/lib/dhcp/tests/pkt_filter6_test_utils.cc @@ -10,8 +10,6 @@ #include #include -#include - #include #include #include @@ -181,7 +179,7 @@ PktFilter6Stub::openSocket(const Iface& iface, const isc::asiolink::IOAddress& a const uint16_t port, const bool) { // Check if there is any other socket bound to the specified address // and port on this interface. - BOOST_FOREACH(SocketInfo socket, iface.getSockets()) { + for (auto const& socket : iface.getSockets()) { if ((socket.addr_ == addr) && (socket.port_ == port)) { isc_throw(SocketConfigError, "test socket bind error"); } diff --git a/src/lib/dhcp/testutils/iface_mgr_test_config.cc b/src/lib/dhcp/testutils/iface_mgr_test_config.cc index 5532fec255..36df127eae 100644 --- a/src/lib/dhcp/testutils/iface_mgr_test_config.cc +++ b/src/lib/dhcp/testutils/iface_mgr_test_config.cc @@ -13,8 +13,6 @@ #include #include -#include - using namespace isc::asiolink; namespace isc { @@ -165,7 +163,7 @@ IfaceMgrTestConfig::socketOpen(const std::string& iface_name, isc_throw(Unexpected, "No such interface '" << iface_name << "'"); } - BOOST_FOREACH(SocketInfo sock, iface->getSockets()) { + for (auto const& sock : iface->getSockets()) { if (sock.family_ == family) { return (true); } @@ -181,7 +179,7 @@ IfaceMgrTestConfig::socketOpen(const std::string& iface_name, isc_throw(Unexpected, "No such interface '" << iface_name << "'"); } - BOOST_FOREACH(SocketInfo sock, iface->getSockets()) { + for (auto const& sock : iface->getSockets()) { if ((sock.family_ == AF_INET) && (sock.addr_ == IOAddress(address))) { return (true); @@ -197,7 +195,7 @@ IfaceMgrTestConfig::unicastOpen(const std::string& iface_name) const { isc_throw(Unexpected, "No such interface '" << iface_name << "'"); } - BOOST_FOREACH(SocketInfo sock, iface->getSockets()) { + for (auto const& sock : iface->getSockets()) { if ((!sock.addr_.isV6LinkLocal()) && (!sock.addr_.isV6Multicast())) { return (true); diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc index 111a3a9347..810409fe4b 100644 --- a/src/lib/dhcpsrv/alloc_engine.cc +++ b/src/lib/dhcpsrv/alloc_engine.cc @@ -388,9 +388,9 @@ AllocEngine::findReservation(ClientContext6& ctx) { // Store the hosts in the temporary map, because some hosts may // belong to subnets outside of the shared network. We'll need // to eliminate them. - for (auto host = hosts.begin(); host != hosts.end(); ++host) { - if ((*host)->getIPv6SubnetID() != SUBNET_ID_GLOBAL) { - host_map[(*host)->getIPv6SubnetID()] = *host; + for (auto const& host : hosts) { + if (host->getIPv6SubnetID() != SUBNET_ID_GLOBAL) { + host_map[host->getIPv6SubnetID()] = host; } } } @@ -621,7 +621,7 @@ AllocEngine::allocateLeases6(ClientContext6& ctx) { // If there are any leases allocated, let's store in them in the // IA context so as they are available when we process subsequent // IAs. - BOOST_FOREACH(Lease6Ptr lease, leases) { + for (auto const& lease : leases) { ctx.addAllocatedResource(lease->addr_, lease->prefixlen_); ctx.new_leases_.push_back(lease); } @@ -1148,7 +1148,7 @@ AllocEngine::allocateReservedLeases6(ClientContext6& ctx, // We want to avoid allocating new lease for an IA if there is already // a valid lease for which client has reservation. So, we first check if // we already have a lease for a reserved address or prefix. - BOOST_FOREACH(const Lease6Ptr& lease, existing_leases) { + for (auto const& lease : existing_leases) { if ((lease->valid_lft_ != 0)) { if ((ctx.hosts_.count(lease->subnet_id_) > 0) && ctx.hosts_[lease->subnet_id_]->hasReservation(makeIPv6Resrv(*lease))) { @@ -1218,7 +1218,7 @@ AllocEngine::allocateReservedLeases6(ClientContext6& ctx, // Get the IPv6 reservations of specified type. const IPv6ResrvRange& reservs = host->getIPv6Reservations(type); - BOOST_FOREACH(IPv6ResrvTuple type_lease_tuple, reservs) { + BOOST_FOREACH(auto const& type_lease_tuple, reservs) { // We do have a reservation for address or prefix. const IOAddress& addr = type_lease_tuple.second.getPrefix(); uint8_t prefix_len = type_lease_tuple.second.getPrefixLen(); @@ -1318,7 +1318,7 @@ AllocEngine::allocateGlobalReservedLeases6(ClientContext6& ctx, // We want to avoid allocating a new lease for an IA if there is already // a valid lease for which client has reservation. So, we first check if // we already have a lease for a reserved address or prefix. - BOOST_FOREACH(const Lease6Ptr& lease, existing_leases) { + for (auto const& lease : existing_leases) { if ((lease->valid_lft_ != 0) && (ghost->hasReservation(makeIPv6Resrv(*lease)))) { // We found existing lease for a reserved address or prefix. @@ -1357,7 +1357,7 @@ AllocEngine::allocateGlobalReservedLeases6(ClientContext6& ctx, IPv6Resrv::TYPE_NA : IPv6Resrv::TYPE_PD; const IPv6ResrvRange& reservs = ghost->getIPv6Reservations(type); - BOOST_FOREACH(IPv6ResrvTuple type_lease_tuple, reservs) { + BOOST_FOREACH(auto const& type_lease_tuple, reservs) { // We do have a reservation for address or prefix. const IOAddress& addr = type_lease_tuple.second.getPrefix(); uint8_t prefix_len = type_lease_tuple.second.getPrefixLen(); @@ -1468,7 +1468,7 @@ AllocEngine::removeNonmatchingReservedLeases6(ClientContext6& ctx, // so the operation shouldn't be that expensive. Lease6Collection copy = existing_leases; - BOOST_FOREACH(const Lease6Ptr& candidate, copy) { + for (auto const& candidate : copy) { // If we have reservation we should check if the reservation is for // the candidate lease. If so, we simply accept the lease. IPv6Resrv resv = makeIPv6Resrv(*candidate); @@ -1576,7 +1576,7 @@ AllocEngine::removeNonmatchingReservedNoHostLeases6(ClientContext6& ctx, // so the operation shouldn't be that expensive. Lease6Collection copy = existing_leases; - BOOST_FOREACH(const Lease6Ptr& candidate, copy) { + for (auto const& candidate : copy) { // Lease can be allocated to us from a dynamic pool, but we must // check if this lease belongs to any allowed pool. If it does, // we can proceed to checking the next lease. @@ -1657,7 +1657,7 @@ AllocEngine::removeNonreservedLeases6(ClientContext6& ctx, lease != existing_leases.end(); ++lease) { // If there is reservation for this keep it. - IPv6Resrv resv = makeIPv6Resrv(*(*lease)); + IPv6Resrv resv = makeIPv6Resrv(**lease); if (ctx.hasGlobalReservation(resv) || ((ctx.hosts_.count((*lease)->subnet_id_) > 0) && (ctx.hosts_[(*lease)->subnet_id_]->hasReservation(resv)))) { @@ -1883,9 +1883,8 @@ AllocEngine::getLifetimes6(ClientContext6& ctx, uint32_t& preferred, uint32_t& v // Iterate over the assigned class definitions. int have_both = 0; - for (auto name = classes.cbegin(); - name != classes.cend() && have_both < 2; ++name) { - ClientClassDefPtr cl = dict->findClass(*name); + for (auto const& name : classes) { + ClientClassDefPtr cl = dict->findClass(name); if (candidate_preferred.unspecified() && (cl && (!cl->getPreferred().unspecified()))) { candidate_preferred = cl->getPreferred(); @@ -1897,6 +1896,9 @@ AllocEngine::getLifetimes6(ClientContext6& ctx, uint32_t& preferred, uint32_t& v candidate_valid = cl->getValid(); ++have_both; } + if (have_both == 2) { + break; + } } } @@ -2139,25 +2141,25 @@ AllocEngine::renewLeases6(ClientContext6& ctx) { } // Extend all existing leases that passed all checks. - for (Lease6Collection::iterator l = leases.begin(); l != leases.end(); ++l) { - if (ctx.currentIA().isNewResource((*l)->addr_, - (*l)->prefixlen_)) { + for (auto const& l : leases) { + if (ctx.currentIA().isNewResource(l->addr_, + l->prefixlen_)) { // This lease was just created so is already extended. continue; } LOG_DEBUG(alloc_engine_logger, ALLOC_ENGINE_DBG_TRACE_DETAIL, ALLOC_ENGINE_V6_EXTEND_LEASE) .arg(ctx.query_->getLabel()) - .arg((*l)->typeToText((*l)->type_)) - .arg((*l)->addr_); - extendLease6(ctx, *l); + .arg(l->typeToText(l->type_)) + .arg(l->addr_); + extendLease6(ctx, l); } if (!leases.empty()) { // If there are any leases allocated, let's store in them in the // IA context so as they are available when we process subsequent // IAs. - BOOST_FOREACH(Lease6Ptr lease, leases) { + for (auto const& lease : leases) { ctx.addAllocatedResource(lease->addr_, lease->prefixlen_); ctx.new_leases_.push_back(lease); } @@ -2418,9 +2420,8 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) { Lease6Collection AllocEngine::updateLeaseData(ClientContext6& ctx, const Lease6Collection& leases) { Lease6Collection updated_leases; - for (Lease6Collection::const_iterator lease_it = leases.begin(); - lease_it != leases.end(); ++lease_it) { - Lease6Ptr lease(new Lease6(**lease_it)); + for (auto const& lease_it : leases) { + Lease6Ptr lease(new Lease6(*lease_it)); if (ctx.currentIA().isNewResource(lease->addr_, lease->prefixlen_)) { // This lease was just created so is already up to date. updated_leases.push_back(lease); @@ -2452,14 +2453,14 @@ AllocEngine::updateLeaseData(ClientContext6& ctx, const Lease6Collection& leases } bool fqdn_changed = ((lease->type_ != Lease::TYPE_PD) && - !(lease->hasIdenticalFqdn(**lease_it))); + !(lease->hasIdenticalFqdn(*lease_it))); lease->cltt_ = time(NULL); if (!fqdn_changed) { setLeaseReusable(lease, current_preferred_lft, ctx); } if (lease->reuseable_valid_lft_ == 0) { - ctx.currentIA().changed_leases_.push_back(*lease_it); + ctx.currentIA().changed_leases_.push_back(lease_it); LeaseMgrFactory::instance().updateLease6(lease); } @@ -2575,7 +2576,7 @@ AllocEngine::reclaimExpiredLeases6Internal(const size_t max_leases, } size_t leases_processed = 0; - BOOST_FOREACH(Lease6Ptr lease, leases) { + for (auto const& lease : leases) { try { // Reclaim the lease. @@ -2738,7 +2739,7 @@ AllocEngine::reclaimExpiredLeases4Internal(const size_t max_leases, } size_t leases_processed = 0; - BOOST_FOREACH(Lease4Ptr lease, leases) { + for (auto const& lease : leases) { try { // Reclaim the lease. @@ -3502,10 +3503,10 @@ void findClientLease(AllocEngine::ClientContext4& ctx, Lease4Ptr& client_lease) // explicitly configured to ignore client identifiers for this subnet // check if there is a lease within this subnet. if (subnet->getMatchClientId()) { - for (auto l = leases_client_id.begin(); l != leases_client_id.end(); ++l) { - if ((*l)->subnet_id_ == subnet->getID()) { + for (auto const& l : leases_client_id) { + if (l->subnet_id_ == subnet->getID()) { // Lease found, so stick to this lease. - client_lease = (*l); + client_lease = l; ctx.subnet_ = subnet; return; } @@ -3530,9 +3531,8 @@ void findClientLease(AllocEngine::ClientContext4& ctx, Lease4Ptr& client_lease) // Try to find the lease that matches current subnet and belongs to // this client, so both HW address and client identifier match. - for (Lease4Collection::const_iterator client_lease_it = leases_hw_address.begin(); - client_lease_it != leases_hw_address.end(); ++client_lease_it) { - Lease4Ptr existing_lease = *client_lease_it; + for (auto const& client_lease_it : leases_hw_address) { + Lease4Ptr existing_lease = client_lease_it; if ((existing_lease->subnet_id_ == subnet->getID()) && existing_lease->belongsToClient(ctx.hwaddr_, client_id)) { // Found the lease of this client, so return it. @@ -3760,9 +3760,9 @@ AllocEngine::findReservation(ClientContext4& ctx) { // Store the hosts in the temporary map, because some hosts may // belong to subnets outside of the shared network. We'll need // to eliminate them. - for (auto host = hosts.begin(); host != hosts.end(); ++host) { - if ((*host)->getIPv4SubnetID() != SUBNET_ID_GLOBAL) { - host_map[(*host)->getIPv4SubnetID()] = *host; + for (auto const& host : hosts) { + if (host->getIPv4SubnetID() != SUBNET_ID_GLOBAL) { + host_map[host->getIPv4SubnetID()] = host; } } } @@ -4172,9 +4172,8 @@ AllocEngine::getOfferLft(const ClientContext4& ctx) { CfgMgr::instance().getCurrentCfg()->getClientClassDictionary(); // Iterate over the assigned class definitions. - for (ClientClasses::const_iterator name = classes.cbegin(); - name != classes.cend(); ++name) { - ClientClassDefPtr cl = dict->findClass(*name); + for (auto const& name : classes) { + ClientClassDefPtr cl = dict->findClass(name); if (cl && (!cl->getOfferLft().unspecified())) { offer_lft = cl->getOfferLft(); break; @@ -4217,9 +4216,8 @@ AllocEngine::getValidLft(const ClientContext4& ctx) { CfgMgr::instance().getCurrentCfg()->getClientClassDictionary(); // Iterate over the assigned class definitions. - for (ClientClasses::const_iterator name = classes.cbegin(); - name != classes.cend(); ++name) { - ClientClassDefPtr cl = dict->findClass(*name); + for (auto const& name : classes) { + ClientClassDefPtr cl = dict->findClass(name); if (cl && (!cl->getValid().unspecified())) { candidate_lft = cl->getValid(); break; diff --git a/src/lib/dhcpsrv/cb_ctl_dhcp.h b/src/lib/dhcpsrv/cb_ctl_dhcp.h index 926946de89..104fa871c2 100644 --- a/src/lib/dhcpsrv/cb_ctl_dhcp.h +++ b/src/lib/dhcpsrv/cb_ctl_dhcp.h @@ -45,14 +45,14 @@ protected: void addGlobalsToConfig(SrvConfigPtr external_cfg, data::StampedValueCollection& cb_globals) const { auto const& index = cb_globals.get(); - for (auto cb_global = index.begin(); cb_global != index.end(); ++cb_global) { + for (auto const& cb_global : index) { - if ((*cb_global)->amNull()) { + if (cb_global->amNull()) { continue; } - external_cfg->addConfiguredGlobal((*cb_global)->getName(), - (*cb_global)->getElementValue()); + external_cfg->addConfiguredGlobal(cb_global->getName(), + cb_global->getElementValue()); } } }; diff --git a/src/lib/dhcpsrv/cb_ctl_dhcp4.cc b/src/lib/dhcpsrv/cb_ctl_dhcp4.cc index 37efb8a4bc..1bc678fdca 100644 --- a/src/lib/dhcpsrv/cb_ctl_dhcp4.cc +++ b/src/lib/dhcpsrv/cb_ctl_dhcp4.cc @@ -13,6 +13,7 @@ #include #include #include +#include using namespace isc::db; using namespace isc::data; @@ -99,37 +100,37 @@ CBControlDHCPv4::databaseConfigApply(const BackendSelector& backend_selector, // audit entry is found. range = index.equal_range(boost::make_tuple("dhcp4_option_def", AuditEntry::ModificationType::DELETE)); - for (auto entry = range.first; entry != range.second; ++entry) { - current_cfg->getCfgOptionDef()->del((*entry)->getObjectId()); + BOOST_FOREACH(auto const& entry, range) { + current_cfg->getCfgOptionDef()->del(entry->getObjectId()); } // Repeat the same for other configuration elements. range = index.equal_range(boost::make_tuple("dhcp4_options", AuditEntry::ModificationType::DELETE)); - for (auto entry = range.first; entry != range.second; ++entry) { - current_cfg->getCfgOption()->del((*entry)->getObjectId()); + BOOST_FOREACH(auto const& entry, range) { + current_cfg->getCfgOption()->del(entry->getObjectId()); } range = index.equal_range(boost::make_tuple("dhcp4_client_class", AuditEntry::ModificationType::DELETE)); - for (auto entry = range.first; entry != range.second; ++entry) { - current_cfg->getClientClassDictionary()->removeClass((*entry)->getObjectId()); + BOOST_FOREACH(auto const& entry, range) { + current_cfg->getClientClassDictionary()->removeClass(entry->getObjectId()); } range = index.equal_range(boost::make_tuple("dhcp4_shared_network", AuditEntry::ModificationType::DELETE)); - for (auto entry = range.first; entry != range.second; ++entry) { - current_cfg->getCfgSharedNetworks4()->del((*entry)->getObjectId()); + BOOST_FOREACH(auto const& entry, range) { + current_cfg->getCfgSharedNetworks4()->del(entry->getObjectId()); } range = index.equal_range(boost::make_tuple("dhcp4_subnet", AuditEntry::ModificationType::DELETE)); - for (auto entry = range.first; entry != range.second; ++entry) { + BOOST_FOREACH(auto const& entry, range) { // If the deleted subnet belongs to a shared network and the // shared network is not being removed, we need to detach the // subnet from the shared network. - auto subnet = current_cfg->getCfgSubnets4()->getBySubnetId((*entry)->getObjectId()); + auto subnet = current_cfg->getCfgSubnets4()->getBySubnetId(entry->getObjectId()); if (subnet) { // Check if the subnet belongs to a shared network. SharedNetwork4Ptr network; @@ -139,7 +140,7 @@ CBControlDHCPv4::databaseConfigApply(const BackendSelector& backend_selector, network->del(subnet->getID()); } // Actually delete the subnet from the configuration. - current_cfg->getCfgSubnets4()->del((*entry)->getObjectId()); + current_cfg->getCfgSubnets4()->del(entry->getObjectId()); } } @@ -177,11 +178,11 @@ CBControlDHCPv4::databaseConfigApply(const BackendSelector& backend_selector, OptionDefContainer option_defs = getMgr().getPool()->getModifiedOptionDefs4(backend_selector, server_selector, lb_modification_time); - for (auto option_def = option_defs.begin(); option_def != option_defs.end(); ++option_def) { - if (!audit_entries.empty() && !hasObjectId(updated_entries, (*option_def)->getId())) { + for (auto const& option_def : option_defs) { + if (!audit_entries.empty() && !hasObjectId(updated_entries, option_def->getId())) { continue; } - external_cfg->getCfgOptionDef()->add(*option_def); + external_cfg->getCfgOptionDef()->add(option_def); } } @@ -193,11 +194,11 @@ CBControlDHCPv4::databaseConfigApply(const BackendSelector& backend_selector, OptionContainer options = getMgr().getPool()->getModifiedOptions4(backend_selector, server_selector, lb_modification_time); - for (auto option = options.begin(); option != options.end(); ++option) { - if (!audit_entries.empty() && !hasObjectId(updated_entries, (*option).getId())) { + for (auto const& option : options) { + if (!audit_entries.empty() && !hasObjectId(updated_entries, option.getId())) { continue; } - external_cfg->getCfgOption()->add((*option), (*option).space_name_); + external_cfg->getCfgOption()->add(option, option.space_name_); } } @@ -257,18 +258,18 @@ CBControlDHCPv4::databaseConfigApply(const BackendSelector& backend_selector, lb_modification_time); } // Iterate over all shared networks that may require reconfiguration. - for (auto network = networks.begin(); network != networks.end(); ++network) { - if (!allocator_changed && cb_update && !hasObjectId(updated_entries, (*network)->getId())) { + for (auto const& network : networks) { + if (!allocator_changed && cb_update && !hasObjectId(updated_entries, network->getId())) { continue; } // In order to take advantage of the dynamic inheritance of global // parameters to a shared network we need to set a callback function // for each network to allow for fetching global parameters. - (*network)->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr { + network->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr { return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals()); }); - (*network)->setDefaultAllocatorType(global_allocator); - external_cfg->getCfgSharedNetworks4()->add((*network)); + network->setDefaultAllocatorType(global_allocator); + external_cfg->getCfgSharedNetworks4()->add(network); } // Next, fetch the subnets. @@ -289,18 +290,18 @@ CBControlDHCPv4::databaseConfigApply(const BackendSelector& backend_selector, lb_modification_time); } // Iterate over all subnets that may require reconfiguration. - for (auto subnet = subnets.begin(); subnet != subnets.end(); ++subnet) { - if (!allocator_changed && cb_update && !hasObjectId(updated_entries, (*subnet)->getID())) { + for (auto const& subnet : subnets) { + if (!allocator_changed && cb_update && !hasObjectId(updated_entries, subnet->getID())) { continue; } // In order to take advantage of the dynamic inheritance of global // parameters to a subnet we need to set a callback function for each // subnet to allow for fetching global parameters. - (*subnet)->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr { + subnet->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr { return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals()); }); - (*subnet)->setDefaultAllocatorType(global_allocator); - external_cfg->getCfgSubnets4()->add((*subnet)); + subnet->setDefaultAllocatorType(global_allocator); + external_cfg->getCfgSubnets4()->add(subnet); } if (reconfig) { diff --git a/src/lib/dhcpsrv/cb_ctl_dhcp6.cc b/src/lib/dhcpsrv/cb_ctl_dhcp6.cc index ca74a5e531..fba428a38b 100644 --- a/src/lib/dhcpsrv/cb_ctl_dhcp6.cc +++ b/src/lib/dhcpsrv/cb_ctl_dhcp6.cc @@ -12,6 +12,7 @@ #include #include #include +#include using namespace isc::db; using namespace isc::data; @@ -98,37 +99,37 @@ CBControlDHCPv6::databaseConfigApply(const db::BackendSelector& backend_selector // audit entry is found. range = index.equal_range(boost::make_tuple("dhcp6_option_def", AuditEntry::ModificationType::DELETE)); - for (auto entry = range.first; entry != range.second; ++entry) { - current_cfg->getCfgOptionDef()->del((*entry)->getObjectId()); + BOOST_FOREACH(auto const& entry, range) { + current_cfg->getCfgOptionDef()->del(entry->getObjectId()); } // Repeat the same for other configuration elements. range = index.equal_range(boost::make_tuple("dhcp6_options", AuditEntry::ModificationType::DELETE)); - for (auto entry = range.first; entry != range.second; ++entry) { - current_cfg->getCfgOption()->del((*entry)->getObjectId()); + BOOST_FOREACH(auto const& entry, range) { + current_cfg->getCfgOption()->del(entry->getObjectId()); } range = index.equal_range(boost::make_tuple("dhcp6_client_class", AuditEntry::ModificationType::DELETE)); - for (auto entry = range.first; entry != range.second; ++entry) { - current_cfg->getClientClassDictionary()->removeClass((*entry)->getObjectId()); + BOOST_FOREACH(auto const& entry, range) { + current_cfg->getClientClassDictionary()->removeClass(entry->getObjectId()); } range = index.equal_range(boost::make_tuple("dhcp6_shared_network", AuditEntry::ModificationType::DELETE)); - for (auto entry = range.first; entry != range.second; ++entry) { - current_cfg->getCfgSharedNetworks6()->del((*entry)->getObjectId()); + BOOST_FOREACH(auto const& entry, range) { + current_cfg->getCfgSharedNetworks6()->del(entry->getObjectId()); } range = index.equal_range(boost::make_tuple("dhcp6_subnet", AuditEntry::ModificationType::DELETE)); - for (auto entry = range.first; entry != range.second; ++entry) { + BOOST_FOREACH(auto const& entry, range) { // If the deleted subnet belongs to a shared network and the // shared network is not being removed, we need to detach the // subnet from the shared network. - auto subnet = current_cfg->getCfgSubnets6()->getBySubnetId((*entry)->getObjectId()); + auto subnet = current_cfg->getCfgSubnets6()->getBySubnetId(entry->getObjectId()); if (subnet) { // Check if the subnet belongs to a shared network. SharedNetwork6Ptr network; @@ -138,7 +139,7 @@ CBControlDHCPv6::databaseConfigApply(const db::BackendSelector& backend_selector network->del(subnet->getID()); } // Actually delete the subnet from the configuration. - current_cfg->getCfgSubnets6()->del((*entry)->getObjectId()); + current_cfg->getCfgSubnets6()->del(entry->getObjectId()); } } @@ -176,11 +177,11 @@ CBControlDHCPv6::databaseConfigApply(const db::BackendSelector& backend_selector OptionDefContainer option_defs = getMgr().getPool()->getModifiedOptionDefs6(backend_selector, server_selector, lb_modification_time); - for (auto option_def = option_defs.begin(); option_def != option_defs.end(); ++option_def) { - if (!audit_entries.empty() && !hasObjectId(updated_entries, (*option_def)->getId())) { + for (auto const& option_def : option_defs) { + if (!audit_entries.empty() && !hasObjectId(updated_entries, option_def->getId())) { continue; } - external_cfg->getCfgOptionDef()->add(*option_def); + external_cfg->getCfgOptionDef()->add(option_def); } } @@ -192,11 +193,11 @@ CBControlDHCPv6::databaseConfigApply(const db::BackendSelector& backend_selector OptionContainer options = getMgr().getPool()->getModifiedOptions6(backend_selector, server_selector, lb_modification_time); - for (auto option = options.begin(); option != options.end(); ++option) { - if (!audit_entries.empty() && !hasObjectId(updated_entries, (*option).getId())) { + for (auto const& option : options) { + if (!audit_entries.empty() && !hasObjectId(updated_entries, option.getId())) { continue; } - external_cfg->getCfgOption()->add((*option), (*option).space_name_); + external_cfg->getCfgOption()->add(option, option.space_name_); } } @@ -268,19 +269,19 @@ CBControlDHCPv6::databaseConfigApply(const db::BackendSelector& backend_selector networks = getMgr().getPool()->getModifiedSharedNetworks6(backend_selector, server_selector, lb_modification_time); } - for (auto network = networks.begin(); network != networks.end(); ++network) { - if (!allocator_changed && cb_update && !hasObjectId(updated_entries, (*network)->getId())) { + for (auto const& network : networks) { + if (!allocator_changed && cb_update && !hasObjectId(updated_entries, network->getId())) { continue; } // In order to take advantage of the dynamic inheritance of global // parameters to a shared network we need to set a callback function // for each network to allow for fetching global parameters. - (*network)->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr { + network->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr { return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals()); }); - (*network)->setDefaultAllocatorType(global_allocator); - (*network)->setDefaultPdAllocatorType(global_pd_allocator); - external_cfg->getCfgSharedNetworks6()->add((*network)); + network->setDefaultAllocatorType(global_allocator); + network->setDefaultPdAllocatorType(global_pd_allocator); + external_cfg->getCfgSharedNetworks6()->add(network); } // Next we fetch subnets. @@ -301,19 +302,19 @@ CBControlDHCPv6::databaseConfigApply(const db::BackendSelector& backend_selector lb_modification_time); } // Iterate over all subnets that may require reconfiguration. - for (auto subnet = subnets.begin(); subnet != subnets.end(); ++subnet) { - if (!audit_entries.empty() && !hasObjectId(updated_entries, (*subnet)->getID())) { + for (auto const& subnet : subnets) { + if (!audit_entries.empty() && !hasObjectId(updated_entries, subnet->getID())) { continue; } // In order to take advantage of the dynamic inheritance of global // parameters to a subnet we need to set a callback function for each // subnet to allow for fetching global parameters. - (*subnet)->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr { + subnet->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr { return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals()); }); - (*subnet)->setDefaultAllocatorType(global_allocator); - (*subnet)->setDefaultPdAllocatorType(global_pd_allocator); - external_cfg->getCfgSubnets6()->add((*subnet)); + subnet->setDefaultAllocatorType(global_allocator); + subnet->setDefaultPdAllocatorType(global_pd_allocator); + external_cfg->getCfgSubnets6()->add(subnet); } if (reconfig) { diff --git a/src/lib/dhcpsrv/cfg_db_access.cc b/src/lib/dhcpsrv/cfg_db_access.cc index e3a37bfa30..37038a46be 100644 --- a/src/lib/dhcpsrv/cfg_db_access.cc +++ b/src/lib/dhcpsrv/cfg_db_access.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include diff --git a/src/lib/dhcpsrv/cfg_globals.cc b/src/lib/dhcpsrv/cfg_globals.cc index ed43125b33..7aab23038d 100644 --- a/src/lib/dhcpsrv/cfg_globals.cc +++ b/src/lib/dhcpsrv/cfg_globals.cc @@ -84,18 +84,17 @@ struct CfgGlobalsChecks { // Build the name vector. std::vector names; names.resize(CfgGlobals::SIZE); - for (auto it = CfgGlobals::nameToIndex.cbegin(); - it != CfgGlobals::nameToIndex.cend(); ++it) { - int idx = it->second; + for (auto const& it : CfgGlobals::nameToIndex) { + int idx = it.second; if ((idx < 0) || (idx >= CfgGlobals::SIZE)) { isc_throw(Unexpected, "invalid index " << idx - << " for name " << it->first); + << " for name " << it.first); } if (!names[idx].empty()) { isc_throw(Unexpected, "duplicated names for " << idx << " got " << names[idx]); } - names[idx] = it->first; + names[idx] = it.first; } // No name should be empty. @@ -160,11 +159,11 @@ CfgGlobals::clear() { const CfgGlobals::MapType CfgGlobals::valuesMap() const { MapType map; - for (auto it = nameToIndex.cbegin(); it != nameToIndex.cend(); ++it) { - int idx = it->second; + for (auto const& it : nameToIndex) { + int idx = it.second; ConstElementPtr value = values_[idx]; if (value) { - map.insert(make_pair(it->first, value)); + map.insert(make_pair(it.first, value)); } } return (map); @@ -173,11 +172,11 @@ CfgGlobals::valuesMap() const { ElementPtr CfgGlobals::toElement() const { ElementPtr result = Element::createMap(); - for (auto it = nameToIndex.cbegin(); it != nameToIndex.cend(); ++it) { - int idx = it->second; + for (auto const& it : nameToIndex) { + int idx = it.second; ConstElementPtr value = values_[idx]; if (value) { - result->set(it->first, value); + result->set(it.first, value); } } return (result); diff --git a/src/lib/dhcpsrv/cfg_host_operations.cc b/src/lib/dhcpsrv/cfg_host_operations.cc index f588b9dc61..08093047b3 100644 --- a/src/lib/dhcpsrv/cfg_host_operations.cc +++ b/src/lib/dhcpsrv/cfg_host_operations.cc @@ -61,9 +61,8 @@ CfgHostOperations::clearIdentifierTypes() { ElementPtr CfgHostOperations::toElement() const { ElementPtr result = Element::createList(); - for (IdentifierTypes::const_iterator id = identifier_types_.begin(); - id != identifier_types_.end(); ++id) { - const std::string& name = Host::getIdentifierName(*id); + for (auto const& id : identifier_types_) { + const std::string& name = Host::getIdentifierName(id); result->add(Element::create(name)); } return (result); diff --git a/src/lib/dhcpsrv/cfg_hosts.cc b/src/lib/dhcpsrv/cfg_hosts.cc index bee54332bc..69b924a0f9 100644 --- a/src/lib/dhcpsrv/cfg_hosts.cc +++ b/src/lib/dhcpsrv/cfg_hosts.cc @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -618,13 +619,12 @@ CfgHosts::getAllInternal4(const IOAddress& address, Storage& storage) const { const HostContainerIndex1& idx = hosts_.get<1>(); HostContainerIndex1Range r = idx.equal_range(address); // Append each Host object to the storage. - for (HostContainerIndex1::iterator host = r.first; host != r.second; - ++host) { + BOOST_FOREACH(auto const& host, r) { LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE_DETAIL_DATA, HOSTS_CFG_GET_ALL_ADDRESS4_HOST) .arg(address.toText()) - .arg((*host)->toText()); - storage.push_back(*host); + .arg(host->toText()); + storage.push_back(host); } LOG_DEBUG(hosts_logger, HOSTS_DBG_RESULTS, HOSTS_CFG_GET_ALL_ADDRESS4_COUNT) @@ -647,13 +647,12 @@ CfgHosts::getAllInternal6(const IOAddress& address, Storage& storage) const { const HostContainer6Index4& idx = hosts6_.get<4>(); HostContainer6Index4Range r = idx.equal_range(address); // Append each Host object to the storage. - for (HostContainer6Index4::iterator reservation = r.first; reservation != r.second; - ++reservation) { + BOOST_FOREACH(auto const& reservation, r) { LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE_DETAIL_DATA, HOSTS_CFG_GET_ALL_ADDRESS6_HOST) .arg(address.toText()) - .arg(reservation->host_->toText()); - storage.push_back(reservation->host_); + .arg(reservation.host_->toText()); + storage.push_back(reservation.host_); } LOG_DEBUG(hosts_logger, HOSTS_DBG_RESULTS, HOSTS_CFG_GET_ALL_ADDRESS6_COUNT) @@ -685,15 +684,14 @@ CfgHosts::get4(const SubnetID& subnet_id, const IOAddress& address) const { .arg(subnet_id).arg(address.toText()); ConstHostCollection hosts = getAll4(address); - for (ConstHostCollection::const_iterator host = hosts.begin(); - host != hosts.end(); ++host) { - if ((*host)->getIPv4SubnetID() == subnet_id) { + for (auto const& host : hosts) { + if (host->getIPv4SubnetID() == subnet_id) { LOG_DEBUG(hosts_logger, HOSTS_DBG_RESULTS, HOSTS_CFG_GET_ONE_SUBNET_ID_ADDRESS4_HOST) .arg(subnet_id) .arg(address.toText()) - .arg((*host)->toText()); - return (*host); + .arg(host->toText()); + return (host); } } @@ -822,15 +820,14 @@ CfgHosts::getHostInternal6(const asiolink::IOAddress& prefix, const HostContainer6Index0& idx = hosts6_.get<0>(); HostContainer6Index0Range r = make_pair(idx.lower_bound(prefix), idx.upper_bound(prefix)); - for (HostContainer6Index0::iterator resrv = r.first; resrv != r.second; - ++resrv) { - if (resrv->resrv_.getPrefixLen() == prefix_len) { + BOOST_FOREACH(auto const& resrv, r) { + if (resrv.resrv_.getPrefixLen() == prefix_len) { LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE_DETAIL_DATA, HOSTS_CFG_GET_ONE_PREFIX_HOST) .arg(prefix.toText()) .arg(static_cast(prefix_len)) - .arg(resrv->host_->toText()); - return (resrv->host_); + .arg(resrv.host_->toText()); + return (resrv.host_); } } @@ -864,13 +861,13 @@ CfgHosts::getAllInternal6(const SubnetID& subnet_id, // in all sane cases, there will be only one such host. (Each host can have // multiple addresses reserved, but for each (address, subnet_id) there should // be at most one host reserving it). - for(HostContainer6Index1::iterator resrv = r.first; resrv != r.second; ++resrv) { + BOOST_FOREACH(auto const& resrv, r) { LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE_DETAIL_DATA, HOSTS_CFG_GET_ALL_SUBNET_ID_ADDRESS6_HOST) .arg(subnet_id) .arg(address.toText()) - .arg(resrv->host_->toText()); - storage.push_back(resrv->host_); + .arg(resrv.host_->toText()); + storage.push_back(resrv.host_); } LOG_DEBUG(hosts_logger, HOSTS_DBG_RESULTS, @@ -901,11 +898,10 @@ CfgHosts::getHostInternal(const SubnetID& subnet_id, const bool subnet6, HostPtr host; // Iterate over the returned hosts and select those for which the // subnet id matches. - for (HostCollection::const_iterator host_it = hosts.begin(); - host_it != hosts.end(); ++host_it) { + for (auto const& host_it : hosts) { // Check if this is IPv4 subnet or IPv6 subnet. - SubnetID host_subnet_id = subnet6 ? (*host_it)->getIPv6SubnetID() : - (*host_it)->getIPv4SubnetID(); + SubnetID host_subnet_id = subnet6 ? host_it->getIPv6SubnetID() : + host_it->getIPv4SubnetID(); if (subnet_id == host_subnet_id) { // If this is the first occurrence of the host for this subnet, @@ -916,7 +912,7 @@ CfgHosts::getHostInternal(const SubnetID& subnet_id, const bool subnet6, // result, and we don't know which reservation we should choose. // Therefore, throw an exception. if (!host) { - host = *host_it; + host = host_it; } else { isc_throw(DuplicateHost, "more than one reservation found" @@ -1066,22 +1062,21 @@ CfgHosts::add6(const HostPtr& host) { } // Now for each reservation, insert corresponding (address, host) tuple. - for (IPv6ResrvIterator it = reservations.first; it != reservations.second; - ++it) { + BOOST_FOREACH(auto const& it, reservations) { if (ip_reservations_unique_) { // If there's an entry for this (subnet-id, address), reject it. - if (get6(host->getIPv6SubnetID(), it->second.getPrefix())) { + if (get6(host->getIPv6SubnetID(), it.second.getPrefix())) { isc_throw(DuplicateHost, "failed to add address reservation for " << "host using the HW address '" << (hwaddr ? hwaddr->toText(false) : "(null)") << " and DUID '" << (duid ? duid->toText() : "(null)") << "' to the IPv6 subnet id '" << host->getIPv6SubnetID() - << "' for address/prefix " << it->second.getPrefix() + << "' for address/prefix " << it.second.getPrefix() << ": There's already reservation for this address/prefix"); } } - hosts6_.insert(HostResrv6Tuple(it->second, host)); + hosts6_.insert(HostResrv6Tuple(it.second, host)); } } @@ -1103,8 +1098,8 @@ CfgHosts::del(const SubnetID& subnet_id, const asiolink::IOAddress& addr) { auto const& range = idx6.equal_range(boost::make_tuple(subnet_id, addr)); erased_addresses = boost::distance(range); // Delete hosts. - for (auto key = range.first; key != range.second; ++key) { - erased_hosts += idx.erase(key->host_->getHostId()); + BOOST_FOREACH(auto const& key, range) { + erased_hosts += idx.erase(key.host_->getHostId()); } idx6.erase(range.first, range.second); } @@ -1137,8 +1132,8 @@ CfgHosts::del4(const SubnetID& subnet_id, const size_t identifier_len) { HostContainerIndex0& idx = hosts_.get<0>(); auto const t = boost::make_tuple(std::vector(identifier_begin, - identifier_begin + identifier_len), - identifier_type); + identifier_begin + identifier_len), + identifier_type); auto const& range = idx.equal_range(t); size_t erased = 0; for (auto key = range.first; key != range.second;) { @@ -1241,14 +1236,13 @@ CfgHosts::toElement4() const { CfgHostsList result; // Iterate using arbitrary the index 0 const HostContainerIndex0& idx = hosts_.get<0>(); - for (HostContainerIndex0::const_iterator host = idx.begin(); - host != idx.end(); ++host) { + for (auto const& host : idx) { // Convert host to element representation - ElementPtr map = (*host)->toElement4(); + ElementPtr map = host->toElement4(); // Push it on the list - SubnetID subnet_id = (*host)->getIPv4SubnetID(); + SubnetID subnet_id = host->getIPv4SubnetID(); result.add(subnet_id, map); } return (result.externalize()); @@ -1259,14 +1253,13 @@ CfgHosts::toElement6() const { CfgHostsList result; // Iterate using arbitrary the index 0 const HostContainerIndex0& idx = hosts_.get<0>(); - for (HostContainerIndex0::const_iterator host = idx.begin(); - host != idx.end(); ++host) { + for (auto const& host : idx) { // Convert host to Element representation - ElementPtr map = (*host)->toElement6(); + ElementPtr map = host->toElement6(); // Push it on the list - SubnetID subnet_id = (*host)->getIPv6SubnetID(); + SubnetID subnet_id = host->getIPv6SubnetID(); result.add(subnet_id, map); } return (result.externalize()); diff --git a/src/lib/dhcpsrv/cfg_hosts_util.cc b/src/lib/dhcpsrv/cfg_hosts_util.cc index 11c9e87aa2..31db3c1eec 100644 --- a/src/lib/dhcpsrv/cfg_hosts_util.cc +++ b/src/lib/dhcpsrv/cfg_hosts_util.cc @@ -62,11 +62,10 @@ void CfgHostsList::internalize(ConstElementPtr list) { ElementPtr CfgHostsList::externalize() const { ElementPtr result = Element::createList(); - for (CfgHostsMap::const_iterator item = map_.begin(); - item != map_.end(); ++item) { + for (auto const& item : map_) { ElementPtr pair = Element::createMap(); - pair->set("id", Element::create(static_cast(item->first))); - pair->set("reservations", item->second); + pair->set("id", Element::create(static_cast(item.first))); + pair->set("reservations", item.second); result->add(pair); } return (result); diff --git a/src/lib/dhcpsrv/cfg_iface.cc b/src/lib/dhcpsrv/cfg_iface.cc index 16f523cada..fa23e54db8 100644 --- a/src/lib/dhcpsrv/cfg_iface.cc +++ b/src/lib/dhcpsrv/cfg_iface.cc @@ -49,7 +49,7 @@ CfgIface::equals(const CfgIface& other) const { bool CfgIface::multipleAddressesPerInterfaceActive() { - for (const IfacePtr& iface : IfaceMgr::instance().getIfaces()) { + for (auto const& iface : IfaceMgr::instance().getIfaces()) { if (iface->countActive4() > 1) { return (true); } @@ -69,17 +69,15 @@ CfgIface::openSockets(const uint16_t family, const uint16_t port, bool loopback_used_ = false; if ((family == AF_INET6) || (socket_type_ == SOCKET_UDP)) { // Check interface set - for (IfaceSet::const_iterator iface_name = iface_set_.begin(); - iface_name != iface_set_.end(); ++iface_name) { - IfacePtr iface = IfaceMgr::instance().getIface(*iface_name); + for (auto const& iface_name : iface_set_) { + IfacePtr iface = IfaceMgr::instance().getIface(iface_name); if (iface && iface->flag_loopback_) { loopback_used_ = true; } } // Check address map - for (ExplicitAddressMap::const_iterator unicast = address_map_.begin(); - unicast != address_map_.end(); ++unicast) { - IfacePtr iface = IfaceMgr::instance().getIface(unicast->first); + for (auto const& unicast : address_map_) { + IfacePtr iface = IfaceMgr::instance().getIface(unicast.first); if (iface && iface->flag_loopback_) { loopback_used_ = true; } @@ -112,9 +110,8 @@ CfgIface::openSockets(const uint16_t family, const uint16_t port, // If there is no wildcard interface specified, we will have to iterate // over the names specified by the caller and enable them. if (!wildcard_used_) { - for (IfaceSet::const_iterator iface_name = iface_set_.begin(); - iface_name != iface_set_.end(); ++iface_name) { - IfacePtr iface = IfaceMgr::instance().getIface(*iface_name); + for (auto const& iface_name : iface_set_) { + IfacePtr iface = IfaceMgr::instance().getIface(iface_name); // This shouldn't really happen because we are checking the // names of interfaces when they are being added (use() // function). But, if someone has triggered detection of @@ -122,7 +119,7 @@ CfgIface::openSockets(const uint16_t family, const uint16_t port, if (iface == NULL) { isc_throw(Unexpected, "fail to open socket on interface '" - << *iface_name << "' as this interface doesn't" + << iface_name << "' as this interface doesn't" " exist"); } else if (family == AF_INET) { @@ -137,21 +134,20 @@ CfgIface::openSockets(const uint16_t family, const uint16_t port, // Select unicast sockets for DHCPv6 or activate specific IPv4 addresses // for DHCPv4. - for (ExplicitAddressMap::const_iterator unicast = address_map_.begin(); - unicast != address_map_.end(); ++unicast) { - IfacePtr iface = IfaceMgr::instance().getIface(unicast->first); + for (auto const& unicast : address_map_) { + IfacePtr iface = IfaceMgr::instance().getIface(unicast.first); if (iface == NULL) { isc_throw(Unexpected, "fail to open unicast socket on interface '" - << unicast->first << "' as this interface doesn't" + << unicast.first << "' as this interface doesn't" " exist"); } if (family == AF_INET6) { - iface->addUnicast(unicast->second); + iface->addUnicast(unicast.second); iface->inactive6_ = false; } else { - iface->setActive(unicast->second, true); + iface->setActive(unicast.second, true); iface->inactive4_ = false; } } @@ -284,7 +280,7 @@ CfgIface::reset() { void CfgIface::setState(const uint16_t family, const bool inactive, const bool loopback_inactive) const { - for (const IfacePtr& iface : IfaceMgr::instance().getIfaces()) { + for (auto const& iface : IfaceMgr::instance().getIfaces()) { bool iface_inactive = iface->flag_loopback_ ? loopback_inactive : inactive; if (family == AF_INET) { iface->inactive4_ = iface_inactive; @@ -301,7 +297,7 @@ void CfgIface::setIfaceAddrsState(const uint16_t family, const bool active, Iface& iface) const { // Activate/deactivate all addresses. - for (const Iface::Address& addr : iface.getAddresses()) { + for (auto const& addr : iface.getAddresses()) { if (addr.get().getFamily() == family) { iface.setActive(addr.get(), active); } @@ -565,13 +561,11 @@ CfgIface::toElement() const { if (wildcard_used_) { ifaces->add(Element::create(std::string(ALL_IFACES_KEYWORD))); } - for (IfaceSet::const_iterator iface = iface_set_.cbegin(); - iface != iface_set_.cend(); ++iface) { - ifaces->add(Element::create(*iface)); + for (auto const& iface : iface_set_) { + ifaces->add(Element::create(iface)); } - for (ExplicitAddressMap::const_iterator address = address_map_.cbegin(); - address != address_map_.cend(); ++address) { - std::string spec = address->first + "/" + address->second.toText(); + for (auto const& address : address_map_) { + std::string spec = address.first + "/" + address.second.toText(); ifaces->add(Element::create(spec)); } result->set("interfaces", ifaces); diff --git a/src/lib/dhcpsrv/cfg_mac_source.cc b/src/lib/dhcpsrv/cfg_mac_source.cc index 7a0db260b3..8fbc9c71d3 100644 --- a/src/lib/dhcpsrv/cfg_mac_source.cc +++ b/src/lib/dhcpsrv/cfg_mac_source.cc @@ -55,9 +55,8 @@ uint32_t CfgMACSource::MACSourceFromText(const std::string& name) { } void CfgMACSource::add(uint32_t source) { - for (CfgMACSources::const_iterator it = mac_sources_.begin(); - it != mac_sources_.end(); ++it) { - if (*it == source) { + for (auto const& it : mac_sources_) { + if (it == source) { isc_throw(InvalidParameter, "mac-source parameter " << source << "' specified twice."); } @@ -67,17 +66,16 @@ void CfgMACSource::add(uint32_t source) { ElementPtr CfgMACSource::toElement() const { ElementPtr result = Element::createList(); - for (CfgMACSources::const_iterator source = mac_sources_.cbegin(); - source != mac_sources_.cend(); ++source) { + for (auto const& source : mac_sources_) { std::string name; for (unsigned i = 0; i < sizeof(sources)/sizeof(sources[0]); ++i) { - if (sources[i].type == *source) { + if (sources[i].type == source) { name = sources[i].name; break; } } if (name.empty()) { - isc_throw(ToElementError, "invalid MAC source: " << *source); + isc_throw(ToElementError, "invalid MAC source: " << source); } result->add(Element::create(name)); } @@ -85,5 +83,5 @@ ElementPtr CfgMACSource::toElement() const { return (result); } -}; -}; +} +} diff --git a/src/lib/dhcpsrv/cfg_option.cc b/src/lib/dhcpsrv/cfg_option.cc index c4b8f47021..4b731090f4 100644 --- a/src/lib/dhcpsrv/cfg_option.cc +++ b/src/lib/dhcpsrv/cfg_option.cc @@ -374,16 +374,14 @@ CfgOption::del(const std::string& option_space, const uint16_t option_code) { auto option_space_names = getOptionSpaceNames(); for (auto const& option_space_from_list : option_space_names) { // Get all options within the particular option space. - auto options_in_space = getAll(option_space_from_list); - for (auto option_it = options_in_space->begin(); - option_it != options_in_space->end(); - ++option_it) { + auto const& options_in_space = getAll(option_space_from_list); + for (auto const& option_it : *options_in_space) { // Check if the option encapsulates our option space and // it does, try to delete our option. - if (option_it->option_ && - (option_it->option_->getEncapsulatedSpace() == option_space)) { - option_it->option_->delOption(option_code); + if (option_it.option_ && + (option_it.option_->getEncapsulatedSpace() == option_space)) { + option_it.option_->delOption(option_code); } } } @@ -413,20 +411,18 @@ CfgOption::del(const uint64_t id) { // any of them. Let's walk over the existing option spaces. for (auto const& space_name : getOptionSpaceNames()) { // Get all options for the option space. - auto options = getAll(space_name); - for (auto option_it = options->begin(); option_it != options->end(); - ++option_it) { - if (!option_it->option_) { + auto const& options = getAll(space_name); + for (auto const& option_it : *options) { + if (!option_it.option_) { continue; } // For each option within the option space we need to dereference // any existing sub options. - auto sub_options = option_it->option_->getOptions(); - for (auto sub = sub_options.begin(); sub != sub_options.end(); - ++sub) { + auto sub_options = option_it.option_->getOptions(); + for (auto const& sub : sub_options) { // Dereference sub option. - option_it->option_->delOption(sub->second->getType()); + option_it.option_->delOption(sub.second->getType()); } } } diff --git a/src/lib/dhcpsrv/cfg_option.h b/src/lib/dhcpsrv/cfg_option.h index a0c6d0b68d..fd33d8df8b 100644 --- a/src/lib/dhcpsrv/cfg_option.h +++ b/src/lib/dhcpsrv/cfg_option.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -516,7 +517,7 @@ public: /// there is no definition matching the option code in the given space, or /// if the definition factory invocation fails. static bool createDescriptorOption(CfgOptionDefPtr cfg_def, const std::string& space, - OptionDescriptor& opt_desc); + OptionDescriptor& opt_desc); /// @brief Merges this configuration to another configuration. /// @@ -646,9 +647,8 @@ public: const OptionContainerTypeIndex& idx = options->get<1>(); OptionContainerTypeRange range = idx.equal_range(option_code); // This code copies descriptors and can be optimized not doing this. - for (OptionContainerTypeIndex::const_iterator od_itr = range.first; - od_itr != range.second; ++od_itr) { - list.push_back(*od_itr); + BOOST_FOREACH(auto const& od_itr, range) { + list.push_back(od_itr); } return (list); diff --git a/src/lib/dhcpsrv/cfg_option_def.cc b/src/lib/dhcpsrv/cfg_option_def.cc index e154d19441..f1671f3f6f 100644 --- a/src/lib/dhcpsrv/cfg_option_def.cc +++ b/src/lib/dhcpsrv/cfg_option_def.cc @@ -23,13 +23,11 @@ CfgOptionDef::copyTo(CfgOptionDef& new_config) const { new_config.option_definitions_.clearItems(); const std::list& names = option_definitions_.getOptionSpaceNames(); - for (std::list::const_iterator name = names.begin(); - name != names.end(); ++name) { - OptionDefContainerPtr defs = getAll(*name); - for (OptionDefContainer::const_iterator def = defs->begin(); - def != defs->end(); ++def) { + for (auto const& name : names) { + OptionDefContainerPtr defs = getAll(name); + for (auto const& def : *defs) { OptionDefinitionPtr new_def = - OptionDefinitionPtr(new OptionDefinition(**def)); + OptionDefinitionPtr(new OptionDefinition(*def)); new_config.add(new_def); } } @@ -49,23 +47,20 @@ CfgOptionDef::equals(const CfgOptionDef& other) const { } // Iterate over all option space names and get the definitions for each // of them. - for (std::list::const_iterator name = names.begin(); - name != names.end(); ++name) { + for (auto const& name : names) { // Get all definitions. - OptionDefContainerPtr defs = getAll(*name); - OptionDefContainerPtr other_defs = other.getAll(*name); + OptionDefContainerPtr defs = getAll(name); + OptionDefContainerPtr other_defs = other.getAll(name); // Compare sizes. If they hold different number of definitions, // they are unequal. if (defs->size() != defs->size()) { return (false); } // For each option definition, try to find one in the other object. - for (OptionDefContainer::const_iterator def = defs->begin(); - def != defs->end(); ++def) { - OptionDefinitionPtr - other_def = other.get(*name, (*def)->getCode()); + for (auto const& def : *defs) { + OptionDefinitionPtr other_def = other.get(name, def->getCode()); // Actually compare them. - if (!other_def || (*other_def != **def)) { + if (!other_def || (*other_def != *def)) { return (false); } } @@ -175,41 +170,40 @@ CfgOptionDef::toElementWithMetadata(const bool include_metadata) const { // Iterate through the container by names and definitions const std::list& names = option_definitions_.getOptionSpaceNames(); - for (std::list::const_iterator name = names.begin(); - name != names.end(); ++name) { - OptionDefContainerPtr defs = getAll(*name); - for (OptionDefContainer::const_iterator def = defs->begin(); - def != defs->end(); ++def) { + for (auto const& name : names) { + OptionDefContainerPtr defs = getAll(name); + for (auto const& def : *defs) { // Get and fill the map for this definition ElementPtr map = Element::createMap(); // Set user context - (*def)->contextToElement(map); + def->contextToElement(map); // Set space from parent iterator - map->set("space", Element::create(*name)); + map->set("space", Element::create(name)); // Set required items: name, code and type - map->set("name", Element::create((*def)->getName())); - map->set("code", Element::create((*def)->getCode())); + map->set("name", Element::create(def->getName())); + map->set("code", Element::create(def->getCode())); std::string data_type = - OptionDataTypeUtil::getDataTypeName((*def)->getType()); + OptionDataTypeUtil::getDataTypeName(def->getType()); map->set("type", Element::create(data_type)); // Set the array type - bool array_type = (*def)->getArrayType(); + bool array_type = def->getArrayType(); map->set("array", Element::create(array_type)); // Set the encapsulate space - std::string encapsulates = (*def)->getEncapsulatedSpace(); + std::string encapsulates = def->getEncapsulatedSpace(); map->set("encapsulate", Element::create(encapsulates)); // Set the record field types OptionDefinition::RecordFieldsCollection fields = - (*def)->getRecordFields(); + def->getRecordFields(); if (!fields.empty()) { std::ostringstream oss; - for (OptionDefinition::RecordFieldsCollection::const_iterator - field = fields.begin(); - field != fields.end(); ++field) { - if (field != fields.begin()) { + bool first = true; + for (auto const& field : fields) { + if (!first) { oss << ", "; + } else { + first = false; } - oss << OptionDataTypeUtil::getDataTypeName(*field); + oss << OptionDataTypeUtil::getDataTypeName(field); } map->set("record-types", Element::create(oss.str())); } else { @@ -218,7 +212,7 @@ CfgOptionDef::toElementWithMetadata(const bool include_metadata) const { // Include metadata if requested. if (include_metadata) { - map->set("metadata", (*def)->getMetadata()); + map->set("metadata", def->getMetadata()); } // Push on the list diff --git a/src/lib/dhcpsrv/cfg_rsoo.cc b/src/lib/dhcpsrv/cfg_rsoo.cc index 30f02e67c2..b9f4e4595c 100644 --- a/src/lib/dhcpsrv/cfg_rsoo.cc +++ b/src/lib/dhcpsrv/cfg_rsoo.cc @@ -42,9 +42,8 @@ ElementPtr CfgRSOO::toElement() const { ElementPtr result = Element::createList(); // We can use LibDHCP::getOptionDef(DHCP6_OPTION_SPACE, *opt) too... - for (std::set::const_iterator opt = rsoo_options_.cbegin(); - opt != rsoo_options_.cend(); ++opt) { - const std::string& code = boost::lexical_cast(*opt); + for (auto const& opt : rsoo_options_) { + const std::string& code = boost::lexical_cast(opt); result->add(Element::create(code)); } return (result); diff --git a/src/lib/dhcpsrv/cfg_shared_networks.h b/src/lib/dhcpsrv/cfg_shared_networks.h index a478220171..4bf38ac50f 100644 --- a/src/lib/dhcpsrv/cfg_shared_networks.h +++ b/src/lib/dhcpsrv/cfg_shared_networks.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -91,8 +92,8 @@ public: // For each shared network found, dereference the subnets belonging // to it. - for (auto it = sn_range.first; it != sn_range.second; ++it) { - (*it)->delAll(); + BOOST_FOREACH(auto const& it, sn_range) { + it->delAll(); } // Remove the shared networks. @@ -123,9 +124,8 @@ public: // Insert shared networks sorted by their names into the list. auto const& index = networks_.template get(); - for (auto shared_network = index.begin(); shared_network != index.end(); - ++shared_network) { - list->add((*shared_network)->toElement()); + for (auto const& shared_network : index) { + list->add(shared_network->toElement()); } return (list); } @@ -165,21 +165,20 @@ public: // Iterate over the subnets to be merged. They will replace the existing // subnets with the same id. All new subnets will be inserted into this // configuration. - auto other_networks = other.getAll(); - for (auto other_network = other_networks->begin(); - other_network != other_networks->end(); ++other_network) { + auto const& other_networks = other.getAll(); + for (auto const& other_network : *other_networks) { // In theory we should drop subnet assignments from "other". The // idea being those that come from the CB should not have subnets_ // populated. We will quietly throw them away, just in case. - (*other_network)->delAll(); + other_network->delAll(); // Check if the other network exists in this config. - auto existing_network = index.find((*other_network)->getName()); + auto existing_network = index.find(other_network->getName()); if (existing_network != index.end()) { // Somehow the same instance is in both, skip it. - if (*existing_network == *other_network) { + if (*existing_network == other_network) { continue; } @@ -189,9 +188,9 @@ public: auto const subnets = (*existing_network)->getAllSubnets(); auto copy_subnets(*subnets); - for (auto subnet = copy_subnets.cbegin(); subnet != copy_subnets.cend(); ++subnet) { - (*existing_network)->del((*subnet)->getID()); - (*other_network)->add(*subnet); + for (auto const& subnet : copy_subnets) { + (*existing_network)->del(subnet->getID()); + other_network->add(subnet); } // Now we discard the existing copy of the network. @@ -199,10 +198,10 @@ public: } // Create the network's options based on the given definitions. - (*other_network)->getCfgOption()->createOptions(cfg_def); + other_network->getCfgOption()->createOptions(cfg_def); // Add the new/updated nework. - static_cast(networks_.push_back(*other_network)); + static_cast(networks_.push_back(other_network)); } } diff --git a/src/lib/dhcpsrv/cfg_subnets6.cc b/src/lib/dhcpsrv/cfg_subnets6.cc index 179c5bd226..b1dcec6035 100644 --- a/src/lib/dhcpsrv/cfg_subnets6.cc +++ b/src/lib/dhcpsrv/cfg_subnets6.cc @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include @@ -210,7 +210,7 @@ CfgSubnets6::initSelector(const Pkt6Ptr& query) { // Initialize fields specific to relayed messages. if (!query->relay_info_.empty()) { - BOOST_REVERSE_FOREACH(Pkt6::RelayInfo relay, query->relay_info_) { + for (auto const& relay : boost::adaptors::reverse(query->relay_info_)) { if (!relay.linkaddr_.isV6Zero() && !relay.linkaddr_.isV6LinkLocal()) { selector.first_relay_linkaddr_ = relay.linkaddr_; diff --git a/src/lib/dhcpsrv/client_class_def.cc b/src/lib/dhcpsrv/client_class_def.cc index 168288343c..033ad36989 100644 --- a/src/lib/dhcpsrv/client_class_def.cc +++ b/src/lib/dhcpsrv/client_class_def.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include @@ -55,7 +54,7 @@ ClientClassDef::ClientClassDef(const ClientClassDef& rhs) if (rhs.match_expr_) { match_expr_.reset(new Expression()); - *match_expr_ = *(rhs.match_expr_); + *match_expr_ = *rhs.match_expr_; } if (rhs.cfg_option_def_) { @@ -215,7 +214,7 @@ ClientClassDef::equals(const ClientClassDef& other) const { return ((name_ == other.name_) && ((!match_expr_ && !other.match_expr_) || (match_expr_ && other.match_expr_ && - (*match_expr_ == *(other.match_expr_)))) && + (*match_expr_ == *other.match_expr_))) && ((!cfg_option_ && !other.cfg_option_) || (cfg_option_ && other.cfg_option_ && (*cfg_option_ == *other.cfg_option_))) && @@ -330,7 +329,7 @@ ClientClassDictionary::ClientClassDictionary() ClientClassDictionary::ClientClassDictionary(const ClientClassDictionary& rhs) : map_(new ClientClassDefMap()), list_(new ClientClassDefList()) { - BOOST_FOREACH(ClientClassDefPtr cclass, *(rhs.list_)) { + for (auto const& cclass : *rhs.list_) { ClientClassDefPtr copy(new ClientClassDef(*cclass)); addClass(copy); } @@ -444,15 +443,14 @@ ClientClassDictionary::dependOnClass(const std::string& name, std::string& dependent_class) const { // Skip previous classes as they should not depend on name. bool found = false; - for (ClientClassDefList::iterator this_class = list_->begin(); - this_class != list_->end(); ++this_class) { + for (auto const& this_class : *list_) { if (found) { - if ((*this_class)->dependOnClass(name)) { - dependent_class = (*this_class)->getName(); + if (this_class->dependOnClass(name)) { + dependent_class = this_class->getName(); return (true); } } else { - if ((*this_class)->getName() == name) { + if (this_class->getName() == name) { found = true; } } @@ -552,9 +550,8 @@ ElementPtr ClientClassDictionary::toElement() const { ElementPtr result = Element::createList(); // Iterate on the map - for (ClientClassDefList::const_iterator this_class = list_->begin(); - this_class != list_->cend(); ++this_class) { - result->add((*this_class)->toElement()); + for (auto const& this_class : *list_) { + result->add(this_class->toElement()); } return (result); } @@ -564,7 +561,7 @@ ClientClassDictionary::operator=(const ClientClassDictionary& rhs) { if (this != &rhs) { list_->clear(); map_->clear(); - for (auto const& cclass : *(rhs.list_)) { + for (auto const& cclass : *rhs.list_) { ClientClassDefPtr copy(new ClientClassDef(*cclass)); addClass(copy); } @@ -597,20 +594,18 @@ builtinPrefixes = { bool isClientClassBuiltIn(const ClientClass& client_class) { - for (std::list::const_iterator bn = builtinNames.cbegin(); - bn != builtinNames.cend(); ++bn) { - if (client_class == *bn) { + for (auto const& bn : builtinNames) { + if (client_class == bn) { return true; } } - for (std::list::const_iterator bt = builtinPrefixes.cbegin(); - bt != builtinPrefixes.cend(); ++bt) { - if (client_class.size() <= bt->size()) { + for (auto const& bt : builtinPrefixes) { + if (client_class.size() <= bt.size()) { continue; } - auto mis = std::mismatch(bt->cbegin(), bt->cend(), client_class.cbegin()); - if (mis.first == bt->cend()) { + auto mis = std::mismatch(bt.cbegin(), bt.cend(), client_class.cbegin()); + if (mis.first == bt.cend()) { return true; } } diff --git a/src/lib/dhcpsrv/d2_client_mgr.h b/src/lib/dhcpsrv/d2_client_mgr.h index 7b282c5c52..f2a67be94d 100644 --- a/src/lib/dhcpsrv/d2_client_mgr.h +++ b/src/lib/dhcpsrv/d2_client_mgr.h @@ -499,12 +499,15 @@ D2ClientMgr::adjustDomainName(const T& fqdn, T& fqdn_resp, const DdnsParams& ddn std::vector labels; boost::algorithm::split(labels, raw_name, boost::is_any_of(".")); std::stringstream ss; - for (auto label = labels.begin(); label != labels.end(); ++label ) { - if (label != labels.begin()) { + bool first = true; + for (auto const& label : labels) { + if (!first) { ss << "."; + } else { + first = false; } - ss << sanitizer->scrub(*label); + ss << sanitizer->scrub(label); } client_name = ss.str(); diff --git a/src/lib/dhcpsrv/dhcp4o6_ipc.cc b/src/lib/dhcpsrv/dhcp4o6_ipc.cc index 4cfe046856..c0b882fdf6 100644 --- a/src/lib/dhcpsrv/dhcp4o6_ipc.cc +++ b/src/lib/dhcpsrv/dhcp4o6_ipc.cc @@ -142,9 +142,8 @@ Pkt6Ptr Dhcp4o6IpcBase::receive() { // Get all vendor option and look for the one with the ISC enterprise id. OptionCollection vendor_options = pkt->getOptions(D6O_VENDOR_OPTS); - for (OptionCollection::const_iterator opt = vendor_options.begin(); - opt != vendor_options.end(); ++opt) { - option_vendor = boost::dynamic_pointer_cast(opt->second); + for (auto const& opt : vendor_options) { + option_vendor = boost::dynamic_pointer_cast(opt.second); if (option_vendor) { if (option_vendor->getVendorId() == ENTERPRISE_ID_ISC) { break; @@ -244,9 +243,8 @@ void Dhcp4o6IpcBase::send(const Pkt6Ptr& pkt) { // Get all vendor option and look for the one with the ISC enterprise id. OptionCollection vendor_options = pkt->getOptions(D6O_VENDOR_OPTS); - for (OptionCollection::const_iterator opt = vendor_options.begin(); - opt != vendor_options.end(); ++opt) { - option_vendor = boost::dynamic_pointer_cast(opt->second); + for (auto const& opt : vendor_options) { + option_vendor = boost::dynamic_pointer_cast(opt.second); if (option_vendor) { if (option_vendor->getVendorId() == ENTERPRISE_ID_ISC) { break; diff --git a/src/lib/dhcpsrv/host.cc b/src/lib/dhcpsrv/host.cc index 30ac4766a5..5c6de5b7c0 100644 --- a/src/lib/dhcpsrv/host.cc +++ b/src/lib/dhcpsrv/host.cc @@ -16,6 +16,7 @@ #include #include +#include #include using namespace isc::data; @@ -448,9 +449,8 @@ bool Host::hasReservation(const IPv6Resrv& reservation) const { IPv6ResrvRange reservations = getIPv6Reservations(reservation.getType()); if (std::distance(reservations.first, reservations.second) > 0) { - for (IPv6ResrvIterator it = reservations.first; - it != reservations.second; ++it) { - if (it->second == reservation) { + BOOST_FOREACH(auto const& it, reservations) { + if (it.second == reservation) { return (true); } } @@ -561,9 +561,8 @@ Host::toElement4() const { // Set client-classes const ClientClasses& cclasses = getClientClasses4(); ElementPtr classes = Element::createList(); - for (ClientClasses::const_iterator cclass = cclasses.cbegin(); - cclass != cclasses.cend(); ++cclass) { - classes->add(Element::create(*cclass)); + for (auto const& cclass : cclasses) { + classes->add(Element::create(cclass)); } map->set("client-classes", classes); // Set option-data @@ -599,19 +598,17 @@ Host::toElement6() const { isc_throw(ToElementError, "invalid DUID type: " << id_type); } // Set reservations (ip-addresses) - IPv6ResrvRange na_resv = getIPv6Reservations(IPv6Resrv::TYPE_NA); + const IPv6ResrvRange& na_resv = getIPv6Reservations(IPv6Resrv::TYPE_NA); ElementPtr resvs = Element::createList(); - for (IPv6ResrvIterator resv = na_resv.first; - resv != na_resv.second; ++resv) { - resvs->add(Element::create(resv->second.toText())); + BOOST_FOREACH(auto const& resv, na_resv) { + resvs->add(Element::create(resv.second.toText())); } map->set("ip-addresses", resvs); // Set reservations (prefixes) - IPv6ResrvRange pd_resv = getIPv6Reservations(IPv6Resrv::TYPE_PD); + const IPv6ResrvRange& pd_resv = getIPv6Reservations(IPv6Resrv::TYPE_PD); resvs = Element::createList(); - for (IPv6ResrvIterator resv = pd_resv.first; - resv != pd_resv.second; ++resv) { - resvs->add(Element::create(resv->second.toText())); + BOOST_FOREACH(auto const& resv, pd_resv) { + resvs->add(Element::create(resv.second.toText())); } map->set("prefixes", resvs); // Set the hostname @@ -620,9 +617,8 @@ Host::toElement6() const { // Set client-classes const ClientClasses& cclasses = getClientClasses6(); ElementPtr classes = Element::createList(); - for (ClientClasses::const_iterator cclass = cclasses.cbegin(); - cclass != cclasses.cend(); ++cclass) { - classes->add(Element::create(*cclass)); + for (auto const& cclass : cclasses) { + classes->add(Element::create(cclass)); } map->set("client-classes", classes); @@ -683,33 +679,35 @@ Host::toText() const { s << " key=" << (key_.toText().empty() ? "(empty)" : key_.toText()); + size_t count = 0; + if (ipv6_reservations_.empty()) { s << " ipv6_reservations=(none)"; } else { // Add all IPv6 reservations. - for (IPv6ResrvIterator resrv = ipv6_reservations_.begin(); - resrv != ipv6_reservations_.end(); ++resrv) { + count = 0; + for (auto const& resrv : ipv6_reservations_) { s << " ipv6_reservation" - << std::distance(ipv6_reservations_.begin(), resrv) - << "=" << resrv->second.toText(); + << count++ + << "=" << resrv.second.toText(); } } // Add DHCPv4 client classes. - for (ClientClasses::const_iterator cclass = dhcp4_client_classes_.cbegin(); - cclass != dhcp4_client_classes_.cend(); ++cclass) { + count = 0; + for (auto const& cclass : dhcp4_client_classes_) { s << " dhcp4_class" - << std::distance(dhcp4_client_classes_.cbegin(), cclass) - << "=" << *cclass; + << count++ + << "=" << cclass; } // Add DHCPv6 client classes. - for (ClientClasses::const_iterator cclass = dhcp6_client_classes_.cbegin(); - cclass != dhcp6_client_classes_.cend(); ++cclass) { + count = 0; + for (auto const& cclass : dhcp6_client_classes_) { s << " dhcp6_class" - << std::distance(dhcp6_client_classes_.cbegin(), cclass) - << "=" << *cclass; + << count++ + << "=" << cclass; } // Add negative cached. diff --git a/src/lib/dhcpsrv/host_data_source_factory.cc b/src/lib/dhcpsrv/host_data_source_factory.cc index 374df12c3b..8ef36ef0e2 100644 --- a/src/lib/dhcpsrv/host_data_source_factory.cc +++ b/src/lib/dhcpsrv/host_data_source_factory.cc @@ -20,7 +20,6 @@ #endif #include -#include #include #include diff --git a/src/lib/dhcpsrv/host_mgr.cc b/src/lib/dhcpsrv/host_mgr.cc index 47997a968d..397cea7dd1 100644 --- a/src/lib/dhcpsrv/host_mgr.cc +++ b/src/lib/dhcpsrv/host_mgr.cc @@ -751,7 +751,7 @@ HostMgr::getAll6(const IOAddress& address, const HostMgrOperationTarget target) } if (target & HostMgrOperationTarget::ALTERNATE_SOURCES) { - for (auto const&source : alternate_sources_) { + for (auto const& source : alternate_sources_) { ConstHostCollection hosts_plus = source->getAll6(address); hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end()); } diff --git a/src/lib/dhcpsrv/lease_file_loader.h b/src/lib/dhcpsrv/lease_file_loader.h index b4f724a5e7..d5663fda32 100644 --- a/src/lib/dhcpsrv/lease_file_loader.h +++ b/src/lib/dhcpsrv/lease_file_loader.h @@ -223,11 +223,9 @@ public: lease_file.open(); // Iterate over the storage area writing out the leases - for (typename StorageType::const_iterator lease = storage.begin(); - lease != storage.end(); - ++lease) { + for (auto const& lease : storage) { try { - lease_file.append(**lease); + lease_file.append(*lease); } catch (const isc::Exception&) { // Close the file lease_file.close(); diff --git a/src/lib/dhcpsrv/lease_mgr.cc b/src/lib/dhcpsrv/lease_mgr.cc index f56a749de4..36bb07d944 100644 --- a/src/lib/dhcpsrv/lease_mgr.cc +++ b/src/lib/dhcpsrv/lease_mgr.cc @@ -15,7 +15,6 @@ #include #include -#include #include #include @@ -106,9 +105,8 @@ LeaseMgr::recountLeaseStats4() { const Subnet4Collection* subnets = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll(); - for (Subnet4Collection::const_iterator subnet = subnets->begin(); - subnet != subnets->end(); ++subnet) { - SubnetID subnet_id = (*subnet)->getID(); + for (auto const& subnet : *subnets) { + SubnetID subnet_id = subnet->getID(); stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id, "assigned-addresses"), zero); @@ -129,7 +127,7 @@ LeaseMgr::recountLeaseStats4() { stats_mgr.setValue(name_rec, zero); } - for (auto const& pool : (*subnet)->getPools(Lease::TYPE_V4)) { + for (auto const& pool : subnet->getPools(Lease::TYPE_V4)) { const std::string name_aa(StatsMgr::generateName("subnet", subnet_id, StatsMgr::generateName("pool", pool->getID(), "assigned-addresses"))); @@ -320,9 +318,8 @@ LeaseMgr::recountLeaseStats6() { const Subnet6Collection* subnets = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll(); - for (Subnet6Collection::const_iterator subnet = subnets->begin(); - subnet != subnets->end(); ++subnet) { - SubnetID subnet_id = (*subnet)->getID(); + for (auto const& subnet : *subnets) { + SubnetID subnet_id = subnet->getID(); stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id, "assigned-nas"), zero); @@ -353,7 +350,7 @@ LeaseMgr::recountLeaseStats6() { zero); } - for (auto const& pool : (*subnet)->getPools(Lease::TYPE_NA)) { + for (auto const& pool : subnet->getPools(Lease::TYPE_NA)) { const std::string& name_anas(StatsMgr::generateName("subnet", subnet_id, StatsMgr::generateName("pool", pool->getID(), "assigned-nas"))); @@ -383,7 +380,7 @@ LeaseMgr::recountLeaseStats6() { } } - for (auto const& pool : (*subnet)->getPools(Lease::TYPE_PD)) { + for (auto const& pool : subnet->getPools(Lease::TYPE_PD)) { const std::string& name_apds(StatsMgr::generateName("subnet", subnet_id, StatsMgr::generateName("pd-pool", pool->getID(), "assigned-pds"))); diff --git a/src/lib/dhcpsrv/lease_mgr_factory.cc b/src/lib/dhcpsrv/lease_mgr_factory.cc index e633916d89..9b71cc1d5b 100644 --- a/src/lib/dhcpsrv/lease_mgr_factory.cc +++ b/src/lib/dhcpsrv/lease_mgr_factory.cc @@ -17,7 +17,6 @@ #endif #include -#include #include #include diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index df812f144a..b94fa0dc7d 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -1168,8 +1169,8 @@ Memfile_LeaseMgr::getLease4Internal(const HWAddr& hwaddr, Lease4StorageHWAddressSubnetIdIndex::const_iterator> l = idx.equal_range(boost::make_tuple(hwaddr.hwaddr_)); - for (auto lease = l.first; lease != l.second; ++lease) { - collection.push_back(Lease4Ptr(new Lease4(**lease))); + BOOST_FOREACH(auto const& lease, l) { + collection.push_back(Lease4Ptr(new Lease4(*lease))); } } @@ -1233,8 +1234,8 @@ Memfile_LeaseMgr::getLease4Internal(const ClientId& client_id, Lease4StorageClientIdSubnetIdIndex::const_iterator> l = idx.equal_range(boost::make_tuple(client_id.getClientId())); - for (auto lease = l.first; lease != l.second; ++lease) { - collection.push_back(Lease4Ptr(new Lease4(**lease))); + BOOST_FOREACH(auto const& lease, l) { + collection.push_back(Lease4Ptr(new Lease4(*lease))); } } @@ -1294,8 +1295,8 @@ Memfile_LeaseMgr::getLeases4Internal(SubnetID subnet_id, Lease4StorageSubnetIdIndex::const_iterator> l = idx.equal_range(subnet_id); - for (auto lease = l.first; lease != l.second; ++lease) { - collection.push_back(Lease4Ptr(new Lease4(**lease))); + BOOST_FOREACH(auto const& lease, l) { + collection.push_back(Lease4Ptr(new Lease4(*lease))); } } @@ -1323,8 +1324,8 @@ Memfile_LeaseMgr::getLeases4Internal(const std::string& hostname, Lease4StorageHostnameIndex::const_iterator> l = idx.equal_range(hostname); - for (auto lease = l.first; lease != l.second; ++lease) { - collection.push_back(Lease4Ptr(new Lease4(**lease))); + BOOST_FOREACH(auto const& lease, l) { + collection.push_back(Lease4Ptr(new Lease4(*lease))); } } @@ -1346,8 +1347,8 @@ Memfile_LeaseMgr::getLeases4(const std::string& hostname) const { void Memfile_LeaseMgr::getLeases4Internal(Lease4Collection& collection) const { - for (auto lease = storage4_.begin(); lease != storage4_.end(); ++lease) { - collection.push_back(Lease4Ptr(new Lease4(**lease))); + for (auto const& lease : storage4_) { + collection.push_back(Lease4Ptr(new Lease4(*lease))); } } @@ -1540,8 +1541,8 @@ Memfile_LeaseMgr::getLeases6Internal(SubnetID subnet_id, Lease6StorageSubnetIdIndex::const_iterator> l = idx.equal_range(subnet_id); - for (auto lease = l.first; lease != l.second; ++lease) { - collection.push_back(Lease6Ptr(new Lease6(**lease))); + BOOST_FOREACH(auto const& lease, l) { + collection.push_back(Lease6Ptr(new Lease6(*lease))); } } @@ -1569,8 +1570,8 @@ Memfile_LeaseMgr::getLeases6Internal(const std::string& hostname, Lease6StorageHostnameIndex::const_iterator> l = idx.equal_range(hostname); - for (auto lease = l.first; lease != l.second; ++lease) { - collection.push_back(Lease6Ptr(new Lease6(**lease))); + BOOST_FOREACH(auto const& lease, l) { + collection.push_back(Lease6Ptr(new Lease6(*lease))); } } @@ -1592,8 +1593,8 @@ Memfile_LeaseMgr::getLeases6(const std::string& hostname) const { void Memfile_LeaseMgr::getLeases6Internal(Lease6Collection& collection) const { - for (auto lease = storage6_.begin(); lease != storage6_.end(); ++lease) { - collection.push_back(Lease6Ptr(new Lease6(**lease))); + for (auto const& lease : storage6_) { + collection.push_back(Lease6Ptr(new Lease6(*lease))); } } @@ -1620,8 +1621,8 @@ Memfile_LeaseMgr::getLeases6Internal(const DUID& duid, Lease6StorageDuidIndex::const_iterator> l = idx.equal_range(duid.getDuid()); - for (auto lease = l.first; lease != l.second; ++lease) { - collection.push_back(Lease6Ptr(new Lease6(**lease))); + BOOST_FOREACH(auto const& lease, l) { + collection.push_back(Lease6Ptr(new Lease6(*lease))); } } @@ -2589,13 +2590,13 @@ Memfile_LeaseMgr::wipeLeases4(const SubnetID& subnet_id) { // Let's collect all leases. Lease4Collection leases; - for (auto lease = l.first; lease != l.second; ++lease) { - leases.push_back(*lease); + BOOST_FOREACH(auto const& lease, l) { + leases.push_back(lease); } size_t num = leases.size(); - for (auto l = leases.begin(); l != leases.end(); ++l) { - deleteLease(*l); + for (auto const& l : leases) { + deleteLease(l); } LOG_INFO(dhcpsrv_logger, DHCPSRV_MEMFILE_WIPE_LEASES4_FINISHED) .arg(subnet_id).arg(num); @@ -2618,13 +2619,13 @@ Memfile_LeaseMgr::wipeLeases6(const SubnetID& subnet_id) { // Let's collect all leases. Lease6Collection leases; - for (auto lease = l.first; lease != l.second; ++lease) { - leases.push_back(*lease); + BOOST_FOREACH(auto const& lease, l) { + leases.push_back(lease); } size_t num = leases.size(); - for (auto l = leases.begin(); l != leases.end(); ++l) { - deleteLease(*l); + for (auto const& l : leases) { + deleteLease(l); } LOG_INFO(dhcpsrv_logger, DHCPSRV_MEMFILE_WIPE_LEASES6_FINISHED) .arg(subnet_id).arg(num); @@ -2635,10 +2636,10 @@ Memfile_LeaseMgr::wipeLeases6(const SubnetID& subnet_id) { void Memfile_LeaseMgr::recountClassLeases4() { class_lease_counter_.clear(); - for (auto lease = storage4_.begin(); lease != storage4_.end(); ++lease) { + for (auto const& lease : storage4_) { // Bump the appropriate accumulator - if ((*lease)->state_ == Lease::STATE_DEFAULT) { - class_lease_counter_.addLease(*lease); + if (lease->state_ == Lease::STATE_DEFAULT) { + class_lease_counter_.addLease(lease); } } } @@ -2646,10 +2647,10 @@ Memfile_LeaseMgr::recountClassLeases4() { void Memfile_LeaseMgr::recountClassLeases6() { class_lease_counter_.clear(); - for (auto lease = storage6_.begin(); lease != storage6_.end(); ++lease) { + for (auto const& lease : storage6_) { // Bump the appropriate accumulator - if ((*lease)->state_ == Lease::STATE_DEFAULT) { - class_lease_counter_.addLease(*lease); + if (lease->state_ == Lease::STATE_DEFAULT) { + class_lease_counter_.addLease(lease); } } } @@ -2899,13 +2900,12 @@ idToText(const OptionBuffer& id) { std::stringstream tmp; tmp << std::hex; bool delim = false; - for (std::vector::const_iterator it = id.begin(); - it != id.end(); ++it) { + for (auto const& it : id) { if (delim) { tmp << ":"; } tmp << std::setw(2) << std::setfill('0') - << static_cast(*it); + << static_cast(it); delim = true; } return (tmp.str()); @@ -3058,21 +3058,21 @@ Memfile_LeaseMgr::getLeases4ByRemoteIdInternal(const OptionBuffer& remote_id, const Lease4StorageRemoteIdIndex& idx = storage4_.get(); Lease4StorageRemoteIdRange er = idx.equal_range(remote_id); // Store all convenient leases being within the page size. - for (auto it = er.first; it != er.second; ++it) { - const IOAddress& addr = (*it)->addr_; + BOOST_FOREACH(auto const& it, er) { + const IOAddress& addr = it->addr_; if (addr <= lower_bound_address) { // Not greater than lower_bound_address. continue; } - if ((qry_start_time > 0) && ((*it)->cltt_ < qry_start_time)) { + if ((qry_start_time > 0) && (it->cltt_ < qry_start_time)) { // Too old. continue; } - if ((qry_end_time > 0) && ((*it)->cltt_ > qry_end_time)) { + if ((qry_end_time > 0) && (it->cltt_ > qry_end_time)) { // Too young. continue; } - sorted[addr] = *it; + sorted[addr] = it; } // Return all leases being within the page size. @@ -3207,8 +3207,8 @@ Memfile_LeaseMgr::getLeases6ByRemoteIdInternal(const OptionBuffer& remote_id, const RemoteIdIndex& idx = remote_id6_.get(); RemoteIdIndexRange er = idx.equal_range(remote_id); // Store all addresses greater than lower_bound_address. - for (auto it = er.first; it != er.second; ++it) { - const IOAddress& addr = (*it)->lease_addr_; + BOOST_FOREACH(auto const& it, er) { + const IOAddress& addr = it->lease_addr_; if (addr <= lower_bound_address) { continue; } diff --git a/src/lib/dhcpsrv/mysql_host_data_source.cc b/src/lib/dhcpsrv/mysql_host_data_source.cc index 8a84817b59..5b76e1645e 100644 --- a/src/lib/dhcpsrv/mysql_host_data_source.cc +++ b/src/lib/dhcpsrv/mysql_host_data_source.cc @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -3140,11 +3141,11 @@ MySqlHostDataSourceImpl::addOptions(MySqlHostContextPtr& ctx, // For each option space retrieve all options and insert them into the // database. - for (auto space = option_spaces.begin(); space != option_spaces.end(); ++space) { - OptionContainerPtr options = options_cfg->getAllCombined(*space); + for (auto const& space : option_spaces) { + OptionContainerPtr options = options_cfg->getAllCombined(space); if (options && !options->empty()) { - for (auto opt = options->begin(); opt != options->end(); ++opt) { - addOption(ctx, stindex, *opt, *space, Optional(), host_id); + for (auto const& opt : *options) { + addOption(ctx, stindex, opt, space, Optional(), host_id); } } } @@ -3336,9 +3337,8 @@ MySqlHostDataSource::add(const HostPtr& host) { // Insert IPv6 reservations. IPv6ResrvRange v6resv = host->getIPv6Reservations(); if (std::distance(v6resv.first, v6resv.second) > 0) { - for (IPv6ResrvIterator resv = v6resv.first; resv != v6resv.second; - ++resv) { - impl_->addResv(ctx, resv->second, host_id); + BOOST_FOREACH(auto const& resv, v6resv) { + impl_->addResv(ctx, resv.second, host_id); } } diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc index 1b71d52c57..270ea8468b 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.cc +++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc @@ -4077,13 +4077,12 @@ idToText(const OptionBuffer& id) { std::stringstream tmp; tmp << std::hex; bool delim = false; - for (std::vector::const_iterator it = id.begin(); - it != id.end(); ++it) { + for (auto const& it : id) { if (delim) { tmp << ":"; } tmp << std::setw(2) << std::setfill('0') - << static_cast(*it); + << static_cast(it); delim = true; } return (tmp.str()); diff --git a/src/lib/dhcpsrv/network.cc b/src/lib/dhcpsrv/network.cc index 14770d5658..211caa0352 100644 --- a/src/lib/dhcpsrv/network.cc +++ b/src/lib/dhcpsrv/network.cc @@ -128,8 +128,8 @@ Network::toElement() const { ElementPtr relay_map = Element::createMap(); ElementPtr address_list = Element::createList(); const IOAddressList addresses = getRelayAddresses(); - for (auto address = addresses.begin(); address != addresses.end(); ++address) { - address_list->add(Element::create((*address).toText())); + for (auto const& address : addresses) { + address_list->add(Element::create(address.toText())); } relay_map->set("ip-addresses", address_list); @@ -144,9 +144,8 @@ Network::toElement() const { const ClientClasses& classes = getRequiredClasses(); if (!classes.empty()) { ElementPtr class_list = Element::createList(); - for (ClientClasses::const_iterator it = classes.cbegin(); - it != classes.cend(); ++it) { - class_list->add(Element::create(*it)); + for (auto const& it : classes) { + class_list->add(Element::create(it)); } map->set("require-client-classes", class_list); } diff --git a/src/lib/dhcpsrv/parsers/client_class_def_parser.cc b/src/lib/dhcpsrv/parsers/client_class_def_parser.cc index 0d04293f05..dc6a7aa938 100644 --- a/src/lib/dhcpsrv/parsers/client_class_def_parser.cc +++ b/src/lib/dhcpsrv/parsers/client_class_def_parser.cc @@ -16,7 +16,6 @@ #include #include -#include #include #include @@ -131,7 +130,7 @@ ClientClassDefParser::parse(ClientClassDictionaryPtr& class_dictionary, SimpleParser6::OPTION6_DEF_DEFAULTS); OptionDefParser parser(family); - BOOST_FOREACH(ConstElementPtr option_def, option_defs->listValue()) { + for (auto const& option_def : option_defs->listValue()) { OptionDefinitionPtr def = parser.parse(option_def); // Verify if the definition is for an option which is in a deferred @@ -346,8 +345,7 @@ ClientClassDictionaryPtr ClientClassDefListParser::parse(ConstElementPtr client_class_def_list, uint16_t family, bool check_dependencies) { ClientClassDictionaryPtr dictionary(new ClientClassDictionary()); - BOOST_FOREACH(ConstElementPtr client_class_def, - client_class_def_list->listValue()) { + for (auto const& client_class_def : client_class_def_list->listValue()) { ClientClassDefParser parser; parser.parse(dictionary, client_class_def, family, true, check_dependencies); } diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc index c064227362..e7fc071692 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc @@ -52,7 +52,7 @@ MACSourcesListConfigParser::parse(CfgMACSource& mac_sources, ConstElementPtr val // If user specified anything, we need to get rid of that default. mac_sources.clear(); - BOOST_FOREACH(ConstElementPtr source_elem, value->listValue()) { + for (auto const& source_elem : value->listValue()) { std::string source_str = source_elem->stringValue(); try { source = CfgMACSource::MACSourceFromText(source_str); @@ -204,11 +204,11 @@ OptionDefParser::parse(ConstElementPtr option_def) { isc::util::str::tokens(record_types, ","); // Iterate over each token and add a record type into // option definition. - BOOST_FOREACH(std::string record_type, record_tokens) { + for (auto const& record_type : record_tokens) { try { - boost::trim(record_type); - if (!record_type.empty()) { - def->addRecordField(record_type); + auto const trim_rec = boost::trim_copy(record_type); + if (!trim_rec.empty()) { + def->addRecordField(trim_rec); } } catch (const Exception& ex) { isc_throw(DhcpConfigError, "invalid record type values" @@ -246,7 +246,7 @@ OptionDefListParser::parse(CfgOptionDefPtr storage, ConstElementPtr option_def_l } OptionDefParser parser(address_family_); - BOOST_FOREACH(ConstElementPtr option_def, option_def_list->listValue()) { + for (auto const& option_def : option_def_list->listValue()) { OptionDefinitionPtr def = parser.parse(option_def); try { storage->add(def); @@ -304,7 +304,7 @@ RelayInfoParser::parse(const isc::dhcp::Network::RelayInfoPtr& relay_info, "(" << getPosition("ip-addresses", relay_elem) << ")"); } - BOOST_FOREACH(ConstElementPtr address_element, addresses->listValue()) { + for (auto const& address_element : addresses->listValue()) { addAddress("ip-addresses", address_element->stringValue(), relay_elem, relay_info); } @@ -505,22 +505,20 @@ PoolParser::parse(PoolStoragePtr pools, ConstElementPtr class_list = pool_structure->get("require-client-classes"); if (class_list) { const std::vector& classes = class_list->listValue(); - for (auto cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { - if (((*cclass)->getType() != Element::string) || - (*cclass)->stringValue().empty()) { + for (auto const& cclass : classes) { + if ((cclass->getType() != Element::string) || + cclass->stringValue().empty()) { isc_throw(DhcpConfigError, "invalid class name (" - << (*cclass)->getPosition() << ")"); + << cclass->getPosition() << ")"); } - pool->requireClientClass((*cclass)->stringValue()); + pool->requireClientClass(cclass->stringValue()); } } } boost::shared_ptr PoolParser::createOptionDataListParser(const uint16_t address_family) const { - auto parser = boost::make_shared(address_family); - return (parser); + return (boost::make_shared(address_family)); } //****************************** Pool4Parser ************************* @@ -540,16 +538,15 @@ Pool4Parser::poolMaker (IOAddress &min, IOAddress &max, int32_t) { void Pools4ListParser::parse(PoolStoragePtr pools, ConstElementPtr pools_list, bool encapsulate_options) { - BOOST_FOREACH(ConstElementPtr pool, pools_list->listValue()) { - auto parser = createPoolConfigParser(); + for (auto const& pool : pools_list->listValue()) { + auto const& parser = createPoolConfigParser(); parser->parse(pools, pool, AF_INET, encapsulate_options); } } boost::shared_ptr Pools4ListParser::createPoolConfigParser() const { - auto parser = boost::make_shared(); - return (parser); + return (boost::make_shared()); } //****************************** SubnetConfigParser ************************* @@ -682,8 +679,7 @@ SubnetConfigParser::createSubnet(ConstElementPtr params) { boost::shared_ptr SubnetConfigParser::createOptionDataListParser() const { - auto parser = boost::make_shared(address_family_); - return (parser); + return (boost::make_shared(address_family_)); } //****************************** Subnet4ConfigParser ************************* @@ -700,7 +696,7 @@ Subnet4ConfigParser::parse(ConstElementPtr subnet, bool encapsulate_options) { /// Parse Pools first. ConstElementPtr pools = subnet->get("pools"); if (pools) { - auto parser = createPoolsListParser(); + auto const& parser = createPoolsListParser(); parser->parse(pools_, pools, encapsulate_options); } @@ -731,9 +727,9 @@ Subnet4ConfigParser::parse(ConstElementPtr subnet, bool encapsulate_options) { HostCollection hosts; HostReservationsListParser parser; parser.parse(subnet_->getID(), reservations, hosts); - for (auto h = hosts.begin(); h != hosts.end(); ++h) { - validateResv(sn4ptr, *h); - CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(*h); + for (auto const& h : hosts) { + validateResv(sn4ptr, h); + CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(h); } } @@ -890,14 +886,13 @@ Subnet4ConfigParser::initSubnet(data::ConstElementPtr params, ConstElementPtr class_list = params->get("require-client-classes"); if (class_list) { const std::vector& classes = class_list->listValue(); - for (auto cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { - if (((*cclass)->getType() != Element::string) || - (*cclass)->stringValue().empty()) { + for (auto const& cclass : classes) { + if ((cclass->getType() != Element::string) || + cclass->stringValue().empty()) { isc_throw(DhcpConfigError, "invalid class name (" - << (*cclass)->getPosition() << ")"); + << cclass->getPosition() << ")"); } - subnet4->requireClientClass((*cclass)->stringValue()); + subnet4->requireClientClass(cclass->stringValue()); } } @@ -985,8 +980,7 @@ Subnet4ConfigParser::validateResv(const Subnet4Ptr& subnet, ConstHostPtr host) { boost::shared_ptr Subnet4ConfigParser::createPoolsListParser() const { - auto parser = boost::make_shared(); - return (parser); + return (boost::make_shared()); } //**************************** Subnets4ListConfigParser ********************** @@ -1000,9 +994,9 @@ Subnets4ListConfigParser::parse(SrvConfigPtr cfg, ConstElementPtr subnets_list, bool encapsulate_options) { size_t cnt = 0; - BOOST_FOREACH(ConstElementPtr subnet_json, subnets_list->listValue()) { + for (auto const& subnet_json : subnets_list->listValue()) { - auto parser = createSubnetConfigParser(); + auto const& parser = createSubnetConfigParser(); Subnet4Ptr subnet = parser->parse(subnet_json, encapsulate_options); if (subnet) { @@ -1026,9 +1020,9 @@ Subnets4ListConfigParser::parse(Subnet4Collection& subnets, data::ConstElementPtr subnets_list, bool encapsulate_options) { size_t cnt = 0; - BOOST_FOREACH(ConstElementPtr subnet_json, subnets_list->listValue()) { + for (auto const& subnet_json : subnets_list->listValue()) { - auto parser = createSubnetConfigParser(); + auto const& parser = createSubnetConfigParser(); Subnet4Ptr subnet = parser->parse(subnet_json, encapsulate_options); if (subnet) { try { @@ -1049,8 +1043,7 @@ Subnets4ListConfigParser::parse(Subnet4Collection& subnets, boost::shared_ptr Subnets4ListConfigParser::createSubnetConfigParser() const { - auto parser = boost::make_shared(check_iface_); - return (parser); + return (boost::make_shared(check_iface_)); } //**************************** Pool6Parser ********************************* @@ -1075,16 +1068,15 @@ Pool6Parser::poolMaker(IOAddress &min, IOAddress &max, int32_t ptype) void Pools6ListParser::parse(PoolStoragePtr pools, ConstElementPtr pools_list, bool encapsulate_options) { - BOOST_FOREACH(ConstElementPtr pool, pools_list->listValue()) { - auto parser = createPoolConfigParser(); + for (auto const& pool : pools_list->listValue()) { + auto const& parser = createPoolConfigParser(); parser->parse(pools, pool, AF_INET6, encapsulate_options); } } boost::shared_ptr Pools6ListParser::createPoolConfigParser() const { - auto parser = boost::make_shared(); - return (parser); + return (boost::make_shared()); } //**************************** PdPoolParser ****************************** @@ -1167,14 +1159,13 @@ PdPoolParser::parse(PoolStoragePtr pools, ConstElementPtr pd_pool_, if (class_list) { const std::vector& classes = class_list->listValue(); - for (auto cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { - if (((*cclass)->getType() != Element::string) || - (*cclass)->stringValue().empty()) { + for (auto const& cclass : classes) { + if ((cclass->getType() != Element::string) || + cclass->stringValue().empty()) { isc_throw(DhcpConfigError, "invalid class name (" - << (*cclass)->getPosition() << ")"); + << cclass->getPosition() << ")"); } - pool_->requireClientClass((*cclass)->stringValue()); + pool_->requireClientClass(cclass->stringValue()); } } @@ -1184,8 +1175,7 @@ PdPoolParser::parse(PoolStoragePtr pools, ConstElementPtr pd_pool_, boost::shared_ptr PdPoolParser::createOptionDataListParser() const { - auto parser = boost::make_shared(AF_INET6); - return (parser); + return (boost::make_shared(AF_INET6)); } //**************************** PdPoolsListParser ************************ @@ -1193,16 +1183,15 @@ PdPoolParser::createOptionDataListParser() const { void PdPoolsListParser::parse(PoolStoragePtr pools, ConstElementPtr pd_pool_list) { // Loop through the list of pd pools. - BOOST_FOREACH(ConstElementPtr pd_pool, pd_pool_list->listValue()) { - auto parser = createPdPoolConfigParser(); + for (auto const& pd_pool : pd_pool_list->listValue()) { + auto const& parser = createPdPoolConfigParser(); parser->parse(pools, pd_pool); } } boost::shared_ptr PdPoolsListParser::createPdPoolConfigParser() const { - auto parser = boost::make_shared(); - return (parser); + return (boost::make_shared()); } //**************************** Subnet6ConfigParser *********************** @@ -1219,12 +1208,12 @@ Subnet6ConfigParser::parse(ConstElementPtr subnet, bool encapsulate_options) { /// Parse all pools first. ConstElementPtr pools = subnet->get("pools"); if (pools) { - auto parser = createPoolsListParser(); + auto const& parser = createPoolsListParser(); parser->parse(pools_, pools, encapsulate_options); } ConstElementPtr pd_pools = subnet->get("pd-pools"); if (pd_pools) { - auto parser = createPdPoolsListParser(); + auto const& parser = createPdPoolsListParser(); parser->parse(pools_, pd_pools); } @@ -1255,9 +1244,9 @@ Subnet6ConfigParser::parse(ConstElementPtr subnet, bool encapsulate_options) { HostCollection hosts; HostReservationsListParser parser; parser.parse(subnet_->getID(), reservations, hosts); - for (auto h = hosts.begin(); h != hosts.end(); ++h) { - validateResvs(sn6ptr, *h); - CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(*h); + for (auto const& h : hosts) { + validateResvs(sn6ptr, h); + CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(h); } } @@ -1417,14 +1406,13 @@ Subnet6ConfigParser::initSubnet(data::ConstElementPtr params, ConstElementPtr class_list = params->get("require-client-classes"); if (class_list) { const std::vector& classes = class_list->listValue(); - for (auto cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { - if (((*cclass)->getType() != Element::string) || - (*cclass)->stringValue().empty()) { + for (auto const& cclass : classes) { + if ((cclass->getType() != Element::string) || + cclass->stringValue().empty()) { isc_throw(DhcpConfigError, "invalid class name (" - << (*cclass)->getPosition() << ")"); + << cclass->getPosition() << ")"); } - subnet6->requireClientClass((*cclass)->stringValue()); + subnet6->requireClientClass(cclass->stringValue()); } } } @@ -1444,9 +1432,9 @@ Subnet6ConfigParser::initSubnet(data::ConstElementPtr params, void Subnet6ConfigParser::validateResvs(const Subnet6Ptr& subnet, ConstHostPtr host) { - IPv6ResrvRange range = host->getIPv6Reservations(IPv6Resrv::TYPE_NA); - for (auto it = range.first; it != range.second; ++it) { - const IOAddress& address = it->second.getPrefix(); + const IPv6ResrvRange& range = host->getIPv6Reservations(IPv6Resrv::TYPE_NA); + BOOST_FOREACH(auto const& it, range) { + const IOAddress& address = it.second.getPrefix(); if (!subnet->inRange(address)) { isc_throw(DhcpConfigError, "specified reservation '" << address << "' is not within the IPv6 subnet '" @@ -1457,14 +1445,12 @@ Subnet6ConfigParser::validateResvs(const Subnet6Ptr& subnet, ConstHostPtr host) boost::shared_ptr Subnet6ConfigParser::createPoolsListParser() const { - auto parser = boost::make_shared(); - return (parser); + return (boost::make_shared()); } boost::shared_ptr Subnet6ConfigParser::createPdPoolsListParser() const { - auto parser = boost::make_shared(); - return (parser); + return (boost::make_shared()); } //**************************** Subnet6ListConfigParser ******************** @@ -1478,9 +1464,9 @@ Subnets6ListConfigParser::parse(SrvConfigPtr cfg, ConstElementPtr subnets_list, bool encapsulate_options) { size_t cnt = 0; - BOOST_FOREACH(ConstElementPtr subnet_json, subnets_list->listValue()) { + for (auto const& subnet_json : subnets_list->listValue()) { - auto parser = createSubnetConfigParser(); + auto const& parser = createSubnetConfigParser(); Subnet6Ptr subnet = parser->parse(subnet_json, encapsulate_options); // Adding a subnet to the Configuration Manager may fail if the @@ -1502,9 +1488,9 @@ Subnets6ListConfigParser::parse(Subnet6Collection& subnets, ConstElementPtr subnets_list, bool encapsulate_options) { size_t cnt = 0; - BOOST_FOREACH(ConstElementPtr subnet_json, subnets_list->listValue()) { + for (auto const& subnet_json : subnets_list->listValue()) { - auto parser = createSubnetConfigParser(); + auto const& parser = createSubnetConfigParser(); Subnet6Ptr subnet = parser->parse(subnet_json, encapsulate_options); if (subnet) { try { @@ -1525,8 +1511,7 @@ Subnets6ListConfigParser::parse(Subnet6Collection& subnets, boost::shared_ptr Subnets6ListConfigParser::createSubnetConfigParser() const { - auto parser = boost::make_shared(check_iface_); - return (parser); + return (boost::make_shared(check_iface_)); } //**************************** D2ClientConfigParser ********************** diff --git a/src/lib/dhcpsrv/parsers/dhcp_queue_control_parser.cc b/src/lib/dhcpsrv/parsers/dhcp_queue_control_parser.cc index e3bca0fff2..e9b4e1bd5b 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_queue_control_parser.cc +++ b/src/lib/dhcpsrv/parsers/dhcp_queue_control_parser.cc @@ -10,7 +10,6 @@ #include #include #include -#include #include #include diff --git a/src/lib/dhcpsrv/parsers/duid_config_parser.cc b/src/lib/dhcpsrv/parsers/duid_config_parser.cc index 937a542c0d..7082e04901 100644 --- a/src/lib/dhcpsrv/parsers/duid_config_parser.cc +++ b/src/lib/dhcpsrv/parsers/duid_config_parser.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/src/lib/dhcpsrv/parsers/expiration_config_parser.cc b/src/lib/dhcpsrv/parsers/expiration_config_parser.cc index 3bbe333860..52d9740e86 100644 --- a/src/lib/dhcpsrv/parsers/expiration_config_parser.cc +++ b/src/lib/dhcpsrv/parsers/expiration_config_parser.cc @@ -11,7 +11,6 @@ #include #include #include -#include using namespace isc::data; diff --git a/src/lib/dhcpsrv/parsers/host_reservation_parser.cc b/src/lib/dhcpsrv/parsers/host_reservation_parser.cc index ed89b3b5f2..f71fe9c9d2 100644 --- a/src/lib/dhcpsrv/parsers/host_reservation_parser.cc +++ b/src/lib/dhcpsrv/parsers/host_reservation_parser.cc @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -119,7 +118,7 @@ HostReservationParser::parseInternal(const SubnetID&, try { // Gather those parameters that are common for both IPv4 and IPv6 // reservations. - BOOST_FOREACH(auto const& element, reservation_data->mapValue()) { + for (auto const& element : reservation_data->mapValue()) { // Check if we support this parameter. if (!isSupportedParameter(element.first)) { isc_throw(DhcpConfigError, "unsupported configuration" @@ -148,7 +147,7 @@ HostReservationParser::parseInternal(const SubnetID&, // error message and include the information what identifiers // are supported. std::ostringstream s; - BOOST_FOREACH(std::string param_name, getSupportedParameters(true)) { + for (auto const& param_name : getSupportedParameters(true)) { if (s.tellp() != std::streampos(0)) { s << ", "; } @@ -196,7 +195,7 @@ HostReservationParser4::parseInternal(const SubnetID& subnet_id, host->setIPv4SubnetID(subnet_id); - BOOST_FOREACH(auto const& element, reservation_data->mapValue()) { + for (auto const& element : reservation_data->mapValue()) { // For 'option-data' element we will use another parser which // already returns errors with position appended, so don't // surround it with try-catch. @@ -209,8 +208,8 @@ HostReservationParser4::parseInternal(const SubnetID& subnet_id, OptionDataListParser parser(AF_INET); parser.parse(cfg_option, element.second, encapsulate_options); - // Everything else should be surrounded with try-catch to append - // position. + // Everything else should be surrounded with try-catch to append + // position. } else { try { if (element.first == "ip-address") { @@ -226,8 +225,7 @@ HostReservationParser4::parseInternal(const SubnetID& subnet_id, host->setBootFileName(element.second->stringValue()); } else if (element.first == "client-classes") { - BOOST_FOREACH(ConstElementPtr class_element, - element.second->listValue()) { + for (auto const& class_element : element.second->listValue()) { host->addClientClass4(class_element->stringValue()); } } @@ -257,7 +255,7 @@ HostReservationParser6::parseInternal(const SubnetID& subnet_id, host->setIPv6SubnetID(subnet_id); - BOOST_FOREACH(auto const& element, reservation_data->mapValue()) { + for (auto const& element : reservation_data->mapValue()) { // Parse option values. Note that the configuration option parser // returns errors with position information appended, so there is no // need to surround it with try-clause (and rethrow with position @@ -272,8 +270,7 @@ HostReservationParser6::parseInternal(const SubnetID& subnet_id, parser.parse(cfg_option, element.second, encapsulate_options); } else if (element.first == "ip-addresses" || element.first == "prefixes") { - BOOST_FOREACH(ConstElementPtr prefix_element, - element.second->listValue()) { + for (auto const& prefix_element : element.second->listValue()) { try { // For the IPv6 address the prefix length is 128 and the // value specified in the list is a reserved address. @@ -351,8 +348,7 @@ HostReservationParser6::parseInternal(const SubnetID& subnet_id, } else if (element.first == "client-classes") { try { - BOOST_FOREACH(ConstElementPtr class_element, - element.second->listValue()) { + for (auto const& class_element : element.second->listValue()) { host->addClientClass6(class_element->stringValue()); } } catch (const std::exception& ex) { @@ -385,7 +381,7 @@ HostReservationIdsParser::parseInternal(isc::data::ConstElementPtr ids_list) { // Remove existing identifier types. staging_cfg_->clearIdentifierTypes(); - BOOST_FOREACH(ConstElementPtr element, ids_list->listValue()) { + for (auto const& element : ids_list->listValue()) { std::string id_name = element->stringValue(); try { if (id_name != "auto") { diff --git a/src/lib/dhcpsrv/parsers/host_reservations_list_parser.h b/src/lib/dhcpsrv/parsers/host_reservations_list_parser.h index 9f6ce2f68f..fd857055e1 100644 --- a/src/lib/dhcpsrv/parsers/host_reservations_list_parser.h +++ b/src/lib/dhcpsrv/parsers/host_reservations_list_parser.h @@ -11,7 +11,6 @@ #include #include #include -#include namespace isc { namespace dhcp { @@ -39,7 +38,7 @@ public: void parse(const SubnetID& subnet_id, isc::data::ConstElementPtr hr_list, HostCollection& hosts_list) { HostCollection hosts; - BOOST_FOREACH(data::ConstElementPtr reservation, hr_list->listValue()) { + for (auto const& reservation : hr_list->listValue()) { HostReservationParserType parser; hosts.push_back(parser.parse(subnet_id, reservation)); } diff --git a/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc b/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc index c375b403c2..fee4484a65 100644 --- a/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc +++ b/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc @@ -9,7 +9,6 @@ #include #include #include -#include #include #include @@ -21,7 +20,7 @@ namespace dhcp { void IfacesConfigParser::parseInterfacesList(const CfgIfacePtr& cfg_iface, ConstElementPtr ifaces_list) { - BOOST_FOREACH(ConstElementPtr iface, ifaces_list->listValue()) { + for (auto const& iface : ifaces_list->listValue()) { std::string iface_name = iface->stringValue(); try { cfg_iface->use(protocol_, iface_name); @@ -50,7 +49,7 @@ IfacesConfigParser::parse(const CfgIfacePtr& cfg, } bool socket_type_specified = false; - BOOST_FOREACH(ConfigPair element, ifaces_config->mapValue()) { + for (auto const& element : ifaces_config->mapValue()) { try { if (element.first == "re-detect") { continue; diff --git a/src/lib/dhcpsrv/parsers/option_data_parser.cc b/src/lib/dhcpsrv/parsers/option_data_parser.cc index 6a321cde6d..87d98d92b1 100644 --- a/src/lib/dhcpsrv/parsers/option_data_parser.cc +++ b/src/lib/dhcpsrv/parsers/option_data_parser.cc @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -458,7 +457,7 @@ void OptionDataListParser::parse(const CfgOptionPtr& cfg, isc::data::ConstElementPtr option_data_list, bool encapsulate) { auto option_parser = createOptionDataParser(); - BOOST_FOREACH(ConstElementPtr data, option_data_list->listValue()) { + for (auto const& data : option_data_list->listValue()) { std::pair option = option_parser->parse(data); // Use the option description to keep the formatted value diff --git a/src/lib/dhcpsrv/parsers/shared_network_parser.cc b/src/lib/dhcpsrv/parsers/shared_network_parser.cc index ef9cc1dc00..ed196f4bfa 100644 --- a/src/lib/dhcpsrv/parsers/shared_network_parser.cc +++ b/src/lib/dhcpsrv/parsers/shared_network_parser.cc @@ -88,9 +88,8 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data, parser->parse(subnets, json); // Add all returned subnets into shared network. - for (auto subnet = subnets.cbegin(); subnet != subnets.cend(); - ++subnet) { - shared_network->add(*subnet); + for (auto const& subnet : subnets) { + shared_network->add(subnet); } } @@ -170,14 +169,13 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data, if (shared_network_data->contains("require-client-classes")) { const std::vector& class_list = shared_network_data->get("require-client-classes")->listValue(); - for (auto cclass = class_list.cbegin(); - cclass != class_list.cend(); ++cclass) { - if (((*cclass)->getType() != Element::string) || - (*cclass)->stringValue().empty()) { + for (auto const& cclass : class_list) { + if ((cclass->getType() != Element::string) || + cclass->stringValue().empty()) { isc_throw(DhcpConfigError, "invalid class name (" - << (*cclass)->getPosition() << ")"); + << cclass->getPosition() << ")"); } - shared_network->requireClientClass((*cclass)->stringValue()); + shared_network->requireClientClass(cclass->stringValue()); } } @@ -344,14 +342,13 @@ SharedNetwork6Parser::parse(const data::ConstElementPtr& shared_network_data, if (shared_network_data->contains("require-client-classes")) { const std::vector& class_list = shared_network_data->get("require-client-classes")->listValue(); - for (auto cclass = class_list.cbegin(); - cclass != class_list.cend(); ++cclass) { - if (((*cclass)->getType() != Element::string) || - (*cclass)->stringValue().empty()) { + for (auto const& cclass : class_list) { + if ((cclass->getType() != Element::string) || + cclass->stringValue().empty()) { isc_throw(DhcpConfigError, "invalid class name (" - << (*cclass)->getPosition() << ")"); + << cclass->getPosition() << ")"); } - shared_network->requireClientClass((*cclass)->stringValue()); + shared_network->requireClientClass(cclass->stringValue()); } } @@ -364,9 +361,8 @@ SharedNetwork6Parser::parse(const data::ConstElementPtr& shared_network_data, parser->parse(subnets, json); // Add all returned subnets into shared network. - for (auto subnet = subnets.cbegin(); subnet != subnets.cend(); - ++subnet) { - shared_network->add(*subnet); + for (auto const& subnet : subnets) { + shared_network->add(subnet); } } diff --git a/src/lib/dhcpsrv/parsers/shared_networks_list_parser.h b/src/lib/dhcpsrv/parsers/shared_networks_list_parser.h index 5f49c8b097..3705ad224c 100644 --- a/src/lib/dhcpsrv/parsers/shared_networks_list_parser.h +++ b/src/lib/dhcpsrv/parsers/shared_networks_list_parser.h @@ -57,10 +57,9 @@ public: const std::vector& networks_list = shared_networks_list_data->listValue(); // Iterate over all networks and do the parsing. - for (auto network_element = networks_list.cbegin(); - network_element != networks_list.cend(); ++network_element) { + for (auto const& network_element : networks_list) { SharedNetworkParserType parser(check_iface_); - auto network = parser.parse(*network_element); + auto network = parser.parse(network_element); cfg->add(network); } } catch (const DhcpConfigError&) { diff --git a/src/lib/dhcpsrv/parsers/simple_parser4.cc b/src/lib/dhcpsrv/parsers/simple_parser4.cc index ce16628fbd..a7b12ead29 100644 --- a/src/lib/dhcpsrv/parsers/simple_parser4.cc +++ b/src/lib/dhcpsrv/parsers/simple_parser4.cc @@ -8,7 +8,6 @@ #include #include -#include #include using namespace isc::data; @@ -428,7 +427,7 @@ size_t SimpleParser4::setAllDefaults(ElementPtr global) { // Now set option definition defaults for each specified option definition ConstElementPtr option_defs = global->get("option-def"); if (option_defs) { - BOOST_FOREACH(ElementPtr option_def, option_defs->listValue()) { + for (auto const& option_def : option_defs->listValue()) { cnt += SimpleParser::setDefaults(option_def, OPTION4_DEF_DEFAULTS); } } @@ -455,7 +454,7 @@ size_t SimpleParser4::setAllDefaults(ElementPtr global) { // Set defaults for shared networks ConstElementPtr shared = global->get("shared-networks"); if (shared) { - BOOST_FOREACH(ElementPtr net, shared->listValue()) { + for (auto const& net : shared->listValue()) { cnt += setDefaults(net, SHARED_NETWORK4_DEFAULTS); @@ -512,7 +511,7 @@ size_t SimpleParser4::deriveParameters(ElementPtr global) { // Now derive global parameters into subnets. ConstElementPtr subnets = global->get("subnet4"); if (subnets) { - BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) { + for (auto const& single_subnet : subnets->listValue()) { cnt += SimpleParser::deriveParams(global, single_subnet, INHERIT_TO_SUBNET4); } @@ -523,7 +522,7 @@ size_t SimpleParser4::deriveParameters(ElementPtr global) { // subnets within derive from it. ConstElementPtr shared = global->get("shared-networks"); if (shared) { - BOOST_FOREACH(ElementPtr net, shared->listValue()) { + for (auto const& net : shared->listValue()) { // First try to inherit the parameters from shared network, // if defined there. // Then try to inherit them from global. @@ -533,7 +532,7 @@ size_t SimpleParser4::deriveParameters(ElementPtr global) { // Now we need to go thrugh all the subnets in this net. subnets = net->get("subnet4"); if (subnets) { - BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) { + for (auto const& single_subnet : subnets->listValue()) { cnt += SimpleParser::deriveParams(net, single_subnet, INHERIT_TO_SUBNET4); } diff --git a/src/lib/dhcpsrv/parsers/simple_parser6.cc b/src/lib/dhcpsrv/parsers/simple_parser6.cc index accde74d33..2c9c98f50f 100644 --- a/src/lib/dhcpsrv/parsers/simple_parser6.cc +++ b/src/lib/dhcpsrv/parsers/simple_parser6.cc @@ -9,8 +9,6 @@ #include #include -#include - using namespace isc::data; namespace isc { @@ -442,7 +440,7 @@ size_t SimpleParser6::setAllDefaults(ElementPtr global) { // Now set the defaults for each specified option definition ConstElementPtr option_defs = global->get("option-def"); if (option_defs) { - BOOST_FOREACH(ElementPtr option_def, option_defs->listValue()) { + for (auto const& option_def : option_defs->listValue()) { cnt += SimpleParser::setDefaults(option_def, OPTION6_DEF_DEFAULTS); } } @@ -450,7 +448,7 @@ size_t SimpleParser6::setAllDefaults(ElementPtr global) { // Set the defaults for option data ConstElementPtr options = global->get("option-data"); if (options) { - BOOST_FOREACH(ElementPtr single_option, options->listValue()) { + for (auto const& single_option : options->listValue()) { cnt += SimpleParser::setDefaults(single_option, OPTION6_DEFAULTS); } } @@ -471,7 +469,7 @@ size_t SimpleParser6::setAllDefaults(ElementPtr global) { // Set defaults for shared networks ConstElementPtr shared = global->get("shared-networks"); if (shared) { - BOOST_FOREACH(ElementPtr net, shared->listValue()) { + for (auto const& net : shared->listValue()) { cnt += setDefaults(net, SHARED_NETWORK6_DEFAULTS); @@ -528,7 +526,7 @@ size_t SimpleParser6::deriveParameters(ElementPtr global) { // Now derive global parameters into subnets. ConstElementPtr subnets = global->get("subnet6"); if (subnets) { - BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) { + for (auto const& single_subnet : subnets->listValue()) { cnt += SimpleParser::deriveParams(global, single_subnet, INHERIT_TO_SUBNET6); } @@ -539,7 +537,7 @@ size_t SimpleParser6::deriveParameters(ElementPtr global) { // subnets within derive from it. ConstElementPtr shared = global->get("shared-networks"); if (shared) { - BOOST_FOREACH(ElementPtr net, shared->listValue()) { + for (auto const& net : shared->listValue()) { // First try to inherit the parameters from shared network, // if defined there. // Then try to inherit them from global. @@ -549,7 +547,7 @@ size_t SimpleParser6::deriveParameters(ElementPtr global) { // Now we need to go thrugh all the subnets in this net. subnets = net->get("subnet6"); if (subnets) { - BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) { + for (auto const& single_subnet : subnets->listValue()) { cnt += SimpleParser::deriveParams(net, single_subnet, INHERIT_TO_SUBNET6); } diff --git a/src/lib/dhcpsrv/pgsql_host_data_source.cc b/src/lib/dhcpsrv/pgsql_host_data_source.cc index 6a88942bdc..ffe2461f1f 100644 --- a/src/lib/dhcpsrv/pgsql_host_data_source.cc +++ b/src/lib/dhcpsrv/pgsql_host_data_source.cc @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -2556,11 +2557,11 @@ PgSqlHostDataSourceImpl::addOptions(PgSqlHostContextPtr& ctx, // For each option space retrieve all options and insert them into the // database. - for (auto space = option_spaces.begin(); space != option_spaces.end(); ++space) { - OptionContainerPtr options = options_cfg->getAllCombined(*space); + for (auto const& space : option_spaces) { + OptionContainerPtr options = options_cfg->getAllCombined(space); if (options && !options->empty()) { - for (auto opt = options->begin(); opt != options->end(); ++opt) { - addOption(ctx, stindex, *opt, *space, Optional(), host_id); + for (auto const& opt : *options) { + addOption(ctx, stindex, opt, space, Optional(), host_id); } } } @@ -2709,9 +2710,8 @@ PgSqlHostDataSource::add(const HostPtr& host) { // Insert IPv6 reservations. IPv6ResrvRange v6resv = host->getIPv6Reservations(); if (std::distance(v6resv.first, v6resv.second) > 0) { - for (IPv6ResrvIterator resv = v6resv.first; resv != v6resv.second; - ++resv) { - impl_->addResv(ctx, resv->second, host_id); + BOOST_FOREACH(auto const& resv, v6resv) { + impl_->addResv(ctx, resv.second, host_id); } } diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.cc b/src/lib/dhcpsrv/pgsql_lease_mgr.cc index 01718d9b5b..c32d9738e6 100644 --- a/src/lib/dhcpsrv/pgsql_lease_mgr.cc +++ b/src/lib/dhcpsrv/pgsql_lease_mgr.cc @@ -3205,13 +3205,12 @@ idToText(const OptionBuffer& id) { std::stringstream tmp; tmp << std::hex; bool delim = false; - for (std::vector::const_iterator it = id.begin(); - it != id.end(); ++it) { + for (auto const& it : id) { if (delim) { tmp << ":"; } tmp << std::setw(2) << std::setfill('0') - << static_cast(*it); + << static_cast(it); delim = true; } return (tmp.str()); diff --git a/src/lib/dhcpsrv/pool.cc b/src/lib/dhcpsrv/pool.cc index 2a47333a34..876038ae17 100644 --- a/src/lib/dhcpsrv/pool.cc +++ b/src/lib/dhcpsrv/pool.cc @@ -125,9 +125,8 @@ Pool::toElement() const { const ClientClasses& classes = getRequiredClasses(); if (!classes.empty()) { ElementPtr class_list = Element::createList(); - for (ClientClasses::const_iterator it = classes.cbegin(); - it != classes.cend(); ++it) { - class_list->add(Element::create(*it)); + for (auto const& it : classes) { + class_list->add(Element::create(it)); } map->set("require-client-classes", class_list); } diff --git a/src/lib/dhcpsrv/shared_network.cc b/src/lib/dhcpsrv/shared_network.cc index 1580b18d1f..f7a72e1382 100644 --- a/src/lib/dhcpsrv/shared_network.cc +++ b/src/lib/dhcpsrv/shared_network.cc @@ -303,15 +303,15 @@ public: const Lease::Type& lease_type) { auto preferred_subnet = selected_subnet; - for (auto s = subnets.begin(); s != subnets.end(); ++s) { + for (auto const& s : subnets) { // It doesn't make sense to check the subnet against itself. - if (preferred_subnet == (*s)) { + if (preferred_subnet == s) { continue; } - if ((*s)->getClientClass().get() != selected_subnet->getClientClass().get()) { + if (s->getClientClass().get() != selected_subnet->getClientClass().get()) { continue; } - auto current_subnet_state = (*s)->getAllocationState(lease_type); + auto current_subnet_state = s->getAllocationState(lease_type); if (!current_subnet_state) { continue; } @@ -324,7 +324,7 @@ public: // instance. if (current_subnet_state->getLastAllocatedTime() > preferred_subnet_state->getLastAllocatedTime()) { - preferred_subnet = (*s); + preferred_subnet = s; } } return (preferred_subnet); @@ -378,9 +378,9 @@ SharedNetwork4::del(const SubnetID& subnet_id) { void SharedNetwork4::delAll() { - for (auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) { - (*subnet)->setSharedNetwork(NetworkPtr()); - (*subnet)->setSharedNetworkName(""); + for (auto const& subnet : subnets_) { + subnet->setSharedNetwork(NetworkPtr()); + subnet->setSharedNetworkName(""); } subnets_.clear(); } @@ -429,8 +429,8 @@ SharedNetwork4::toElement() const { } ElementPtr subnet4 = Element::createList(); - for (auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) { - subnet4->add((*subnet)->toElement()); + for (auto const& subnet : subnets_) { + subnet4->add(subnet->toElement()); } map->set("subnet4", subnet4); @@ -480,8 +480,8 @@ SharedNetwork6::del(const SubnetID& subnet_id) { void SharedNetwork6::delAll() { - for (auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) { - (*subnet)->setSharedNetwork(NetworkPtr()); + for (auto const& subnet : subnets_) { + subnet->setSharedNetwork(NetworkPtr()); } subnets_.clear(); } @@ -518,8 +518,8 @@ SharedNetwork6::toElement() const { } ElementPtr subnet6 = Element::createList(); - for (auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) { - subnet6->add((*subnet)->toElement()); + for (auto const& subnet : subnets_) { + subnet6->add(subnet->toElement()); } map->set("subnet6", subnet6); diff --git a/src/lib/dhcpsrv/srv_config.cc b/src/lib/dhcpsrv/srv_config.cc index a07f964fee..ab6ee72168 100644 --- a/src/lib/dhcpsrv/srv_config.cc +++ b/src/lib/dhcpsrv/srv_config.cc @@ -134,9 +134,8 @@ SrvConfig::copy(SrvConfig& new_config) const { // Replace configured hooks libraries. new_config.hooks_config_.clear(); using namespace isc::hooks; - for (HookLibsCollection::const_iterator it = hooks_config_.get().begin(); - it != hooks_config_.get().end(); ++it) { - new_config.hooks_config_.add(it->first, it->second); + for (auto const& it : hooks_config_.get()) { + new_config.hooks_config_.add(it.first, it.second); } } @@ -401,10 +400,10 @@ SrvConfig::extractConfiguredGlobals(isc::data::ConstElementPtr config) { } const std::map& values = config->mapValue(); - for (auto value = values.begin(); value != values.end(); ++value) { - if (value->second->getType() != Element::list && - value->second->getType() != Element::map) { - addConfiguredGlobal(value->first, value->second); + for (auto const& value : values) { + if (value.second->getType() != Element::list && + value.second->getType() != Element::map) { + addConfiguredGlobal(value.first, value.second); } } } @@ -688,15 +687,14 @@ SrvConfig::toElement() const { // Get plain subnets ElementPtr plain_subnets = Element::createList(); const Subnet4Collection* subnets = cfg_subnets4_->getAll(); - for (Subnet4Collection::const_iterator subnet = subnets->cbegin(); - subnet != subnets->cend(); ++subnet) { + for (auto const& subnet : *subnets) { // Skip subnets which are in a shared-network SharedNetwork4Ptr network; - (*subnet)->getSharedNetwork(network); + subnet->getSharedNetwork(network); if (network) { continue; } - ElementPtr subnet_cfg = (*subnet)->toElement(); + ElementPtr subnet_cfg = subnet->toElement(); sn_list.push_back(subnet_cfg); plain_subnets->add(subnet_cfg); } @@ -708,13 +706,11 @@ SrvConfig::toElement() const { // Get subnets in shared network subnet lists const std::vector networks = shared_networks->listValue(); - for (auto network = networks.cbegin(); - network != networks.cend(); ++network) { + for (auto const& network : networks) { const std::vector sh_list = - (*network)->get("subnet4")->listValue(); - for (auto subnet = sh_list.cbegin(); - subnet != sh_list.cend(); ++subnet) { - sn_list.push_back(*subnet); + network->get("subnet4")->listValue(); + for (auto const& subnet : sh_list) { + sn_list.push_back(subnet); } } @@ -722,15 +718,14 @@ SrvConfig::toElement() const { // Get plain subnets ElementPtr plain_subnets = Element::createList(); const Subnet6Collection* subnets = cfg_subnets6_->getAll(); - for (Subnet6Collection::const_iterator subnet = subnets->cbegin(); - subnet != subnets->cend(); ++subnet) { + for (auto const& subnet : *subnets) { // Skip subnets which are in a shared-network SharedNetwork6Ptr network; - (*subnet)->getSharedNetwork(network); + subnet->getSharedNetwork(network); if (network) { continue; } - ElementPtr subnet_cfg = (*subnet)->toElement(); + ElementPtr subnet_cfg = subnet->toElement(); sn_list.push_back(subnet_cfg); plain_subnets->add(subnet_cfg); } @@ -742,13 +737,11 @@ SrvConfig::toElement() const { // Get subnets in shared network subnet lists const std::vector networks = shared_networks->listValue(); - for (auto network = networks.cbegin(); - network != networks.cend(); ++network) { + for (auto const& network : networks) { const std::vector sh_list = - (*network)->get("subnet6")->listValue(); - for (auto subnet = sh_list.cbegin(); - subnet != sh_list.cend(); ++subnet) { - sn_list.push_back(*subnet); + network->get("subnet6")->listValue(); + for (auto const& subnet : sh_list) { + sn_list.push_back(subnet); } } } @@ -764,15 +757,14 @@ SrvConfig::toElement() const { } // Insert subnet reservations - for (std::vector::const_iterator subnet = sn_list.cbegin(); - subnet != sn_list.cend(); ++subnet) { - ConstElementPtr id = (*subnet)->get("id"); + for (auto const& subnet : sn_list) { + ConstElementPtr id = subnet->get("id"); if (isNull(id)) { isc_throw(ToElementError, "subnet has no id"); } SubnetID subnet_id = id->intValue(); ConstElementPtr resvs = resv_list.get(subnet_id); - (*subnet)->set("reservations", resvs); + subnet->set("reservations", resvs); } // Set expired-leases-processing diff --git a/src/lib/dhcpsrv/tests/alloc_engine_utils.cc b/src/lib/dhcpsrv/tests/alloc_engine_utils.cc index 0823bb3451..700d925d88 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine_utils.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine_utils.cc @@ -277,18 +277,18 @@ AllocEngine6Test::allocateTest(AllocEngine& engine, const Pool6Ptr& pool, findReservation(engine, ctx); EXPECT_NO_THROW(leases = engine.allocateLeases6(ctx)); - for (Lease6Collection::iterator it = leases.begin(); it != leases.end(); ++it) { + for (auto const& it : leases) { // Do all checks on the lease - checkLease6(duid_, *it, type, expected_len, in_pool, in_pool); + checkLease6(duid_, it, type, expected_len, in_pool, in_pool); // Check that context has been updated with allocated addresses or // prefixes. - checkAllocatedResources(*it, ctx); + checkAllocatedResources(it, ctx); // Check that the lease is indeed in LeaseMgr Lease6Ptr from_mgr = LeaseMgrFactory::instance().getLease6(type, - (*it)->addr_); + it->addr_); if (!fake) { // This is a real (REQUEST) allocation, the lease must be in the DB EXPECT_TRUE(from_mgr) << "Lease " << from_mgr->addr_.toText() @@ -299,7 +299,7 @@ AllocEngine6Test::allocateTest(AllocEngine& engine, const Pool6Ptr& pool, } // Now check that the lease in LeaseMgr has the same parameters - detailCompareLease(*it, from_mgr); + detailCompareLease(it, from_mgr); } else { // This is a fake (SOLICIT) allocation, the lease must not be in DB EXPECT_FALSE(from_mgr) << "Lease " << from_mgr->addr_.toText() @@ -459,18 +459,18 @@ AllocEngine6Test::renewTest(AllocEngine& engine, const Pool6Ptr& pool, findReservation(engine, ctx); Lease6Collection leases = engine.renewLeases6(ctx); - for (Lease6Collection::iterator it = leases.begin(); it != leases.end(); ++it) { + for (auto const& it : leases) { // Do all checks on the lease - checkLease6(duid_, *it, type, expected_len, in_subnet, in_pool); + checkLease6(duid_, it, type, expected_len, in_subnet, in_pool); // Check that context has been updated with allocated addresses or // prefixes. - checkAllocatedResources(*it, ctx); + checkAllocatedResources(it, ctx); // Check that the lease is indeed in LeaseMgr Lease6Ptr from_mgr = LeaseMgrFactory::instance().getLease6(type, - (*it)->addr_); + it->addr_); // This is a real (REQUEST) allocation, the lease must be in the DB EXPECT_TRUE(from_mgr) << "Lease " << from_mgr->addr_.toText() @@ -481,7 +481,7 @@ AllocEngine6Test::renewTest(AllocEngine& engine, const Pool6Ptr& pool, } // Now check that the lease in LeaseMgr has the same parameters - detailCompareLease(*it, from_mgr); + detailCompareLease(it, from_mgr); } return (leases); diff --git a/src/lib/dhcpsrv/tests/cb_ctl_dhcp_unittest.cc b/src/lib/dhcpsrv/tests/cb_ctl_dhcp_unittest.cc index 15b0c97f3f..2ceacdd85c 100644 --- a/src/lib/dhcpsrv/tests/cb_ctl_dhcp_unittest.cc +++ b/src/lib/dhcpsrv/tests/cb_ctl_dhcp_unittest.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -176,8 +177,8 @@ public: if (!audit_entries_.empty()) { auto const& index = audit_entries_.get(); auto range = index.equal_range(object_type); - for (auto it = range.first; it != range.second; ++it) { - if (((*it)->getModificationType() != AuditEntry::ModificationType::DELETE)) { + BOOST_FOREACH(auto const& it, range) { + if (it->getModificationType() != AuditEntry::ModificationType::DELETE) { return (true); } } @@ -198,8 +199,8 @@ public: auto const& index = audit_entries_.get(); auto range = index.equal_range(boost::make_tuple(object_type, AuditEntry::ModificationType::DELETE)); - for (auto it = range.first; it != range.second; ++it) { - if ((*it)->getObjectId() == object_id) { + BOOST_FOREACH(auto const& it, range) { + if (it->getObjectId() == object_id) { return (true); } } diff --git a/src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc b/src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc index 58c0d03a4f..177339508a 100644 --- a/src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc @@ -475,9 +475,8 @@ TEST_F(CfgHostsTest, getAll4ByAddress) { HostCollection hosts = cfg.getAll4(IOAddress("192.0.2.10")); std::set subnet_ids; - for (HostCollection::const_iterator host = hosts.begin(); host != hosts.end(); - ++host) { - subnet_ids.insert((*host)->getIPv4SubnetID()); + for (auto const& host : hosts) { + subnet_ids.insert(host->getIPv4SubnetID()); } ASSERT_EQ(25, subnet_ids.size()); EXPECT_EQ(1, *subnet_ids.begin()); @@ -726,9 +725,8 @@ TEST_F(CfgHostsTest, deleteAll4) { // Get all inserted hosts. HostCollection hosts = cfg.getAll4(IOAddress::IPV4_ZERO_ADDRESS()); std::set subnet_ids; - for (HostCollection::const_iterator host = hosts.begin(); host != hosts.end(); - ++host) { - subnet_ids.insert((*host)->getIPv4SubnetID()); + for (auto const& host : hosts) { + subnet_ids.insert(host->getIPv4SubnetID()); } // Make sure there are two unique subnets: 1 and 2. ASSERT_EQ(2, subnet_ids.size()); @@ -741,9 +739,8 @@ TEST_F(CfgHostsTest, deleteAll4) { // Gather the host counts again. subnet_ids.clear(); hosts = cfg.getAll4(IOAddress::IPV4_ZERO_ADDRESS()); - for (HostCollection::const_iterator host = hosts.begin(); host != hosts.end(); - ++host) { - subnet_ids.insert((*host)->getIPv4SubnetID()); + for (auto const& host : hosts) { + subnet_ids.insert(host->getIPv4SubnetID()); } // We should only have hosts for one subnet and it should be the subnet // with ID of 1. diff --git a/src/lib/dhcpsrv/tests/cfg_option_def_unittest.cc b/src/lib/dhcpsrv/tests/cfg_option_def_unittest.cc index e79817317b..9dc92341cb 100644 --- a/src/lib/dhcpsrv/tests/cfg_option_def_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_option_def_unittest.cc @@ -94,11 +94,11 @@ TEST(CfgOptionDefTest, getAllThenDelete) { // valid codes. Also, their order should be the same as they // were added (codes 100-109). uint16_t code = 100; - for (OptionDefContainer::const_iterator it = option_defs1->begin(); - it != option_defs1->end(); ++it, ++code) { - OptionDefinitionPtr def(*it); + for (auto const& it : *option_defs1) { + OptionDefinitionPtr def(it); ASSERT_TRUE(def); EXPECT_EQ(code, def->getCode()); + ++code; } // Sanity check that all 10 option definitions are there. @@ -108,11 +108,11 @@ TEST(CfgOptionDefTest, getAllThenDelete) { // Check that the option codes are valid. code = 105; - for (OptionDefContainer::const_iterator it = option_defs2->begin(); - it != option_defs2->end(); ++it, ++code) { - OptionDefinitionPtr def(*it); + for (auto const& it : *option_defs2) { + OptionDefinitionPtr def(it); ASSERT_TRUE(def); EXPECT_EQ(code, def->getCode()); + ++code; } // Let's make one more check that the empty set is returned when diff --git a/src/lib/dhcpsrv/tests/cfg_option_unittest.cc b/src/lib/dhcpsrv/tests/cfg_option_unittest.cc index ab3c1de824..55b0995c09 100644 --- a/src/lib/dhcpsrv/tests/cfg_option_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_option_unittest.cc @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -278,10 +277,9 @@ TEST_F(CfgOptionTest, add) { // Validate codes of options added to dhcp6 option space. uint16_t expected_code = 100; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } @@ -292,10 +290,9 @@ TEST_F(CfgOptionTest, add) { // Validate codes of options added to isc option space. expected_code = 105; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } @@ -720,8 +717,7 @@ TEST_F(CfgOptionTest, encapsulate) { ASSERT_EQ(19, first_level.size()); // Iterate over all first level sub-options. - std::pair first_level_opt; - BOOST_FOREACH(first_level_opt, first_level) { + for (auto const& first_level_opt : first_level) { // Each option in this test comprises a single one byte field and // should cast to OptionUint8 type. OptionUint8Ptr first_level_uint8 = boost::dynamic_pointer_cast< @@ -744,8 +740,7 @@ TEST_F(CfgOptionTest, encapsulate) { // Iterate over sub-options and make sure they include the expected // values. - std::pair second_level_opt; - BOOST_FOREACH(second_level_opt, second_level) { + for (auto const& second_level_opt : second_level) { OptionUint8Ptr second_level_uint8 = boost::dynamic_pointer_cast< OptionUint8>(second_level_opt.second); ASSERT_TRUE(second_level_uint8); @@ -1060,10 +1055,9 @@ TEST_F(CfgOptionTest, addNonUniqueOptions) { // have been returned for the particular code. ASSERT_EQ(2, distance(range.first, range.second)); // Check that returned options actually have the expected option code. - for (OptionContainerTypeIndex::const_iterator option_desc = range.first; - option_desc != range.second; ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(code, option_desc->option_->getType()); + BOOST_FOREACH(auto const& option_desc, range) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(code, option_desc.option_->getType()); } } @@ -1186,10 +1180,9 @@ TEST_F(CfgOptionTest, addVendorOptions) { // Validate codes of options added to dhcp6 option space. uint16_t expected_code = 100; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } @@ -1199,10 +1192,9 @@ TEST_F(CfgOptionTest, addVendorOptions) { // Validate codes of options added to isc option space. expected_code = 105; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } @@ -1236,13 +1228,12 @@ TEST_F(CfgOptionTest, getVendorIdsSpaceNames) { ASSERT_EQ(10, space_names.size()); // Check that the option space names for those vendor ids are correct. - for (std::list::iterator name = space_names.begin(); - name != space_names.end(); ++name) { - uint16_t id = static_cast(std::distance(space_names.begin(), - name)); + size_t id = 0; + for (auto const& name : space_names) { std::ostringstream s; s << "vendor-" << (100 + id); - EXPECT_EQ(s.str(), *name); + EXPECT_EQ(s.str(), name); + id++; } } diff --git a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc index d10fd8ee5e..dfe3ce4c13 100644 --- a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -122,29 +123,29 @@ TEST(CfgSubnets4Test, getSpecificSubnet) { subnets.push_back(subnet3); // Add all subnets to the configuration. - for (auto subnet = subnets.cbegin(); subnet != subnets.cend(); ++subnet) { - ASSERT_NO_THROW(cfg.add(*subnet)) << "failed to add subnet with id: " - << (*subnet)->getID(); + for (auto const& subnet : subnets) { + ASSERT_NO_THROW(cfg.add(subnet)) << "failed to add subnet with id: " + << subnet->getID(); } // Iterate over all subnets and make sure they can be retrieved by // subnet identifier. - for (auto subnet = subnets.rbegin(); subnet != subnets.rend(); ++subnet) { - ConstSubnet4Ptr subnet_returned = cfg.getBySubnetId((*subnet)->getID()); + for (auto const& subnet : boost::adaptors::reverse(subnets)) { + ConstSubnet4Ptr subnet_returned = cfg.getBySubnetId(subnet->getID()); ASSERT_TRUE(subnet_returned) << "failed to return subnet with id: " - << (*subnet)->getID(); - EXPECT_EQ((*subnet)->getID(), subnet_returned->getID()); - EXPECT_EQ((*subnet)->toText(), subnet_returned->toText()); + << subnet->getID(); + EXPECT_EQ(subnet->getID(), subnet_returned->getID()); + EXPECT_EQ(subnet->toText(), subnet_returned->toText()); } // Repeat the previous test, but this time retrieve subnets by their // prefixes. - for (auto subnet = subnets.rbegin(); subnet != subnets.rend(); ++subnet) { - ConstSubnet4Ptr subnet_returned = cfg.getByPrefix((*subnet)->toText()); + for (auto const& subnet : boost::adaptors::reverse(subnets)) { + ConstSubnet4Ptr subnet_returned = cfg.getByPrefix(subnet->toText()); ASSERT_TRUE(subnet_returned) << "failed to return subnet with id: " - << (*subnet)->getID(); - EXPECT_EQ((*subnet)->getID(), subnet_returned->getID()); - EXPECT_EQ((*subnet)->toText(), subnet_returned->toText()); + << subnet->getID(); + EXPECT_EQ(subnet->getID(), subnet_returned->getID()); + EXPECT_EQ(subnet->toText(), subnet_returned->toText()); } // Make sure that null pointers are returned for non-existing subnets. @@ -1368,14 +1369,14 @@ TEST(CfgSubnets4Test, teeTimePercentValidation) { // Iterate over the test scenarios, verifying each prescribed // outcome. - for (auto test = tests.begin(); test != tests.end(); ++test) { + for (auto const& test : tests) { { - SCOPED_TRACE("test: " + (*test).label); + SCOPED_TRACE("test: " + test.label); // Set this scenario's configuration parameters - elems->set("calculate-tee-times", data::Element::create((*test).calculate_tee_times)); - elems->set("t1-percent", data::Element::create((*test).t1_percent)); - elems->set("t2-percent", data::Element::create((*test).t2_percent)); + elems->set("calculate-tee-times", data::Element::create(test.calculate_tee_times)); + elems->set("t1-percent", data::Element::create(test.t1_percent)); + elems->set("t2-percent", data::Element::create(test.t2_percent)); Subnet4Ptr subnet; try { @@ -1383,9 +1384,9 @@ TEST(CfgSubnets4Test, teeTimePercentValidation) { Subnet4ConfigParser parser; subnet = parser.parse(elems); } catch (const std::exception& ex) { - if (!(*test).error_message.empty()) { + if (!test.error_message.empty()) { // We expected a failure, did we fail the correct way? - EXPECT_EQ((*test).error_message, ex.what()); + EXPECT_EQ(test.error_message, ex.what()); } else { // Should not have failed. ADD_FAILURE() << "Scenario should not have failed: " << ex.what(); @@ -1396,9 +1397,9 @@ TEST(CfgSubnets4Test, teeTimePercentValidation) { } // We parsed correctly, make sure the values are right. - EXPECT_EQ((*test).calculate_tee_times, subnet->getCalculateTeeTimes()); - EXPECT_TRUE(util::areDoublesEquivalent((*test).t1_percent, subnet->getT1Percent())); - EXPECT_TRUE(util::areDoublesEquivalent((*test).t2_percent, subnet->getT2Percent())); + EXPECT_EQ(test.calculate_tee_times, subnet->getCalculateTeeTimes()); + EXPECT_TRUE(util::areDoublesEquivalent(test.t1_percent, subnet->getT1Percent())); + EXPECT_TRUE(util::areDoublesEquivalent(test.t2_percent, subnet->getT2Percent())); } } } @@ -1779,12 +1780,12 @@ TEST(CfgSubnets4Test, cacheParamValidation) { // Iterate over the test scenarios, verifying each prescribed // outcome. - for (auto test = tests.begin(); test != tests.end(); ++test) { + for (auto const& test : tests) { { - SCOPED_TRACE("test: " + (*test).label); + SCOPED_TRACE("test: " + test.label); // Set this scenario's configuration parameters - elems->set("cache-threshold", data::Element::create((*test).threshold)); + elems->set("cache-threshold", data::Element::create(test.threshold)); Subnet4Ptr subnet; try { @@ -1792,9 +1793,9 @@ TEST(CfgSubnets4Test, cacheParamValidation) { Subnet4ConfigParser parser; subnet = parser.parse(elems); } catch (const std::exception& ex) { - if (!(*test).error_message.empty()) { + if (!test.error_message.empty()) { // We expected a failure, did we fail the correct way? - EXPECT_EQ((*test).error_message, ex.what()); + EXPECT_EQ(test.error_message, ex.what()); } else { // Should not have failed. ADD_FAILURE() << "Scenario should not have failed: " << ex.what(); @@ -1805,7 +1806,7 @@ TEST(CfgSubnets4Test, cacheParamValidation) { } // We parsed correctly, make sure the values are right. - EXPECT_TRUE(util::areDoublesEquivalent((*test).threshold, subnet->getCacheThreshold())); + EXPECT_TRUE(util::areDoublesEquivalent(test.threshold, subnet->getCacheThreshold())); } } } diff --git a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc index 20707fed8e..1959fb2cfa 100644 --- a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -129,29 +130,29 @@ TEST(CfgSubnets6Test, getSpecificSubnet) { subnets.push_back(subnet3); // Add all subnets to the configuration. - for (auto subnet = subnets.cbegin(); subnet != subnets.cend(); ++subnet) { - ASSERT_NO_THROW(cfg.add(*subnet)) << "failed to add subnet with id: " - << (*subnet)->getID(); + for (auto const& subnet : subnets) { + ASSERT_NO_THROW(cfg.add(subnet)) << "failed to add subnet with id: " + << subnet->getID(); } // Iterate over all subnets and make sure they can be retrieved by // subnet identifier. - for (auto subnet = subnets.rbegin(); subnet != subnets.rend(); ++subnet) { - ConstSubnet6Ptr subnet_returned = cfg.getBySubnetId((*subnet)->getID()); + for (auto const& subnet : boost::adaptors::reverse(subnets)) { + ConstSubnet6Ptr subnet_returned = cfg.getBySubnetId(subnet->getID()); ASSERT_TRUE(subnet_returned) << "failed to return subnet with id: " - << (*subnet)->getID(); - EXPECT_EQ((*subnet)->getID(), subnet_returned->getID()); - EXPECT_EQ((*subnet)->toText(), subnet_returned->toText()); + << subnet->getID(); + EXPECT_EQ(subnet->getID(), subnet_returned->getID()); + EXPECT_EQ(subnet->toText(), subnet_returned->toText()); } // Repeat the previous test, but this time retrieve subnets by their // prefixes. - for (auto subnet = subnets.rbegin(); subnet != subnets.rend(); ++subnet) { - ConstSubnet6Ptr subnet_returned = cfg.getByPrefix((*subnet)->toText()); + for (auto const& subnet : boost::adaptors::reverse(subnets)) { + ConstSubnet6Ptr subnet_returned = cfg.getByPrefix(subnet->toText()); ASSERT_TRUE(subnet_returned) << "failed to return subnet with id: " - << (*subnet)->getID(); - EXPECT_EQ((*subnet)->getID(), subnet_returned->getID()); - EXPECT_EQ((*subnet)->toText(), subnet_returned->toText()); + << subnet->getID(); + EXPECT_EQ(subnet->getID(), subnet_returned->getID()); + EXPECT_EQ(subnet->toText(), subnet_returned->toText()); } // Make sure that null pointers are returned for non-existing subnets. @@ -1164,14 +1165,14 @@ TEST(CfgSubnets6Test, teeTimePercentValidation) { // Iterate over the test scenarios, verifying each prescribed // outcome. - for (auto test = tests.begin(); test != tests.end(); ++test) { + for (auto const& test : tests) { { - SCOPED_TRACE("test: " + (*test).label); + SCOPED_TRACE("test: " + test.label); // Set this scenario's configuration parameters - elems->set("calculate-tee-times", data::Element::create((*test).calculate_tee_times)); - elems->set("t1-percent", data::Element::create((*test).t1_percent)); - elems->set("t2-percent", data::Element::create((*test).t2_percent)); + elems->set("calculate-tee-times", data::Element::create(test.calculate_tee_times)); + elems->set("t1-percent", data::Element::create(test.t1_percent)); + elems->set("t2-percent", data::Element::create(test.t2_percent)); Subnet6Ptr subnet; try { @@ -1179,9 +1180,9 @@ TEST(CfgSubnets6Test, teeTimePercentValidation) { Subnet6ConfigParser parser; subnet = parser.parse(elems); } catch (const std::exception& ex) { - if (!(*test).error_message.empty()) { + if (!test.error_message.empty()) { // We expected a failure, did we fail the correct way? - EXPECT_EQ((*test).error_message, ex.what()); + EXPECT_EQ(test.error_message, ex.what()); } else { // Should not have failed. ADD_FAILURE() << "Scenario should not have failed: " << ex.what(); @@ -1192,11 +1193,11 @@ TEST(CfgSubnets6Test, teeTimePercentValidation) { } // We parsed correctly, make sure the values are right. - EXPECT_EQ((*test).calculate_tee_times, subnet->getCalculateTeeTimes()); - EXPECT_TRUE(util::areDoublesEquivalent((*test).t1_percent, subnet->getT1Percent())) - << "expected:" << (*test).t1_percent << " actual: " << subnet->getT1Percent(); - EXPECT_TRUE(util::areDoublesEquivalent((*test).t2_percent, subnet->getT2Percent())) - << "expected:" << (*test).t2_percent << " actual: " << subnet->getT2Percent(); + EXPECT_EQ(test.calculate_tee_times, subnet->getCalculateTeeTimes()); + EXPECT_TRUE(util::areDoublesEquivalent(test.t1_percent, subnet->getT1Percent())) + << "expected:" << test.t1_percent << " actual: " << subnet->getT1Percent(); + EXPECT_TRUE(util::areDoublesEquivalent(test.t2_percent, subnet->getT2Percent())) + << "expected:" << test.t2_percent << " actual: " << subnet->getT2Percent(); } } } @@ -1555,12 +1556,12 @@ TEST(CfgSubnets6Test, cacheParamValidation) { // Iterate over the test scenarios, verifying each prescribed // outcome. - for (auto test = tests.begin(); test != tests.end(); ++test) { + for (auto const& test : tests) { { - SCOPED_TRACE("test: " + (*test).label); + SCOPED_TRACE("test: " + test.label); // Set this scenario's configuration parameters - elems->set("cache-threshold", data::Element::create((*test).threshold)); + elems->set("cache-threshold", data::Element::create(test.threshold)); Subnet6Ptr subnet; try { @@ -1568,9 +1569,9 @@ TEST(CfgSubnets6Test, cacheParamValidation) { Subnet6ConfigParser parser; subnet = parser.parse(elems); } catch (const std::exception& ex) { - if (!(*test).error_message.empty()) { + if (!test.error_message.empty()) { // We expected a failure, did we fail the correct way? - EXPECT_EQ((*test).error_message, ex.what()); + EXPECT_EQ(test.error_message, ex.what()); } else { // Should not have failed. ADD_FAILURE() << "Scenario should not have failed: " << ex.what(); @@ -1581,7 +1582,7 @@ TEST(CfgSubnets6Test, cacheParamValidation) { } // We parsed correctly, make sure the values are right. - EXPECT_TRUE(util::areDoublesEquivalent((*test).threshold, subnet->getCacheThreshold())); + EXPECT_TRUE(util::areDoublesEquivalent(test.threshold, subnet->getCacheThreshold())); } } } diff --git a/src/lib/dhcpsrv/tests/client_class_def_unittest.cc b/src/lib/dhcpsrv/tests/client_class_def_unittest.cc index bb7b2f67a9..1909c8dddf 100644 --- a/src/lib/dhcpsrv/tests/client_class_def_unittest.cc +++ b/src/lib/dhcpsrv/tests/client_class_def_unittest.cc @@ -602,7 +602,7 @@ TEST(ClientClassDictionary, initMatchExprError) { ASSERT_THROW(dictionary->initMatchExpr(AF_INET), std::exception); // Ensure that no classes have their match expressions modified. - for (auto const& c : (*dictionary->getClasses())) { + for (auto const& c : *dictionary->getClasses()) { EXPECT_FALSE(c->getMatchExpr()); } } @@ -1448,7 +1448,7 @@ TEST(ClientClassDictionary, templateInitMatchExprError) { ASSERT_THROW(dictionary->initMatchExpr(AF_INET), std::exception); // Ensure that no classes have their match expressions modified. - for (auto const& c : (*dictionary->getClasses())) { + for (auto const& c : *dictionary->getClasses()) { EXPECT_FALSE(c->getMatchExpr()); } } diff --git a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc index 84f429a6e1..ce98d2b0d0 100644 --- a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc +++ b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc @@ -36,7 +36,6 @@ #include #include -#include #include #include @@ -197,12 +196,11 @@ public: return (answer); } - ConfigPair config_pair; try { // Iterate over the config elements. const std::map& values_map = config_set->mapValue(); - BOOST_FOREACH(config_pair, values_map) { + for (auto const& config_pair : values_map) { // These are the simple parsers. No need to go through // the ParserPtr hooplas with them. @@ -337,14 +335,14 @@ public: // Now set option definition defaults for each specified option definition ConstElementPtr option_defs = global->get("option-def"); if (option_defs) { - BOOST_FOREACH(ElementPtr single_def, option_defs->listValue()) { + for (auto const& single_def : option_defs->listValue()) { cnt += SimpleParser::setDefaults(single_def, option_def_defaults); } } ConstElementPtr options = global->get("option-data"); if (options) { - BOOST_FOREACH(ElementPtr single_option, options->listValue()) { + for (auto const& single_option : options->listValue()) { cnt += SimpleParser::setDefaults(single_option, option_defaults); } } diff --git a/src/lib/dhcpsrv/tests/host_reservation_parser_unittest.cc b/src/lib/dhcpsrv/tests/host_reservation_parser_unittest.cc index fd2ed2e0b9..b8e81cef9e 100644 --- a/src/lib/dhcpsrv/tests/host_reservation_parser_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_reservation_parser_unittest.cc @@ -20,8 +20,9 @@ #include #include #include -#include #include +#include +#include #include #include #include @@ -67,9 +68,8 @@ protected: /// in which the reservation will be searched. bool reservationExists(const IPv6Resrv& resrv, const IPv6ResrvRange& range) { - for (IPv6ResrvIterator it = range.first; it != range.second; - ++it) { - if (resrv == it->second) { + BOOST_FOREACH(auto const& it, range) { + if (resrv == it.second) { return (true); } } diff --git a/src/lib/dhcpsrv/tests/host_reservations_list_parser_unittest.cc b/src/lib/dhcpsrv/tests/host_reservations_list_parser_unittest.cc index c10adde0bf..8468e4e634 100644 --- a/src/lib/dhcpsrv/tests/host_reservations_list_parser_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_reservations_list_parser_unittest.cc @@ -173,8 +173,8 @@ TEST_F(HostReservationsListParserTest, ipv4Reservations) { HostReservationsListParser parser; ASSERT_NO_THROW(parser.parse(SubnetID(1), config_element, hosts)); - for (auto h = hosts.begin(); h != hosts.end(); ++h) { - CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(*h); + for (auto const& h : hosts) { + CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(h); } CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts(); @@ -248,8 +248,8 @@ TEST_F(HostReservationsListParserTest, duplicatedIdentifierValue4) { HostReservationsListParser parser; EXPECT_THROW({ parser.parse(SubnetID(1), config_element, hosts); - for (auto h = hosts.begin(); h != hosts.end(); ++h) { - CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(*h); + for (auto const& h : hosts) { + CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(h); } }, DuplicateHost); // The code threw exception, because the second insertion failed. @@ -285,8 +285,8 @@ TEST_F(HostReservationsListParserTest, ipv6Reservations) { HostReservationsListParser parser; ASSERT_NO_THROW(parser.parse(SubnetID(2), config_element, hosts)); - for (auto h = hosts.begin(); h != hosts.end(); ++h) { - CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(*h); + for (auto const& h : hosts) { + CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(h); } CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts(); @@ -378,8 +378,8 @@ TEST_F(HostReservationsListParserTest, duplicatedIdentifierValue6) { HostReservationsListParser parser; EXPECT_THROW({ parser.parse(SubnetID(1), config_element, hosts); - for (auto h = hosts.begin(); h != hosts.end(); ++h) { - CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(*h); + for (auto const& h : hosts) { + CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(h); } }, DuplicateHost); } diff --git a/src/lib/dhcpsrv/tests/host_unittest.cc b/src/lib/dhcpsrv/tests/host_unittest.cc index be8c674448..2661e8e13b 100644 --- a/src/lib/dhcpsrv/tests/host_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_unittest.cc @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -167,9 +168,8 @@ public: /// @return true if reservation exists, false otherwise. bool reservationExists(const IPv6Resrv& resrv, const IPv6ResrvRange& range) { - for (IPv6ResrvIterator it = range.first; it != range.second; - ++it) { - if (resrv == it->second) { + BOOST_FOREACH(auto const& it, range) { + if (resrv == it.second) { return (true); } } @@ -925,10 +925,9 @@ TEST_F(HostTest, addOptions4) { // Validate codes of options added to dhcp4 option space. uint16_t expected_code = 100; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } @@ -938,10 +937,9 @@ TEST_F(HostTest, addOptions4) { // Validate codes of options added to isc option space. expected_code = 105; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } @@ -1013,10 +1011,9 @@ TEST_F(HostTest, addOptions6) { // Validate codes of options added to dhcp6 option space. uint16_t expected_code = 100; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } @@ -1026,10 +1023,9 @@ TEST_F(HostTest, addOptions6) { // Validate codes of options added to isc option space. expected_code = 105; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } diff --git a/src/lib/dhcpsrv/tests/pool_unittest.cc b/src/lib/dhcpsrv/tests/pool_unittest.cc index d40ee33a23..c1ba331528 100644 --- a/src/lib/dhcpsrv/tests/pool_unittest.cc +++ b/src/lib/dhcpsrv/tests/pool_unittest.cc @@ -156,10 +156,9 @@ TEST(Pool4Test, addOptions) { // Validate codes of options added to dhcp4 option space. uint16_t expected_code = 100; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } @@ -169,10 +168,9 @@ TEST(Pool4Test, addOptions) { // Validate codes of options added to isc option space. expected_code = 105; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } @@ -562,10 +560,9 @@ TEST(Pool6Test, addOptions) { // Validate codes of options added to dhcp6 option space. uint16_t expected_code = 100; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } @@ -575,10 +572,9 @@ TEST(Pool6Test, addOptions) { // Validate codes of options added to isc option space. expected_code = 105; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } diff --git a/src/lib/dhcpsrv/tests/shared_network_parser_unittest.cc b/src/lib/dhcpsrv/tests/shared_network_parser_unittest.cc index 3472e0f190..213d628dd0 100644 --- a/src/lib/dhcpsrv/tests/shared_network_parser_unittest.cc +++ b/src/lib/dhcpsrv/tests/shared_network_parser_unittest.cc @@ -92,10 +92,9 @@ public: ASSERT_EQ(test.addresses_.size(), network.getRelayAddresses().size()); // Are the expected addresses in the list? - for (auto exp_address = test.addresses_.begin(); exp_address != test.addresses_.end(); - ++exp_address) { - EXPECT_TRUE(network.hasRelayAddress(*exp_address)) - << " expected address: " << (*exp_address).toText() << " not found" ; + for (auto const& exp_address : test.addresses_) { + EXPECT_TRUE(network.hasRelayAddress(exp_address)) + << " expected address: " << exp_address.toText() << " not found" ; } } @@ -451,11 +450,9 @@ TEST_F(SharedNetwork4ParserTest, relayInfoTests) { // Iterate over the test scenarios, verifying each prescribed // outcome. - for (auto test = tests.begin(); test != tests.end(); ++test) { - { - SCOPED_TRACE((*test).description_); - relayTest(*test); - } + for (auto const& test : tests) { + SCOPED_TRACE(test.description_); + relayTest(test); } } @@ -1030,11 +1027,9 @@ TEST_F(SharedNetwork6ParserTest, relayInfoTests) { // Iterate over the test scenarios, verifying each prescribed // outcome. - for (auto test = tests.begin(); test != tests.end(); ++test) { - { - SCOPED_TRACE((*test).description_); - relayTest(*test); - } + for (auto const& test : tests) { + SCOPED_TRACE(test.description_); + relayTest(test); } } diff --git a/src/lib/dhcpsrv/tests/srv_config_unittest.cc b/src/lib/dhcpsrv/tests/srv_config_unittest.cc index 77673c4074..e9d3b4f8e3 100644 --- a/src/lib/dhcpsrv/tests/srv_config_unittest.cc +++ b/src/lib/dhcpsrv/tests/srv_config_unittest.cc @@ -551,21 +551,21 @@ TEST_F(SrvConfigTest, configuredGlobals) { // Maps and lists should be excluded. auto globals = srv_globals->valuesMap(); - for (auto global = globals.begin(); global != globals.end(); ++global) { - if (global->first == "comment") { - ASSERT_EQ(Element::string, global->second->getType()); - EXPECT_EQ("okay", global->second->stringValue()); - } else if (global->first == "valid-lifetime") { - ASSERT_EQ(Element::integer, global->second->getType()); - EXPECT_EQ(444, global->second->intValue()); - } else if (global->first == "store-extended-info") { - ASSERT_EQ(Element::boolean, global->second->getType()); - EXPECT_TRUE(global->second->boolValue()); - } else if (global->first == "t1-percent") { - ASSERT_EQ(Element::real, global->second->getType()); - EXPECT_EQ(1.234, global->second->doubleValue()); + for (auto const& global : globals) { + if (global.first == "comment") { + ASSERT_EQ(Element::string, global.second->getType()); + EXPECT_EQ("okay", global.second->stringValue()); + } else if (global.first == "valid-lifetime") { + ASSERT_EQ(Element::integer, global.second->getType()); + EXPECT_EQ(444, global.second->intValue()); + } else if (global.first == "store-extended-info") { + ASSERT_EQ(Element::boolean, global.second->getType()); + EXPECT_TRUE(global.second->boolValue()); + } else if (global.first == "t1-percent") { + ASSERT_EQ(Element::real, global.second->getType()); + EXPECT_EQ(1.234, global.second->doubleValue()); } else { - ADD_FAILURE() << "unexpected element found:" << global->first; + ADD_FAILURE() << "unexpected element found:" << global.first; } } diff --git a/src/lib/dhcpsrv/tests/subnet_unittest.cc b/src/lib/dhcpsrv/tests/subnet_unittest.cc index 69f762cace..c13680438a 100644 --- a/src/lib/dhcpsrv/tests/subnet_unittest.cc +++ b/src/lib/dhcpsrv/tests/subnet_unittest.cc @@ -1380,10 +1380,9 @@ TEST(Subnet6Test, addOptions) { // Validate codes of options added to dhcp6 option space. uint16_t expected_code = 100; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } @@ -1393,10 +1392,9 @@ TEST(Subnet6Test, addOptions) { // Validate codes of options added to isc option space. expected_code = 105; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } @@ -1435,10 +1433,9 @@ TEST(Subnet6Test, addNonUniqueOptions) { // have been returned for the particular code. ASSERT_EQ(2, distance(range.first, range.second)); // Check that returned options actually have the expected option code. - for (OptionContainerTypeIndex::const_iterator option_desc = range.first; - option_desc != range.second; ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(code, option_desc->option_->getType()); + BOOST_FOREACH(auto const& option_desc, range) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(code, option_desc.option_->getType()); } } @@ -1544,10 +1541,9 @@ TEST(Subnet6Test, addVendorOption) { // Validate codes of options added to dhcp6 option space. uint16_t expected_code = 100; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } @@ -1557,10 +1553,9 @@ TEST(Subnet6Test, addVendorOption) { // Validate codes of options added to isc option space. expected_code = 105; - for (OptionContainer::const_iterator option_desc = options->begin(); - option_desc != options->end(); ++option_desc) { - ASSERT_TRUE(option_desc->option_); - EXPECT_EQ(expected_code, option_desc->option_->getType()); + for (auto const& option_desc : *options) { + ASSERT_TRUE(option_desc.option_); + EXPECT_EQ(expected_code, option_desc.option_->getType()); ++expected_code; } diff --git a/src/lib/dhcpsrv/tests/timer_mgr_unittest.cc b/src/lib/dhcpsrv/tests/timer_mgr_unittest.cc index d1eba33643..fbc3c75b46 100644 --- a/src/lib/dhcpsrv/tests/timer_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/timer_mgr_unittest.cc @@ -295,12 +295,12 @@ TimerMgrTest::testUnregisterTimers() { doWait(500); // Make sure that all timers have been executed at least once. - for (CallsCount::iterator it = calls_count_.begin(); - it != calls_count_.end(); ++it) { - unsigned int calls_count = it->second; + size_t count = 0; + for (auto const& it : calls_count_) { + unsigned int calls_count = it.second; ASSERT_GT(calls_count, 0) - << "expected calls counter for timer" - << (std::distance(calls_count_.begin(), it) + 1) + << "expected calls counter for timer " + << ++count << " greater than 0"; } diff --git a/src/lib/dhcpsrv/testutils/generic_backend_unittest.cc b/src/lib/dhcpsrv/testutils/generic_backend_unittest.cc index 55540e0aae..462dbdfa09 100644 --- a/src/lib/dhcpsrv/testutils/generic_backend_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_backend_unittest.cc @@ -13,6 +13,8 @@ #include #include +#include + using namespace isc::data; using namespace isc::db; @@ -168,11 +170,13 @@ GenericBackendTest::testNewAuditEntry(const std::string& exp_object_type, // Iterate over specified number of entries starting from the most recent // one and check they have correct values. - for (auto audit_entry_it = mod_time_idx.rbegin(); - ((std::distance(mod_time_idx.rbegin(), audit_entry_it) < new_entries_num) && - (std::distance(mod_time_idx.rbegin(), audit_entry_it) < max_tested_entries)); - ++audit_entry_it) { - auto audit_entry = *audit_entry_it; + size_t count = 0; + for (auto const& audit_entry_it : boost::adaptors::reverse(mod_time_idx)) { + if (count >= new_entries_num || count >= max_tested_entries) { + break; + } + count++; + auto audit_entry = audit_entry_it; EXPECT_EQ(exp_object_type, audit_entry->getObjectType()) << logExistingAuditEntries(tag); EXPECT_EQ(exp_modification_type, audit_entry->getModificationType()) @@ -219,11 +223,13 @@ GenericBackendTest::testNewAuditEntry(const std::vector& exp_entr // Iterate over specified number of entries starting from the most recent // one and check they have correct values. auto exp_entry = exp_entries.rbegin(); - for (auto audit_entry_it = mod_time_idx.rbegin(); - ((std::distance(mod_time_idx.rbegin(), audit_entry_it) < new_entries_num)); - ++audit_entry_it) { - - auto audit_entry = *audit_entry_it; + size_t count = 0; + for (auto const& audit_entry_it : boost::adaptors::reverse(mod_time_idx)) { + if (count >= new_entries_num) { + break; + } + count++; + auto audit_entry = audit_entry_it; EXPECT_EQ((*exp_entry).object_type, audit_entry->getObjectType()) << logExistingAuditEntries(tag); EXPECT_EQ((*exp_entry).modification_type, audit_entry->getModificationType()) @@ -260,10 +266,8 @@ GenericBackendTest::logExistingAuditEntries(const std::string& server_tag) { auto& mod_time_idx = audit_entries_[server_tag].get(); - for (auto audit_entry_it = mod_time_idx.begin(); - audit_entry_it != mod_time_idx.end(); - ++audit_entry_it) { - auto audit_entry = *audit_entry_it; + for (auto const& audit_entry_it : mod_time_idx) { + auto audit_entry = audit_entry_it; s << audit_entry->getObjectType() << ", " << audit_entry->getObjectId() << ", " << static_cast(audit_entry->getModificationType()) << ", " diff --git a/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc b/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc index 4d71fce430..4abf305689 100644 --- a/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc @@ -776,9 +776,9 @@ GenericConfigBackendDHCPv4Test::globalParameters4WithServerTagsTest() { // Capture the returned values into the map so as we can check the // values against the servers. std::map values; - for (auto g = returned_globals.begin(); g != returned_globals.end(); ++g) { - ASSERT_EQ(1, (*g)->getServerTags().size()); - values[(*g)->getServerTags().begin()->get()] = ((*g)->getValue()); + for (auto const& g : returned_globals) { + ASSERT_EQ(1, g->getServerTags().size()); + values[g->getServerTags().begin()->get()] = g->getValue(); } ASSERT_EQ(3, values.size()); @@ -895,10 +895,9 @@ GenericConfigBackendDHCPv4Test::getAllGlobalParameters4Test() { EXPECT_TRUE((*parameters_index.find("name4"))->getBoolValue()); EXPECT_EQ(1.65, (*parameters_index.find("name5"))->getDoubleValue()); - for (auto param = parameters_index.begin(); param != parameters_index.end(); - ++param) { - ASSERT_EQ(1, (*param)->getServerTags().size()); - EXPECT_EQ("all", (*param)->getServerTags().begin()->get()); + for (auto const& param : parameters_index) { + ASSERT_EQ(1, param->getServerTags().size()); + EXPECT_EQ("all", param->getServerTags().begin()->get()); } // Should be able to fetch these parameters when explicitly providing @@ -3101,17 +3100,17 @@ GenericConfigBackendDHCPv4Test::getAllOptionDefs4Test() { ASSERT_EQ(test_option_defs_.size() - updates_num, option_defs.size()); // See if option definitions are returned ok. - for (auto def = option_defs.begin(); def != option_defs.end(); ++def) { - ASSERT_EQ(1, (*def)->getServerTags().size()); - EXPECT_EQ("all", (*def)->getServerTags().begin()->get()); + for (auto const& def : option_defs) { + ASSERT_EQ(1, def->getServerTags().size()); + EXPECT_EQ("all", def->getServerTags().begin()->get()); bool success = false; for (auto i = 1; i < test_option_defs_.size(); ++i) { - if ((*def)->equals(*test_option_defs_[i])) { + if (def->equals(*test_option_defs_[i])) { success = true; } } - ASSERT_TRUE(success) << "failed for option definition " << (*def)->getCode() - << ", option space " << (*def)->getOptionSpaceName(); + ASSERT_TRUE(success) << "failed for option definition " << def->getCode() + << ", option space " << def->getOptionSpaceName(); } // Deleting non-existing option definition should return 0. @@ -4610,12 +4609,13 @@ GenericConfigBackendDHCPv4Test::multipleAuditEntriesTest() { // Check that partial retrieves return the right count. auto& mod_time_idx = audit_entries.get(); - for (auto it = mod_time_idx.begin(); it != mod_time_idx.end(); ++it) { + size_t distance = mod_time_idx.size(); + for (auto const& it : mod_time_idx) { size_t partial_size = cbptr_->getRecentAuditEntries(server_selector, - (*it)->getModificationTime(), - (*it)->getRevisionId()).size(); - EXPECT_EQ(partial_size + 1, - std::distance(it, mod_time_idx.end())); + it->getModificationTime(), + it->getRevisionId()).size(); + EXPECT_EQ(partial_size + 1, distance); + distance--; } } diff --git a/src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc b/src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc index 62985934c5..b9cf42b1eb 100644 --- a/src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc @@ -808,9 +808,9 @@ GenericConfigBackendDHCPv6Test::globalParameters6WithServerTagsTest() { // Capture the returned values into the map so as we can check the // values against the servers. std::map values; - for (auto g = returned_globals.begin(); g != returned_globals.end(); ++g) { - ASSERT_EQ(1, (*g)->getServerTags().size()); - values[(*g)->getServerTags().begin()->get()] = ((*g)->getValue()); + for (auto const& g : returned_globals) { + ASSERT_EQ(1, g->getServerTags().size()); + values[g->getServerTags().begin()->get()] = g->getValue(); } ASSERT_EQ(3, values.size()); @@ -927,10 +927,9 @@ GenericConfigBackendDHCPv6Test::getAllGlobalParameters6Test() { EXPECT_TRUE((*parameters_index.find("name4"))->getBoolValue()); EXPECT_EQ(1.65, (*parameters_index.find("name5"))->getDoubleValue()); - for (auto param = parameters_index.begin(); param != parameters_index.end(); - ++param) { - ASSERT_EQ(1, (*param)->getServerTags().size()); - EXPECT_EQ("all", (*param)->getServerTags().begin()->get()); + for (auto const& param : parameters_index) { + ASSERT_EQ(1, param->getServerTags().size()); + EXPECT_EQ("all", param->getServerTags().begin()->get()); } // Should be able to fetch these parameters when explicitly providing @@ -3127,17 +3126,17 @@ GenericConfigBackendDHCPv6Test::getAllOptionDefs6Test() { ASSERT_EQ(test_option_defs_.size() - updates_num, option_defs.size()); // See if option definitions are returned ok. - for (auto def = option_defs.begin(); def != option_defs.end(); ++def) { - ASSERT_EQ(1, (*def)->getServerTags().size()); - EXPECT_EQ("all", (*def)->getServerTags().begin()->get()); + for (auto const& def : option_defs) { + ASSERT_EQ(1, def->getServerTags().size()); + EXPECT_EQ("all", def->getServerTags().begin()->get()); bool success = false; for (auto i = 1; i < test_option_defs_.size(); ++i) { - if ((*def)->equals(*test_option_defs_[i])) { + if (def->equals(*test_option_defs_[i])) { success = true; } } - ASSERT_TRUE(success) << "failed for option definition " << (*def)->getCode() - << ", option space " << (*def)->getOptionSpaceName(); + ASSERT_TRUE(success) << "failed for option definition " << def->getCode() + << ", option space " << def->getOptionSpaceName(); } // Deleting non-existing option definition should return 0. @@ -4761,12 +4760,13 @@ GenericConfigBackendDHCPv6Test::multipleAuditEntriesTest() { // Check that partial retrieves return the right count. auto& mod_time_idx = audit_entries.get(); - for (auto it = mod_time_idx.begin(); it != mod_time_idx.end(); ++it) { + size_t distance = mod_time_idx.size(); + for (auto const& it : mod_time_idx) { size_t partial_size = cbptr_->getRecentAuditEntries(server_selector, - (*it)->getModificationTime(), - (*it)->getRevisionId()).size(); - EXPECT_EQ(partial_size + 1, - std::distance(it, mod_time_idx.end())); + it->getModificationTime(), + it->getRevisionId()).size(); + EXPECT_EQ(partial_size + 1, distance); + distance--; } } diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc index f3caa3f8c6..c14e398c67 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc @@ -1446,22 +1446,20 @@ GenericHostDataSourceTest::testHostname(std::string name, int num) { } // Now add them all to the host data source. - for (vector::const_iterator it = hosts.begin(); it != hosts.end(); - ++it) { + for (auto const& it : hosts) { // Try to add both of the to the host data source. - ASSERT_NO_THROW(hdsptr_->add(*it)); + ASSERT_NO_THROW(hdsptr_->add(it)); } // And finally retrieve them one by one and check // if the hostname was preserved. - for (vector::const_iterator it = hosts.begin(); it != hosts.end(); - ++it) { + for (auto const& it : hosts) { ConstHostPtr from_hds; - ASSERT_NO_THROW(from_hds = hdsptr_->get4((*it)->getIPv4SubnetID(), - (*it)->getIPv4Reservation())); + ASSERT_NO_THROW(from_hds = hdsptr_->get4(it->getIPv4SubnetID(), + it->getIPv4Reservation())); ASSERT_TRUE(from_hds); - EXPECT_EQ((*it)->getHostname(), from_hds->getHostname()); + EXPECT_EQ(it->getHostname(), from_hds->getHostname()); } } @@ -1542,10 +1540,9 @@ GenericHostDataSourceTest::testMultipleSubnets(int subnets, // Verify that the values returned are proper. int i = 0; - for (ConstHostCollection::const_iterator it = all_by_addr.begin(); - it != all_by_addr.end(); ++it) { - EXPECT_EQ(IOAddress("192.0.2.1"), (*it)->getIPv4Reservation()); - EXPECT_EQ(1000 + i++, (*it)->getIPv4SubnetID()); + for (auto const& it : all_by_addr) { + EXPECT_EQ(IOAddress("192.0.2.1"), it->getIPv4Reservation()); + EXPECT_EQ(1000 + i++, it->getIPv4SubnetID()); } // Finally, check that the hosts can be retrieved by HW address or DUID @@ -1555,10 +1552,9 @@ GenericHostDataSourceTest::testMultipleSubnets(int subnets, // Check that the returned values are as expected. i = 0; - for (ConstHostCollection::const_iterator it = all_by_id.begin(); - it != all_by_id.end(); ++it) { - EXPECT_EQ(IOAddress("192.0.2.1"), (*it)->getIPv4Reservation()); - EXPECT_EQ(1000 + i++, (*it)->getIPv4SubnetID()); + for (auto const& it : all_by_id) { + EXPECT_EQ(IOAddress("192.0.2.1"), it->getIPv4Reservation()); + EXPECT_EQ(1000 + i++, it->getIPv4SubnetID()); } } @@ -1678,10 +1674,9 @@ GenericHostDataSourceTest::testSubnetId6(int subnets, Host::IdentifierType id) { // Check that the returned values are as expected. int i = 0; - for (ConstHostCollection::const_iterator it = all_by_id.begin(); - it != all_by_id.end(); ++it) { - EXPECT_EQ(IOAddress("0.0.0.0"), (*it)->getIPv4Reservation()); - EXPECT_EQ(1000 + i++, (*it)->getIPv6SubnetID()); + for (auto const& it : all_by_id) { + EXPECT_EQ(IOAddress("0.0.0.0"), it->getIPv4Reservation()); + EXPECT_EQ(1000 + i++, it->getIPv6SubnetID()); } } @@ -2354,9 +2349,8 @@ GenericHostDataSourceTest::stressTest(unsigned int nOfHosts /* = 0xfffdU */) { start = (struct timespec){0, 0}; end = (struct timespec){0, 0}; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start); - for (std::vector::const_iterator it = hosts.begin(); - it != hosts.end(); it++) { - ASSERT_NO_THROW(hdsptr_->add(*it)); + for (auto const& it : hosts) { + ASSERT_NO_THROW(hdsptr_->add(it)); } clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end); double s = static_cast(end.tv_sec - start.tv_sec) + @@ -2371,15 +2365,14 @@ GenericHostDataSourceTest::stressTest(unsigned int nOfHosts /* = 0xfffdU */) { start = (struct timespec){0, 0}; end = (struct timespec){0, 0}; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start); - for (std::vector::const_iterator it = hosts.begin(); - it != hosts.end(); it++) { - IPv6ResrvRange range = (*it)->getIPv6Reservations(); + for (auto const& it : hosts) { + IPv6ResrvRange range = it->getIPv6Reservations(); // This get6() call is particularly useful to test because it involves a // subquery for MySQL and PostgreSQL. ConstHostPtr from_hds = hdsptr_->get6(range.first->second.getPrefix(), 128); ASSERT_TRUE(from_hds); - HostDataSourceUtils::compareHosts(*it, from_hds); + HostDataSourceUtils::compareHosts(it, from_hds); } clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end); s = static_cast(end.tv_sec - start.tv_sec) + diff --git a/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc index 9e1d87c9eb..e832efec09 100644 --- a/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include @@ -575,20 +575,18 @@ GenericLeaseMgrTest::testGetLease4HWAddr2() { // Check the lease[5] (and only this one) has an user context. size_t contexts = 0; - for (Lease4Collection::const_iterator i = returned.begin(); - i != returned.end(); ++i) { - if ((*i)->getContext()) { + for (auto const& i : returned) { + if (i->getContext()) { ++contexts; - EXPECT_EQ("{ \"foo\": true }", (*i)->getContext()->str()); + EXPECT_EQ("{ \"foo\": true }", i->getContext()->str()); } } EXPECT_EQ(1, contexts); // Easiest way to check is to look at the addresses. vector addresses; - for (Lease4Collection::const_iterator i = returned.begin(); - i != returned.end(); ++i) { - addresses.push_back((*i)->addr_.toText()); + for (auto const& i : returned) { + addresses.push_back(i->addr_.toText()); } sort(addresses.begin(), addresses.end()); EXPECT_EQ(straddress4_[1], addresses[0]); @@ -1172,20 +1170,18 @@ GenericLeaseMgrTest::testGetLease4ClientId2() { // Check the lease[5] (and only this one) has an user context. size_t contexts = 0; - for (Lease4Collection::const_iterator i = returned.begin(); - i != returned.end(); ++i) { - if ((*i)->getContext()) { + for (auto const& i : returned) { + if (i->getContext()) { ++contexts; - EXPECT_EQ("{ \"foo\": true }", (*i)->getContext()->str()); + EXPECT_EQ("{ \"foo\": true }", i->getContext()->str()); } } EXPECT_EQ(1, contexts); // Easiest way to check is to look at the addresses. vector addresses; - for (Lease4Collection::const_iterator i = returned.begin(); - i != returned.end(); ++i) { - addresses.push_back((*i)->addr_.toText()); + for (auto const& i : returned) { + addresses.push_back(i->addr_.toText()); } sort(addresses.begin(), addresses.end()); EXPECT_EQ(straddress4_[1], addresses[0]); @@ -1335,7 +1331,7 @@ GenericLeaseMgrTest::testGetLeases4Paged() { Lease4Collection page = lmptr_->getLeases4(last_address, LeasePageSize(3)); // Collect leases in a common structure. They may be out of order. - for (const Lease4Ptr& lease : page) { + for (auto const& lease : page) { all_leases.push_back(lease); } @@ -1356,9 +1352,9 @@ GenericLeaseMgrTest::testGetLeases4Paged() { // Make sure that all leases that we stored in the lease database // have been retrieved. - for (const Lease4Ptr& lease : leases) { + for (auto const& lease : leases) { bool found = false; - for (const Lease4Ptr& returned_lease : all_leases) { + for (auto const& returned_lease : all_leases) { if (lease->addr_ == returned_lease->addr_) { found = true; break; @@ -1421,7 +1417,7 @@ GenericLeaseMgrTest::testGetLeases6SubnetIdPaged() { LeasePageSize(3)); // Collect leases in a common structure. - for (Lease6Ptr lease : page) { + for (auto const& lease : page) { all_leases.push_back(lease); } @@ -1440,12 +1436,12 @@ GenericLeaseMgrTest::testGetLeases6SubnetIdPaged() { // Make sure that all leases that we stored in the lease database // have been retrieved at the exception of the third. - for (Lease6Ptr lease : leases) { + for (auto const& lease : leases) { if (lease == leases[3]) { continue; } bool found = false; - for (Lease6Ptr returned_lease : all_leases) { + for (auto const& returned_lease : all_leases) { if (lease->addr_ == returned_lease->addr_) { found = true; break; @@ -1517,7 +1513,7 @@ GenericLeaseMgrTest::testGetLeases6Paged() { Lease6Collection page = lmptr_->getLeases6(last_address, LeasePageSize(3)); // Collect leases in a common structure. They may be out of order. - for (const Lease6Ptr& lease : page) { + for (auto const& lease : page) { all_leases.push_back(lease); } @@ -1538,9 +1534,9 @@ GenericLeaseMgrTest::testGetLeases6Paged() { // Make sure that all leases that we stored in the lease database // have been retrieved. - for (const Lease6Ptr& lease : leases) { + for (auto const& lease : leases) { bool found = false; - for (const Lease6Ptr& returned_lease : all_leases) { + for (auto const& returned_lease : all_leases) { if (lease->addr_ == returned_lease->addr_) { found = true; break; @@ -1576,9 +1572,8 @@ GenericLeaseMgrTest::testGetLeases6DuidIaid() { // Easiest way to check is to look at the addresses. vector addresses; - for (Lease6Collection::const_iterator i = returned.begin(); - i != returned.end(); ++i) { - addresses.push_back((*i)->addr_.toText()); + for (auto const& i : returned) { + addresses.push_back(i->addr_.toText()); } sort(addresses.begin(), addresses.end()); EXPECT_EQ(straddress6_[1], addresses[0]); @@ -1694,9 +1689,8 @@ GenericLeaseMgrTest::testLease6LeaseTypeCheck() { // Collection order returned is not guaranteed. // Easiest way to check is to look at the addresses. vector addresses; - for (Lease6Collection::const_iterator it = returned.begin(); - it != returned.end(); ++it) { - addresses.push_back((*it)->addr_.toText()); + for (auto const& it : returned) { + addresses.push_back(it->addr_.toText()); } auto compare_addr = [](const string& left, const string& right) { @@ -2205,13 +2199,13 @@ GenericLeaseMgrTest::testGetExpiredLeases4() { // The expired leases should be returned from the most to least expired. // This matches the reverse order to which they have been added. - for (Lease4Collection::reverse_iterator lease = expired_leases.rbegin(); - lease != expired_leases.rend(); ++lease) { - int index = static_cast(std::distance(expired_leases.rbegin(), lease)); + size_t count = 0; + for (auto const& lease : boost::adaptors::reverse(expired_leases)) { + int index = count++; // Multiple current index by two, because only leases with even indexes // should have been returned. ASSERT_LE(2 * index, leases.size()); - EXPECT_EQ(leases[2 * index]->addr_, (*lease)->addr_); + EXPECT_EQ(leases[2 * index]->addr_, lease->addr_); } // Update current time for the next test. @@ -2239,11 +2233,11 @@ GenericLeaseMgrTest::testGetExpiredLeases4() { ASSERT_EQ(static_cast(leases.size() / 2), expired_leases.size()); // This time leases should be returned in the non-reverse order. - for (Lease4Collection::iterator lease = expired_leases.begin(); - lease != expired_leases.end(); ++lease) { - int index = static_cast(std::distance(expired_leases.begin(), lease)); + count = 0; + for (auto const& lease : expired_leases) { + int index = count++; ASSERT_LE(2 * index, leases.size()); - EXPECT_EQ(leases[2 * index]->addr_, (*lease)->addr_); + EXPECT_EQ(leases[2 * index]->addr_, lease->addr_); } // Remember expired leases returned. @@ -2259,11 +2253,11 @@ GenericLeaseMgrTest::testGetExpiredLeases4() { ASSERT_EQ(2, expired_leases.size()); // Test that most expired leases have been returned. - for (Lease4Collection::iterator lease = expired_leases.begin(); - lease != expired_leases.end(); ++lease) { - int index = static_cast(std::distance(expired_leases.begin(), lease)); + count = 0; + for (auto const& lease : expired_leases) { + int index = count++; ASSERT_LE(2 * index, leases.size()); - EXPECT_EQ(leases[2 * index]->addr_, (*lease)->addr_); + EXPECT_EQ(leases[2 * index]->addr_, lease->addr_); } // Mark every other expired lease as reclaimed. @@ -2284,10 +2278,10 @@ GenericLeaseMgrTest::testGetExpiredLeases4() { // Make sure that returned leases are those that are not reclaimed, i.e. // those that have even index. - for (Lease4Collection::iterator lease = expired_leases.begin(); - lease != expired_leases.end(); ++lease) { - int index = static_cast(std::distance(expired_leases.begin(), lease)); - EXPECT_EQ(saved_expired_leases[2 * index]->addr_, (*lease)->addr_); + count = 0; + for (auto const& lease : expired_leases) { + int index = count++; + EXPECT_EQ(saved_expired_leases[2 * index]->addr_, lease->addr_); } } @@ -2327,12 +2321,12 @@ GenericLeaseMgrTest::testGetExpiredLeases6() { // The expired leases should be returned from the most to least expired. // This matches the reverse order to which they have been added. - for (Lease6Collection::reverse_iterator lease = expired_leases.rbegin(); - lease != expired_leases.rend(); ++lease) { - int index = static_cast(std::distance(expired_leases.rbegin(), lease)); + size_t count = 0; + for (auto const& lease : boost::adaptors::reverse(expired_leases)) { + int index = count++; // Multiple current index by two, because only leases with even indexes // should have been returned. - EXPECT_EQ(leases[2 * index]->addr_, (*lease)->addr_); + EXPECT_EQ(leases[2 * index]->addr_, lease->addr_); } // Update current time for the next test. @@ -2361,10 +2355,10 @@ GenericLeaseMgrTest::testGetExpiredLeases6() { ASSERT_EQ(static_cast(leases.size() / 2), expired_leases.size()); // This time leases should be returned in the non-reverse order. - for (Lease6Collection::iterator lease = expired_leases.begin(); - lease != expired_leases.end(); ++lease) { - int index = static_cast(std::distance(expired_leases.begin(), lease)); - EXPECT_EQ(leases[2 * index]->addr_, (*lease)->addr_); + count = 0; + for (auto const& lease : expired_leases) { + int index = count++; + EXPECT_EQ(leases[2 * index]->addr_, lease->addr_); } // Remember expired leases returned. @@ -2380,10 +2374,10 @@ GenericLeaseMgrTest::testGetExpiredLeases6() { ASSERT_EQ(2, expired_leases.size()); // Test that most expired leases have been returned. - for (Lease6Collection::iterator lease = expired_leases.begin(); - lease != expired_leases.end(); ++lease) { - int index = static_cast(std::distance(expired_leases.begin(), lease)); - EXPECT_EQ(leases[2 * index]->addr_, (*lease)->addr_); + count = 0; + for (auto const& lease : expired_leases) { + int index = count++; + EXPECT_EQ(leases[2 * index]->addr_, lease->addr_); } // Mark every other expired lease as reclaimed. @@ -2404,10 +2398,10 @@ GenericLeaseMgrTest::testGetExpiredLeases6() { // Make sure that returned leases are those that are not reclaimed, i.e. // those that have even index. - for (Lease6Collection::iterator lease = expired_leases.begin(); - lease != expired_leases.end(); ++lease) { - int index = static_cast(std::distance(expired_leases.begin(), lease)); - EXPECT_EQ(saved_expired_leases[2 * index]->addr_, (*lease)->addr_); + count = 0; + for (auto const& lease : expired_leases) { + int index = count++; + EXPECT_EQ(saved_expired_leases[2 * index]->addr_, lease->addr_); } } @@ -2708,17 +2702,17 @@ GenericLeaseMgrTest::testGetDeclinedLeases4() { // The expired leases should be returned from the most to least expired. // This matches the reverse order to which they have been added. - for (Lease4Collection::reverse_iterator lease = expired_leases.rbegin(); - lease != expired_leases.rend(); ++lease) { - int index = static_cast(std::distance(expired_leases.rbegin(), lease)); + size_t count = 0; + for (auto const& lease : boost::adaptors::reverse(expired_leases)) { + int index = count++; // Multiple current index by two, because only leases with even indexes // should have been returned. - EXPECT_EQ(leases[2 * index]->addr_, (*lease)->addr_); + EXPECT_EQ(leases[2 * index]->addr_, lease->addr_); // Count leases in default and declined states - if ((*lease)->state_ == Lease::STATE_DEFAULT) { + if (lease->state_ == Lease::STATE_DEFAULT) { default_state++; - } else if ((*lease)->state_ == Lease::STATE_DECLINED) { + } else if (lease->state_ == Lease::STATE_DECLINED) { declined_state++; } } @@ -2763,15 +2757,15 @@ GenericLeaseMgrTest::testGetDeclinedLeases4() { // This time leases should be returned in the non-reverse order. declined_state = 0; default_state = 0; - for (Lease4Collection::iterator lease = expired_leases.begin(); - lease != expired_leases.end(); ++lease) { - int index = static_cast(std::distance(expired_leases.begin(), lease)); - EXPECT_EQ(leases[2 * index]->addr_, (*lease)->addr_); + count = 0; + for (auto const& lease : expired_leases) { + int index = count++; + EXPECT_EQ(leases[2 * index]->addr_, lease->addr_); // Count leases in default and declined states - if ((*lease)->state_ == Lease::STATE_DEFAULT) { + if (lease->state_ == Lease::STATE_DEFAULT) { default_state++; - } else if ((*lease)->state_ == Lease::STATE_DECLINED) { + } else if (lease->state_ == Lease::STATE_DECLINED) { declined_state++; } } @@ -2790,10 +2784,10 @@ GenericLeaseMgrTest::testGetDeclinedLeases4() { ASSERT_EQ(2, expired_leases.size()); // Test that most expired leases have been returned. - for (Lease4Collection::iterator lease = expired_leases.begin(); - lease != expired_leases.end(); ++lease) { - int index = static_cast(std::distance(expired_leases.begin(), lease)); - EXPECT_EQ(leases[2 * index]->addr_, (*lease)->addr_); + count = 0; + for (auto const& lease : expired_leases) { + int index = count++; + EXPECT_EQ(leases[2 * index]->addr_, lease->addr_); } } @@ -2858,17 +2852,17 @@ GenericLeaseMgrTest::testGetDeclinedLeases6() { // The expired leases should be returned from the most to least expired. // This matches the reverse order to which they have been added. - for (Lease6Collection::reverse_iterator lease = expired_leases.rbegin(); - lease != expired_leases.rend(); ++lease) { - int index = static_cast(std::distance(expired_leases.rbegin(), lease)); + size_t count = 0; + for (auto const& lease : boost::adaptors::reverse(expired_leases)) { + int index = count++; // Multiple current index by two, because only leases with even indexes // should have been returned. - EXPECT_EQ(leases[2 * index]->addr_, (*lease)->addr_); + EXPECT_EQ(leases[2 * index]->addr_, lease->addr_); // Count leases in default and declined states - if ((*lease)->state_ == Lease::STATE_DEFAULT) { + if (lease->state_ == Lease::STATE_DEFAULT) { default_state++; - } else if ((*lease)->state_ == Lease::STATE_DECLINED) { + } else if (lease->state_ == Lease::STATE_DECLINED) { declined_state++; } } @@ -2913,15 +2907,15 @@ GenericLeaseMgrTest::testGetDeclinedLeases6() { // This time leases should be returned in the non-reverse order. declined_state = 0; default_state = 0; - for (Lease6Collection::iterator lease = expired_leases.begin(); - lease != expired_leases.end(); ++lease) { - int index = static_cast(std::distance(expired_leases.begin(), lease)); - EXPECT_EQ(leases[2 * index]->addr_, (*lease)->addr_); + count = 0; + for (auto const& lease : expired_leases) { + int index = count++; + EXPECT_EQ(leases[2 * index]->addr_, lease->addr_); // Count leases in default and declined states - if ((*lease)->state_ == Lease::STATE_DEFAULT) { + if (lease->state_ == Lease::STATE_DEFAULT) { default_state++; - } else if ((*lease)->state_ == Lease::STATE_DECLINED) { + } else if (lease->state_ == Lease::STATE_DECLINED) { declined_state++; } } @@ -2940,10 +2934,10 @@ GenericLeaseMgrTest::testGetDeclinedLeases6() { ASSERT_EQ(2, expired_leases.size()); // Test that most expired leases have been returned. - for (Lease6Collection::iterator lease = expired_leases.begin(); - lease != expired_leases.end(); ++lease) { - int index = static_cast(std::distance(expired_leases.begin(), lease)); - EXPECT_EQ(leases[2 * index]->addr_, (*lease)->addr_); + count = 0; + for (auto const& lease : expired_leases) { + int index = count++; + EXPECT_EQ(leases[2 * index]->addr_, lease->addr_); } } @@ -2955,7 +2949,7 @@ GenericLeaseMgrTest::checkLeaseStats(const StatValMapList& expectedStats) { // Iterate over all stats for each subnet for (int subnet_idx = 0; subnet_idx < expectedStats.size(); ++subnet_idx) { - BOOST_FOREACH(StatValPair expectedStat, expectedStats[subnet_idx]) { + for (auto const& expectedStat : expectedStats[subnet_idx]) { // Verify the per subnet value. checkStat(stats::StatsMgr::generateName("subnet", subnet_idx + 1, expectedStat.first), @@ -3886,9 +3880,9 @@ GenericLeaseMgrTest::checkLeaseRange(const Lease4Collection& returned, const std::vector& expected_addresses) { ASSERT_EQ(expected_addresses.size(), returned.size()); - for (auto a = returned.cbegin(); a != returned.cend(); ++a) { - EXPECT_EQ(expected_addresses[std::distance(returned.cbegin(), a)], - (*a)->addr_.toText()); + size_t count = 0; + for (auto const& a : returned) { + EXPECT_EQ(expected_addresses[count++], a->addr_.toText()); } } diff --git a/src/lib/dhcpsrv/testutils/host_data_source_utils.cc b/src/lib/dhcpsrv/testutils/host_data_source_utils.cc index 8d378d0e31..5be6a2b72d 100644 --- a/src/lib/dhcpsrv/testutils/host_data_source_utils.cc +++ b/src/lib/dhcpsrv/testutils/host_data_source_utils.cc @@ -8,10 +8,11 @@ #include #include -#include #include #include +#include + using namespace std; using namespace isc::data; using namespace isc::asiolink; @@ -128,8 +129,8 @@ HostDataSourceUtils::initializeHost6(std::string address, bool HostDataSourceUtils::reservationExists(const IPv6Resrv& resrv, const IPv6ResrvRange& range) { - for (IPv6ResrvIterator it = range.first; it != range.second; ++it) { - if (resrv == it->second) { + BOOST_FOREACH(auto const& it, range) { + if (resrv == it.second) { return true; } } @@ -332,7 +333,7 @@ HostDataSourceUtils::compareOptions(const ConstCfgOptionPtr& cfg1, EXPECT_EQ(vendor_spaces.size(), cfg1->getVendorIdsSpaceNames().size()); // Iterate over all option spaces existing in cfg2. - BOOST_FOREACH (std::string space, option_spaces) { + for (auto const& space : option_spaces) { // Retrieve options belonging to the current option space. OptionContainerPtr options1 = cfg1->getAll(space); OptionContainerPtr options2 = cfg2->getAll(space); @@ -344,7 +345,7 @@ HostDataSourceUtils::compareOptions(const ConstCfgOptionPtr& cfg1, << "failed for option space " << space; // Iterate over all options within this option space. - BOOST_FOREACH (OptionDescriptor desc1, *options1) { + for (auto const& desc1 : *options1) { OptionDescriptor desc2 = cfg2->get(space, desc1.option_->getType()); // Compare persistent flag. EXPECT_EQ(desc1.persistent_, desc2.persistent_) diff --git a/src/lib/dhcpsrv/testutils/memory_host_data_source.cc b/src/lib/dhcpsrv/testutils/memory_host_data_source.cc index ef1b2bcd64..f570a4ac04 100644 --- a/src/lib/dhcpsrv/testutils/memory_host_data_source.cc +++ b/src/lib/dhcpsrv/testutils/memory_host_data_source.cc @@ -7,6 +7,7 @@ #include #include +#include using namespace isc::db; using namespace std; @@ -21,14 +22,14 @@ MemHostDataSource::getAll(const Host::IdentifierType& identifier_type, const size_t identifier_len) const { vector ident(identifier_begin, identifier_begin + identifier_len); ConstHostCollection hosts; - for (auto h = store_.begin(); h != store_.end(); ++h) { + for (auto const& h : store_) { // If identifier type do not match, it's not for us - if ((*h)->getIdentifierType() != identifier_type) { + if (h->getIdentifierType() != identifier_type) { continue; } // If the identifier matches, we found one! - if ((*h)->getIdentifier() == ident) { - hosts.push_back(*h); + if (h->getIdentifier() == ident) { + hosts.push_back(h); } } return (hosts); @@ -37,10 +38,10 @@ MemHostDataSource::getAll(const Host::IdentifierType& identifier_type, ConstHostCollection MemHostDataSource::getAll4(const SubnetID& subnet_id) const { ConstHostCollection hosts; - for (auto h = store_.begin(); h != store_.end(); ++h) { + for (auto const& h : store_) { // Keep it when subnet_id matches. - if ((*h)->getIPv4SubnetID() == subnet_id) { - hosts.push_back(*h); + if (h->getIPv4SubnetID() == subnet_id) { + hosts.push_back(h); } } return (hosts); @@ -49,10 +50,10 @@ MemHostDataSource::getAll4(const SubnetID& subnet_id) const { ConstHostCollection MemHostDataSource::getAll6(const SubnetID& subnet_id) const { ConstHostCollection hosts; - for (auto h = store_.begin(); h != store_.end(); ++h) { + for (auto const& h : store_) { // Keep it when subnet_id matches. - if ((*h)->getIPv6SubnetID() == subnet_id) { - hosts.push_back(*h); + if (h->getIPv6SubnetID() == subnet_id) { + hosts.push_back(h); } } return (hosts); @@ -61,10 +62,10 @@ MemHostDataSource::getAll6(const SubnetID& subnet_id) const { ConstHostCollection MemHostDataSource::getAllbyHostname(const std::string& hostname) const { ConstHostCollection hosts; - for (auto h = store_.begin(); h != store_.end(); ++h) { + for (auto const& h : store_) { // Keep it when hostname matches. - if ((*h)->getLowerHostname() == hostname) { - hosts.push_back(*h); + if (h->getLowerHostname() == hostname) { + hosts.push_back(h); } } return (hosts); @@ -74,11 +75,11 @@ ConstHostCollection MemHostDataSource::getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id) const { ConstHostCollection hosts; - for (auto h = store_.begin(); h != store_.end(); ++h) { + for (auto const& h : store_) { // Keep it when hostname and subnet_id match. - if (((*h)->getLowerHostname() == hostname) && - ((*h)->getIPv4SubnetID() == subnet_id)) { - hosts.push_back(*h); + if ((h->getLowerHostname() == hostname) && + (h->getIPv4SubnetID() == subnet_id)) { + hosts.push_back(h); } } return (hosts); @@ -88,11 +89,11 @@ ConstHostCollection MemHostDataSource::getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id) const { ConstHostCollection hosts; - for (auto h = store_.begin(); h != store_.end(); ++h) { + for (auto const& h : store_) { // Keep it when hostname and subnet_id match. - if (((*h)->getLowerHostname() == hostname) && - ((*h)->getIPv6SubnetID() == subnet_id)) { - hosts.push_back(*h); + if ((h->getLowerHostname() == hostname) && + (h->getIPv6SubnetID() == subnet_id)) { + hosts.push_back(h); } } return (hosts); @@ -104,15 +105,15 @@ MemHostDataSource::getPage4(const SubnetID& subnet_id, uint64_t lower_host_id, const HostPageSize& page_size) const { ConstHostCollection hosts; - for (auto h = store_.begin(); h != store_.end(); ++h) { + for (auto const& h : store_) { // Skip it when subnet_id does not match. - if ((*h)->getIPv4SubnetID() != subnet_id) { + if (h->getIPv4SubnetID() != subnet_id) { continue; } - if (lower_host_id && ((*h)->getHostId() <= lower_host_id)) { + if (lower_host_id && (h->getHostId() <= lower_host_id)) { continue; } - hosts.push_back(*h); + hosts.push_back(h); if (hosts.size() == page_size.page_size_) { break; } @@ -126,15 +127,15 @@ MemHostDataSource::getPage6(const SubnetID& subnet_id, uint64_t lower_host_id, const HostPageSize& page_size) const { ConstHostCollection hosts; - for (auto h = store_.begin(); h != store_.end(); ++h) { + for (auto const& h : store_) { // Skip it when subnet_id does not match. - if ((*h)->getIPv6SubnetID() != subnet_id) { + if (h->getIPv6SubnetID() != subnet_id) { continue; } - if (lower_host_id && ((*h)->getHostId() <= lower_host_id)) { + if (lower_host_id && (h->getHostId() <= lower_host_id)) { continue; } - hosts.push_back(*h); + hosts.push_back(h); if (hosts.size() == page_size.page_size_) { break; } @@ -147,11 +148,11 @@ MemHostDataSource::getPage4(size_t& /*source_index*/, uint64_t lower_host_id, const HostPageSize& page_size) const { ConstHostCollection hosts; - for (auto h = store_.begin(); h != store_.end(); ++h) { - if (lower_host_id && ((*h)->getHostId() <= lower_host_id)) { + for (auto const& h : store_) { + if (lower_host_id && (h->getHostId() <= lower_host_id)) { continue; } - hosts.push_back(*h); + hosts.push_back(h); if (hosts.size() == page_size.page_size_) { break; } @@ -164,11 +165,11 @@ MemHostDataSource::getPage6(size_t& /*source_index*/, uint64_t lower_host_id, const HostPageSize& page_size) const { ConstHostCollection hosts; - for (auto h = store_.begin(); h != store_.end(); ++h) { - if (lower_host_id && ((*h)->getHostId() <= lower_host_id)) { + for (auto const& h : store_) { + if (lower_host_id && (h->getHostId() <= lower_host_id)) { continue; } - hosts.push_back(*h); + hosts.push_back(h); if (hosts.size() == page_size.page_size_) { break; } @@ -179,7 +180,7 @@ MemHostDataSource::getPage6(size_t& /*source_index*/, ConstHostCollection MemHostDataSource::getAll4(const asiolink::IOAddress& address) const { ConstHostCollection hosts; - for (auto const & h : store_) { + for (auto const& h : store_) { if (h->getIPv4Reservation() == address) { hosts.push_back(h); } @@ -194,16 +195,16 @@ MemHostDataSource::get4(const SubnetID& subnet_id, const uint8_t* identifier_begin, const size_t identifier_len) const { vector ident(identifier_begin, identifier_begin + identifier_len); - for (auto h = store_.begin(); h != store_.end(); ++h) { + for (auto const& h : store_) { // If either subnet-id or identifier type do not match, // it's not our host - if (((*h)->getIPv4SubnetID() != subnet_id) || - ((*h)->getIdentifierType() != identifier_type)) { + if ((h->getIPv4SubnetID() != subnet_id) || + (h->getIdentifierType() != identifier_type)) { continue; } // If the identifier matches, we found it! - if ((*h)->getIdentifier() == ident) { - return (*h); + if (h->getIdentifier() == ident) { + return (h); } } @@ -217,16 +218,16 @@ MemHostDataSource::get6(const SubnetID& subnet_id, const uint8_t* identifier_begin, const size_t identifier_len) const { vector ident(identifier_begin, identifier_begin + identifier_len); - for (auto h = store_.begin(); h != store_.end(); ++h) { + for (auto const& h : store_) { // If either subnet-id or identifier type do not match, // it's not our host - if (((*h)->getIPv6SubnetID() != subnet_id) || - ((*h)->getIdentifierType() != identifier_type)) { + if ((h->getIPv6SubnetID() != subnet_id) || + (h->getIdentifierType() != identifier_type)) { continue; } // If the identifier matches, we found it! - if ((*h)->getIdentifier() == ident) { - return (*h); + if (h->getIdentifier() == ident) { + return (h); } } @@ -236,10 +237,10 @@ MemHostDataSource::get6(const SubnetID& subnet_id, ConstHostPtr MemHostDataSource::get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const { - for (auto h = store_.begin(); h != store_.end(); ++h) { - if ((*h)->getIPv4SubnetID() == subnet_id && - (*h)->getIPv4Reservation() == address) { - return (*h); + for (auto const& h : store_) { + if (h->getIPv4SubnetID() == subnet_id && + h->getIPv4Reservation() == address) { + return (h); } } @@ -250,7 +251,7 @@ ConstHostCollection MemHostDataSource::getAll4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const { ConstHostCollection hosts; - for (auto const & h : store_) { + for (auto const& h : store_) { if (h->getIPv4SubnetID() == subnet_id && h->getIPv4Reservation() == address) { hosts.push_back(h); @@ -269,22 +270,22 @@ MemHostDataSource::get6(const asiolink::IOAddress& /*prefix*/, ConstHostPtr MemHostDataSource::get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const { - for (auto h = store_.begin(); h != store_.end(); ++h) { + for (auto const& h : store_) { // Naive approach: check hosts one by one // First check: subnet-id must match. - if ((*h)->getIPv6SubnetID() != subnet_id) { + if (h->getIPv6SubnetID() != subnet_id) { // wrong subnet-id? ok, skip this one continue; } // Second check: the v6 reservation must much. This is very simple // as we ignore the reservation type. - auto resrvs = (*h)->getIPv6Reservations(); - for (auto r = resrvs.first; r != resrvs.second; ++r) { - if ((*r).second.getPrefix() == address) { - return (*h); + auto const& resrvs = h->getIPv6Reservations(); + BOOST_FOREACH(auto const& r, resrvs) { + if (r.second.getPrefix() == address) { + return (h); } } } @@ -296,14 +297,14 @@ ConstHostCollection MemHostDataSource::getAll6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const { ConstHostCollection hosts; - for (auto const & h : store_) { + for (auto const& h : store_) { if (h->getIPv6SubnetID() != subnet_id) { continue; } - auto resrvs = h->getIPv6Reservations(); - for (auto r = resrvs.first; r != resrvs.second; ++r) { - if ((*r).second.getPrefix() == address) { + auto const& resrvs = h->getIPv6Reservations(); + BOOST_FOREACH(auto const& r, resrvs) { + if (r.second.getPrefix() == address) { hosts.push_back(h); } } @@ -315,10 +316,10 @@ MemHostDataSource::getAll6(const SubnetID& subnet_id, ConstHostCollection MemHostDataSource::getAll6(const asiolink::IOAddress& address) const { ConstHostCollection hosts; - for (auto const & h : store_) { - auto resrvs = h->getIPv6Reservations(); - for (auto r = resrvs.first; r != resrvs.second; ++r) { - if ((*r).second.getPrefix() == address) { + for (auto const& h : store_) { + auto const& resrvs = h->getIPv6Reservations(); + BOOST_FOREACH(auto const& r, resrvs) { + if (r.second.getPrefix() == address) { hosts.push_back(h); } } @@ -351,9 +352,9 @@ MemHostDataSource::del(const SubnetID& subnet_id, // Second check: the v6 reservation must much. This is very simple // as we ignore the reservation type. - auto resrvs = (*h)->getIPv6Reservations(); - for (auto r = resrvs.first; r != resrvs.second; ++r) { - if ((*r).second.getPrefix() == addr) { + auto const& resrvs = (*h)->getIPv6Reservations(); + BOOST_FOREACH(auto const& r, resrvs) { + if (r.second.getPrefix() == addr) { store_.erase(h); return (true); } diff --git a/src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc b/src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc index 98be2a1337..51adf520fe 100644 --- a/src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc +++ b/src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc @@ -8,6 +8,7 @@ #include #include +#include #include using namespace isc::data; @@ -296,17 +297,15 @@ TestConfigBackendDHCPv4::getOptionDef4(const db::ServerSelector& server_selector auto const& index = option_defs_.get<1>(); auto option_def_it_pair = index.equal_range(code); - for (auto option_def_it = option_def_it_pair.first; - option_def_it != option_def_it_pair.second; - ++option_def_it) { - if ((*option_def_it)->getOptionSpaceName() == space) { + BOOST_FOREACH(auto const& option_def_it, option_def_it_pair) { + if (option_def_it->getOptionSpaceName() == space) { for (auto const& tag : tags) { - if ((*option_def_it)->hasServerTag(ServerTag(tag))) { - return (*option_def_it); + if (option_def_it->hasServerTag(ServerTag(tag))) { + return (option_def_it); } } - if ((*option_def_it)->hasAllServerTag()) { - candidate = *option_def_it; + if (option_def_it->hasAllServerTag()) { + candidate = option_def_it; } } } @@ -378,16 +377,15 @@ TestConfigBackendDHCPv4::getOption4(const db::ServerSelector& server_selector, auto const& index = options_.get<1>(); auto option_it_pair = index.equal_range(code); - for (auto option_it = option_it_pair.first; option_it != option_it_pair.second; - ++option_it) { - if (option_it->space_name_ == space) { + BOOST_FOREACH(auto const& option_it, option_it_pair) { + if (option_it.space_name_ == space) { for (auto const& tag : tags) { - if (option_it->hasServerTag(ServerTag(tag))) { - return (OptionDescriptorPtr(new OptionDescriptor(*option_it))); + if (option_it.hasServerTag(ServerTag(tag))) { + return (OptionDescriptorPtr(new OptionDescriptor(option_it))); } } - if (option_it->hasAllServerTag()) { - candidate = OptionDescriptorPtr(new OptionDescriptor(*option_it)); + if (option_it.hasAllServerTag()) { + candidate = OptionDescriptorPtr(new OptionDescriptor(option_it)); } } } @@ -451,15 +449,14 @@ TestConfigBackendDHCPv4::getGlobalParameter4(const db::ServerSelector& server_se auto candidate = StampedValuePtr(); auto const& index = globals_.get(); auto global_range = index.equal_range(name); - for (auto global_it = global_range.first; global_it != global_range.second; - ++global_it) { + BOOST_FOREACH(auto const& global_it, global_range) { for (auto const& tag : tags) { - if ((*global_it)->hasServerTag(ServerTag(tag))) { - return (*global_it); + if (global_it->hasServerTag(ServerTag(tag))) { + return (global_it); } } - if ((*global_it)->hasAllServerTag()) { - candidate = *global_it; + if (global_it->hasAllServerTag()) { + candidate = global_it; } } @@ -1091,9 +1088,9 @@ TestConfigBackendDHCPv4::deleteSharedNetwork4(const db::ServerSelector& server_s } // Remove this shared network. - for (auto subnet = subnets_.begin(); subnet != subnets_.end(); ++subnet) { - if ((*subnet)->getSharedNetworkName() == name) { - (*subnet)->setSharedNetworkName(""); + for (auto const& subnet : subnets_) { + if (subnet->getSharedNetworkName() == name) { + subnet->setSharedNetworkName(""); } } (*network_it)->delAll(); diff --git a/src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.cc b/src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.cc index 9a3fe1d6d7..c31b14745b 100644 --- a/src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.cc +++ b/src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.cc @@ -8,6 +8,7 @@ #include #include +#include using namespace isc::data; using namespace isc::db; @@ -48,7 +49,7 @@ TestConfigBackendDHCPv6::getSubnet6(const db::ServerSelector& server_selector, if (server_selector.amUnassigned()) { return (subnet->getServerTags().empty() ? subnet : Subnet6Ptr()); } - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (subnet->hasServerTag(ServerTag(tag))) { return (subnet); @@ -72,7 +73,7 @@ TestConfigBackendDHCPv6::getSubnet6(const db::ServerSelector& server_selector, if (server_selector.amUnassigned()) { return (subnet->getServerTags().empty() ? subnet : Subnet6Ptr()); } - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (subnet->hasServerTag(ServerTag(tag))) { return (subnet); @@ -96,7 +97,7 @@ TestConfigBackendDHCPv6::getAllSubnets6(const db::ServerSelector& server_selecto continue; } bool got = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (subnet->hasServerTag(ServerTag(tag))) { subnets.insert(subnet); @@ -132,7 +133,7 @@ TestConfigBackendDHCPv6::getModifiedSubnets6(const db::ServerSelector& server_se continue; } bool got = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if ((*subnet)->hasServerTag(ServerTag(tag))) { subnets.insert(*subnet); @@ -166,7 +167,7 @@ TestConfigBackendDHCPv6::getSharedNetworkSubnets6(const db::ServerSelector& serv } if (!server_selector.amAny()) { bool got = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (subnet->hasServerTag(ServerTag(tag))) { got = true; @@ -208,7 +209,7 @@ TestConfigBackendDHCPv6::getSharedNetwork6(const db::ServerSelector& server_sele if (server_selector.amUnassigned()) { return (network->getServerTags().empty() ? network : SharedNetwork6Ptr()); } - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (network->hasServerTag(ServerTag(tag))) { return (network); @@ -232,7 +233,7 @@ TestConfigBackendDHCPv6::getAllSharedNetworks6(const db::ServerSelector& server_ continue; } bool got = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (shared_network->hasServerTag(ServerTag(tag))) { shared_networks.push_back(shared_network); @@ -268,7 +269,7 @@ TestConfigBackendDHCPv6::getModifiedSharedNetworks6(const db::ServerSelector& se continue; } bool got = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if ((*shared_network)->hasServerTag(ServerTag(tag))) { shared_networks.push_back(*shared_network); @@ -290,22 +291,20 @@ OptionDefinitionPtr TestConfigBackendDHCPv6::getOptionDef6(const db::ServerSelector& server_selector, const uint16_t code, const std::string& space) const { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); auto candidate = OptionDefinitionPtr(); auto const& index = option_defs_.get<1>(); auto option_def_it_pair = index.equal_range(code); - for (auto option_def_it = option_def_it_pair.first; - option_def_it != option_def_it_pair.second; - ++option_def_it) { - if ((*option_def_it)->getOptionSpaceName() == space) { + BOOST_FOREACH(auto const& option_def_it, option_def_it_pair) { + if (option_def_it->getOptionSpaceName() == space) { for (auto const& tag : tags) { - if ((*option_def_it)->hasServerTag(ServerTag(tag))) { - return (*option_def_it); + if (option_def_it->hasServerTag(ServerTag(tag))) { + return (option_def_it); } } - if ((*option_def_it)->hasAllServerTag()) { - candidate = *option_def_it; + if (option_def_it->hasAllServerTag()) { + candidate = option_def_it; } } } @@ -314,7 +313,7 @@ TestConfigBackendDHCPv6::getOptionDef6(const db::ServerSelector& server_selector OptionDefContainer TestConfigBackendDHCPv6::getAllOptionDefs6(const db::ServerSelector& server_selector) const { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); OptionDefContainer option_defs; for (auto const& option_def : option_defs_) { bool got = false; @@ -345,7 +344,7 @@ TestConfigBackendDHCPv6::getAllOptionDefs6(const db::ServerSelector& server_sele OptionDefContainer TestConfigBackendDHCPv6::getModifiedOptionDefs6(const db::ServerSelector& server_selector, const boost::posix_time::ptime& modification_time) const { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); OptionDefContainer option_defs; auto const& index = option_defs_.get<3>(); auto lb = index.lower_bound(modification_time); @@ -372,21 +371,20 @@ OptionDescriptorPtr TestConfigBackendDHCPv6::getOption6(const db::ServerSelector& server_selector, const uint16_t code, const std::string& space) const { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); auto candidate = OptionDescriptorPtr(); auto const& index = options_.get<1>(); auto option_it_pair = index.equal_range(code); - for (auto option_it = option_it_pair.first; option_it != option_it_pair.second; - ++option_it) { - if (option_it->space_name_ == space) { + BOOST_FOREACH(auto const& option_it, option_it_pair) { + if (option_it.space_name_ == space) { for (auto const& tag : tags) { - if (option_it->hasServerTag(ServerTag(tag))) { - return (OptionDescriptorPtr(new OptionDescriptor(*option_it))); + if (option_it.hasServerTag(ServerTag(tag))) { + return (OptionDescriptorPtr(new OptionDescriptor(option_it))); } } - if (option_it->hasAllServerTag()) { - candidate = OptionDescriptorPtr(new OptionDescriptor(*option_it)); + if (option_it.hasAllServerTag()) { + candidate = OptionDescriptorPtr(new OptionDescriptor(option_it)); } } } @@ -396,7 +394,7 @@ TestConfigBackendDHCPv6::getOption6(const db::ServerSelector& server_selector, OptionContainer TestConfigBackendDHCPv6::getAllOptions6(const db::ServerSelector& server_selector) const { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); OptionContainer options; for (auto const& option : options_) { bool got = false; @@ -420,7 +418,7 @@ TestConfigBackendDHCPv6::getAllOptions6(const db::ServerSelector& server_selecto OptionContainer TestConfigBackendDHCPv6::getModifiedOptions6(const db::ServerSelector& server_selector, const boost::posix_time::ptime& modification_time) const { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); OptionContainer options; auto const& index = options_.get<3>(); auto lb = index.lower_bound(modification_time); @@ -446,19 +444,18 @@ TestConfigBackendDHCPv6::getModifiedOptions6(const db::ServerSelector& server_se StampedValuePtr TestConfigBackendDHCPv6::getGlobalParameter6(const db::ServerSelector& server_selector, const std::string& name) const { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); auto candidate = StampedValuePtr(); auto const& index = globals_.get(); auto global_range = index.equal_range(name); - for (auto global_it = global_range.first; global_it != global_range.second; - ++global_it) { + BOOST_FOREACH(auto const& global_it, global_range) { for (auto const& tag : tags) { - if ((*global_it)->hasServerTag(ServerTag(tag))) { - return (*global_it); + if (global_it->hasServerTag(ServerTag(tag))) { + return (global_it); } } - if ((*global_it)->hasAllServerTag()) { - candidate = *global_it; + if (global_it->hasAllServerTag()) { + candidate = global_it; } } @@ -468,7 +465,7 @@ TestConfigBackendDHCPv6::getGlobalParameter6(const db::ServerSelector& server_se StampedValueCollection TestConfigBackendDHCPv6::getAllGlobalParameters6(const db::ServerSelector& server_selector) const { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); StampedValueCollection globals; for (auto const& global : globals_) { bool got = false; @@ -492,7 +489,7 @@ TestConfigBackendDHCPv6::getAllGlobalParameters6(const db::ServerSelector& serve StampedValueCollection TestConfigBackendDHCPv6::getModifiedGlobalParameters6(const db::ServerSelector& server_selector, const boost::posix_time::ptime& modification_time) const { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); StampedValueCollection globals; auto const& index = globals_.get(); auto lb = index.lower_bound(modification_time); @@ -531,7 +528,7 @@ TestConfigBackendDHCPv6::getClientClass6(const db::ServerSelector& server_select if (server_selector.amUnassigned()) { return (client_class->getServerTags().empty() ? client_class : ClientClassDefPtr()); } - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (client_class->hasServerTag(ServerTag(tag))) { return (client_class); @@ -542,7 +539,7 @@ TestConfigBackendDHCPv6::getClientClass6(const db::ServerSelector& server_select ClientClassDictionary TestConfigBackendDHCPv6::getAllClientClasses6(const db::ServerSelector& server_selector) const { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); ClientClassDictionary all_classes; for (auto const& client_class : classes_) { if (server_selector.amAny()) { @@ -576,7 +573,7 @@ TestConfigBackendDHCPv6::getAllClientClasses6(const db::ServerSelector& server_s ClientClassDictionary TestConfigBackendDHCPv6::getModifiedClientClasses6(const db::ServerSelector& server_selector, const boost::posix_time::ptime& modification_time) const { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); ClientClassDictionary modified_classes; for (auto const& client_class : classes_) { if (client_class->getModificationTime() >= modification_time) { @@ -695,7 +692,7 @@ TestConfigBackendDHCPv6::createUpdateSharedNetwork6(const db::ServerSelector& se void TestConfigBackendDHCPv6::createUpdateOptionDef6(const db::ServerSelector& server_selector, const OptionDefinitionPtr& option_def) { - auto tag = getServerTag(server_selector); + auto const& tag = getServerTag(server_selector); option_def->setServerTag(tag); // Index #1 is by option code. @@ -734,7 +731,7 @@ TestConfigBackendDHCPv6::createUpdateOptionDef6(const db::ServerSelector& server void TestConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& server_selector, const OptionDescriptorPtr& option) { - auto tag = getServerTag(server_selector); + auto const& tag = getServerTag(server_selector); option->setServerTag(tag); auto& index = options_.get<1>(); @@ -776,7 +773,7 @@ TestConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& server_se } else if (shared_network->hasAllServerTag()) { found = true; } else { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (shared_network->hasServerTag(ServerTag(tag))) { found = true; @@ -817,7 +814,7 @@ TestConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& server_se } else if (subnet->hasAllServerTag()) { found = true; } else { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (subnet->hasServerTag(ServerTag(tag))) { found = true; @@ -856,7 +853,7 @@ TestConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& server_se } } else if (!server_selector.amAny() && !subnet->hasAllServerTag()) { auto in_tags = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (subnet->hasServerTag(ServerTag(tag))) { in_tags = true; @@ -910,7 +907,7 @@ TestConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& server_se } } else if (!server_selector.amAny() && !subnet->hasAllServerTag()) { auto in_tags = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (subnet->hasServerTag(ServerTag(tag))) { in_tags = true; @@ -946,7 +943,7 @@ TestConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& server_se void TestConfigBackendDHCPv6::createUpdateGlobalParameter6(const db::ServerSelector& server_selector, const data::StampedValuePtr& value) { - auto tag = getServerTag(server_selector); + auto const& tag = getServerTag(server_selector); value->setServerTag(tag); auto& index = globals_.get(); @@ -991,7 +988,7 @@ TestConfigBackendDHCPv6::deleteSubnet6(const db::ServerSelector& server_selector } if (!server_selector.amAny()) { bool got = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if ((*subnet_it)->hasServerTag(ServerTag(tag))) { got = true; @@ -1019,7 +1016,7 @@ TestConfigBackendDHCPv6::deleteSubnet6(const db::ServerSelector& server_selector } if (!server_selector.amAny()) { bool got = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if ((*subnet_it)->hasServerTag(ServerTag(tag))) { got = true; @@ -1049,7 +1046,7 @@ TestConfigBackendDHCPv6::deleteAllSubnets6(const db::ServerSelector& server_sele continue; } bool got = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (subnet->hasServerTag(ServerTag(tag))) { ids.push_back(subnet->getID()); @@ -1087,7 +1084,7 @@ TestConfigBackendDHCPv6::deleteSharedNetworkSubnets6(const db::ServerSelector& s } if (!server_selector.amAny()) { bool got = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if ((*subnet)->hasServerTag(ServerTag(tag))) { got = true; @@ -1131,7 +1128,7 @@ TestConfigBackendDHCPv6::deleteSharedNetwork6(const db::ServerSelector& server_s } if (!server_selector.amAny()) { bool got = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if ((*network_it)->hasServerTag(ServerTag(tag))) { got = true; @@ -1144,9 +1141,9 @@ TestConfigBackendDHCPv6::deleteSharedNetwork6(const db::ServerSelector& server_s } // Remove this shared network. - for (auto subnet = subnets_.begin(); subnet != subnets_.end(); ++subnet) { - if ((*subnet)->getSharedNetworkName() == name) { - (*subnet)->setSharedNetworkName(""); + for (auto const& subnet : subnets_) { + if (subnet->getSharedNetworkName() == name) { + subnet->setSharedNetworkName(""); } } (*network_it)->delAll(); @@ -1169,7 +1166,7 @@ TestConfigBackendDHCPv6::deleteAllSharedNetworks6(const db::ServerSelector& serv continue; } bool got = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (shared_network->hasServerTag(ServerTag(tag))) { names.push_back(shared_network->getName()); @@ -1198,7 +1195,7 @@ uint64_t TestConfigBackendDHCPv6::deleteOptionDef6(const db::ServerSelector& server_selector, const uint16_t code, const std::string& space) { - auto tag = getServerTag(server_selector); + auto const& tag = getServerTag(server_selector); uint64_t erased = 0; for (auto option_def_it = option_defs_.begin(); option_def_it != option_defs_.end(); ) { if (((*option_def_it)->getCode() == code) && @@ -1215,7 +1212,7 @@ TestConfigBackendDHCPv6::deleteOptionDef6(const db::ServerSelector& server_selec uint64_t TestConfigBackendDHCPv6::deleteAllOptionDefs6(const db::ServerSelector& server_selector) { - auto tag = getServerTag(server_selector); + auto const& tag = getServerTag(server_selector); uint64_t erased = 0; for (auto option_def_it = option_defs_.begin(); option_def_it != option_defs_.end(); ) { if ((*option_def_it)->hasServerTag(ServerTag(tag))) { @@ -1232,7 +1229,7 @@ uint64_t TestConfigBackendDHCPv6::deleteOption6(const db::ServerSelector& server_selector, const uint16_t code, const std::string& space) { - auto tag = getServerTag(server_selector); + auto const& tag = getServerTag(server_selector); uint64_t erased = 0; for (auto option_it = options_.begin(); option_it != options_.end(); ) { if ((option_it->option_->getType() == code) && @@ -1271,7 +1268,7 @@ TestConfigBackendDHCPv6::deleteOption6(const db::ServerSelector& server_selector } else if (shared_network->hasAllServerTag()) { found = true; } else { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (shared_network->hasServerTag(ServerTag(tag))) { found = true; @@ -1312,7 +1309,7 @@ TestConfigBackendDHCPv6::deleteOption6(const db::ServerSelector& server_selector } else if (subnet->hasAllServerTag()) { found = true; } else { - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (subnet->hasServerTag(ServerTag(tag))) { found = true; @@ -1352,7 +1349,7 @@ TestConfigBackendDHCPv6::deleteOption6(const db::ServerSelector& server_selector } } else if (!server_selector.amAny() && !subnet->hasAllServerTag()) { auto in_tags = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (subnet->hasServerTag(ServerTag(tag))) { in_tags = true; @@ -1401,7 +1398,7 @@ TestConfigBackendDHCPv6::deleteOption6(const db::ServerSelector& server_selector } } else if (!server_selector.amAny() && !subnet->hasAllServerTag()) { auto in_tags = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (subnet->hasServerTag(ServerTag(tag))) { in_tags = true; @@ -1433,7 +1430,7 @@ TestConfigBackendDHCPv6::deleteOption6(const db::ServerSelector& server_selector uint64_t TestConfigBackendDHCPv6::deleteGlobalParameter6(const db::ServerSelector& server_selector, const std::string& name) { - auto tag = getServerTag(server_selector); + auto const& tag = getServerTag(server_selector); auto& index = globals_.get(); auto global_it_pair = index.equal_range(name); @@ -1450,7 +1447,7 @@ TestConfigBackendDHCPv6::deleteGlobalParameter6(const db::ServerSelector& server uint64_t TestConfigBackendDHCPv6::deleteAllGlobalParameters6(const db::ServerSelector& server_selector) { - auto tag = getServerTag(server_selector); + auto const& tag = getServerTag(server_selector); uint64_t cnt = 0; for (auto global_it = globals_.begin(); global_it != globals_.end(); ) { auto value = *global_it; @@ -1484,7 +1481,7 @@ TestConfigBackendDHCPv6::deleteClientClass6(const db::ServerSelector& server_sel } if (!server_selector.amAny()) { bool got = false; - auto tags = server_selector.getTags(); + auto const& tags = server_selector.getTags(); for (auto const& tag : tags) { if (existing_class->hasServerTag(ServerTag(tag))) { got = true; @@ -1517,8 +1514,8 @@ TestConfigBackendDHCPv6::deleteAllClientClasses6(const db::ServerSelector& serve continue; } bool got = false; - auto tags = server_selector.getTags(); - for (auto tag : tags) { + auto const& tags = server_selector.getTags(); + for (auto const& tag : tags) { if (client_class->hasServerTag(ServerTag(tag))) { c = classes_.erase(c); ++count; diff --git a/src/lib/dhcpsrv/timer_mgr.cc b/src/lib/dhcpsrv/timer_mgr.cc index cc4005b177..e5adce66ef 100644 --- a/src/lib/dhcpsrv/timer_mgr.cc +++ b/src/lib/dhcpsrv/timer_mgr.cc @@ -334,9 +334,8 @@ TimerMgrImpl::unregisterTimersInternal() { TimerInfoMap registered_timers_copy(registered_timers_); // Iterate over the existing timers and unregister them. - for (TimerInfoMap::iterator timer_info_it = registered_timers_copy.begin(); - timer_info_it != registered_timers_copy.end(); ++timer_info_it) { - unregisterTimerInternal(timer_info_it->first); + for (auto const& timer_info_it : registered_timers_copy) { + unregisterTimerInternal(timer_info_it.first); } } diff --git a/src/lib/dhcpsrv/tracking_lease_mgr.cc b/src/lib/dhcpsrv/tracking_lease_mgr.cc index 35c8192b47..2424e2642a 100644 --- a/src/lib/dhcpsrv/tracking_lease_mgr.cc +++ b/src/lib/dhcpsrv/tracking_lease_mgr.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include using namespace isc::asiolink; @@ -139,8 +140,7 @@ TrackingLeaseMgr::runCallbacksForSubnetID(CallbackType type, SubnetID subnet_id, if (cbs.first == cbs.second) { return; } - for (auto it = cbs.first; it != cbs.second; ++it) { - auto cb = *it; + BOOST_FOREACH(auto const& cb, cbs) { try { cb.fn(lease); } catch (const std::exception& ex) { diff --git a/src/lib/dns/master_lexer.cc b/src/lib/dns/master_lexer.cc index 0d1292e0c3..a9fa83591f 100644 --- a/src/lib/dns/master_lexer.cc +++ b/src/lib/dns/master_lexer.cc @@ -12,7 +12,6 @@ #include #include -#include #include #include @@ -213,7 +212,7 @@ MasterLexer::getTotalSourceSize() const { size_t MasterLexer::getPosition() const { size_t position = impl_->popped_size_; - BOOST_FOREACH(InputSourcePtr& src, impl_->sources_) { + for (auto const& src : impl_->sources_) { position += src->getPosition(); } return (position); diff --git a/src/lib/dns/master_loader.cc b/src/lib/dns/master_loader.cc index 568fdea507..c1ed91a094 100644 --- a/src/lib/dns/master_loader.cc +++ b/src/lib/dns/master_loader.cc @@ -638,7 +638,7 @@ MasterLoader::MasterLoaderImpl::generateForIter(const std::string& str, { std::string rstr; - for (std::string::const_iterator it = str.begin(); it != str.end();) { + for (auto it = str.begin(); it != str.end();) { switch (*it) { case '$': // This is the case when the '$' character is encountered in diff --git a/src/lib/dns/message.cc b/src/lib/dns/message.cc index fe05a3e588..4fb105b477 100644 --- a/src/lib/dns/message.cc +++ b/src/lib/dns/message.cc @@ -14,7 +14,6 @@ #include #include -#include #include #include @@ -527,7 +526,7 @@ Message::hasRRset(const Section section, const Name& name, isc_throw(OutOfRange, "Invalid message section: " << static_cast(section)); } - BOOST_FOREACH(ConstRRsetPtr r, impl_->rrsets_[section]) { + for (auto const& r : impl_->rrsets_[section]) { if (r->getClass() == rrclass && r->getType() == rrtype && r->getName() == name) { @@ -551,8 +550,7 @@ Message::removeRRset(const Section section, RRsetIterator& iterator) { } bool removed = false; - for (vector::iterator i = impl_->rrsets_[section].begin(); - i != impl_->rrsets_[section].end(); ++i) { + for (auto i = impl_->rrsets_[section].begin(); i != impl_->rrsets_[section].end(); ++i) { if (((*i)->getName() == (*iterator)->getName()) && ((*i)->getClass() == (*iterator)->getClass()) && ((*i)->getType() == (*iterator)->getType())) { @@ -1001,15 +999,11 @@ Message::appendSection(const Section section, const Message& source) { } if (section == SECTION_QUESTION) { - for (QuestionIterator qi = source.beginQuestion(); - qi != source.endQuestion(); - ++qi) { + for (auto qi = source.beginQuestion(); qi != source.endQuestion(); ++qi) { addQuestion(*qi); } } else { - for (RRsetIterator rrsi = source.beginSection(section); - rrsi != source.endSection(section); - ++rrsi) { + for (auto rrsi = source.beginSection(section); rrsi != source.endSection(section); ++rrsi) { addRRset(section, *rrsi); } } diff --git a/src/lib/dns/name.cc b/src/lib/dns/name.cc index 3f75fa0064..cec88f03d2 100644 --- a/src/lib/dns/name.cc +++ b/src/lib/dns/name.cc @@ -359,8 +359,7 @@ Name::Name(const char* namedata, size_t data_len, const Name* origin, size_t offset_count = offsets_.size(); offsets_.insert(offsets_.end(), origin->offsets_.begin(), origin->offsets_.end()); - for (NameOffsets::iterator it(offsets_.begin() + offset_count); - it != offsets_.end(); ++it) { + for (auto it(offsets_.begin() + offset_count); it != offsets_.end(); ++it) { *it += offset; } diff --git a/src/lib/dns/rdata/generic/detail/char_string.cc b/src/lib/dns/rdata/generic/detail/char_string.cc index 8eee8c0edc..485eba395a 100644 --- a/src/lib/dns/rdata/generic/detail/char_string.cc +++ b/src/lib/dns/rdata/generic/detail/char_string.cc @@ -123,9 +123,13 @@ stringToCharStringData(const MasterToken::StringRegion& str_region, std::string charStringToString(const CharString& char_string) { std::string s; - for (CharString::const_iterator it = char_string.begin() + 1; - it != char_string.end(); ++it) { - const uint8_t ch = *it; + bool first = true; + for (auto const& it : char_string) { + if (first) { + first = false; + continue; + } + const uint8_t ch = it; if ((ch < 0x20) || (ch >= 0x7f)) { // convert to escaped \xxx (decimal) format s.push_back('\\'); @@ -146,9 +150,8 @@ charStringToString(const CharString& char_string) { std::string charStringDataToString(const CharStringData& char_string) { std::string s; - for (CharString::const_iterator it = char_string.begin(); - it != char_string.end(); ++it) { - const uint8_t ch = *it; + for (auto const& it : char_string) { + const uint8_t ch = it; if ((ch < 0x20) || (ch >= 0x7f)) { // convert to escaped \xxx (decimal) format s.push_back('\\'); diff --git a/src/lib/dns/rdata/generic/dnskey_48.cc b/src/lib/dns/rdata/generic/dnskey_48.cc index 7bea847427..f1b60f3c25 100644 --- a/src/lib/dns/rdata/generic/dnskey_48.cc +++ b/src/lib/dns/rdata/generic/dnskey_48.cc @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/src/lib/dns/rdata/generic/opt_41.cc b/src/lib/dns/rdata/generic/opt_41.cc index 40cb1c73ae..6dcb6ff7f6 100644 --- a/src/lib/dns/rdata/generic/opt_41.cc +++ b/src/lib/dns/rdata/generic/opt_41.cc @@ -11,8 +11,6 @@ #include #include -#include - #include #include @@ -157,7 +155,7 @@ OPT::toText() const { void OPT::toWire(OutputBuffer& buffer) const { - BOOST_FOREACH(const PseudoRR& pseudo_rr, impl_->pseudo_rrs_) { + for (auto const& pseudo_rr : impl_->pseudo_rrs_) { buffer.writeUint16(pseudo_rr.getCode()); const uint16_t length = pseudo_rr.getLength(); buffer.writeUint16(length); @@ -169,7 +167,7 @@ OPT::toWire(OutputBuffer& buffer) const { void OPT::toWire(AbstractMessageRenderer& renderer) const { - BOOST_FOREACH(const PseudoRR& pseudo_rr, impl_->pseudo_rrs_) { + for (auto const& pseudo_rr : impl_->pseudo_rrs_) { renderer.writeUint16(pseudo_rr.getCode()); const uint16_t length = pseudo_rr.getLength(); renderer.writeUint16(length); diff --git a/src/lib/dns/rdataclass.cc b/src/lib/dns/rdataclass.cc index dcd5e13895..9b50b9a054 100644 --- a/src/lib/dns/rdataclass.cc +++ b/src/lib/dns/rdataclass.cc @@ -1549,7 +1549,6 @@ DNAME::getDname() const { #include #include -#include #include #include @@ -3646,8 +3645,6 @@ NSEC::compare(const Rdata& other) const { #include #include -#include - #include #include @@ -3794,7 +3791,7 @@ OPT::toText() const { void OPT::toWire(OutputBuffer& buffer) const { - BOOST_FOREACH(const PseudoRR& pseudo_rr, impl_->pseudo_rrs_) { + for (auto const& pseudo_rr : impl_->pseudo_rrs_) { buffer.writeUint16(pseudo_rr.getCode()); const uint16_t length = pseudo_rr.getLength(); buffer.writeUint16(length); @@ -3806,7 +3803,7 @@ OPT::toWire(OutputBuffer& buffer) const { void OPT::toWire(AbstractMessageRenderer& renderer) const { - BOOST_FOREACH(const PseudoRR& pseudo_rr, impl_->pseudo_rrs_) { + for (auto const& pseudo_rr : impl_->pseudo_rrs_) { renderer.writeUint16(pseudo_rr.getCode()); const uint16_t length = pseudo_rr.getLength(); renderer.writeUint16(length); diff --git a/src/lib/dns/rrset.cc b/src/lib/dns/rrset.cc index b2170029d4..5359cd77ab 100644 --- a/src/lib/dns/rrset.cc +++ b/src/lib/dns/rrset.cc @@ -11,7 +11,6 @@ #include #include -#include #include #include @@ -202,7 +201,7 @@ BasicRRsetImpl::toWire(AbstractMessageRenderer& renderer, size_t limit) const { // sort the set of Rdata based on rrset-order and sortlist, and possible // other options. Details to be considered. - BOOST_FOREACH(const ConstRdataPtr& rdata, rdatalist_) { + for (auto const& rdata : rdatalist_) { const size_t pos0 = renderer.getLength(); assert(pos0 < 65536); diff --git a/src/lib/dns/tests/message_unittest.cc b/src/lib/dns/tests/message_unittest.cc index 8b6832b7dc..5dbf687a91 100644 --- a/src/lib/dns/tests/message_unittest.cc +++ b/src/lib/dns/tests/message_unittest.cc @@ -880,10 +880,8 @@ commonTSIGToWireCheck(Message& message, MessageRenderer& renderer, if (answer_data != NULL) { RRsetPtr ans_rrset(new RRset(Name("www.example.com"), RRClass::IN(), qtype, RRTTL(86400))); - for (vector::const_iterator it = answer_data->begin(); - it != answer_data->end(); - ++it) { - ans_rrset->addRdata(createRdata(qtype, RRClass::IN(), *it)); + for (auto const& it : *answer_data) { + ans_rrset->addRdata(createRdata(qtype, RRClass::IN(), it)); } message.addRRset(Message::SECTION_ANSWER, ans_rrset); } diff --git a/src/lib/dns/tests/name_unittest.cc b/src/lib/dns/tests/name_unittest.cc index caf1f12e16..f9a3dbc7fe 100644 --- a/src/lib/dns/tests/name_unittest.cc +++ b/src/lib/dns/tests/name_unittest.cc @@ -226,9 +226,8 @@ TEST_F(NameTest, fromText) { // decimal representation for "WWW" strnames.push_back("\\087\\087\\087.example.com"); - vector::const_iterator it; - for (it = strnames.begin(); it != strnames.end(); ++it) { - EXPECT_PRED_FORMAT2(UnitTestUtil::matchName, example_name, Name(*it)); + for (auto const& it : strnames) { + EXPECT_PRED_FORMAT2(UnitTestUtil::matchName, example_name, Name(it)); } // root names @@ -595,13 +594,11 @@ TEST_F(NameTest, compare) { NameComparisonResult::EQUAL, 0, 5)); - vector::const_iterator it; - for (it = params.begin(); it != params.end(); ++it) { - NameComparisonResult result = (*it).name1.compare((*it).name2); - EXPECT_EQ((*it).reln, result.getRelation()); - EXPECT_EQ((*it).order, - CompareParameters::normalizeOrder(result.getOrder())); - EXPECT_EQ((*it).labels, result.getCommonLabels()); + for (auto const& it : params) { + NameComparisonResult result = it.name1.compare(it.name2); + EXPECT_EQ(it.reln, result.getRelation()); + EXPECT_EQ(it.order, CompareParameters::normalizeOrder(result.getOrder())); + EXPECT_EQ(it.labels, result.getCommonLabels()); } } diff --git a/src/lib/dns/tests/rdata_nsec_unittest.cc b/src/lib/dns/tests/rdata_nsec_unittest.cc index 570a2abb58..613ef26347 100644 --- a/src/lib/dns/tests/rdata_nsec_unittest.cc +++ b/src/lib/dns/tests/rdata_nsec_unittest.cc @@ -126,6 +126,7 @@ TEST_F(Rdata_NSEC_Test, compare) { vector compare_set; compare_set.push_back(generic::NSEC("a.example. A")); compare_set.push_back(generic::NSEC("example. A")); + vector::const_iterator it; const vector::const_iterator it_end = compare_set.end(); for (it = compare_set.begin(); it != it_end - 1; ++it) { diff --git a/src/lib/dns/tests/rdata_txt_like_unittest.cc b/src/lib/dns/tests/rdata_txt_like_unittest.cc index e2828c2d3a..a9f5cee74d 100644 --- a/src/lib/dns/tests/rdata_txt_like_unittest.cc +++ b/src/lib/dns/tests/rdata_txt_like_unittest.cc @@ -186,9 +186,8 @@ TYPED_TEST(Rdata_TXT_LIKE_Test, createMultiStringsFromText) { texts.push_back("Test-String\"Test-String\""); // and no space either std::stringstream ss; - for (std::vector::const_iterator it = texts.begin(); - it != texts.end(); ++it) { - ss << *it << "\n"; + for (auto const& it : texts) { + ss << it << "\n"; } this->lexer.pushSource(ss); @@ -199,10 +198,9 @@ TYPED_TEST(Rdata_TXT_LIKE_Test, createMultiStringsFromText) { // Confirm we can construct the Rdata from the test text, both from // std::string and with lexer, and that matches the from-wire data. - for (std::vector::const_iterator it = texts.begin(); - it != texts.end(); ++it) { - SCOPED_TRACE(*it); - EXPECT_EQ(0, TypeParam(*it).compare(*rdata)); + for (auto const& it : texts) { + SCOPED_TRACE(it); + EXPECT_EQ(0, TypeParam(it).compare(*rdata)); EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, this->loader_cb).compare(*rdata)); diff --git a/src/lib/dns/tests/rrset_collection_unittest.cc b/src/lib/dns/tests/rrset_collection_unittest.cc index be16ab5b51..fa6923535b 100644 --- a/src/lib/dns/tests/rrset_collection_unittest.cc +++ b/src/lib/dns/tests/rrset_collection_unittest.cc @@ -154,10 +154,9 @@ TEST_F(RRsetCollectionTest, iteratorTest) { // Here, we just count the records and do some basic tests on them. size_t count = 0; - for (RRsetCollection::Iterator it = collection.begin(); - it != collection.end(); ++it) { + for (auto const& it : collection) { ++count; - const AbstractRRset& rrset = *it; + const AbstractRRset& rrset = it; EXPECT_EQ(rrclass, rrset.getClass()); EXPECT_EQ(RRTTL(3600), rrset.getTTL()); } diff --git a/src/lib/eval/dependency.cc b/src/lib/eval/dependency.cc index 66e36007ec..98b61bc6f8 100644 --- a/src/lib/eval/dependency.cc +++ b/src/lib/eval/dependency.cc @@ -25,13 +25,13 @@ bool dependOnClass(const ExpressionPtr& expr, const std::string& name) { if (!expr) { return (false); } - for (auto it = expr->cbegin(); it != expr->cend(); ++it) { - if (dependOnClass(*it, name)) { + for (auto const& it : *expr) { + if (dependOnClass(it, name)) { return (true); } } return (false); } -}; // end of isc::dhcp namespace -}; // end of isc namespace +} // end of isc::dhcp namespace +} // end of isc namespace diff --git a/src/lib/eval/evaluate.cc b/src/lib/eval/evaluate.cc index f2cadce925..530f1a902e 100644 --- a/src/lib/eval/evaluate.cc +++ b/src/lib/eval/evaluate.cc @@ -13,9 +13,8 @@ namespace dhcp { bool evaluateBool(const Expression& expr, Pkt& pkt) { ValueStack values; - for (Expression::const_iterator it = expr.begin(); - it != expr.end(); ++it) { - (*it)->evaluate(pkt, values); + for (auto const& it : expr) { + it->evaluate(pkt, values); } if (values.size() != 1) { isc_throw(EvalBadStack, "Incorrect stack order. Expected exactly " @@ -27,8 +26,8 @@ bool evaluateBool(const Expression& expr, Pkt& pkt) { std::string evaluateString(const Expression& expr, Pkt& pkt) { ValueStack values; - for (auto it = expr.begin(); it != expr.end(); ++it) { - (*it)->evaluate(pkt, values); + for (auto const& it : expr) { + it->evaluate(pkt, values); } if (values.size() != 1) { isc_throw(EvalBadStack, "Incorrect stack order. Expected exactly " @@ -37,6 +36,5 @@ evaluateString(const Expression& expr, Pkt& pkt) { return (values.top()); } - -}; // end of isc::dhcp namespace -}; // end of isc namespace +} // end of isc::dhcp namespace +} // end of isc namespace 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 CalloutHandle::getArgumentNames() const { vector 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 CalloutHandle::getContextNames() const { vector 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 #include #include -#include #include #include @@ -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 extractNames(const isc::hooks::HookLibsCollection& libraries) { std::vector 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 #include #include +#include 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 ServerHooks::getHookNames() const { - vector 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 diff --git a/src/lib/http/connection_pool.cc b/src/lib/http/connection_pool.cc index de92eb20e6..b32c397843 100644 --- a/src/lib/http/connection_pool.cc +++ b/src/lib/http/connection_pool.cc @@ -61,10 +61,8 @@ HttpConnectionPool::stopAll() { void HttpConnectionPool::stopAllInternal() { - for (auto connection = connections_.begin(); - connection != connections_.end(); - ++connection) { - (*connection)->close(); + for (auto const& connection : connections_) { + connection->close(); } connections_.clear(); diff --git a/src/lib/http/request.cc b/src/lib/http/request.cc index f753fea549..15a4ea2e04 100644 --- a/src/lib/http/request.cc +++ b/src/lib/http/request.cc @@ -90,10 +90,8 @@ HttpRequest::create() { } // Copy headers from the context. - for (auto header = context_->headers_.begin(); - header != context_->headers_.end(); - ++header) { - HttpHeaderPtr hdr(new HttpHeader(header->name_, header->value_)); + for (auto const& header : context_->headers_) { + HttpHeaderPtr hdr(new HttpHeader(header.name_, header.value_)); headers_[hdr->getLowerCaseName()] = hdr; } @@ -105,19 +103,17 @@ HttpRequest::create() { // Iterate over required headers and check that they exist // in the HTTP request. - for (auto req_header = required_headers_.begin(); - req_header != required_headers_.end(); - ++req_header) { - auto header = headers_.find(req_header->first); + for (auto const& req_header : required_headers_) { + auto header = headers_.find(req_header.first); if (header == headers_.end()) { - isc_throw(BadValue, "required header " << req_header->first + isc_throw(BadValue, "required header " << req_header.first << " not found in the HTTP request"); - } else if (!req_header->second->getValue().empty() && - !header->second->isValueEqual(req_header->second->getValue())) { + } else if (!req_header.second->getValue().empty() && + !header->second->isValueEqual(req_header.second->getValue())) { // If specific value is required for the header, check // that the value in the HTTP request matches it. isc_throw(BadValue, "required header's " << header->first - << " value is " << req_header->second->getValue() + << " value is " << req_header.second->getValue() << ", but " << header->second->getValue() << " was found"); } } @@ -200,10 +196,9 @@ HttpRequest::toString() const { } // Add all other headers. - for (auto header_it = headers_.cbegin(); header_it != headers_.cend(); - ++header_it) { - if (header_it->second->getName() != "Host") { - s << header_it->second->getName() << ": " << header_it->second->getValue() + for (auto const& header_it : headers_) { + if (header_it.second->getName() != "Host") { + s << header_it.second->getName() << ": " << header_it.second->getValue() << crlf; } } diff --git a/src/lib/http/response.cc b/src/lib/http/response.cc index cdc419a406..fc52311cdf 100644 --- a/src/lib/http/response.cc +++ b/src/lib/http/response.cc @@ -80,10 +80,8 @@ HttpResponse::create() { } // Copy headers from the context. - for (auto header = context_->headers_.begin(); - header != context_->headers_.end(); - ++header) { - HttpHeaderPtr hdr(new HttpHeader(header->name_, header->value_)); + for (auto const& header : context_->headers_) { + HttpHeaderPtr hdr(new HttpHeader(header.name_, header.value_)); headers_[hdr->getLowerCaseName()] = hdr; } @@ -98,19 +96,17 @@ HttpResponse::create() { // Iterate over required headers and check that they exist // in the HTTP response. - for (auto req_header = required_headers_.begin(); - req_header != required_headers_.end(); - ++req_header) { - auto header = headers_.find(req_header->first); + for (auto const& req_header : required_headers_) { + auto header = headers_.find(req_header.first); if (header == headers_.end()) { - isc_throw(BadValue, "required header " << req_header->first + isc_throw(BadValue, "required header " << req_header.first << " not found in the HTTP response"); - } else if (!req_header->second->getValue().empty() && - !header->second->isValueEqual(req_header->second->getValue())) { + } else if (!req_header.second->getValue().empty() && + !header->second->isValueEqual(req_header.second->getValue())) { // If specific value is required for the header, check // that the value in the HTTP response matches it. isc_throw(BadValue, "required header's " << header->first - << " value is " << req_header->second->getValue() + << " value is " << req_header.second->getValue() << ", but " << header->second->getValue() << " was found"); } } @@ -215,9 +211,8 @@ HttpResponse::toString() const { // HTTP version number and status code. s << toBriefString() << crlf; - for (auto header_it = headers_.cbegin(); header_it != headers_.cend(); - ++header_it) { - s << header_it->second->getName() << ": " << header_it->second->getValue() + for (auto const& header_it : headers_) { + s << header_it.second->getName() << ": " << header_it.second->getValue() << crlf; } diff --git a/src/lib/http/tests/server_client_unittests.cc b/src/lib/http/tests/server_client_unittests.cc index 517d1c8ce9..ab94490ccf 100644 --- a/src/lib/http/tests/server_client_unittests.cc +++ b/src/lib/http/tests/server_client_unittests.cc @@ -409,9 +409,8 @@ public: /// /// Removes active HTTP clients. virtual ~HttpListenerTest() { - for (auto client = clients_.begin(); client != clients_.end(); - ++client) { - (*client)->close(); + for (auto const& client : clients_) { + client->close(); } } diff --git a/src/lib/http/tests/tls_server_unittests.cc b/src/lib/http/tests/tls_server_unittests.cc index 3f41eb1ca3..e0d91b1b26 100644 --- a/src/lib/http/tests/tls_server_unittests.cc +++ b/src/lib/http/tests/tls_server_unittests.cc @@ -657,9 +657,8 @@ public: /// /// Removes active HTTP clients. virtual ~HttpsListenerTest() { - for (auto client = clients_.begin(); client != clients_.end(); - ++client) { - (*client)->close(); + for (auto const& client : clients_) { + client->close(); } } diff --git a/src/lib/log/buffer_appender_impl.cc b/src/lib/log/buffer_appender_impl.cc index 6ce8d402af..1e09805ff7 100644 --- a/src/lib/log/buffer_appender_impl.cc +++ b/src/lib/log/buffer_appender_impl.cc @@ -39,10 +39,9 @@ BufferAppender::flushStdout() { // be a good idea; as we can't reliably know whether in what // state the logger instance is now (or what the specific logger's // settings were). - LogEventList::const_iterator it; - for (it = stored_.begin(); it != stored_.end(); ++it) { - const std::string level(it->first); - LogEventPtr event(it->second); + for (auto const& it : stored_) { + const std::string level(it.first); + LogEventPtr event(it.second); std::printf("%s [%s]: %s\n", level.c_str(), event->getLoggerName().c_str(), event->getMessage().c_str()); @@ -55,9 +54,8 @@ BufferAppender::flush() { LogEventList stored_copy; stored_.swap(stored_copy); - LogEventList::const_iterator it; - for (it = stored_copy.begin(); it != stored_copy.end(); ++it) { - LogEventPtr event(it->second); + for (auto const& it : stored_copy) { + LogEventPtr event(it.second); log4cplus::Logger logger = log4cplus::Logger::getInstance(event->getLoggerName()); diff --git a/src/lib/log/compiler/message.cc b/src/lib/log/compiler/message.cc index 8f19c5a3a6..2d80af3892 100644 --- a/src/lib/log/compiler/message.cc +++ b/src/lib/log/compiler/message.cc @@ -31,8 +31,6 @@ #include -#include - using namespace std; using namespace isc::log; using namespace isc::util; @@ -144,9 +142,8 @@ vector sortedIdentifiers(MessageDictionary& dictionary) { vector ident; - for (MessageDictionary::const_iterator i = dictionary.begin(); - i != dictionary.end(); ++i) { - ident.push_back(i->first); + for (auto const& i : dictionary) { + ident.push_back(i.first); } sort(ident.begin(), ident.end()); @@ -267,9 +264,8 @@ writeHeaderFile(const string& file, writeOpeningNamespace(hfile, ns_components); vector idents = sortedIdentifiers(dictionary); - for (vector::const_iterator j = idents.begin(); - j != idents.end(); ++j) { - hfile << "extern const isc::log::MessageID " << *j << ";\n"; + for (auto const& j : idents) { + hfile << "extern const isc::log::MessageID " << j << ";\n"; } hfile << "\n"; @@ -368,10 +364,9 @@ writeProgramFile(const string& file, writeOpeningNamespace(ccfile, ns_components); vector idents = sortedIdentifiers(dictionary); - for (vector::const_iterator j = idents.begin(); - j != idents.end(); ++j) { - ccfile << "extern const isc::log::MessageID " << *j << - " = \"" << *j << "\";\n"; + for (auto const& j : idents) { + ccfile << "extern const isc::log::MessageID " << j << + " = \"" << j << "\";\n"; } ccfile << "\n"; @@ -386,10 +381,8 @@ writeProgramFile(const string& file, // Output the identifiers and the associated text. idents = sortedIdentifiers(dictionary); - for (vector::const_iterator i = idents.begin(); - i != idents.end(); ++i) { - ccfile << " \"" << *i << "\", \"" << - quoteString(dictionary.getText(*i)) << "\",\n"; + for (auto const& i : idents) { + ccfile << " \"" << i << "\", \"" << quoteString(dictionary.getText(i)) << "\",\n"; } // ... and the postamble @@ -431,9 +424,9 @@ errorDuplicates(MessageReader& reader) { sort(duplicates.begin(), duplicates.end()); MessageReader::MessageIDCollection::iterator new_end = unique(duplicates.begin(), duplicates.end()); - for (MessageReader::MessageIDCollection::iterator i = duplicates.begin(); - i != new_end; ++i) { - cout << " " << *i << "\n"; + duplicates.erase(new_end, duplicates.end()); + for (auto const& i : duplicates) { + cout << " " << i << "\n"; } exit(1); } diff --git a/src/lib/log/logger_manager.cc b/src/lib/log/logger_manager.cc index 1890706898..5da754bac0 100644 --- a/src/lib/log/logger_manager.cc +++ b/src/lib/log/logger_manager.cc @@ -144,9 +144,8 @@ LoggerManager::logDuplicatedMessages() { // There are duplicates present. This list itself may contain // duplicates; if so, the message ID is listed as many times as // there are duplicates. - for (list::const_iterator i = duplicates.begin(); - i != duplicates.end(); ++i) { - LOG_WARN(logger, LOG_DUPLICATE_MESSAGE_ID).arg(*i); + for (auto const& i : duplicates) { + LOG_WARN(logger, LOG_DUPLICATE_MESSAGE_ID).arg(i); } MessageInitializer::clearDuplicates(); } diff --git a/src/lib/log/logger_manager_impl.cc b/src/lib/log/logger_manager_impl.cc index 946e16348f..e25bb9cce4 100644 --- a/src/lib/log/logger_manager_impl.cc +++ b/src/lib/log/logger_manager_impl.cc @@ -295,10 +295,8 @@ void LoggerManagerImpl::setAppenderLayout( void LoggerManagerImpl::storeBufferAppenders() { // Walk through all loggers, and find any buffer appenders there log4cplus::LoggerList loggers = log4cplus::Logger::getCurrentLoggers(); - log4cplus::LoggerList::iterator it; - for (it = loggers.begin(); it != loggers.end(); ++it) { - log4cplus::SharedAppenderPtr buffer_appender = - it->getAppender("buffer"); + for (auto& it : loggers) { + log4cplus::SharedAppenderPtr buffer_appender = it.getAppender("buffer"); if (buffer_appender) { buffer_appender_store_.push_back(buffer_appender); } @@ -309,10 +307,8 @@ void LoggerManagerImpl::flushBufferAppenders() { std::vector copy; buffer_appender_store_.swap(copy); - std::vector::iterator it; - for (it = copy.begin(); it != copy.end(); ++it) { - internal::BufferAppender* app = - dynamic_cast(it->get()); + for (auto const& it : copy) { + internal::BufferAppender* app = dynamic_cast(it.get()); isc_throw_assert(app); app->flush(); } diff --git a/src/lib/log/message_initializer.cc b/src/lib/log/message_initializer.cc index a7c85ed2e6..94e5be15a7 100644 --- a/src/lib/log/message_initializer.cc +++ b/src/lib/log/message_initializer.cc @@ -103,9 +103,8 @@ MessageInitializer::loadDictionary(bool ignore_duplicates) { const MessageDictionaryPtr& global = MessageDictionary::globalDictionary(); const LoggerValuesListPtr& logger_values = getNonConstLoggerValues(); - for (LoggerValuesList::const_iterator values = logger_values->begin(); - values != logger_values->end(); ++values) { - std::vector repeats = global->load(*values); + for (auto const& values : *logger_values) { + std::vector repeats = global->load(values); // Append the IDs in the list just loaded (the "repeats") to the // global list of duplicate IDs. diff --git a/src/lib/process/cb_ctl_base.h b/src/lib/process/cb_ctl_base.h index b333d5463c..11d7218972 100644 --- a/src/lib/process/cb_ctl_base.h +++ b/src/lib/process/cb_ctl_base.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -271,9 +272,9 @@ protected: db::AuditEntryCollection result; auto const& index = audit_entries.get(); auto range = index.equal_range(object_type); - for (auto it = range.first; it != range.second; ++it) { - if ((*it)->getModificationType() != db::AuditEntry::ModificationType::DELETE) { - result.insert(*it); + BOOST_FOREACH(auto const& it, range) { + if (it->getModificationType() != db::AuditEntry::ModificationType::DELETE) { + result.insert(it); } } diff --git a/src/lib/process/config_base.cc b/src/lib/process/config_base.cc index 1e02fad2ac..96c9e46008 100644 --- a/src/lib/process/config_base.cc +++ b/src/lib/process/config_base.cc @@ -77,9 +77,8 @@ void ConfigBase::copy(ConfigBase& other) const { // We will entirely replace loggers in the new configuration. other.logging_info_.clear(); - for (LoggingInfoStorage::const_iterator it = logging_info_.begin(); - it != logging_info_.end(); ++it) { - other.addLoggingInfo(*it); + for (auto const& it : logging_info_) { + other.addLoggingInfo(it); } // Clone the config control info diff --git a/src/lib/process/config_ctl_info.cc b/src/lib/process/config_ctl_info.cc index b7b87a388f..c4eeb1b69b 100644 --- a/src/lib/process/config_ctl_info.cc +++ b/src/lib/process/config_ctl_info.cc @@ -71,13 +71,11 @@ ConfigControlInfo::addConfigDatabase(const std::string& access_str) { const ConfigDbInfo& ConfigControlInfo::findConfigDb(const std::string& param_name, const std::string& param_value) { - for (ConfigDbInfoList::iterator db = db_infos_.begin(); - db != db_infos_.end(); ++db) { + for (auto const& db : db_infos_) { std::string db_value; - if (db->getParameterValue(param_name, db_value) && - (param_value == db_value)) { - return (*db); - } + if (db.getParameterValue(param_name, db_value) && (param_value == db_value)) { + return (db); + } } return (EMPTY_DB()); diff --git a/src/lib/process/config_ctl_parser.cc b/src/lib/process/config_ctl_parser.cc index 38f7ac06fe..f6adb9eef4 100644 --- a/src/lib/process/config_ctl_parser.cc +++ b/src/lib/process/config_ctl_parser.cc @@ -32,10 +32,10 @@ ConfigControlParser::parse(const data::ConstElementPtr& config_control) { } const std::vector& db_list = elem->listValue(); - for (auto db = db_list.cbegin(); db != db_list.end(); ++db) { + for (auto const& db : db_list) { db::DbAccessParser parser; std::string access_string; - parser.parse(access_string, *db); + parser.parse(access_string, db); /// @todo do we still need access_string for this at all? /// can't we just use params directly and get rid of the /// string now that DatabaseConnection::toElement(map) exists? diff --git a/src/lib/process/d_cfg_mgr.cc b/src/lib/process/d_cfg_mgr.cc index a08a903862..e0cb701387 100644 --- a/src/lib/process/d_cfg_mgr.cc +++ b/src/lib/process/d_cfg_mgr.cc @@ -15,7 +15,6 @@ #include #include -#include #include #include diff --git a/src/lib/process/log_parser.cc b/src/lib/process/log_parser.cc index 01a6167112..5fa33561f2 100644 --- a/src/lib/process/log_parser.cc +++ b/src/lib/process/log_parser.cc @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -33,7 +32,7 @@ void LogConfigParser::parseConfiguration(const isc::data::ConstElementPtr& logge verbose_ = verbose; // Iterate over all entries in "Server/loggers" list - BOOST_FOREACH(ConstElementPtr logger, loggers->listValue()) { + for (auto const& logger : loggers->listValue()) { parseConfigEntry(logger); } } @@ -119,7 +118,7 @@ void LogConfigParser::parseOutputOptions(std::vector& destin isc_throw(BadValue, "Missing 'output-options' structure in 'loggers'"); } - BOOST_FOREACH(ConstElementPtr output_option, output_options->listValue()) { + for (auto const& output_option : output_options->listValue()) { LoggingDestination dest; diff --git a/src/lib/process/logging_info.cc b/src/lib/process/logging_info.cc index f75c9acdbc..0fadde502a 100644 --- a/src/lib/process/logging_info.cc +++ b/src/lib/process/logging_info.cc @@ -88,7 +88,7 @@ LoggingInfo::equals(const LoggingInfo& other) const { // that they are at the same index of the vectors. for (auto const& dest : destinations_) { bool match = false; - for (auto const &dest_other : other.destinations_) { + for (auto const& dest_other : other.destinations_) { if (dest.equals(dest_other)) { match = true; break; diff --git a/src/lib/process/tests/d_cfg_mgr_unittests.cc b/src/lib/process/tests/d_cfg_mgr_unittests.cc index faa3e92897..80d14a3161 100644 --- a/src/lib/process/tests/d_cfg_mgr_unittests.cc +++ b/src/lib/process/tests/d_cfg_mgr_unittests.cc @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/src/lib/stats/observation.cc b/src/lib/stats/observation.cc index 034f2b9745..933683e99b 100644 --- a/src/lib/stats/observation.cc +++ b/src/lib/stats/observation.cc @@ -443,10 +443,10 @@ Observation::getJSON() const { // Iteration over all elements in the list // and adding alternately value and timestamp to the entry - for (std::list::iterator it = s.begin(); it != s.end(); ++it) { + for (auto const& it : s) { entry = isc::data::Element::createList(); - value = isc::data::Element::create(static_cast((*it).first)); - timestamp = isc::data::Element::create(isc::util::clockToText((*it).second)); + value = isc::data::Element::create(static_cast(it.first)); + timestamp = isc::data::Element::create(isc::util::clockToText(it.second)); entry->add(value); entry->add(timestamp); @@ -477,10 +477,10 @@ Observation::getJSON() const { // Iteration over all elements in the list // and adding alternately value and timestamp to the entry - for (std::list::iterator it = s.begin(); it != s.end(); ++it) { + for (auto const& it : s) { entry = isc::data::Element::createList(); - value = isc::data::Element::create((*it).first); - timestamp = isc::data::Element::create(isc::util::clockToText((*it).second)); + value = isc::data::Element::create(it.first); + timestamp = isc::data::Element::create(isc::util::clockToText(it.second)); entry->add(value); entry->add(timestamp); @@ -494,10 +494,10 @@ Observation::getJSON() const { // Iteration over all elements in the list // and adding alternately value and timestamp to the entry - for (std::list::iterator it = s.begin(); it != s.end(); ++it) { + for (auto const& it : s) { entry = isc::data::Element::createList(); - value = isc::data::Element::create(isc::util::durationToText((*it).first)); - timestamp = isc::data::Element::create(isc::util::clockToText((*it).second)); + value = isc::data::Element::create(isc::util::durationToText(it.first)); + timestamp = isc::data::Element::create(isc::util::clockToText(it.second)); entry->add(value); entry->add(timestamp); @@ -511,10 +511,10 @@ Observation::getJSON() const { // Iteration over all elements in the list // and adding alternately value and timestamp to the entry - for (std::list::iterator it = s.begin(); it != s.end(); ++it) { + for (auto const& it : s) { entry = isc::data::Element::createList(); - value = isc::data::Element::create((*it).first); - timestamp = isc::data::Element::create(isc::util::clockToText((*it).second)); + value = isc::data::Element::create(it.first); + timestamp = isc::data::Element::create(isc::util::clockToText(it.second)); entry->add(value); entry->add(timestamp); diff --git a/src/lib/stats/tests/observation_unittest.cc b/src/lib/stats/tests/observation_unittest.cc index 63fbecea2d..7b9fad6a61 100644 --- a/src/lib/stats/tests/observation_unittest.cc +++ b/src/lib/stats/tests/observation_unittest.cc @@ -219,27 +219,27 @@ TEST_F(ObservationTest, moreThanOne) { std::list samples_bigint = e.getBigIntegers(); // List of all big integer samples uint32_t i = 2; // Index pointed to the end of array of samples - for (std::list::iterator it = samples_int.begin(); it != samples_int.end(); ++it) { - EXPECT_EQ(int_samples[i], static_cast((*it).first)); + for (auto const& it : samples_int) { + EXPECT_EQ(int_samples[i], static_cast(it.first)); --i; } i = 2; - for (std::list::iterator it = samples_float.begin(); it != samples_float.end(); ++it) { - EXPECT_EQ(float_samples[i], (*it).first); + for (auto const& it : samples_float) { + EXPECT_EQ(float_samples[i], it.first); --i; } i = 2; - for (std::list::iterator it = samples_dur.begin(); it != samples_dur.end(); ++it) { - EXPECT_EQ(duration_samples[i], (*it).first); + for (auto const& it : samples_dur) { + EXPECT_EQ(duration_samples[i], it.first); --i; } i = 2; - for (std::list::iterator it = samples_str.begin(); it != samples_str.end(); ++it) { - EXPECT_EQ(string_samples[i], (*it).first); + for (auto const& it : samples_str) { + EXPECT_EQ(string_samples[i], it.first); --i; } i = 2; - for (BigIntegerSample const& sample : samples_bigint) { + for (auto const& sample : samples_bigint) { EXPECT_EQ(bigint_samples[i], sample.first); --i; } @@ -345,27 +345,27 @@ TEST_F(ObservationTest, setCountLimit) { // And whether stored values are correct uint32_t i = 20; // index of the last element in array of test's samples - for (std::list::iterator it = samples_int.begin(); it != samples_int.end(); ++it) { - EXPECT_EQ((*it).first, int_samples[i]); + for (auto const& it : samples_int) { + EXPECT_EQ(it.first, int_samples[i]); --i; } i = 20; // index of last element in array of test's samples - for (std::list::iterator it = samples_float.begin(); it != samples_float.end(); ++it) { - EXPECT_EQ((*it).first, float_samples[i]); + for (auto const& it : samples_float) { + EXPECT_EQ(it.first, float_samples[i]); --i; } i = 20; // index of last element in array of test's samples - for (std::list::iterator it = samples_duration.begin(); it != samples_duration.end(); ++it) { - EXPECT_EQ((*it).first, duration_samples[i]); + for (auto const& it : samples_duration) { + EXPECT_EQ(it.first, duration_samples[i]); --i; } i = 20; // index of last element in array of test's samples - for (std::list::iterator it = samples_string.begin(); it != samples_string.end(); ++it) { - EXPECT_EQ((*it).first, string_samples[i]); + for (auto const& it : samples_string) { + EXPECT_EQ(it.first, string_samples[i]); --i; } i = 20; // index of last element in array of test's samples - for (BigIntegerSample const& sample : samples_bigint) { + for (auto const& sample : samples_bigint) { EXPECT_EQ(sample.first, int_samples[i]); --i; } @@ -392,27 +392,27 @@ TEST_F(ObservationTest, setCountLimit) { // And whether storages contain only the 10 newest values i = 20; // index of last element in array of test's samples - for (std::list::iterator it = samples_int.begin(); it != samples_int.end(); ++it) { - EXPECT_EQ((*it).first, int_samples[i]); + for (auto const& it : samples_int) { + EXPECT_EQ(it.first, int_samples[i]); --i; } i = 20; // index of last element in array of test's samples - for (std::list::iterator it = samples_float.begin(); it != samples_float.end(); ++it) { - EXPECT_EQ((*it).first, float_samples[i]); + for (auto const& it : samples_float) { + EXPECT_EQ(it.first, float_samples[i]); --i; } i = 20; // index of last element in array of test's samples - for (std::list::iterator it = samples_duration.begin(); it != samples_duration.end(); ++it) { - EXPECT_EQ((*it).first, duration_samples[i]); + for (auto const& it : samples_duration) { + EXPECT_EQ(it.first, duration_samples[i]); --i; } i = 20; // index of last element in array of test's samples - for (std::list::iterator it = samples_string.begin(); it != samples_string.end(); ++it) { - EXPECT_EQ((*it).first, string_samples[i]); + for (auto const& it : samples_string) { + EXPECT_EQ(it.first, string_samples[i]); --i; } i = 20; // index of last element in array of test's samples - for (BigIntegerSample const& sample : samples_bigint) { + for (auto const& sample : samples_bigint) { EXPECT_EQ(sample.first, int_samples[i]); --i; } @@ -451,27 +451,27 @@ TEST_F(ObservationTest, setCountLimit) { ASSERT_EQ(e.getSize(), 11); i = 21; // index of last element in array of test's samples - for (std::list::iterator it = samples_int.begin(); it != samples_int.end(); ++it) { - EXPECT_EQ((*it).first, int_samples[i]); + for (auto const& it : samples_int) { + EXPECT_EQ(it.first, int_samples[i]); --i; } i = 21; // index of last element in array of test's samples - for (std::list::iterator it = samples_float.begin(); it != samples_float.end(); ++it) { - EXPECT_EQ((*it).first, float_samples[i]); + for (auto const& it : samples_float) { + EXPECT_EQ(it.first, float_samples[i]); --i; } i = 21; // index of last element in array of test's samples - for (std::list::iterator it = samples_duration.begin(); it != samples_duration.end(); ++it) { - EXPECT_EQ((*it).first, duration_samples[i]); + for (auto const& it : samples_duration) { + EXPECT_EQ(it.first, duration_samples[i]); --i; } i = 21; // index of last element in array of test's samples - for (std::list::iterator it = samples_string.begin(); it != samples_string.end(); ++it) { - EXPECT_EQ((*it).first, string_samples[i]); + for (auto const& it : samples_string) { + EXPECT_EQ(it.first, string_samples[i]); --i; } i = 21; // index of last element in array of test's samples - for (BigIntegerSample const& sample : samples_bigint) { + for (auto const& sample : samples_bigint) { EXPECT_EQ(sample.first, int_samples[i]); --i; } @@ -510,8 +510,8 @@ TEST_F(ObservationTest, setAgeLimit) { // and whether it contains expected values uint32_t i = 9; - for (std::list::iterator it = samples_duration.begin(); it != samples_duration.end(); ++it) { - EXPECT_EQ((*it).first, milliseconds(i)); + for (auto const& it : samples_duration) { + EXPECT_EQ(it.first, milliseconds(i)); --i; } } diff --git a/src/lib/tcp/tcp_connection_pool.cc b/src/lib/tcp/tcp_connection_pool.cc index b7de361c88..9182776f2c 100644 --- a/src/lib/tcp/tcp_connection_pool.cc +++ b/src/lib/tcp/tcp_connection_pool.cc @@ -86,10 +86,8 @@ TcpConnectionPool::stopAll() { void TcpConnectionPool::stopAllInternal() { - for (auto connection = connections_.begin(); - connection != connections_.end(); - ++connection) { - (*connection)->close(); + for (auto const& connection : connections_) { + connection->close(); } size_t cnt = connections_.size(); diff --git a/src/lib/testutils/user_context_utils.cc b/src/lib/testutils/user_context_utils.cc index bad26bc87c..6e3d4d8ed8 100644 --- a/src/lib/testutils/user_context_utils.cc +++ b/src/lib/testutils/user_context_utils.cc @@ -59,9 +59,8 @@ Value moveComments1(EP element) { ElementPtr result = ElementPtr(new ListElement()); typedef std::vector ListType; const ListType& list = element->listValue(); - for (ListType::const_iterator it = list.cbegin(); - it != list.cend(); ++it) { - Value item = moveComments1(*it); + for (auto const& it : list) { + Value item = moveComments1(it); result->add(item.get()); if (!item.isShared()) { modified = true; @@ -81,17 +80,17 @@ Value moveComments1(EP element) { bool has_comment = false; typedef std::map map_type; const map_type& map = element->mapValue(); - for (map_type::const_iterator it = map.cbegin(); it != map.cend(); ++it) { - if (it->first == "comment") { + for (auto const& it : map) { + if (it.first == "comment") { // Note there is a comment entry to move has_comment = true; - } else if (it->first == "user-context") { + } else if (it.first == "user-context") { // Do not traverse user-context entries - result->set("user-context", it->second); + result->set("user-context", it.second); } else { // Not comment or user-context - Value item = moveComments1(it->second); - result->set(it->first, item.get()); + Value item = moveComments1(it.second); + result->set(it.first, item.get()); if (!item.isShared()) { modified = true; } diff --git a/src/lib/util/multi_threading_mgr.cc b/src/lib/util/multi_threading_mgr.cc index cf3eaa8b67..b85bfe13ec 100644 --- a/src/lib/util/multi_threading_mgr.cc +++ b/src/lib/util/multi_threading_mgr.cc @@ -8,6 +8,8 @@ #include +#include + namespace isc { namespace util { @@ -178,9 +180,9 @@ void MultiThreadingMgr::callEntryCallbacks() { if (getMode()) { auto const& callbacks = cs_callbacks_.getCallbackSets(); - for (auto cb_it = callbacks.begin(); cb_it != callbacks.end(); cb_it++) { + for (auto const& cb_it : callbacks) { try { - (cb_it->entry_cb_)(); + (cb_it.entry_cb_)(); } catch (...) { // We can't log it and throwing could be chaos. // We'll swallow it and tell people their callbacks @@ -194,9 +196,9 @@ void MultiThreadingMgr::callExitCallbacks() { if (getMode()) { auto const& callbacks = cs_callbacks_.getCallbackSets(); - for (auto cb_it = callbacks.rbegin(); cb_it != callbacks.rend(); cb_it++) { + for (auto const& cb_it : boost::adaptors::reverse(callbacks)) { try { - (cb_it->exit_cb_)(); + (cb_it.exit_cb_)(); } catch (...) { // We can't log it and throwing could be chaos. // We'll swallow it and tell people their callbacks diff --git a/src/lib/util/strutil.cc b/src/lib/util/strutil.cc index 55f5f9750b..449e38f9a8 100644 --- a/src/lib/util/strutil.cc +++ b/src/lib/util/strutil.cc @@ -79,15 +79,15 @@ tokens(const std::string& text, const std::string& delim, bool escape) { string token; bool in_token = false; bool escaped = false; - for (auto c = text.cbegin(); c != text.cend(); ++c) { - if (delim.find(*c) != string::npos) { + for (auto const& c : text) { + if (delim.find(c) != string::npos) { // Current character is a delimiter if (!in_token) { // Two or more delimiters, eat them } else if (escaped) { // Escaped delimiter in a token: reset escaped and keep it escaped = false; - token.push_back(*c); + token.push_back(c); } else { // End of the current token: save it if not empty if (!token.empty()) { @@ -97,7 +97,7 @@ tokens(const std::string& text, const std::string& delim, bool escape) { in_token = false; token.clear(); } - } else if (escape && (*c == '\\')) { + } else if (escape && (c == '\\')) { // Current character is the escape character if (!in_token) { // The escape character is the first character of a new token @@ -106,7 +106,7 @@ tokens(const std::string& text, const std::string& delim, bool escape) { if (escaped) { // Escaped escape: reset escaped and keep one character escaped = false; - token.push_back(*c); + token.push_back(c); } else { // Remember to keep the next character escaped = true; @@ -121,10 +121,10 @@ tokens(const std::string& text, const std::string& delim, bool escape) { // Escaped common character: as escape was false escaped = false; token.push_back('\\'); - token.push_back(*c); + token.push_back(c); } else { // The common case: keep it - token.push_back(*c); + token.push_back(c); } } } diff --git a/src/lib/util/strutil.h b/src/lib/util/strutil.h index 4182692efe..d4a1914f19 100644 --- a/src/lib/util/strutil.h +++ b/src/lib/util/strutil.h @@ -71,8 +71,8 @@ std::string trim(const std::string& instring); template Iterator seekTrimmed(Iterator begin, Iterator end, uint8_t trim_val) { - for ( ; end != begin && *(end - 1) == trim_val; --end); - return(end); + for (; end != begin && *(end - 1) == trim_val; --end); + return (end); } /// @brief Split String into Tokens diff --git a/src/lib/util/tests/base32hex_unittest.cc b/src/lib/util/tests/base32hex_unittest.cc index bf28f6295e..83616b2354 100644 --- a/src/lib/util/tests/base32hex_unittest.cc +++ b/src/lib/util/tests/base32hex_unittest.cc @@ -64,10 +64,8 @@ decodeCheck(const string& input_string, vector& output, } TEST_F(Base32HexTest, decode) { - for (vector::const_iterator it = test_sequence.begin(); - it != test_sequence.end(); - ++it) { - decodeCheck((*it).second, decoded_data, (*it).first); + for (auto const& it : test_sequence) { + decodeCheck(it.second, decoded_data, it.first); } // whitespace should be allowed @@ -94,19 +92,15 @@ TEST_F(Base32HexTest, decode) { } TEST_F(Base32HexTest, decodeLower) { - for (vector::const_iterator it = test_sequence_lower.begin(); - it != test_sequence_lower.end(); - ++it) { - decodeCheck((*it).second, decoded_data, (*it).first); + for (auto const& it : test_sequence_lower) { + decodeCheck(it.second, decoded_data, it.first); } } TEST_F(Base32HexTest, encode) { - for (vector::const_iterator it = test_sequence.begin(); - it != test_sequence.end(); - ++it) { - decoded_data.assign((*it).first.begin(), (*it).first.end()); - EXPECT_EQ((*it).second, encodeBase32Hex(decoded_data)); + for (auto const& it : test_sequence) { + decoded_data.assign(it.first.begin(), it.first.end()); + EXPECT_EQ(it.second, encodeBase32Hex(decoded_data)); } } diff --git a/src/lib/util/tests/base64_unittest.cc b/src/lib/util/tests/base64_unittest.cc index 516925e539..95b518bcad 100644 --- a/src/lib/util/tests/base64_unittest.cc +++ b/src/lib/util/tests/base64_unittest.cc @@ -50,10 +50,8 @@ decodeCheck(const string& input_string, vector& output, } TEST_F(Base64Test, decode) { - for (vector::const_iterator it = test_sequence.begin(); - it != test_sequence.end(); - ++it) { - decodeCheck((*it).second, decoded_data, (*it).first); + for (auto const& it : test_sequence) { + decodeCheck(it.second, decoded_data, it.first); } // whitespace should be allowed @@ -83,11 +81,9 @@ TEST_F(Base64Test, decode) { } TEST_F(Base64Test, encode) { - for (vector::const_iterator it = test_sequence.begin(); - it != test_sequence.end(); - ++it) { - decoded_data.assign((*it).first.begin(), (*it).first.end()); - EXPECT_EQ((*it).second, encodeBase64(decoded_data)); + for (auto const& it : test_sequence) { + decoded_data.assign(it.first.begin(), it.first.end()); + EXPECT_EQ(it.second, encodeBase64(decoded_data)); } } } diff --git a/src/lib/util/unittests/testdata.cc b/src/lib/util/unittests/testdata.cc index 111cc37204..8f01af3f4a 100644 --- a/src/lib/util/unittests/testdata.cc +++ b/src/lib/util/unittests/testdata.cc @@ -34,9 +34,8 @@ addTestDataPath(const string& path) { void openTestData(const char* const datafile, ifstream& ifs) { - for (vector::const_iterator it = getDataPaths().begin(); - it != getDataPaths().end(); ++it) { - string data_path = *it; + for (auto const& it : getDataPaths()) { + string data_path = it; if (data_path.empty() || *data_path.rbegin() != '/') { data_path.push_back('/'); } diff --git a/src/lib/yang/adaptor_host.cc b/src/lib/yang/adaptor_host.cc index 990a103f72..d6ff1f37d4 100644 --- a/src/lib/yang/adaptor_host.cc +++ b/src/lib/yang/adaptor_host.cc @@ -49,12 +49,11 @@ AdaptorHost::quoteIdentifier(ElementPtr host) { stringstream tmp; tmp << hex; bool delim = false; - for (vector::const_iterator it = binary.begin(); - it != binary.end(); ++it) { + for (auto const& it : binary) { if (delim) { tmp << ":"; } - tmp << setw(2) << setfill('0') << static_cast(*it); + tmp << setw(2) << setfill('0') << static_cast(it); delim = true; } host->set("flex-id", Element::create(tmp.str())); diff --git a/src/lib/yang/tests/config_unittests.cc b/src/lib/yang/tests/config_unittests.cc index cb7396ca39..a25bf8e802 100644 --- a/src/lib/yang/tests/config_unittests.cc +++ b/src/lib/yang/tests/config_unittests.cc @@ -324,7 +324,7 @@ TEST_F(ConfigTestKeaV4, examples4) { "vivso.json", //"with-ddns.json", }; - for (const string& file : examples) { + for (auto const& file : examples) { resetSession(); string path = string(CFG_EXAMPLES) + "/kea4/" + file; SCOPED_TRACE("\n* Tested file: " + path); @@ -367,7 +367,7 @@ TEST_F(ConfigTestKeaV6, examples6) { "tee-times.json", //"with-ddns.json", }; - for (const string& file : examples) { + for (auto const& file : examples) { resetSession(); string path = string(CFG_EXAMPLES) + "/kea6/" + file; SCOPED_TRACE("\n* Tested file: " + path);