Use foreach

This commit is contained in:
Uwe Seimet 2021-08-25 13:46:14 +02:00
parent 1b0032c25f
commit d6874f04ef
3 changed files with 15 additions and 21 deletions

View File

@ -238,9 +238,9 @@ void Cleanup()
void Reset() void Reset()
{ {
// Reset all of the controllers // Reset all of the controllers
for (auto it = controllers.begin(); it != controllers.end(); ++it) { for (const auto& controller : controllers) {
if (*it) { if (controller) {
(*it)->Reset(); controller->Reset();
} }
} }
@ -383,7 +383,7 @@ bool MapController(Device **map)
} }
// If there are no units connected // If there are no units connected
if (sasi_num == 0 && scsi_num == 0) { if (!sasi_num && !scsi_num) {
if (*it) { if (*it) {
delete *it; delete *it;
*it = NULL; *it = NULL;
@ -519,8 +519,8 @@ void LogDevices(const string& devices)
void GetLogLevels(PbServerInfo& serverInfo) void GetLogLevels(PbServerInfo& serverInfo)
{ {
for (auto it = log_levels.begin(); it != log_levels.end(); ++it) { for (const auto& log_level : log_levels) {
serverInfo.add_log_levels(*it); serverInfo.add_log_levels(log_level);
} }
} }
@ -531,8 +531,8 @@ void GetDeviceTypeFeatures(PbServerInfo& serverInfo)
types_properties->set_type(SAHD); types_properties->set_type(SAHD);
properties->set_supports_file(true); properties->set_supports_file(true);
vector<int> block_sizes = device_factory.GetSasiSectorSizes(); vector<int> block_sizes = device_factory.GetSasiSectorSizes();
for (auto it = block_sizes.begin(); it != block_sizes.end(); ++it) { for (const auto& block_size : block_sizes) {
properties->add_block_sizes(*it); properties->add_block_sizes(block_size);
} }
block_sizes = device_factory.GetScsiSectorSizes(); block_sizes = device_factory.GetScsiSectorSizes();
@ -542,8 +542,8 @@ void GetDeviceTypeFeatures(PbServerInfo& serverInfo)
properties = types_properties->add_properties(); properties = types_properties->add_properties();
properties->set_protectable(true); properties->set_protectable(true);
properties->set_supports_file(true); properties->set_supports_file(true);
for (auto it = block_sizes.begin(); it != block_sizes.end(); ++it) { for (const auto& block_size : block_sizes) {
properties->add_block_sizes(*it); properties->add_block_sizes(block_size);
} }
types_properties = serverInfo.add_types_properties(); types_properties = serverInfo.add_types_properties();
@ -553,8 +553,8 @@ void GetDeviceTypeFeatures(PbServerInfo& serverInfo)
properties->set_removable(true); properties->set_removable(true);
properties->set_lockable(true); properties->set_lockable(true);
properties->set_supports_file(true); properties->set_supports_file(true);
for (auto it = block_sizes.begin(); it != block_sizes.end(); ++it) { for (const auto& block_size : block_sizes) {
properties->add_block_sizes(*it); properties->add_block_sizes(block_size);
} }
types_properties = serverInfo.add_types_properties(); types_properties = serverInfo.add_types_properties();

View File

@ -205,9 +205,7 @@ void CommandServerInfo(const string& hostname, int port)
sorted_files.sort([](const PbImageFile& a, const PbImageFile& b) { return a.name() < b.name(); }); sorted_files.sort([](const PbImageFile& a, const PbImageFile& b) { return a.name() < b.name(); });
cout << "Image files available in the default folder:" << endl; cout << "Image files available in the default folder:" << endl;
for (auto it = sorted_files.begin(); it != sorted_files.end(); ++it) { for (const auto& file : sorted_files) {
const PbImageFile& file = *it;
cout << " " << file.name() << " (" << file.size() << " bytes)" << (file.read_only() ? ", read-only": "") cout << " " << file.name() << " (" << file.size() << " bytes)" << (file.read_only() ? ", read-only": "")
<< endl; << endl;
} }
@ -284,9 +282,7 @@ void CommandServerInfo(const string& hostname, int port)
} }
sorted_devices.sort([](const PbDevice& a, const PbDevice& b) { return a.id() < b.id(); }); sorted_devices.sort([](const PbDevice& a, const PbDevice& b) { return a.id() < b.id(); });
for (auto it = sorted_devices.begin(); it != sorted_devices.end(); ++it) { for (const auto& device : sorted_devices) {
const PbDevice& device = *it;
cout << " " << device.id() << ":" << device.unit() << " " << PbDeviceType_Name(device.type()) cout << " " << device.id() << ":" << device.unit() << " " << PbDeviceType_Name(device.type())
<< " " << device.vendor() << ":" << device.product() << ":" << device.revision(); << " " << device.vendor() << ":" << device.product() << ":" << device.revision();
if (device.block_size()) { if (device.block_size()) {

View File

@ -39,9 +39,7 @@ string ListDevices(const PbDevices& devices)
} }
sorted_devices.sort([](const PbDevice& a, const PbDevice& b) { return a.id() < b.id(); }); sorted_devices.sort([](const PbDevice& a, const PbDevice& b) { return a.id() < b.id(); });
for (auto it = sorted_devices.begin(); it != sorted_devices.end(); ++it) { for (const auto& device : sorted_devices) {
const PbDevice& device = *it;
string filename; string filename;
switch (device.type()) { switch (device.type()) {
case SCBR: case SCBR: