diff --git a/include/BitMap.h b/include/BitMap.h index 533cd55355..cdc243a18b 100644 --- a/include/BitMap.h +++ b/include/BitMap.h @@ -324,7 +324,6 @@ private: { std::vector strings; std::vector range; - std::vector::const_iterator it; std::istringstream iss; @@ -332,10 +331,10 @@ private: strings = one_util::split(reserved, ',', true); - for (it = strings.begin(); it != strings.end(); it++) + for (const auto& str : strings) { // Try to split it by ':' - range = one_util::split(*it, ':', true); + range = one_util::split(str, ':', true); iss.clear(); iss.str(range[0]); diff --git a/include/NebulaUtil.h b/include/NebulaUtil.h index f7c9bcc366..ba724f50d1 100644 --- a/include/NebulaUtil.h +++ b/include/NebulaUtil.h @@ -183,13 +183,12 @@ namespace one_util void split_unique(const std::string& st, char delim, std::set& result) { T elem; - std::vector::const_iterator it; std::vector strings = split(st, delim, true); - for (it = strings.begin(); it != strings.end(); it++) + for (const auto& str : strings) { - std::istringstream iss(*it); + std::istringstream iss(str); iss >> elem; if ( iss.fail() ) diff --git a/include/ObjectXML.h b/include/ObjectXML.h index eeb27a92ae..8ec0d67e25 100644 --- a/include/ObjectXML.h +++ b/include/ObjectXML.h @@ -262,11 +262,9 @@ public: */ void free_nodes(std::vector& content) const { - std::vector::iterator it; - - for (it = content.begin(); it < content.end(); it++) + for (auto it : content) { - xmlFreeNode(*it); + xmlFreeNode(it); } }; diff --git a/include/RaftManager.h b/include/RaftManager.h index 3639470918..642e853864 100644 --- a/include/RaftManager.h +++ b/include/RaftManager.h @@ -220,12 +220,11 @@ public: */ uint64_t get_next_index(int follower_id) { - std::map::iterator it; uint64_t _index = UINT64_MAX; std::lock_guard lock(raft_mutex); - it = next.find(follower_id); + auto it = next.find(follower_id); if ( it != next.end() ) { diff --git a/include/ReplicaRequest.h b/include/ReplicaRequest.h index 8a64d93adc..e58f61c1bf 100644 --- a/include/ReplicaRequest.h +++ b/include/ReplicaRequest.h @@ -127,9 +127,9 @@ public: std::lock_guard lock(_mutex); - std::map::iterator it = requests.find(rindex); + auto it = requests.find(rindex); - if ( it != requests.end() && it->second != 0 ) + if ( it != requests.end() && it->second ) { it->second->add_replica(); diff --git a/include/VMGroupRole.h b/include/VMGroupRole.h index 467c7a9103..5f06447aa3 100644 --- a/include/VMGroupRole.h +++ b/include/VMGroupRole.h @@ -347,13 +347,11 @@ private: VMGroupRole * get(T k) { - typename std::map::iterator it; - - it = roles.find(k); + auto it = roles.find(k); if ( it == roles.end() ) { - return 0; + return nullptr; } return it->second; diff --git a/include/VMGroupRule.h b/include/VMGroupRule.h index 6483f170f5..d87b79040c 100644 --- a/include/VMGroupRule.h +++ b/include/VMGroupRule.h @@ -58,13 +58,11 @@ public: VMGroupRule(VMGroupPolicy p, std::set roles_id):policy(p) { - std::set::iterator it; - - for ( it = roles_id.begin(); it != roles_id.end(); ++it ) + for ( auto rid : roles_id ) { - if ( *it < VMGroupRoles::MAX_ROLES ) + if ( rid < VMGroupRoles::MAX_ROLES ) { - roles[*it] = 1; + roles[rid] = 1; } } }; diff --git a/include/VirtualMachineNic.h b/include/VirtualMachineNic.h index 3e66c5b698..aa4286747b 100644 --- a/include/VirtualMachineNic.h +++ b/include/VirtualMachineNic.h @@ -187,7 +187,6 @@ public: std::vector vas; std::vector alias; std::vector pcis; - std::vector::iterator it; tmpl->get(NIC_NAME, vas); @@ -195,17 +194,17 @@ public: tmpl->get("PCI", pcis); - for ( it=pcis.begin(); it != pcis.end() ; ++it) + for (auto pci : pcis) { - if ( (*it)->vector_value("TYPE") == "NIC" ) + if ( pci->vector_value("TYPE") == "NIC" ) { - vas.push_back(*it); + vas.push_back(pci); } } - for ( it=alias.begin(); it != alias.end(); ++it) + for (auto al : alias) { - vas.push_back(*it); + vas.push_back(al); } init(vas, false); diff --git a/src/acl/AclManager.cc b/src/acl/AclManager.cc index 06e80e121b..789ff3ec7f 100644 --- a/src/acl/AclManager.cc +++ b/src/acl/AclManager.cc @@ -232,18 +232,15 @@ bool AclManager::authorize( if (!obj_perms.disable_cluster_acl) { - set::iterator i; - - for(i = obj_perms.cids.begin(); i != obj_perms.cids.end(); i++) + for (auto perm : obj_perms.cids) { - resource_cid_req.insert( obj_perms.obj_type | - AclRule::CLUSTER_ID | - *i - ); + resource_cid_req.insert(obj_perms.obj_type | + AclRule::CLUSTER_ID | + perm); } } - long long resource_all_req ; + long long resource_all_req; if (!obj_perms.disable_all_acl) { @@ -357,11 +354,9 @@ bool AclManager::authorize( // Look for rules that apply to each one of the user's groups // ---------------------------------------------------------- - set::iterator g_it; - - for (g_it = user_groups.begin(); g_it != user_groups.end(); g_it++) + for (auto group : user_groups) { - user_req = AclRule::GROUP_ID | *g_it; + user_req = AclRule::GROUP_ID | group; auth = match_rules_wrapper(user_req, resource_oid_req, resource_gid_req, @@ -463,12 +458,10 @@ static bool match_cluster_req( long long resource_cid_mask, long long rule_resource) { - set::iterator i; - - for(i = resource_cid_req.begin(); i != resource_cid_req.end(); i++) + for (auto cid : resource_cid_req) { // rule's object type and cluster object ID match - if ( ( rule_resource & resource_cid_mask ) == *i ) + if ( ( rule_resource & resource_cid_mask ) == cid ) { return true; } @@ -495,18 +488,13 @@ bool AclManager::match_rules( bool auth = false; ostringstream oss; - multimap::const_iterator it; - - pair::const_iterator, - multimap::const_iterator> index; - long long zone_oid_mask = AclRule::INDIVIDUAL_ID | 0x00000000FFFFFFFFLL; long long zone_req = AclRule::INDIVIDUAL_ID | zone_id; long long zone_all_req = AclRule::ALL_ID; - index = rules.equal_range( user_req ); + auto index = rules.equal_range( user_req ); - for ( it = index.first; it != index.second; it++) + for ( auto it = index.first; it != index.second; it++) { if (NebulaLog::log_level() >= Log::DDEBUG) { @@ -582,15 +570,11 @@ int AclManager::add_rule(long long user, long long resource, long long rights, ostringstream oss; int rc; - multimap::iterator it; - pair::iterator, - multimap::iterator> index; - bool found = false; - index = acl_rules.equal_range( user ); + auto index = acl_rules.equal_range( user ); - for ( it = index.first; (it != index.second && !found); it++) + for ( auto it = index.first; (it != index.second && !found); it++) { found = *(it->second) == *rule; } @@ -652,11 +636,6 @@ error_common: int AclManager::del_rule(int oid, string& error_str) { - - multimap::iterator it; - pair::iterator, - multimap::iterator> index; - AclRule * rule; int rc; bool found = false; @@ -690,9 +669,9 @@ int AclManager::del_rule(int oid, string& error_str) found = false; - index = acl_rules.equal_range( rule->user ); + auto index = acl_rules.equal_range( rule->user ); - it = index.first; + auto it = index.first; while ( !found && it != index.second ) { found = *rule == *(it->second); @@ -854,7 +833,6 @@ void AclManager::del_resource_rules(int oid, PoolObjectSQL::ObjectType obj_type) void AclManager::del_user_matching_rules(long long user_req) { vector oids; - vector::iterator oid_it; string error_str; { @@ -868,9 +846,9 @@ void AclManager::del_user_matching_rules(long long user_req) } } - for ( oid_it = oids.begin() ; oid_it < oids.end(); oid_it++ ) + for ( auto oid : oids ) { - del_rule(*oid_it, error_str); + del_rule(oid, error_str); } } diff --git a/src/client/Client.cc b/src/client/Client.cc index 893f7b2e01..1a0f24b0b5 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -141,14 +141,11 @@ void Client::call(const std::string &method, const std::string format, va_list args; va_start(args, result); - std::string::const_iterator i; - std::string sval; int ival; bool bval; std::set * vval; - std::set::iterator it; const char* pval; vector x_vval; @@ -157,9 +154,9 @@ void Client::call(const std::string &method, const std::string format, plist.add(xmlrpc_c::value_string(one_auth)); - for (i = format.begin(); i != format.end(); ++i) + for (auto ch : format) { - switch(*i) + switch(ch) { case 's': pval = static_cast(va_arg(args, char *)); @@ -184,7 +181,7 @@ void Client::call(const std::string &method, const std::string format, vval = static_cast *>(va_arg(args, std::set *)); - for (it = vval->begin(); it != vval->end(); ++it) + for (auto it = vval->begin(); it != vval->end(); ++it) { x_vval.push_back(xmlrpc_c::value_int(*it)); } diff --git a/src/cluster/ClusterPool.cc b/src/cluster/ClusterPool.cc index b19275cc88..827dd68c9f 100644 --- a/src/cluster/ClusterPool.cc +++ b/src/cluster/ClusterPool.cc @@ -208,7 +208,7 @@ void ClusterPool::cluster_acl_filter(ostringstream& filter, return; } - for ( vector::const_iterator it = cids.begin(); it < cids.end(); it++ ) + for ( auto it = cids.begin(); it != cids.end(); it++ ) { if ( it != cids.begin() ) { diff --git a/src/common/Attribute.cc b/src/common/Attribute.cc index 485335669e..479fc66eb7 100644 --- a/src/common/Attribute.cc +++ b/src/common/Attribute.cc @@ -31,8 +31,6 @@ string VectorAttribute::marshall(const char * _sep) const ostringstream os; const char * my_sep; - map::const_iterator it; - if ( _sep == 0 ) { my_sep = magic_sep; @@ -47,7 +45,7 @@ string VectorAttribute::marshall(const char * _sep) const return 0; } - it = attribute_value.begin(); + auto it = attribute_value.begin(); os << it->first << "=" << it->second; @@ -64,11 +62,9 @@ string VectorAttribute::marshall(const char * _sep) const void VectorAttribute::to_xml(ostringstream &oss) const { - map::const_iterator it; - oss << "<" << name() << ">"; - for (it=attribute_value.begin();it!=attribute_value.end();it++) + for (auto it=attribute_value.begin(); it!=attribute_value.end(); it++) { if ( it->first.empty() ) { @@ -91,7 +87,7 @@ void VectorAttribute::to_json(std::ostringstream& s) const return; } - map::const_iterator it = attribute_value.begin(); + auto it = attribute_value.begin(); bool is_first = true; s << "{"; @@ -121,9 +117,7 @@ void VectorAttribute::to_json(std::ostringstream& s) const void VectorAttribute::to_token(std::ostringstream& s) const { - map::const_iterator it; - - for (it=attribute_value.begin(); it!=attribute_value.end(); it++) + for (auto it=attribute_value.begin(); it!=attribute_value.end(); it++) { if (it->first.empty() || it->second.empty()) { @@ -205,14 +199,11 @@ void VectorAttribute::replace(const map& attr) void VectorAttribute::merge(VectorAttribute* vattr, bool replace) { - map::const_iterator it; - map::iterator jt; - const map& source_values = vattr->value(); - for(it=source_values.begin(); it!=source_values.end(); it++) + for (auto it=source_values.begin(); it!=source_values.end(); it++) { - jt = attribute_value.find(it->first); + auto jt = attribute_value.find(it->first); if (jt != attribute_value.end()) { @@ -235,9 +226,7 @@ void VectorAttribute::merge(VectorAttribute* vattr, bool replace) void VectorAttribute::replace(const string& name, const string& value) { - map::iterator it; - - it = attribute_value.find(name); + auto it = attribute_value.find(name); if ( it != attribute_value.end() ) { @@ -252,9 +241,7 @@ void VectorAttribute::replace(const string& name, const string& value) void VectorAttribute::remove(const string& name) { - map::iterator it; - - it = attribute_value.find(name); + auto it = attribute_value.find(name); if ( it != attribute_value.end() ) { @@ -267,9 +254,7 @@ void VectorAttribute::remove(const string& name) string VectorAttribute::vector_value(const string& name) const { - map::const_iterator it; - - it = attribute_value.find(name); + auto it = attribute_value.find(name); if ( it == attribute_value.end() ) { @@ -286,9 +271,7 @@ string VectorAttribute::vector_value(const string& name) const int VectorAttribute::vector_value(const string& name, string& value) const { - map::const_iterator it; - - it = attribute_value.find(name); + auto it = attribute_value.find(name); if (it == attribute_value.end()) { @@ -305,10 +288,8 @@ int VectorAttribute::vector_value(const string& name, string& value) const int VectorAttribute::vector_value(const string& name, bool& value) const { - map::const_iterator it; - value = false; - it = attribute_value.find(name); + auto it = attribute_value.find(name); if (it == attribute_value.end()) { diff --git a/src/common/ExtendedAttribute.cc b/src/common/ExtendedAttribute.cc index f4d4334d81..ee7925aaa5 100644 --- a/src/common/ExtendedAttribute.cc +++ b/src/common/ExtendedAttribute.cc @@ -21,9 +21,7 @@ ExtendedAttributeSet::~ExtendedAttributeSet() { - std::map::iterator it; - - for (it = a_set.begin(); it != a_set.end(); ++it) + for (auto it = a_set.begin(); it != a_set.end(); ++it) { if ( dispose ) { @@ -39,11 +37,11 @@ ExtendedAttributeSet::~ExtendedAttributeSet() ExtendedAttribute * ExtendedAttributeSet::get_attribute(int id) const { - std::map::const_iterator it = a_set.find(id); + auto it = a_set.find(id); if ( it == a_set.end() ) { - return 0; + return nullptr; } return it->second; @@ -55,10 +53,10 @@ ExtendedAttribute * ExtendedAttributeSet::get_attribute(int id) const void ExtendedAttributeSet::init_attribute_map(const std::string& id_name, std::vector& vas) { - std::vector::iterator it; - int id, auto_id; + int id; + int auto_id = 0; - for (it = vas.begin(), auto_id = 0; it != vas.end(); ++it, ++auto_id) + for (auto it = vas.begin(); it != vas.end(); ++it, ++auto_id) { if (id_name.empty()) { @@ -80,11 +78,11 @@ void ExtendedAttributeSet::init_attribute_map(const std::string& id_name, ExtendedAttribute * ExtendedAttributeSet::delete_attribute(int id) { - std::map::iterator it = a_set.find(id); + auto it = a_set.find(id); if ( it == a_set.end() ) { - return 0; + return nullptr; } a_set.erase(it); diff --git a/src/common/NebulaUtil.cc b/src/common/NebulaUtil.cc index 61b850c21a..9310a6abf1 100644 --- a/src/common/NebulaUtil.cc +++ b/src/common/NebulaUtil.cc @@ -326,19 +326,16 @@ static bool not_space(int c) string one_util::trim(const string& str) { - string::const_iterator wfirst; - string::const_reverse_iterator rwlast; - - wfirst = find_if(str.begin(), str.end(), not_space); + auto wfirst = find_if(str.begin(), str.end(), not_space); if (wfirst == str.end()) { return string(); } - rwlast = find_if(str.rbegin(),str.rend(),not_space); + auto rwlast = find_if(str.rbegin(),str.rend(),not_space); - string::const_iterator wlast(rwlast.base()); + auto wlast(rwlast.base()); string tstr(wfirst, wlast); @@ -376,13 +373,11 @@ string one_util::gsub(const string& st, const string& sfind, void one_util::escape_json(const string& str, ostringstream& s) { - string::const_iterator it; - s << "\""; - for (it = str.begin(); it != str.end(); ++it) + for (auto ch : str) { - switch (*it) + switch (ch) { case '\\': s << "\\\\"; break; case '"' : s << "\\\""; break; @@ -392,7 +387,7 @@ void one_util::escape_json(const string& str, ostringstream& s) case '\n': s << "\\n"; break; case '\r': s << "\\r"; break; case '\t': s << "\\t"; break; - default : s << *it; + default : s << ch; } } @@ -404,11 +399,9 @@ void one_util::escape_json(const string& str, ostringstream& s) void one_util::escape_token(const string& str, ostringstream& s) { - string::const_iterator it; - - for (it = str.begin(); it != str.end(); ++it) + for (auto ch : str) { - switch (*it) + switch (ch) { case '-': case '_': @@ -417,7 +410,7 @@ void one_util::escape_token(const string& str, ostringstream& s) s << '_'; break; default : - s << *it; + s << ch; } } } @@ -428,12 +421,10 @@ void one_util::escape_token(const string& str, ostringstream& s) template<> void one_util::split_unique(const string& st, char delim, set& res) { - vector::const_iterator it; - vector strings = split(st, delim, true); - for (it = strings.begin(); it != strings.end(); it++) + for (const auto& str : strings) { - res.insert(*it); + res.insert(str); } } diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index 8c61e8a96f..35483e6f6a 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -99,8 +99,6 @@ void Datastore::disk_attribute( string current_val; string type; - vector::const_iterator it; - disk->replace("DATASTORE", get_name()); disk->replace("DATASTORE_ID", oid); disk->replace("TM_MAD", get_tm_mad()); @@ -155,14 +153,14 @@ void Datastore::disk_attribute( disk->replace("LN_TARGET", st); } - for (it = inherit_attrs.begin(); it != inherit_attrs.end(); it++) + for (const auto& inherit : inherit_attrs) { - current_val = disk->vector_value(*it); - get_template_attribute(*it, inherit_val); + current_val = disk->vector_value(inherit); + get_template_attribute(inherit, inherit_val); if ( current_val.empty() && !inherit_val.empty() ) { - disk->replace(*it, inherit_val); + disk->replace(inherit, inherit_val); } } @@ -252,7 +250,7 @@ int Datastore::set_ds_mad(std::string &mad, std::string &error_str) std::vector vrequired_attrs; int rc; - std::string required_attrs, required_attr, value; + std::string required_attrs, value; std::ostringstream oss; @@ -277,11 +275,8 @@ int Datastore::set_ds_mad(std::string &mad, std::string &error_str) vrequired_attrs = one_util::split(required_attrs, ','); - for ( std::vector::const_iterator it = vrequired_attrs.begin(); - it != vrequired_attrs.end(); it++ ) + for ( auto& required_attr : vrequired_attrs ) { - required_attr = *it; - required_attr = one_util::trim(required_attr); one_util::toupper(required_attr); @@ -289,7 +284,9 @@ int Datastore::set_ds_mad(std::string &mad, std::string &error_str) if ( value.empty() ) { - goto error_required; + oss << "Datastore template is missing the \"" << required_attr + << "\" attribute or it's empty."; + goto error_common; } } @@ -299,10 +296,6 @@ error_conf: oss << "DS_MAD named \"" << mad << "\" is not defined in oned.conf"; goto error_common; -error_required: - oss << "Datastore template is missing the \"" << required_attr - << "\" attribute or it's empty."; - error_common: error_str = oss.str(); return -1; @@ -368,17 +361,15 @@ int Datastore::set_tm_mad(string &tm_mad, string &error_str) if (!st.empty()) { - std::vector::iterator it; - replace_template_attribute("TM_MAD_SYSTEM", st); modes = one_util::split(st, ',', true); string s; - for (it = modes.begin() ; it != modes.end(); ++it) + for (const auto &mode : modes) { - string tm_mad_t = one_util::trim(*it); + string tm_mad_t = one_util::trim(mode); string tm_mad = one_util::toupper(tm_mad_t); st = vatt->vector_value("LN_TARGET_" + tm_mad); diff --git a/src/datastore/DatastorePool.cc b/src/datastore/DatastorePool.cc index d34ed2e209..caa0505146 100644 --- a/src/datastore/DatastorePool.cc +++ b/src/datastore/DatastorePool.cc @@ -53,11 +53,9 @@ DatastorePool::DatastorePool( ostringstream oss; string error_str; - vector::const_iterator it; - - for (it = _inherit_attrs.begin(); it != _inherit_attrs.end(); it++) + for (auto sattr : _inherit_attrs) { - inherit_attrs.push_back((*it)->value()); + inherit_attrs.push_back(sattr->value()); } if (get_lastOID() == -1) //lastOID is set in PoolSQL::init_cb diff --git a/src/group/Group.cc b/src/group/Group.cc index c83375df1f..fe2f2ebb77 100644 --- a/src/group/Group.cc +++ b/src/group/Group.cc @@ -267,7 +267,6 @@ int Group::from_xml(const string& xml) string error; vector content; - vector::iterator it; // Initialize the internal XML object update_from_str(xml); diff --git a/src/host/HostSharePCI.cc b/src/host/HostSharePCI.cc index ee58ab8ff2..cbd2e41ec7 100644 --- a/src/host/HostSharePCI.cc +++ b/src/host/HostSharePCI.cc @@ -80,27 +80,25 @@ void HostSharePCI::init() bool HostSharePCI::test(const vector &devs) const { - vector::const_iterator it; - map::const_iterator jt; - std::set assigned; unsigned int vendor_id, device_id, class_id; int vendor_rc, device_rc, class_rc; bool found; - for ( it=devs.begin(); it!= devs.end(); it++) + for (auto device : devs) { - vendor_rc = get_pci_value("VENDOR", *it, vendor_id); - device_rc = get_pci_value("DEVICE", *it, device_id); - class_rc = get_pci_value("CLASS" , *it, class_id); + vendor_rc = get_pci_value("VENDOR", device, vendor_id); + device_rc = get_pci_value("DEVICE", device, device_id); + class_rc = get_pci_value("CLASS" , device, class_id); if (vendor_rc <= 0 && device_rc <= 0 && class_rc <= 0) { return false; } - for (jt= pci_devices.begin(), found=false; jt!=pci_devices.end(); jt++) + found = false; + for (auto jt = pci_devices.begin(); jt != pci_devices.end(); jt++) { PCIDevice * dev = jt->second; @@ -111,7 +109,7 @@ bool HostSharePCI::test(const vector &devs) const assigned.find(dev->address) == assigned.end()) { assigned.insert(dev->address); - found=true; + found = true; break; } @@ -131,22 +129,19 @@ bool HostSharePCI::test(const vector &devs) const void HostSharePCI::add(vector &devs, int vmid) { - vector::iterator it; - map::const_iterator jt; - unsigned int vendor_id, device_id, class_id; string address; int vendor_rc, device_rc, class_rc, addr_rc; - for ( it=devs.begin(); it!= devs.end(); it++) + for (auto device : devs) { - vendor_rc = get_pci_value("VENDOR", *it, vendor_id); - device_rc = get_pci_value("DEVICE", *it, device_id); - class_rc = get_pci_value("CLASS" , *it, class_id); + vendor_rc = get_pci_value("VENDOR", device, vendor_id); + device_rc = get_pci_value("DEVICE", device, device_id); + class_rc = get_pci_value("CLASS" , device, class_id); - addr_rc = (*it)->vector_value("ADDRESS", address); + addr_rc = device->vector_value("ADDRESS", address); - for (jt = pci_devices.begin(); jt != pci_devices.end(); jt++) + for (auto jt = pci_devices.begin(); jt != pci_devices.end(); jt++) { PCIDevice * dev = jt->second; @@ -160,21 +155,21 @@ void HostSharePCI::add(vector &devs, int vmid) dev->vmid = vmid; dev->attrs->replace("VMID", vmid); - (*it)->replace("DOMAIN", dev->attrs->vector_value("DOMAIN")); - (*it)->replace("BUS", dev->attrs->vector_value("BUS")); - (*it)->replace("SLOT", dev->attrs->vector_value("SLOT")); - (*it)->replace("FUNCTION",dev->attrs->vector_value("FUNCTION")); + device->replace("DOMAIN", dev->attrs->vector_value("DOMAIN")); + device->replace("BUS", dev->attrs->vector_value("BUS")); + device->replace("SLOT", dev->attrs->vector_value("SLOT")); + device->replace("FUNCTION",dev->attrs->vector_value("FUNCTION")); - (*it)->replace("ADDRESS", dev->attrs->vector_value("ADDRESS")); + device->replace("ADDRESS", dev->attrs->vector_value("ADDRESS")); if (addr_rc != -1 && !address.empty()) { - (*it)->replace("PREV_ADDRESS", address); + device->replace("PREV_ADDRESS", address); } if (dev->attrs->vector_value("NUMA_NODE", node)==0 && node !=-1) { - (*it)->replace("NUMA_NODE", node); + device->replace("NUMA_NODE", node); } break; @@ -188,24 +183,21 @@ void HostSharePCI::add(vector &devs, int vmid) void HostSharePCI::del(const vector &devs) { - vector::const_iterator it; - map::iterator pci_it; - - for ( it=devs.begin(); it!= devs.end(); it++) + for (auto device : devs) { - pci_it = pci_devices.find((*it)->vector_value("PREV_ADDRESS")); + auto pci_it = pci_devices.find(device->vector_value("PREV_ADDRESS")); if (pci_it != pci_devices.end()) { pci_it->second->vmid = -1; pci_it->second->attrs->replace("VMID",-1); - (*it)->remove("PREV_ADDRESS"); + device->remove("PREV_ADDRESS"); continue; } - pci_it = pci_devices.find((*it)->vector_value("ADDRESS")); + pci_it = pci_devices.find(device->vector_value("ADDRESS")); if (pci_it != pci_devices.end()) { @@ -213,7 +205,7 @@ void HostSharePCI::del(const vector &devs) pci_it->second->attrs->replace("VMID",-1); // Clean address from VM as it's not using it anymore - (*it)->remove("ADDRESS"); + device->remove("ADDRESS"); } } }; @@ -223,27 +215,21 @@ void HostSharePCI::del(const vector &devs) void HostSharePCI::set_monitorization(Template& ht) { - vector::iterator it; - map::iterator pci_it; - string address; std::set missing; - std::set::iterator jt; vector pci_att; ht.remove("PCI", pci_att); - for (pci_it = pci_devices.begin(); pci_it != pci_devices.end(); pci_it++) + for (auto pci_it = pci_devices.begin(); pci_it != pci_devices.end(); pci_it++) { missing.insert(pci_it->first); } - for (it = pci_att.begin(); it != pci_att.end(); it++) + for (auto pci : pci_att) { - VectorAttribute * pci = *it; - address = pci->vector_value("ADDRESS"); if (address.empty()) @@ -252,7 +238,7 @@ void HostSharePCI::set_monitorization(Template& ht) continue; } - pci_it = pci_devices.find(address); + auto pci_it = pci_devices.find(address); if (pci_it != pci_devices.end()) { @@ -270,9 +256,9 @@ void HostSharePCI::set_monitorization(Template& ht) } //Remove missing devices from the share if there are no VMs using them - for ( jt = missing.begin() ; jt != missing.end(); jt ++ ) + for (const auto& miss : missing) { - pci_it = pci_devices.find(*jt); + auto pci_it = pci_devices.find(miss); if ( pci_it->second->vmid != -1 ) { @@ -286,7 +272,6 @@ void HostSharePCI::set_monitorization(Template& ht) delete pci_it->second; pci_devices.erase(pci_it); - } }; diff --git a/src/image/Image.cc b/src/image/Image.cc index 36ed41116d..e9db1aa88a 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -493,8 +493,6 @@ void Image::disk_attribute(VirtualMachineDisk * disk, bool ro; - vector::const_iterator it; - img_type = type; target = disk->vector_value("TARGET"); driver = disk->vector_value("DRIVER"); @@ -654,13 +652,13 @@ void Image::disk_attribute(VirtualMachineDisk * disk, disk->replace("TARGET", template_target); } - for (it = inherit_attrs.begin(); it != inherit_attrs.end(); it++) + for (const auto& inherit : inherit_attrs) { - get_template_attribute(*it, inherit_val); + get_template_attribute(inherit, inherit_val); if (!inherit_val.empty()) { - disk->replace(*it, inherit_val); + disk->replace(inherit, inherit_val); } } } @@ -845,9 +843,9 @@ void Image::set_state(ImageState _state) LifeCycleManager* lcm = Nebula::instance().get_lcm(); const set& vms = vm_collection.get_collection(); - for (set::iterator i = vms.begin(); i != vms.end(); i++) + for (auto vm_id : vms) { - lcm->trigger_disk_lock_failure(*i); + lcm->trigger_disk_lock_failure(vm_id); } } else if (state == LOCKED) @@ -915,9 +913,9 @@ void Image::set_state_unlock() { const set& vms = vm_collection.get_collection(); - for (set::iterator i = vms.begin(); i != vms.end(); i++) + for (auto vm_id : vms) { - lcm->trigger_disk_lock_success(*i); + lcm->trigger_disk_lock_success(vm_id); } } } diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 8242772408..6717443b0e 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -54,11 +54,9 @@ ImagePool::ImagePool( _default_cdrom_dev_prefix = __default_cdrom_dev_prefix; // Init inherit attributes - vector::const_iterator it; - - for (it = _inherit_attrs.begin(); it != _inherit_attrs.end(); it++) + for (auto sattr : _inherit_attrs) { - inherit_attrs.push_back((*it)->value()); + inherit_attrs.push_back(sattr->value()); } // Set default type diff --git a/src/market/MarketPlace.cc b/src/market/MarketPlace.cc index 453d7ddc61..e3c4997ba5 100644 --- a/src/market/MarketPlace.cc +++ b/src/market/MarketPlace.cc @@ -66,7 +66,7 @@ int MarketPlace::set_market_mad(std::string &mad, std::string &error_str) std::vector vrequired_attrs; int rc; - std::string required_attrs, required_attr, value; + std::string required_attrs, value; std::ostringstream oss; @@ -86,11 +86,8 @@ int MarketPlace::set_market_mad(std::string &mad, std::string &error_str) vrequired_attrs = one_util::split(required_attrs, ','); - for ( std::vector::const_iterator it = vrequired_attrs.begin(); - it != vrequired_attrs.end(); it++ ) + for ( auto& required_attr : vrequired_attrs ) { - required_attr = *it; - required_attr = one_util::trim(required_attr); one_util::toupper(required_attr); @@ -98,7 +95,10 @@ int MarketPlace::set_market_mad(std::string &mad, std::string &error_str) if ( value.empty() ) { - goto error_required; + oss << "MarketPlace template is missing the \"" << required_attr + << "\" attribute or it's empty."; + + goto error_common; } } @@ -108,10 +108,6 @@ error_conf: oss << "MARKET_MAD_CONF named \"" << mad << "\" is not defined in oned.conf"; goto error_common; -error_required: - oss << "MarketPlace template is missing the \"" << required_attr - << "\" attribute or it's empty."; - error_common: error_str = oss.str(); return -1; @@ -292,16 +288,15 @@ static void set_supported_actions(ActionSet& as, const string& astr) { std::vector actions; - std::vector::iterator vit; std::string action; MarketPlaceApp::Action id; actions = one_util::split(astr, ','); - for (vit = actions.begin() ; vit != actions.end() ; ++vit) + for (const auto& act : actions) { - action = one_util::trim(*vit); + action = one_util::trim(act); if ( MarketPlaceApp::action_from_str(action, id) != 0 ) { diff --git a/src/market/MarketPlaceAppPool.cc b/src/market/MarketPlaceAppPool.cc index a09aaeafb2..1ced5e9f25 100644 --- a/src/market/MarketPlaceAppPool.cc +++ b/src/market/MarketPlaceAppPool.cc @@ -315,7 +315,7 @@ const int MarketPlaceAppPool::MAX_MISSING_MONITORS = 3; bool MarketPlaceAppPool::test_map_check(int app_id) { - map::iterator it = map_check.find(app_id); + auto it = map_check.find(app_id); if ( it == map_check.end() ) { @@ -338,7 +338,7 @@ bool MarketPlaceAppPool::test_map_check(int app_id) void MarketPlaceAppPool::reset_map_check(int app_id) { - map::iterator it = map_check.find(app_id); + auto it = map_check.find(app_id); if ( it == map_check.end() ) { diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 77772d8661..158d1e5c44 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -1298,7 +1298,6 @@ int Nebula::get_conf_attribute( const std::string& name, const VectorAttribute* &value) const { - std::vector::const_iterator it; std::vector values; std::string template_name; std::string name_upper = name; @@ -1307,20 +1306,20 @@ int Nebula::get_conf_attribute( nebula_configuration->get(key, values); - for (it = values.begin(); it != values.end(); it ++) + for (auto vattr : values) { - value = *it; - template_name = (*it)->vector_value("NAME"); + template_name = vattr->vector_value("NAME"); one_util::toupper(template_name); if ( template_name == name_upper ) { + value = vattr; return 0; } } - value = 0; + value = nullptr; return -1; }; diff --git a/src/parsers/expr_bool.cc b/src/parsers/expr_bool.cc index 024999ab0c..09785e4fdd 100644 --- a/src/parsers/expr_bool.cc +++ b/src/parsers/expr_bool.cc @@ -1473,13 +1473,12 @@ yyreduce: #line 135 "expr_bool.y" { std::vector val; - std::vector::iterator it; (yyval.val_int) = false; oxml->search((yyvsp[-3].val_str),val); - for (it=val.begin(); it != val.end(); ++it) + for (auto it=val.begin(); it != val.end(); ++it) { if ((yyvsp[0].val_int) == *it) { @@ -1539,13 +1538,12 @@ yyreduce: #line 181 "expr_bool.y" { std::vector val; - std::vector::iterator it; (yyval.val_int) = false; oxml->search((yyvsp[-3].val_str),val); - for (it=val.begin(); it != val.end(); ++it) + for (auto it=val.begin(); it != val.end(); ++it) { if ((yyvsp[0].val_float) == *it) { @@ -1585,7 +1583,6 @@ yyreduce: #line 215 "expr_bool.y" { std::vector val; - std::vector::iterator it; (yyval.val_int) = false; @@ -1593,7 +1590,7 @@ yyreduce: { oxml->search((yyvsp[-3].val_str),val); - for (it=val.begin(); it != val.end(); ++it) + for (auto it=val.begin(); it != val.end(); ++it) { if ( fnmatch((yyvsp[0].val_str), (*it).c_str(), 0) == 0 ) { diff --git a/src/parsers/expr_bool.y b/src/parsers/expr_bool.y index a5412c2757..102efbcf5e 100644 --- a/src/parsers/expr_bool.y +++ b/src/parsers/expr_bool.y @@ -134,13 +134,12 @@ expr: STRING '=' INTEGER { | STRING '@''>' INTEGER { std::vector val; - std::vector::iterator it; $$ = false; oxml->search($1,val); - for (it=val.begin(); it != val.end(); ++it) + for (auto it=val.begin(); it != val.end(); ++it) { if ($4 == *it) { @@ -180,13 +179,12 @@ expr: STRING '=' INTEGER { | STRING '@''>' FLOAT { std::vector val; - std::vector::iterator it; $$ = false; oxml->search($1,val); - for (it=val.begin(); it != val.end(); ++it) + for (auto it=val.begin(); it != val.end(); ++it) { if ($4 == *it) { @@ -214,7 +212,6 @@ expr: STRING '=' INTEGER { | STRING '@''>' STRING { std::vector val; - std::vector::iterator it; $$ = false; @@ -222,7 +219,7 @@ expr: STRING '=' INTEGER { { oxml->search($1,val); - for (it=val.begin(); it != val.end(); ++it) + for (auto it=val.begin(); it != val.end(); ++it) { if ( fnmatch($4, (*it).c_str(), 0) == 0 ) { diff --git a/src/pool/ObjectCollection.cc b/src/pool/ObjectCollection.cc index 684356476c..676ae8d3be 100644 --- a/src/pool/ObjectCollection.cc +++ b/src/pool/ObjectCollection.cc @@ -106,9 +106,7 @@ string& ObjectCollection::to_xml(string& xml) const int ObjectCollection::add(int id) { - pair::iterator,bool> ret; - - ret = collection_set.insert(id); + auto ret = collection_set.insert(id); if( !ret.second ) { @@ -141,7 +139,7 @@ int ObjectCollection::pop(int& elem) return -1; } - set::iterator it = collection_set.begin(); + auto it = collection_set.begin(); elem = *it; diff --git a/src/pool/PoolSQL.cc b/src/pool/PoolSQL.cc index e14109b54b..157731924c 100644 --- a/src/pool/PoolSQL.cc +++ b/src/pool/PoolSQL.cc @@ -156,12 +156,11 @@ int PoolSQL::allocate(PoolObjectSQL *objsql, string& error_str) void PoolSQL::exist(const string& id_str, std::set& id_list) { std::vector existing_items; - std::set::iterator iterator; one_util::split_unique(id_str, ',', id_list); search(existing_items, table.c_str(), "1 order by 1 ASC"); - for (iterator = id_list.begin(); iterator != id_list.end(); ++iterator) + for (auto iterator = id_list.begin(); iterator != id_list.end(); ++iterator) { if (!std::binary_search(existing_items.begin(), existing_items.end(), *iterator)) { @@ -291,7 +290,6 @@ void PoolSQL::acl_filter(int uid, AclManager* aclm = nd.get_aclm(); ostringstream acl_filter; - vector::iterator it; vector oids; vector gids; @@ -309,14 +307,14 @@ void PoolSQL::acl_filter(int uid, gids, cids); - for ( it = oids.begin(); it < oids.end(); it++ ) + for ( auto oid : oids ) { - acl_filter << " OR oid = " << *it; + acl_filter << " OR oid = " << oid; } - for ( it = gids.begin(); it < gids.end(); it++ ) + for ( auto gid : gids ) { - acl_filter << " OR gid = " << *it; + acl_filter << " OR gid = " << gid; } ClusterPool::cluster_acl_filter(acl_filter, auth_object, cids); @@ -336,8 +334,6 @@ void PoolSQL::usr_filter(int uid, { ostringstream uid_filter; - set::iterator g_it; - if ( filter_flag == RequestManagerPoolInfoFilter::MINE ) { uid_filter << "uid = " << uid; @@ -352,9 +348,9 @@ void PoolSQL::usr_filter(int uid, string sep = " "; - for (g_it = user_groups.begin(); g_it != user_groups.end(); g_it++) + for (auto g_id : user_groups) { - uid_filter << sep << "( gid = " << *g_it << " )"; + uid_filter << sep << "( gid = " << g_id << " )"; sep = " OR "; } @@ -364,9 +360,9 @@ void PoolSQL::usr_filter(int uid, { uid_filter << " AND ( other_u = 1"; - for (g_it = user_groups.begin(); g_it != user_groups.end(); g_it++) + for (auto g_id : user_groups) { - uid_filter << " OR ( gid = " << *g_it << " AND group_u = 1 )"; + uid_filter << " OR ( gid = " << g_id << " AND group_u = 1 )"; } uid_filter << acl_str << ")"; @@ -381,9 +377,9 @@ void PoolSQL::usr_filter(int uid, uid_filter << " uid = " << uid << " OR other_u = 1"; - for (g_it = user_groups.begin(); g_it != user_groups.end(); g_it++) + for (auto g_id : user_groups) { - uid_filter << " OR ( gid = " << *g_it << " AND group_u = 1 )"; + uid_filter << " OR ( gid = " << g_id << " AND group_u = 1 )"; } uid_filter << acl_str; @@ -397,9 +393,9 @@ void PoolSQL::usr_filter(int uid, { uid_filter << " AND ( other_u = 1"; - for (g_it = user_groups.begin(); g_it != user_groups.end(); g_it++) + for (auto g_id : user_groups) { - uid_filter << " OR ( gid = " << *g_it << " AND group_u = 1 )"; + uid_filter << " OR ( gid = " << g_id << " AND group_u = 1 )"; } uid_filter << acl_str << ")"; diff --git a/src/pool/PoolSQLCache.cc b/src/pool/PoolSQLCache.cc index b50c7fcdbd..f2246cb298 100644 --- a/src/pool/PoolSQLCache.cc +++ b/src/pool/PoolSQLCache.cc @@ -30,14 +30,12 @@ std::mutex * PoolSQLCache::lock_line(int oid) { static unsigned int num_locks = 0; - std::map::iterator it; - CacheLine * cl; { std::lock_guard lock(_mutex); - it = cache.find(oid); + auto it = cache.find(oid); if ( it == cache.end() ) { @@ -77,7 +75,7 @@ std::mutex * PoolSQLCache::lock_line(int oid) void PoolSQLCache::flush_cache_lines() { - for (std::map::iterator it=cache.begin(); it!=cache.end();) + for (auto it=cache.begin(); it!=cache.end();) { CacheLine * cl = it->second; diff --git a/src/raft/FedReplicaManager.cc b/src/raft/FedReplicaManager.cc index 4efc8bbe5d..4cc525842d 100644 --- a/src/raft/FedReplicaManager.cc +++ b/src/raft/FedReplicaManager.cc @@ -41,9 +41,7 @@ FedReplicaManager::~FedReplicaManager() { Nebula& nd = Nebula::instance(); - std::map::iterator it; - - for ( it = zones.begin() ; it != zones.end() ; ++it ) + for ( auto it = zones.begin() ; it != zones.end() ; ++it ) { delete it->second; } @@ -89,8 +87,6 @@ void FedReplicaManager::update_zones(std::vector& zone_ids) Nebula& nd = Nebula::instance(); ZonePool * zpool = nd.get_zonepool(); - vector::iterator it; - int zone_id = nd.get_zone_id(); if ( zpool->list_zones(zone_ids) != 0 ) @@ -104,7 +100,7 @@ void FedReplicaManager::update_zones(std::vector& zone_ids) zones.clear(); - for (it = zone_ids.begin() ; it != zone_ids.end(); ) + for (auto it = zone_ids.begin() ; it != zone_ids.end(); ) { if ( *it == zone_id ) { @@ -174,11 +170,9 @@ void FedReplicaManager::delete_zone(int zone_id) { std::ostringstream oss; - std::map::iterator it; - lock_guard ul(fed_mutex); - it = zones.find(zone_id); + auto it = zones.find(zone_id); if ( it == zones.end() ) { @@ -212,7 +206,7 @@ int FedReplicaManager::get_next_record(int zone_id, std::string& zedp, { lock_guard ul(fed_mutex); - std::map::iterator it = zones.find(zone_id); + auto it = zones.find(zone_id); if ( it == zones.end() ) { @@ -275,7 +269,7 @@ void FedReplicaManager::replicate_success(int zone_id) { lock_guard ul(fed_mutex); - std::map::iterator it = zones.find(zone_id); + auto it = zones.find(zone_id); if ( it == zones.end() ) { @@ -300,7 +294,7 @@ void FedReplicaManager::replicate_failure(int zone_id, uint64_t last_zone) { lock_guard ul(fed_mutex); - std::map::iterator it = zones.find(zone_id); + auto it = zones.find(zone_id); if ( it != zones.end() ) { diff --git a/src/raft/RaftManager.cc b/src/raft/RaftManager.cc index 2592fccb6a..5a40171c13 100644 --- a/src/raft/RaftManager.cc +++ b/src/raft/RaftManager.cc @@ -229,9 +229,7 @@ int RaftManager::get_leader_endpoint(std::string& endpoint) } else { - std::map::iterator it; - - it = servers.find(leader_id); + auto it = servers.find(leader_id); if ( it == servers.end() ) { @@ -332,7 +330,6 @@ void RaftManager::leader() FedReplicaManager * frm = nd.get_frm(); - std::map::iterator it; std::vector _follower_ids; uint64_t index, _applied, _next_index; @@ -383,7 +380,7 @@ void RaftManager::leader() _next_index = index + 1; } - for (it = servers.begin(); it != servers.end() ; ++it ) + for (auto it = servers.begin(); it != servers.end() ; ++it) { if ( it->first == server_id ) { @@ -523,9 +520,7 @@ void RaftManager::replicate_log(ReplicaRequest * request) //Count servers that need to replicate this record int to_commit = num_servers / 2; - std::map::iterator it; - - for (it = next.begin(); it != next.end() ; ++it) + for (auto it = next.begin(); it != next.end() ; ++it) { if ( request->index() < it->second ) { @@ -561,11 +556,6 @@ void RaftManager::replicate_log(ReplicaRequest * request) void RaftManager::replicate_success(int follower_id) { - std::map::iterator it; - - std::map::iterator next_it; - std::map::iterator match_it; - Nebula& nd = Nebula::instance(); LogDB * logdb = nd.get_logdb(); @@ -576,8 +566,8 @@ void RaftManager::replicate_success(int follower_id) std::lock_guard lock(raft_mutex); - next_it = next.find(follower_id); - match_it = match.find(follower_id); + auto next_it = next.find(follower_id); + auto match_it = match.find(follower_id); if ( next_it == next.end() || match_it == match.end() ) { @@ -606,11 +596,9 @@ void RaftManager::replicate_success(int follower_id) void RaftManager::replicate_failure(int follower_id) { - std::map::iterator next_it; - std::lock_guard lock(raft_mutex); - next_it = next.find(follower_id); + auto next_it = next.find(follower_id); if ( next_it != next.end() ) { @@ -795,8 +783,6 @@ void RaftManager::request_vote() int _server_id; std::map _servers; - std::map::iterator it; - std::ostringstream oss; @@ -858,7 +844,7 @@ void RaftManager::request_vote() /* ------------------------------------------------------------------ */ /* Request vote on all the followers */ /* ------------------------------------------------------------------ */ - for (it = _servers.begin(); it != _servers.end() ; ++it, oss.str("") ) + for (auto it = _servers.begin(); it != _servers.end() ; ++it, oss.str("") ) { int id = it->first; @@ -969,14 +955,12 @@ int RaftManager::xmlrpc_replicate_log(int follower_id, LogDBRecord * lr, std::string follower_edp; - std::map::iterator it; - int xml_rc = 0; { std::lock_guard lock(raft_mutex); - it = servers.find(follower_id); + auto it = servers.find(follower_id); if ( it == servers.end() ) { @@ -1065,14 +1049,12 @@ int RaftManager::xmlrpc_request_vote(int follower_id, uint64_t lindex, std::string follower_edp; - std::map::iterator it; - int xml_rc = 0; { std::lock_guard lock(raft_mutex); - it = servers.find(follower_id); + auto it = servers.find(follower_id); if ( it == servers.end() ) { @@ -1195,8 +1177,6 @@ std::string& RaftManager::to_xml(std::string& raft_xml) void RaftManager::reset_index(int follower_id) { - std::map::iterator next_it; - unsigned int log_term; uint64_t log_index; @@ -1206,7 +1186,7 @@ void RaftManager::reset_index(int follower_id) std::lock_guard lock(raft_mutex); - next_it = next.find(follower_id); + auto next_it = next.find(follower_id); if ( next_it != next.end() ) { diff --git a/src/raft/ReplicaManager.cc b/src/raft/ReplicaManager.cc index 3af15cf15d..df90020d4c 100644 --- a/src/raft/ReplicaManager.cc +++ b/src/raft/ReplicaManager.cc @@ -24,9 +24,7 @@ ReplicaThread * ReplicaManager::get_thread(int server_id) { - std::map::iterator it; - - it = thread_pool.find(server_id); + auto it = thread_pool.find(server_id); if ( it == thread_pool.end() ) { @@ -41,11 +39,9 @@ ReplicaThread * ReplicaManager::get_thread(int server_id) void ReplicaManager::start_replica_threads(std::vector& fids) { - std::vector::iterator it; - - for (it = fids.begin(); it != fids.end(); ++it) + for (auto id : fids) { - add_replica_thread(*it); + add_replica_thread(id); } }; @@ -54,9 +50,7 @@ void ReplicaManager::start_replica_threads(std::vector& fids) void ReplicaManager::stop_replica_threads() { - std::map::iterator it; - - for ( it = thread_pool.begin() ; it != thread_pool.end() ; ++it ) + for ( auto it = thread_pool.begin() ; it != thread_pool.end() ; ++it ) { it->second->finalize(); } @@ -69,9 +63,7 @@ void ReplicaManager::stop_replica_threads() void ReplicaManager::replicate() { - std::map::iterator it; - - for ( it = thread_pool.begin() ; it != thread_pool.end() ; ++it ) + for ( auto it = thread_pool.begin() ; it != thread_pool.end() ; ++it ) { it->second->add_request(); } @@ -94,10 +86,7 @@ void ReplicaManager::replicate(int follower) void ReplicaManager::delete_replica_thread(int follower_id) { - - std::map::iterator it; - - it = thread_pool.find(follower_id); + auto it = thread_pool.find(follower_id); if ( it == thread_pool.end() ) { diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index e88ab92289..9116e4e561 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -787,7 +787,6 @@ bool UserAllocate::allocate_authorization( PoolObjectAuth * cluster_perms) { vector param_arr; - vector::const_iterator it; if ( paramList.size() > 4 ) { @@ -799,7 +798,7 @@ bool UserAllocate::allocate_authorization( ar.add_create_auth(att.uid, att.gid, auth_object, ""); - for (it = param_arr.begin(); it != param_arr.end(); it++) + for (auto it = param_arr.begin(); it != param_arr.end(); it++) { int tmp_gid = xmlrpc_c::value_int(*it); @@ -856,7 +855,6 @@ Request::ErrorCode UserAllocate::pool_allocate( int gid = -1; vector param_arr; - vector::const_iterator it; if ( paramList.size() > 4 ) { @@ -866,7 +864,7 @@ Request::ErrorCode UserAllocate::pool_allocate( AuthRequest ar(att.uid, att.group_ids); - for (it = param_arr.begin(); it != param_arr.end(); it++) + for (auto it = param_arr.begin(); it != param_arr.end(); it++) { int tmp_gid = xmlrpc_c::value_int(*it); diff --git a/src/rm/RequestManagerChmod.cc b/src/rm/RequestManagerChmod.cc index 3ef124c769..0da36f823d 100644 --- a/src/rm/RequestManagerChmod.cc +++ b/src/rm/RequestManagerChmod.cc @@ -248,8 +248,7 @@ Request::ErrorCode TemplateChmod::chmod( if ( !error_ids.empty() ) { att.resp_msg = "Cannot chmod " + object_name(PoolObjectSQL::IMAGE) + - ": " + one_util::join::iterator>(error_ids.begin(), - error_ids.end(), ','); + ": " + one_util::join(error_ids.begin(), error_ids.end(), ','); return ACTION; } diff --git a/src/rm/RequestManagerDelete.cc b/src/rm/RequestManagerDelete.cc index dfcde0a288..ee4eca5b18 100644 --- a/src/rm/RequestManagerDelete.cc +++ b/src/rm/RequestManagerDelete.cc @@ -230,7 +230,6 @@ int TemplateDelete::drop(std::unique_ptr object, bool recursive, RequestAttributes& att) { vector vdisks; - vector::iterator i; VirtualMachineDisks disks(true); @@ -272,8 +271,7 @@ int TemplateDelete::drop(std::unique_ptr object, bool recursive, if ( !error_ids.empty() ) { att.resp_msg = "Cannot delete " + object_name(PoolObjectSQL::IMAGE) + - ": " + one_util::join::iterator>(error_ids.begin(), - error_ids.end(), ','); + ": " + one_util::join(error_ids.begin(), error_ids.end(), ','); return -1; } diff --git a/src/scheduler/include/HostXML.h b/src/scheduler/include/HostXML.h index 1f795c6f6d..d08371b32f 100644 --- a/src/scheduler/include/HostXML.h +++ b/src/scheduler/include/HostXML.h @@ -327,14 +327,13 @@ private: if (s_name == "CURRENT_VMS") { - typename std::vector::iterator it; std::vector results; xpaths(results, "/HOST/VMS/ID"); - for (it=results.begin(); it!=results.end(); it++) + for (const auto& vm_id : results) { - if (*it == value) + if (vm_id == value) { return 0; //VMID found in VMS value is VMID } diff --git a/src/scheduler/src/pool/AclXML.cc b/src/scheduler/src/pool/AclXML.cc index 6fb6a90338..450ee1b613 100644 --- a/src/scheduler/src/pool/AclXML.cc +++ b/src/scheduler/src/pool/AclXML.cc @@ -74,14 +74,13 @@ int AclXML::load_rules(const string& xml_str) ObjectXML acl_xml(xml_str); vector rules; - vector::iterator it; acl_xml.get_nodes("/ACL_POOL/ACL",rules); - for (it = rules.begin(); it != rules.end() ; it++) + for (auto node : rules) { AclRule * rule = new AclRule(0,0,0,0,0); - int rc = rule->from_xml(*it); + int rc = rule->from_xml(node); if ( rc == 0 ) { @@ -100,9 +99,7 @@ int AclXML::load_rules(const string& xml_str) void AclXML::flush_rules() { - multimap::iterator it; - - for ( it = acl_rules.begin(); it != acl_rules.end(); it++ ) + for ( auto it = acl_rules.begin(); it != acl_rules.end(); it++ ) { delete it->second; } diff --git a/src/scheduler/src/pool/HostPoolXML.cc b/src/scheduler/src/pool/HostPoolXML.cc index a6d6bcd628..083f7cfb22 100644 --- a/src/scheduler/src/pool/HostPoolXML.cc +++ b/src/scheduler/src/pool/HostPoolXML.cc @@ -33,9 +33,7 @@ int HostPoolXML::set_up() { oss << "Discovered Hosts (enabled):" << endl; - map::iterator it; - - for (it=objects.begin();it!=objects.end();it++) + for (auto it=objects.begin(); it!=objects.end(); it++) { HostXML * h = dynamic_cast(it->second); @@ -98,15 +96,13 @@ int HostPoolXML::load_info(xmlrpc_c::value &result) void HostPoolXML::merge_clusters(ClusterPoolXML * clpool) { - map::iterator it; - ClusterXML* cluster; HostXML* host; int cluster_id; vector nodes; - for (it=objects.begin(); it!=objects.end(); it++) + for (auto it=objects.begin(); it!=objects.end(); it++) { host = static_cast(it->second); @@ -135,11 +131,9 @@ void HostPoolXML::merge_clusters(ClusterPoolXML * clpool) void HostPoolXML::merge_monitoring(MonitorPoolXML * mpool) { - map::iterator it; - vector nodes; - for (it=objects.begin(); it!=objects.end(); it++) + for (auto it=objects.begin(); it!=objects.end(); it++) { HostXML* host = static_cast(it->second); diff --git a/src/scheduler/src/pool/VMGroupXML.cc b/src/scheduler/src/pool/VMGroupXML.cc index 239503fe9d..ee5443ed2b 100644 --- a/src/scheduler/src/pool/VMGroupXML.cc +++ b/src/scheduler/src/pool/VMGroupXML.cc @@ -27,8 +27,6 @@ void VMGroupXML::init_attributes() vector content; std::vector srules; - std::vector::iterator it; - xpath(oid, "/VM_GROUP/ID", -1); xpath(name,"/VM_GROUP/NAME", "undefined"); @@ -46,11 +44,11 @@ void VMGroupXML::init_attributes() xpaths(srules, "/VM_GROUP/TEMPLATE/AFFINED"); - for ( it = srules.begin() ; it != srules.end(); ++it ) + for ( const auto& srule : srules ) { std::set id_set; - roles.names_to_ids(*it, id_set); + roles.names_to_ids(srule, id_set); VMGroupRule rule(VMGroupPolicy::AFFINED, id_set); @@ -61,11 +59,11 @@ void VMGroupXML::init_attributes() xpaths(srules, "/VM_GROUP/TEMPLATE/ANTI_AFFINED"); - for ( it = srules.begin() ; it != srules.end(); ++it ) + for ( const auto& srule : srules ) { std::set id_set; - roles.names_to_ids(*it, id_set); + roles.names_to_ids(srule, id_set); VMGroupRule rule(VMGroupPolicy::ANTI_AFFINED, id_set); @@ -79,8 +77,6 @@ void VMGroupXML::init_attributes() void VMGroupXML::set_antiaffinity_requirements(VirtualMachinePoolXML * vmpool, std::ostringstream& oss) { - VMGroupRoles::role_iterator it; - oss << "\n"; oss << setfill('-') << setw(80) << '-' << setfill(' ') << "\n"; oss << "Intra-role Anti-affinity rules \n"; @@ -91,37 +87,34 @@ void VMGroupXML::set_antiaffinity_requirements(VirtualMachinePoolXML * vmpool, /* ---------------------------------------------------------------------- */ /* Intra-role anti-affinity placement rule */ /* ---------------------------------------------------------------------- */ - for ( it = roles.begin(); it != roles.end() ; ++it ) + for ( auto r : roles ) { - VMGroupRole * r = *it; - if ( r->policy() != VMGroupPolicy::ANTI_AFFINED || r->size_vms() <= 1 ) { continue; } const std::set& vms = r->get_vms(); - std::set::const_iterator jt; - for ( jt = vms.begin() ; jt != vms.end(); ++jt ) + for ( auto vm_id : vms ) { std::string reqs; - VirtualMachineXML * vm = vmpool->get(*jt); + VirtualMachineXML * vm = vmpool->get(vm_id); if ( vm == 0 ) { continue; } - r->vm_role_requirements(*jt, reqs); + r->vm_role_requirements(vm_id, reqs); if ( !reqs.empty() ) { vm->add_requirements(reqs); } - oss << left << setw(8) << r->id() << left << setw(8) << *jt << reqs + oss << left << setw(8) << r->id() << left << setw(8) << vm_id << reqs << "\n"; } } @@ -136,11 +129,10 @@ void VMGroupXML::set_antiaffinity_requirements(VirtualMachinePoolXML * vmpool, oss << left << setw(8)<< "ROLE" << " " << left << setw(8) <<"VM" << " " << left << "ANTI_AFFINITY REQUIRMENTS\n" << setfill('-') << setw(80) << '-' << setfill(' ') << "\n"; - VMGroupRule::rule_set::iterator rt; - for ( rt = anti_affined.begin() ; rt != anti_affined.end() ; ++rt ) + for ( const auto& rt : anti_affined ) { - VMGroupRule::role_bitset rroles = (*rt).get_roles(); + const VMGroupRule::role_bitset& rroles = rt.get_roles(); for ( int i=0 ; i < VMGroupRoles::MAX_ROLES; ++i) { @@ -187,11 +179,10 @@ void VMGroupXML::set_antiaffinity_requirements(VirtualMachinePoolXML * vmpool, VMGroupRole * r = roles.get(i); const std::set& vms = r->get_vms(); - std::set::const_iterator vt; - for ( vt=vms.begin() ; vt!=vms.end(); ++vt ) + for ( auto vm_id : vms ) { - VirtualMachineXML * vm = vmpool->get(*vt); + VirtualMachineXML * vm = vmpool->get(vm_id); if ( vm == 0 ) { @@ -200,7 +191,7 @@ void VMGroupXML::set_antiaffinity_requirements(VirtualMachinePoolXML * vmpool, vm->add_requirements(role_reqs); - oss << left << setw(8) << r->id() << left << setw(8) << *vt + oss << left << setw(8) << r->id() << left << setw(8) << vm_id << vm->get_requirements() << "\n"; } } @@ -213,8 +204,6 @@ void VMGroupXML::set_antiaffinity_requirements(VirtualMachinePoolXML * vmpool, void VMGroupXML::set_host_requirements(VirtualMachinePoolXML * vmpool, std::ostringstream& oss) { - VMGroupRoles::role_iterator it; - oss << "\n"; oss << setfill('-') << setw(80) << '-' << setfill(' ') << "\n"; oss << "Host affinity rules \n"; @@ -222,12 +211,10 @@ void VMGroupXML::set_host_requirements(VirtualMachinePoolXML * vmpool, << " " << left << "AFFINITY REQUIRMENTS\n" << setfill('-') << setw(80) << '-' << setfill(' ') << "\n"; - for ( it = roles.begin(); it != roles.end() ; ++it ) + for ( auto r : roles ) { std::string areqs, aareqs; - VMGroupRole * r = *it; - r->affined_host_requirements(areqs); r->antiaffined_host_requirements(aareqs); @@ -239,9 +226,9 @@ void VMGroupXML::set_host_requirements(VirtualMachinePoolXML * vmpool, const std::set& vms = r->get_vms(); - for (std::set::const_iterator jt=vms.begin(); jt!=vms.end(); ++jt) + for (auto vm_id : vms) { - VirtualMachineXML * vm = vmpool->get(*jt); + VirtualMachineXML * vm = vmpool->get(vm_id); if ( vm == 0 ) { @@ -258,7 +245,7 @@ void VMGroupXML::set_host_requirements(VirtualMachinePoolXML * vmpool, vm->add_requirements(aareqs); } - oss << left << setw(8) << r->id() << left << setw(8) << *jt + oss << left << setw(8) << r->id() << left << setw(8) << vm_id << vm->get_requirements() << "\n"; } } @@ -286,7 +273,7 @@ static void schecule_affined_set(const std::set& vms, { VirtualMachineXML * vm = vm_roles_pool->get(*it); - if ( vm == 0 ) + if ( vm ) { continue; } @@ -299,7 +286,7 @@ static void schecule_affined_set(const std::set& vms, } } - if ( hosts.size() == 0 ) + if ( hosts.empty() ) { /* ------------------------------------------------------------------ */ /* No VMs of the set are running: */ @@ -313,13 +300,13 @@ static void schecule_affined_set(const std::set& vms, { vm = vmpool->get(*it); - if ( vm != 0 ) + if ( !vm ) { break; } } - if ( vm == 0 ) + if ( vm ) { return; } @@ -336,7 +323,7 @@ static void schecule_affined_set(const std::set& vms, VirtualMachineXML * tmp = vmpool->get(*it); - if ( tmp == 0 ) + if ( tmp ) { continue; } @@ -373,7 +360,7 @@ static void schecule_affined_set(const std::set& vms, { VirtualMachineXML * vm = vmpool->get(*it); - if ( vm == 0 || reqs.empty()) + if ( vm || reqs.empty()) { continue; } @@ -391,8 +378,6 @@ static void schecule_affined_set(const std::set& vms, void VMGroupXML::set_affinity_requirements(VirtualMachinePoolXML * vmpool, VirtualMachineRolePoolXML * vm_roles_pool, std::ostringstream& oss) { - VMGroupRoles::role_iterator it; - /* ---------------------------------------------------------------------- */ /* Intra-role affinity placement rule */ /* ---------------------------------------------------------------------- */ @@ -402,10 +387,8 @@ void VMGroupXML::set_affinity_requirements(VirtualMachinePoolXML * vmpool, oss << left << setw(8) << "VMID" << " " << left << "REQUIREMENTS\n"; oss << setfill('-') << setw(80) << '-' << setfill(' ') << "\n"; - for ( it = roles.begin(); it != roles.end() ; ++it ) + for ( auto r : roles ) { - VMGroupRole * r = *it; - if ( r->policy() != VMGroupPolicy::AFFINED || r->size_vms() <= 1 ) { continue; @@ -423,7 +406,6 @@ void VMGroupXML::set_affinity_requirements(VirtualMachinePoolXML * vmpool, /* 3. Schedule the resulting set */ /* ---------------------------------------------------------------------- */ VMGroupRule::rule_set reduced; - VMGroupRule::rule_set::iterator rit; oss << "\n"; oss << setfill('-') << setw(80) << '-' << setfill(' ') << "\n"; @@ -433,9 +415,9 @@ void VMGroupXML::set_affinity_requirements(VirtualMachinePoolXML * vmpool, VMGroupRule::reduce(affined, reduced); - for ( rit = reduced.begin() ; rit != reduced.end(); ++rit ) + for ( const auto& rit : reduced ) { - const VMGroupRule::role_bitset rroles = (*rit).get_roles(); + const VMGroupRule::role_bitset& rroles = rit.get_roles(); std::set rule_vms; for (int i = 0 ; i id() << " " - << left << setw(8) << (*it)->name() << " " - << left << setw(12)<< (*it)->policy_s() << " " - << left << (*it)->vms_s() << "\n"; + os << left << setw(7) << role->id() << " " + << left << setw(8) << role->name() << " " + << left << setw(12)<< role->policy_s() << " " + << left << role->vms_s() << "\n"; } os << "\n"; diff --git a/src/scheduler/src/pool/VirtualMachinePoolXML.cc b/src/scheduler/src/pool/VirtualMachinePoolXML.cc index 2356100d92..91d7dab0bc 100644 --- a/src/scheduler/src/pool/VirtualMachinePoolXML.cc +++ b/src/scheduler/src/pool/VirtualMachinePoolXML.cc @@ -121,8 +121,6 @@ int VirtualMachinePoolXML::set_up() if ( rc == 0 ) { - map::iterator it; - if (objects.empty()) { return -2; @@ -130,7 +128,7 @@ int VirtualMachinePoolXML::set_up() vm_resources.clear(); - for ( it = objects.begin(); it != objects.end(); ++it ) + for ( auto it = objects.begin(); it != objects.end(); ++it ) { vm_resources.add_resource(it->first); } @@ -149,7 +147,7 @@ int VirtualMachinePoolXML::set_up() << " Image DS" << endl << setw(60) << setfill('-') << "-" << setfill(' ') << endl; - for (it = objects.begin() ; it != objects.end() ; ++it) + for (auto it = objects.begin() ; it != objects.end() ; ++it) { HostShareCapacity sr; @@ -178,9 +176,8 @@ int VirtualMachinePoolXML::set_up() << right << setw(11) << sr.disk << " "; map ds_usage = vm->get_storage_usage(); - map::const_iterator ds_it; - for ( ds_it = ds_usage.begin(); ds_it != ds_usage.end(); ds_it++) + for ( auto ds_it = ds_usage.begin(); ds_it != ds_usage.end(); ds_it++) { oss << " DS " << ds_it->first << ": " << ds_it->second <<" "; } @@ -361,9 +358,7 @@ int VirtualMachineActionsPoolXML::set_up() oss.str(""); oss << "VMs with scheduled actions:" << endl; - map::iterator it; - - for (it=objects.begin();it!=objects.end();it++) + for (auto it=objects.begin(); it!=objects.end(); it++) { oss << " " << it->first; } @@ -547,9 +542,7 @@ int VirtualMachineRolePoolXML::set_up() oss << "VMs in VMGroups:" << endl; - map::iterator it; - - for (it=objects.begin();it!=objects.end();it++) + for (auto it=objects.begin(); it!=objects.end(); it++) { oss << " " << it->first; } diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index d8b98da0ed..bd61c41a7f 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -271,7 +271,6 @@ static bool isVolatile(const VectorAttribute * disk) void VirtualMachineXML::init_storage_usage() { vector disks; - vector::iterator it; long long size; long long snapshot_size; @@ -283,11 +282,11 @@ void VirtualMachineXML::init_storage_usage() int num = vm_template->remove("DISK", disks); - for (it=disks.begin(); it != disks.end(); it++) + for (const auto attr : disks) { - const VectorAttribute * disk = dynamic_cast(*it); + const VectorAttribute * disk = dynamic_cast(attr); - if (disk == 0) + if (!disk) { continue; } diff --git a/src/scheduler/src/pool/VirtualNetworkPoolXML.cc b/src/scheduler/src/pool/VirtualNetworkPoolXML.cc index cd740cda80..832a255b6f 100644 --- a/src/scheduler/src/pool/VirtualNetworkPoolXML.cc +++ b/src/scheduler/src/pool/VirtualNetworkPoolXML.cc @@ -39,9 +39,7 @@ int VirtualNetworkPoolXML::set_up() << right << setw(8) << "Leases" << " " << endl << setw(20) << setfill('-') << "-" << setfill(' ') << endl; - map::iterator it; - - for (it=objects.begin();it!=objects.end();it++) + for (auto it=objects.begin(); it!=objects.end(); it++) { VirtualNetworkXML * n = dynamic_cast(it->second); diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index ab552efbec..1761812bea 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -388,7 +388,6 @@ int Scheduler::set_up_pools() { int rc; ostringstream oss; - map::const_iterator it; map shares; //-------------------------------------------------------------------------- @@ -841,11 +840,6 @@ void Scheduler::match_schedule() string m_error; - map::const_iterator vm_it; - map::const_iterator obj_it; - - vector::iterator it; - const map pending_vms = vmpool->get_objects(); const map hosts = hpool->get_objects(); const map datastores = dspool->get_objects(); @@ -862,7 +856,7 @@ void Scheduler::match_schedule() time_t stime = time(0); - for (vm_it=pending_vms.begin(); vm_it != pending_vms.end(); vm_it++) + for (auto vm_it=pending_vms.begin(); vm_it != pending_vms.end(); vm_it++) { vm = static_cast(vm_it->second); @@ -902,7 +896,7 @@ void Scheduler::match_schedule() // --------------------------------------------------------------------- profile(true); - for (obj_it=hosts.begin(); obj_it != hosts.end(); obj_it++) + for (auto obj_it=hosts.begin(); obj_it != hosts.end(); obj_it++) { host = static_cast(obj_it->second); @@ -981,9 +975,9 @@ void Scheduler::match_schedule() // --------------------------------------------------------------------- profile(true); - for (it=host_policies.begin() ; it != host_policies.end() ; it++) + for (auto sp : host_policies) { - (*it)->schedule(vm); + sp->schedule(vm); } vm->sort_match_hosts(); @@ -1009,7 +1003,7 @@ void Scheduler::match_schedule() n_error = 0; n_fits = 0; - for (obj_it=datastores.begin(); obj_it != datastores.end(); obj_it++) + for (auto obj_it=datastores.begin(); obj_it != datastores.end(); obj_it++) { ds = static_cast(obj_it->second); @@ -1100,9 +1094,9 @@ void Scheduler::match_schedule() profile(true); - for (it=ds_policies.begin() ; it != ds_policies.end() ; it++) + for (auto sp : ds_policies) { - (*it)->schedule(vm); + sp->schedule(vm); } vm->sort_match_datastores(); @@ -1115,7 +1109,6 @@ void Scheduler::match_schedule() profile(true); - set::iterator it_nic; const set& nics_ids = vm->get_nics_ids(); bool not_matched = false; @@ -1130,7 +1123,7 @@ void Scheduler::match_schedule() n_fits = 0; - for (obj_it = nets.begin(); obj_it != nets.end(); ++obj_it) + for (auto obj_it = nets.begin(); obj_it != nets.end(); ++obj_it) { net = static_cast(obj_it->second); @@ -1202,9 +1195,9 @@ void Scheduler::match_schedule() profile(true); - for (it = nic_policies.begin() ; it != nic_policies.end() ; it++) + for (auto sp : nic_policies) { - (*it)->schedule(vm->get_nic(nic_id)); + sp->schedule(vm->get_nic(nic_id)); } vm->sort_match_networks(nic_id); @@ -1253,7 +1246,7 @@ void Scheduler::match_schedule() oss << "Scheduling Results:" << endl; - for (map::const_iterator vm_it=pending_vms.begin(); + for (auto vm_it=pending_vms.begin(); vm_it != pending_vms.end(); vm_it++) { vm = static_cast(vm_it->second); @@ -1288,16 +1281,14 @@ void Scheduler::dispatch() vector::const_reverse_iterator i, j, k, n; - vector::iterator sp_it; - ostringstream extra; //-------------------------------------------------------------------------- // Schedule pending VMs according to the VM policies (e.g. User priority) //-------------------------------------------------------------------------- - for (sp_it = vm_policies.begin() ; sp_it != vm_policies.end() ; ++sp_it) + for (auto sp : vm_policies) { - (*sp_it)->schedule(0); + sp->schedule(0); } vmpool->sort_vm_resources(); @@ -1571,9 +1562,7 @@ void Scheduler::dispatch() if ( num_matched_networks < nics_ids.size()) { - map::iterator it; - - for (it = matched_networks.begin(); it != matched_networks.end(); it++) + for (auto it = matched_networks.begin(); it != matched_networks.end(); it++) { net = vnetpool->get(it->first); @@ -1588,9 +1577,7 @@ void Scheduler::dispatch() //------------------------------------------------------------------ if (vmpool->dispatch((*k)->oid, hid, dsid, vm->is_resched(), extra.str()) != 0) { - map::iterator it; - - for ( it = matched_networks.begin(); it != matched_networks.end(); it++) + for ( auto it = matched_networks.begin(); it != matched_networks.end(); it++) { net = vnetpool->get(it->first); @@ -1635,11 +1622,9 @@ void Scheduler::dispatch() if ( affined_vms.size() > 0 ) { - set::const_iterator it; - - for ( it = affined_vms.begin(); it != affined_vms.end(); ++it ) + for ( auto vm_id : affined_vms ) { - VirtualMachineXML * avm = vmpool->get(*it); + VirtualMachineXML * avm = vmpool->get(vm_id); if ( avm == 0 ) { @@ -1690,31 +1675,28 @@ int Scheduler::do_scheduled_actions() VirtualMachineXML* vm; const map vms = vmapool->get_objects(); - map::const_iterator vm_it; string action_st, args_st, error_msg; string time_str = one_util::log_time(time(0)); - for (vm_it=vms.begin(); vm_it != vms.end(); vm_it++) + for (auto vm_it=vms.begin(); vm_it != vms.end(); vm_it++) { - SchedActions::schedaction_iterator action; - vm = static_cast(vm_it->second); SchedActions sas = vm->get_actions(); - for ( action = sas.begin(); action != sas.end(); ++action) + for ( auto action : sas) { ostringstream oss; - if (!(*action)->is_due(vm->get_stime())) + if (!action->is_due(vm->get_stime())) { continue; } - action_st = (*action)->vector_value("ACTION"); - args_st = (*action)->vector_value("ARGS"); + action_st = action->vector_value("ACTION"); + args_st = action->vector_value("ARGS"); int rc = VirtualMachineXML::parse_action_name(action_st); @@ -1734,13 +1716,13 @@ int Scheduler::do_scheduled_actions() time_t done_time = time(0); time_t next_time; - (*action)->remove("MESSAGE"); + action->remove("MESSAGE"); - (*action)->replace("DONE", done_time); + action->replace("DONE", done_time); do { - next_time = (*action)->next_action(); + next_time = action->next_action(); } while ( next_time < done_time && next_time != -1 ); oss << "Success."; @@ -1753,7 +1735,7 @@ int Scheduler::do_scheduled_actions() oss_aux << time_str << " : " << error_msg; - (*action)->replace("MESSAGE", oss_aux.str()); + action->replace("MESSAGE", oss_aux.str()); oss << "Failure. " << error_msg; } @@ -1775,14 +1757,13 @@ int Scheduler::do_scheduled_actions() void Scheduler::do_vm_groups() { - map::const_iterator it; const map vmgrps = vmgpool->get_objects(); ostringstream oss; oss << "VM Group Scheduling information\n"; - for (it = vmgrps.begin(); it != vmgrps.end() ; ++it) + for (auto it = vmgrps.begin(); it != vmgrps.end() ; ++it) { VMGroupXML * grp = static_cast(it->second); diff --git a/src/secgroup/SecurityGroup.cc b/src/secgroup/SecurityGroup.cc index 39e80597d7..73505b17c7 100644 --- a/src/secgroup/SecurityGroup.cc +++ b/src/secgroup/SecurityGroup.cc @@ -57,7 +57,6 @@ SecurityGroup::SecurityGroup( int SecurityGroup::insert(SqlDB *db, string& error_str) { - vector::const_iterator it; vector rules; erase_template_attribute("NAME",name); @@ -69,9 +68,9 @@ int SecurityGroup::insert(SqlDB *db, string& error_str) get_template_attribute("RULE", rules); - for ( it = rules.begin(); it != rules.end(); it++ ) + for ( auto rule : rules ) { - if (!isValidRule(*it, error_str)) + if (!isValidRule(rule, error_str)) { goto error_valid; } @@ -280,15 +279,14 @@ int SecurityGroup::from_xml(const string& xml) void SecurityGroup::get_rules(vector& result) const { - vector::const_iterator it; vector rules; get_template_attribute("RULE", rules); - for ( it = rules.begin(); it != rules.end(); it++ ) + for ( auto rule : rules ) { VectorAttribute* new_rule = new VectorAttribute( - "SECURITY_GROUP_RULE", (*it)->value()); + "SECURITY_GROUP_RULE", rule->value()); new_rule->replace("SECURITY_GROUP_ID", this->get_oid()); new_rule->replace("SECURITY_GROUP_NAME", this->get_name()); @@ -435,14 +433,13 @@ bool SecurityGroup::isValidRule(const VectorAttribute * rule, string& error) con int SecurityGroup::post_update_template(string& error) { - vector::const_iterator it; vector rules; get_template_attribute("RULE", rules); - for ( it = rules.begin(); it != rules.end(); it++ ) + for ( auto rule : rules ) { - if (!isValidRule(*it, error)) + if (!isValidRule(rule, error)) { return -1; } diff --git a/src/secgroup/SecurityGroupPool.cc b/src/secgroup/SecurityGroupPool.cc index e2f4982209..4666adfe5e 100644 --- a/src/secgroup/SecurityGroupPool.cc +++ b/src/secgroup/SecurityGroupPool.cc @@ -138,7 +138,6 @@ error_name: void SecurityGroupPool::get_security_group_rules(int vmid, int sgid, vector &rules) { - vector::iterator rule_it; vector sg_rules; int vnet_id; @@ -160,14 +159,12 @@ void SecurityGroupPool::get_security_group_rules(int vmid, int sgid, return; } - for (rule_it = sg_rules.begin(); rule_it != sg_rules.end(); rule_it++) + for (auto rule : sg_rules) { - if ( (*rule_it)->vector_value("NETWORK_ID", vnet_id) != -1 ) + if ( rule->vector_value("NETWORK_ID", vnet_id) != -1 ) { vector vnet_rules; - VectorAttribute* rule = *rule_it; - if ( auto vnet = vnet_pool->get_ro(vnet_id) ) { vnet->process_security_rule(rule, vnet_rules); @@ -184,7 +181,7 @@ void SecurityGroupPool::get_security_group_rules(int vmid, int sgid, } else { - rules.push_back(*rule_it); + rules.push_back(rule); } } } diff --git a/src/sql/LogDB.cc b/src/sql/LogDB.cc index 5100788b6a..ede055b560 100644 --- a/src/sql/LogDB.cc +++ b/src/sql/LogDB.cc @@ -818,13 +818,11 @@ uint64_t LogDB::last_federated() uint64_t LogDB::previous_federated(uint64_t i) { - set::iterator it; - lock_guard lock(_mutex); uint64_t findex = UINT64_MAX; - it = fed_log.find(i); + auto it = fed_log.find(i); if ( it != fed_log.end() && it != fed_log.begin() ) { @@ -838,13 +836,11 @@ uint64_t LogDB::previous_federated(uint64_t i) uint64_t LogDB::next_federated(uint64_t i) { - set::iterator it; - lock_guard lock(_mutex); uint64_t findex = UINT64_MAX; - it = fed_log.find(i); + auto it = fed_log.find(i); if ( it != fed_log.end() && it != --fed_log.end() ) { diff --git a/src/template/Template.cc b/src/template/Template.cc index 58f470c483..dde4fa57d3 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -33,9 +33,7 @@ using namespace std; Template::~Template() { - multimap::iterator it; - - for ( it = attributes.begin(); it != attributes.end(); it++) + for ( auto it = attributes.begin(); it != attributes.end(); it++) { delete it->second; } @@ -193,13 +191,9 @@ void Template::set(Attribute * attr) { if ( replace_mode == true ) { - multimap::iterator i; - pair::iterator, - multimap::iterator> index; + auto index = attributes.equal_range(attr->name()); - index = attributes.equal_range(attr->name()); - - for ( i = index.first; i != index.second; i++) + for ( auto i = index.first; i != index.second; i++) { delete i->second; } @@ -215,19 +209,13 @@ void Template::set(Attribute * attr) int Template::replace(const string& name, const string& value) { - pair::iterator, - multimap::iterator> index; - - index = attributes.equal_range(name); + auto index = attributes.equal_range(name); if (index.first != index.second ) { - multimap::iterator i; - - for ( i = index.first; i != index.second; i++) + for ( auto i = index.first; i != index.second; i++) { - Attribute * attr = i->second; - delete attr; + delete i->second; } attributes.erase(index.first, index.second); @@ -247,19 +235,13 @@ int Template::replace(const string& name, const bool& value) { string s_val; - pair::iterator, - multimap::iterator> index; - - index = attributes.equal_range(name); + auto index = attributes.equal_range(name); if (index.first != index.second ) { - multimap::iterator i; - - for ( i = index.first; i != index.second; i++) + for ( auto i = index.first; i != index.second; i++) { - Attribute * attr = i->second; - delete attr; + delete i->second; } attributes.erase(index.first, index.second); @@ -286,25 +268,18 @@ int Template::replace(const string& name, const bool& value) int Template::erase(const string& name) { - multimap::iterator i; + int j = 0; - pair< - multimap::iterator, - multimap::iterator - > index; - int j; - - index = attributes.equal_range(name); + auto index = attributes.equal_range(name); if (index.first == index.second ) { return 0; } - for ( i = index.first,j=0 ; i != index.second ; i++,j++ ) + for ( auto i = index.first; i != index.second; i++,j++ ) { - Attribute * attr = i->second; - delete attr; + delete i->second; } attributes.erase(index.first,index.second); @@ -317,16 +292,9 @@ int Template::erase(const string& name) Attribute * Template::remove(Attribute * att) { - multimap::iterator i; + auto index = attributes.equal_range( att->name() ); - pair< - multimap::iterator, - multimap::iterator - > index; - - index = attributes.equal_range( att->name() ); - - for ( i = index.first; i != index.second; i++ ) + for ( auto i = index.first; i != index.second; i++ ) { if ( i->second == att ) { @@ -387,12 +355,11 @@ bool Template::get(const string& name, bool& value) const string& Template::to_xml(string& xml) const { - multimap::const_iterator it; ostringstream oss; oss << "<" << xml_root << ">"; - for ( it = attributes.begin(); it!=attributes.end(); it++) + for ( auto it = attributes.begin(); it!=attributes.end(); it++) { it->second->to_xml(oss); } @@ -406,14 +373,13 @@ string& Template::to_xml(string& xml) const string& Template::to_json(string& json) const { - multimap::const_iterator it; ostringstream oss; bool is_first = true; oss << "\"" << xml_root << "\": {"; - for ( it = attributes.begin(); it!=attributes.end(); ) + for ( auto it = attributes.begin(); it!=attributes.end(); ) { if (!is_first) { @@ -467,9 +433,8 @@ string& Template::to_json(string& json) const string& Template::to_token(string& str) const { ostringstream os; - multimap::const_iterator it; - for ( it = attributes.begin(); it!=attributes.end(); it++) + for ( auto it = attributes.begin(); it!=attributes.end(); it++) { it->second->to_token(os); } @@ -672,9 +637,7 @@ void Template::clear() return; } - multimap::iterator it; - - for ( it = attributes.begin(); it != attributes.end(); it++) + for ( auto it = attributes.begin(); it != attributes.end(); it++) { delete it->second; } @@ -691,14 +654,12 @@ void Template::clear() void Template::merge(const Template * from) { - multimap::const_iterator it, jt; - - for (it = from->attributes.begin(); it != from->attributes.end(); ++it) + for (auto it = from->attributes.begin(); it != from->attributes.end(); ++it) { erase(it->first); } - for (it = from->attributes.begin(); it != from->attributes.end(); ++it) + for (auto it = from->attributes.begin(); it != from->attributes.end(); ++it) { if ( it->second->type() == Attribute::VECTOR ) { @@ -722,11 +683,9 @@ void Template::merge(const Template * from) static void parse_attributes(const vector& as, std::map >& as_m) { - vector::const_iterator it; - - for (it = as.begin(); it != as.end(); ++it) + for (auto attr : as) { - string va = (*it)->value(); + string va = attr->value(); size_t pos = va.find("/"); if (pos != string::npos) //Vector Attribute @@ -734,9 +693,7 @@ static void parse_attributes(const vector& as, string avector = va.substr(0,pos); string vattr = va.substr(pos+1); - map >::iterator jt; - - jt = as_m.find(avector); + auto jt = as_m.find(avector); if ( jt == as_m.end() ) { @@ -787,18 +744,17 @@ static bool restricted_values(const string& vname, const set& vsubs, string value; bool exists; - vector::const_iterator va_it; vector va; exists = tmpl->get(vname, va); - for ( va_it = va.begin(); va_it != va.end() ; ++va_it ) + for ( auto vattr : va ) { - for (set::iterator jt = vsubs.begin(); jt != vsubs.end(); ++jt) + for (const auto& sub : vsubs) { - if ( (*va_it)->vector_value(*jt, value) == 0 ) + if ( vattr->vector_value(sub, value) == 0 ) { - rstrings.push_back(*jt + value); + rstrings.push_back(sub + value); } } } @@ -811,9 +767,7 @@ static bool restricted_values(const string& vname, const set& vsubs, bool Template::check_restricted(string& ra, const Template* base, const std::map >& ras) { - std::map >::const_iterator rit; - - for ( rit = ras.begin(); rit != ras.end(); ++rit ) + for ( auto rit = ras.begin(); rit != ras.end(); ++rit ) { if (!(rit->second).empty()) { @@ -866,9 +820,7 @@ bool Template::check_restricted(string& ra, const Template* base, bool Template::check_restricted(string& ra, const std::map >& ras) { - std::map >::const_iterator rit; - - for ( rit = ras.begin(); rit != ras.end(); ++rit ) + for ( auto rit = ras.begin(); rit != ras.end(); ++rit ) { const std::set& sub = rit->second; @@ -876,20 +828,17 @@ bool Template::check_restricted(string& ra, { // ----------------------------------------------------------------- // ----------------------------------------------------------------- - std::set::iterator jt; - std::vector::iterator va_it; - std::vector va; get(rit->first, va); - for ( va_it = va.begin(); va_it != va.end() ; ++va_it ) + for ( auto vattr : va ) { - for ( jt = sub.begin(); jt != sub.end(); ++jt ) + for ( const auto& s : sub ) { - if ( (*va_it)->vector_value(*jt, ra) == 0 ) + if ( vattr->vector_value(s, ra) == 0 ) { - ra = *jt; + ra = s; return true; } } diff --git a/src/um/LoginToken.cc b/src/um/LoginToken.cc index dd056f6443..12bf45fcec 100644 --- a/src/um/LoginToken.cc +++ b/src/um/LoginToken.cc @@ -41,9 +41,7 @@ LoginTokenPool::~LoginTokenPool() void LoginTokenPool::reset() { - std::map::iterator it; - - for (it = tokens.begin() ; it != tokens.end() ; ++it) + for (auto it = tokens.begin() ; it != tokens.end() ; ++it) { delete it->second; } @@ -75,9 +73,7 @@ int LoginTokenPool::set(std::string& utk, time_t valid, int egid) int LoginTokenPool::reset(const std::string& utk) { - std::map::iterator it; - - it = tokens.find(utk); + auto it = tokens.find(utk); if ( it == tokens.end() ) { @@ -95,21 +91,13 @@ int LoginTokenPool::reset(const std::string& utk) void LoginTokenPool::reset_expired() { - std::map::iterator it, tmp_it; - - for (it = tokens.begin(); it != tokens.end(); ) + for (auto it = tokens.begin(); it != tokens.end(); ) { if ((it->second)->is_expired()) { - tmp_it = it; - - ++tmp_it; - delete it->second; - tokens.erase(it); - - it = tmp_it; + it = tokens.erase(it); } else { @@ -122,10 +110,8 @@ void LoginTokenPool::reset_expired() bool LoginTokenPool::is_valid(const std::string& utk, int& egid, bool& exists_token) { - std::map::iterator it; - egid = -1; - it = tokens.find(utk); + auto it = tokens.find(utk); if ( it == tokens.end() ) { @@ -134,7 +120,7 @@ bool LoginTokenPool::is_valid(const std::string& utk, int& egid, bool& exists_to } exists_token = true; - + if ( it->second->is_valid(utk, egid) == true) { return true; @@ -151,12 +137,10 @@ bool LoginTokenPool::is_valid(const std::string& utk, int& egid, bool& exists_to void LoginTokenPool::from_xml_node(const std::vector& content) { - std::vector::const_iterator it; - - for (it = content.begin(); it != content.end(); ++it) + for (auto node : content) { LoginToken * tk = new LoginToken; - std::string utk = tk->from_xml_node(*it); + std::string utk = tk->from_xml_node(node); tokens.insert(std::pair(utk, tk)); } @@ -166,10 +150,9 @@ void LoginTokenPool::from_xml_node(const std::vector& content) std::string& LoginTokenPool::to_xml(std::string& xml) const { - std::map::const_iterator it; std::ostringstream oss; - for ( it = tokens.begin() ; it != tokens.end() ; ++it) + for ( auto it = tokens.begin() ; it != tokens.end() ; ++it) { it->second->to_xml(oss); } diff --git a/src/um/Quota.cc b/src/um/Quota.cc index b64be36a8f..89fdcb0750 100644 --- a/src/um/Quota.cc +++ b/src/um/Quota.cc @@ -151,7 +151,6 @@ bool Quota::check_quota(const string& qid, { VectorAttribute * q; VectorAttribute * default_q; - map::iterator it; bool check; float limit; @@ -208,7 +207,7 @@ bool Quota::check_quota(const string& qid, metrics_used += "_USED"; - it = usage_req.find(metrics[i]); + auto it = usage_req.find(metrics[i]); if (it == usage_req.end()) { @@ -259,7 +258,7 @@ bool Quota::check_quota(const string& qid, metrics_used += "_USED"; - it = usage_req.find(metrics[i]); + auto it = usage_req.find(metrics[i]); if (it == usage_req.end()) { @@ -278,7 +277,6 @@ bool Quota::check_quota(const string& qid, void Quota::del_quota(const string& qid, map& usage_req) { VectorAttribute * q; - map::iterator it; if ( get_quota(qid, &q) == -1) { @@ -296,7 +294,7 @@ void Quota::del_quota(const string& qid, map& usage_req) metrics_used += "_USED"; - it = usage_req.find(metrics[i]); + auto it = usage_req.find(metrics[i]); if (it == usage_req.end()) { diff --git a/src/um/Quotas.cc b/src/um/Quotas.cc index 89d21be6f1..feced49186 100644 --- a/src/um/Quotas.cc +++ b/src/um/Quotas.cc @@ -326,12 +326,9 @@ void Quotas::ds_del_recreate(int uid, int gid, vector