diff options
author | Chris Robinson <[email protected]> | 2018-10-30 10:00:27 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-10-30 10:01:49 -0700 |
commit | 44f91760b5d4d9c351100eb2b7b248309c6c32db (patch) | |
tree | 1e229166815d380830d09dff6a649973defd9f1d /router | |
parent | e2a1dd4503be8cd1280be8d34826c4858c4d6ed2 (diff) |
Use std::array instead of raw arrays
Diffstat (limited to 'router')
-rw-r--r-- | router/alc.cpp | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/router/alc.cpp b/router/alc.cpp index ea2e340c..b90d9e41 100644 --- a/router/alc.cpp +++ b/router/alc.cpp @@ -13,13 +13,12 @@ #include "router.h" -#define COUNTOF(x) (sizeof(x)/sizeof(x[0])) - -#define DECL(x) { #x, (ALCvoid*)(x) } -static const struct { +#define DECL(x) { #x, reinterpret_cast<void*>(x) } +struct FuncExportEntry { const ALCchar *funcName; ALCvoid *address; -} alcFunctions[] = { +}; +static const std::array<FuncExportEntry,95> alcFunctions{{ DECL(alcCreateContext), DECL(alcMakeContextCurrent), DECL(alcProcessContext), @@ -117,14 +116,15 @@ static const struct { DECL(alDopplerVelocity), DECL(alSpeedOfSound), DECL(alDistanceModel), -}; +}}; #undef DECL #define DECL(x) { #x, (x) } -static const struct { +struct EnumExportEntry { const ALCchar *enumName; ALCenum value; -} alcEnumerations[] = { +}; +static const std::array<EnumExportEntry,92> alcEnumerations{{ DECL(ALC_INVALID), DECL(ALC_FALSE), DECL(ALC_TRUE), @@ -230,7 +230,7 @@ static const struct { DECL(AL_LINEAR_DISTANCE_CLAMPED), DECL(AL_EXPONENT_DISTANCE), DECL(AL_EXPONENT_DISTANCE_CLAMPED), -}; +}}; #undef DECL static const ALCchar alcNoError[] = "No Error"; @@ -562,8 +562,6 @@ ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const A ALC_API void* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcname) { - size_t i; - if(device) { ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device); @@ -575,18 +573,15 @@ ALC_API void* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *f return DriverList[idx].alcGetProcAddress(device, funcname); } - for(i = 0;i < COUNTOF(alcFunctions);i++) - { - if(strcmp(funcname, alcFunctions[i].funcName) == 0) - return alcFunctions[i].address; - } - return nullptr; + auto entry = std::find_if(alcFunctions.cbegin(), alcFunctions.cend(), + [funcname](const FuncExportEntry &entry) -> bool + { return strcmp(funcname, entry.funcName) == 0; } + ); + return (entry != alcFunctions.cend()) ? entry->address : nullptr; } ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumname) { - size_t i; - if(device) { ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device); @@ -598,12 +593,11 @@ ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *e return DriverList[idx].alcGetEnumValue(device, enumname); } - for(i = 0;i < COUNTOF(alcEnumerations);i++) - { - if(strcmp(enumname, alcEnumerations[i].enumName) == 0) - return alcEnumerations[i].value; - } - return 0; + auto entry = std::find_if(alcEnumerations.cbegin(), alcEnumerations.cend(), + [enumname](const EnumExportEntry &entry) -> bool + { return strcmp(enumname, entry.enumName) == 0; } + ); + return (entry != alcEnumerations.cend()) ? entry->value : 0; } ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum param) |