Use std::array instead of raw arrays

This commit is contained in:
Chris Robinson 2018-10-30 10:00:27 -07:00
parent e2a1dd4503
commit 44f91760b5

View File

@ -13,13 +13,12 @@
#include "router.h" #include "router.h"
#define COUNTOF(x) (sizeof(x)/sizeof(x[0])) #define DECL(x) { #x, reinterpret_cast<void*>(x) }
struct FuncExportEntry {
#define DECL(x) { #x, (ALCvoid*)(x) }
static const struct {
const ALCchar *funcName; const ALCchar *funcName;
ALCvoid *address; ALCvoid *address;
} alcFunctions[] = { };
static const std::array<FuncExportEntry,95> alcFunctions{{
DECL(alcCreateContext), DECL(alcCreateContext),
DECL(alcMakeContextCurrent), DECL(alcMakeContextCurrent),
DECL(alcProcessContext), DECL(alcProcessContext),
@ -117,14 +116,15 @@ static const struct {
DECL(alDopplerVelocity), DECL(alDopplerVelocity),
DECL(alSpeedOfSound), DECL(alSpeedOfSound),
DECL(alDistanceModel), DECL(alDistanceModel),
}; }};
#undef DECL #undef DECL
#define DECL(x) { #x, (x) } #define DECL(x) { #x, (x) }
static const struct { struct EnumExportEntry {
const ALCchar *enumName; const ALCchar *enumName;
ALCenum value; ALCenum value;
} alcEnumerations[] = { };
static const std::array<EnumExportEntry,92> alcEnumerations{{
DECL(ALC_INVALID), DECL(ALC_INVALID),
DECL(ALC_FALSE), DECL(ALC_FALSE),
DECL(ALC_TRUE), DECL(ALC_TRUE),
@ -230,7 +230,7 @@ static const struct {
DECL(AL_LINEAR_DISTANCE_CLAMPED), DECL(AL_LINEAR_DISTANCE_CLAMPED),
DECL(AL_EXPONENT_DISTANCE), DECL(AL_EXPONENT_DISTANCE),
DECL(AL_EXPONENT_DISTANCE_CLAMPED), DECL(AL_EXPONENT_DISTANCE_CLAMPED),
}; }};
#undef DECL #undef DECL
static const ALCchar alcNoError[] = "No Error"; 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) ALC_API void* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcname)
{ {
size_t i;
if(device) if(device)
{ {
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, 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); return DriverList[idx].alcGetProcAddress(device, funcname);
} }
for(i = 0;i < COUNTOF(alcFunctions);i++) auto entry = std::find_if(alcFunctions.cbegin(), alcFunctions.cend(),
{ [funcname](const FuncExportEntry &entry) -> bool
if(strcmp(funcname, alcFunctions[i].funcName) == 0) { return strcmp(funcname, entry.funcName) == 0; }
return alcFunctions[i].address; );
} return (entry != alcFunctions.cend()) ? entry->address : nullptr;
return nullptr;
} }
ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumname) ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumname)
{ {
size_t i;
if(device) if(device)
{ {
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, 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); return DriverList[idx].alcGetEnumValue(device, enumname);
} }
for(i = 0;i < COUNTOF(alcEnumerations);i++) auto entry = std::find_if(alcEnumerations.cbegin(), alcEnumerations.cend(),
{ [enumname](const EnumExportEntry &entry) -> bool
if(strcmp(enumname, alcEnumerations[i].enumName) == 0) { return strcmp(enumname, entry.enumName) == 0; }
return alcEnumerations[i].value; );
} return (entry != alcEnumerations.cend()) ? entry->value : 0;
return 0;
} }
ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum param) ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum param)