diff options
author | Chris Robinson <[email protected]> | 2018-11-16 05:23:42 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-11-16 05:23:42 -0800 |
commit | 02eae1123f4bfdd239a9cc858378cc257e3331d3 (patch) | |
tree | 121841b6dcb16eca54deee33704bd73fa0d5a289 | |
parent | fc8191012a99d049dbd589f1a6366d778ff9c7e3 (diff) |
Use iterators instead of indexed loops
-rw-r--r-- | Alc/alc.cpp | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 5706beb4..04792498 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -34,6 +34,7 @@ #include <thread> #include <vector> #include <string> +#include <algorithm> #include "alMain.h" #include "alSource.h" @@ -4053,7 +4054,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) const ALCchar *fmt{}; if(ConfigValueStr(deviceName, nullptr, "channels", &fmt)) { - static constexpr struct { + static constexpr struct ChannelMap { const char name[16]; enum DevFmtChannels chans; ALsizei order; @@ -4069,24 +4070,23 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) { "ambi2", DevFmtAmbi3D, 2 }, { "ambi3", DevFmtAmbi3D, 3 }, }; - size_t i; - for(i = 0;i < COUNTOF(chanlist);i++) + auto iter = std::find_if(std::begin(chanlist), std::end(chanlist), + [fmt](const ChannelMap &entry) -> bool + { return strcasecmp(entry.name, fmt) == 0; } + ); + if(iter == std::end(chanlist)) + ERR("Unsupported channels: %s\n", fmt); + else { - if(strcasecmp(chanlist[i].name, fmt) == 0) - { - device->FmtChans = chanlist[i].chans; - device->AmbiOrder = chanlist[i].order; - device->Flags |= DEVICE_CHANNELS_REQUEST; - break; - } + device->FmtChans = iter->chans; + device->AmbiOrder = iter->order; + device->Flags |= DEVICE_CHANNELS_REQUEST; } - if(i == COUNTOF(chanlist)) - ERR("Unsupported channels: %s\n", fmt); } if(ConfigValueStr(deviceName, nullptr, "sample-type", &fmt)) { - static constexpr struct { + static constexpr struct TypeMap { const char name[16]; enum DevFmtType type; } typelist[] = { @@ -4098,19 +4098,18 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) { "uint32", DevFmtUInt }, { "float32", DevFmtFloat }, }; - size_t i; - for(i = 0;i < COUNTOF(typelist);i++) + auto iter = std::find_if(std::begin(typelist), std::end(typelist), + [fmt](const TypeMap &entry) -> bool + { return strcasecmp(entry.name, fmt) == 0; } + ); + if(iter == std::end(typelist)) + ERR("Unsupported sample-type: %s\n", fmt); + else { - if(strcasecmp(typelist[i].name, fmt) == 0) - { - device->FmtType = typelist[i].type; - device->Flags |= DEVICE_SAMPLE_TYPE_REQUEST; - break; - } + device->FmtType = iter->type; + device->Flags |= DEVICE_SAMPLE_TYPE_REQUEST; } - if(i == COUNTOF(typelist)) - ERR("Unsupported sample-type: %s\n", fmt); } if(ConfigValueUInt(deviceName, nullptr, "frequency", &device->Frequency)) |