aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-06-30 16:57:10 -0700
committerChris Robinson <[email protected]>2019-06-30 16:57:10 -0700
commitf45864223767ac6543e8f432384dcf984d325eea (patch)
tree5ad6bc81cafb6f077b8e622b56f50ec304f22568 /Alc
parent49ceae681b4889ed9500fa9c15b21cca7eb08fc3 (diff)
Use optionals where methods may not return a valid value
Diffstat (limited to 'Alc')
-rw-r--r--Alc/alc.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp
index 014998bc..5b88043e 100644
--- a/Alc/alc.cpp
+++ b/Alc/alc.cpp
@@ -1337,7 +1337,8 @@ ALsizei ChannelsFromDevFmt(DevFmtChannels chans, ALsizei ambiorder) noexcept
return 0;
}
-static ALboolean DecomposeDevFormat(ALenum format, DevFmtChannels *chans, DevFmtType *type)
+struct DevFmtPair { DevFmtChannels chans; DevFmtType type; };
+static al::optional<DevFmtPair> DecomposeDevFormat(ALenum format)
{
static const struct {
ALenum format;
@@ -1372,14 +1373,10 @@ static ALboolean DecomposeDevFormat(ALenum format, DevFmtChannels *chans, DevFmt
for(const auto &item : list)
{
if(item.format == format)
- {
- *chans = item.channels;
- *type = item.type;
- return AL_TRUE;
- }
+ return al::optional<DevFmtPair>{al::in_place, DevFmtPair{item.channels, item.type}};
}
- return AL_FALSE;
+ return al::nullopt;
}
static ALCboolean IsValidALCType(ALCenum type)
@@ -3975,12 +3972,16 @@ START_API_FUNC
DeviceRef device{new ALCdevice{Capture}};
- device->Frequency = frequency;
- if(DecomposeDevFormat(format, &device->FmtChans, &device->FmtType) == AL_FALSE)
+ auto decompfmt = DecomposeDevFormat(format);
+ if(!decompfmt)
{
alcSetError(nullptr, ALC_INVALID_ENUM);
return nullptr;
}
+
+ device->Frequency = frequency;
+ device->FmtChans = decompfmt->chans;
+ device->FmtType = decompfmt->type;
device->Flags.set<FrequencyRequest, ChannelsRequest, SampleTypeRequest>();
device->UpdateSize = samples;