From cfff509e94afbac3b8444157444a63614054420d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 13 Oct 2017 04:39:57 -0700 Subject: [PATCH] Use an actual Version class type for the ALC and EFX versions --- examples/alure-enum.cpp | 8 ++++---- include/AL/alure2.h | 37 +++++++++++++++++-------------------- src/device.cpp | 20 +++++++------------- src/device.h | 4 ++-- 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/examples/alure-enum.cpp b/examples/alure-enum.cpp index 935b148..afa2a64 100644 --- a/examples/alure-enum.cpp +++ b/examples/alure-enum.cpp @@ -36,12 +36,12 @@ int main(int argc, char *argv[]) alure::Device dev = devMgr.openPlayback((argc > 1) ? argv[1] : ""); std::cout<< "Info for device \""< #include #include +#include #include #include #include @@ -341,25 +342,21 @@ ALURE_API ALuint FramesToBytes(ALuint frames, ChannelConfig chans, SampleType ty ALURE_API ALuint BytesToFrames(ALuint bytes, ChannelConfig chans, SampleType type); -/** - * Creates a version number value using the specified major and minor values. - */ -constexpr inline ALCuint MakeVersion(ALCushort major, ALCushort minor) -{ return (major<<16) | minor; } +/** Class for storing a major.minor version number. */ +class Version { + ALuint mMajor : 16; + ALuint mMinor : 16; -/** - * Retrieves the major version of a version number value created by - * MakeVersion. - */ -constexpr inline ALCuint MajorVersion(ALCuint version) -{ return version>>16; } -/** - * Retrieves the minor version of a version number value created by - * MakeVersion. - */ -constexpr inline ALCuint MinorVersion(ALCuint version) -{ return version&0xffff; } +public: + Version(ALuint _maj, ALuint _min) + : mMajor(std::min(_maj, std::numeric_limits::max())) + , mMinor(std::min(_min, std::numeric_limits::max())) + { } + constexpr ALuint getMajor() const noexcept { return mMajor; } + constexpr ALuint getMinor() const noexcept { return mMinor; } + constexpr bool isZero() const noexcept { return mMajor == 0 && mMinor == 0; } +}; #define MAKE_PIMPL(BaseT, ImplT) \ private: \ @@ -459,14 +456,14 @@ public: * Retrieves the ALC version supported by this device, as constructed by * MakeVersion. */ - ALCuint getALCVersion() const; + Version getALCVersion() const; /** * Retrieves the EFX version supported by this device, as constructed by * MakeVersion. If the ALC_EXT_EFX extension is unsupported, this will be - * 0. + * 0.0. */ - ALCuint getEFXVersion() const; + Version getEFXVersion() const; /** Retrieves the device's playback frequency, in hz. */ ALCuint getFrequency() const; diff --git a/src/device.cpp b/src/device.cpp index d6d5788..ed343e5 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -97,33 +97,27 @@ bool ALDevice::queryExtension(const String &name) const return alcIsExtensionPresent(mDevice, name.c_str()); } -ALCuint ALDevice::getALCVersion() const +Version ALDevice::getALCVersion() const { ALCint major=-1, minor=-1; alcGetIntegerv(mDevice, ALC_MAJOR_VERSION, 1, &major); alcGetIntegerv(mDevice, ALC_MINOR_VERSION, 1, &minor); if(major < 0 || minor < 0) throw std::runtime_error("ALC version error"); - return MakeVersion( - (ALCushort)std::min(major, std::numeric_limits::max()), - (ALCushort)std::min(minor, std::numeric_limits::max()) - ); + return Version{ (ALCuint)major, (ALCuint)minor }; } -ALCuint ALDevice::getEFXVersion() const +Version ALDevice::getEFXVersion() const { if(!alcIsExtensionPresent(mDevice, "ALC_EXT_EFX")) - return 0; + return Version{ 0u, 0u }; ALCint major=-1, minor=-1; alcGetIntegerv(mDevice, ALC_EFX_MAJOR_VERSION, 1, &major); alcGetIntegerv(mDevice, ALC_EFX_MINOR_VERSION, 1, &minor); if(major < 0 || minor < 0) throw std::runtime_error("EFX version error"); - return MakeVersion( - (ALCushort)std::min(major, std::numeric_limits::max()), - (ALCushort)std::min(minor, std::numeric_limits::max()) - ); + return Version{ (ALCuint)major, (ALCuint)minor }; } ALCuint ALDevice::getFrequency() const @@ -279,8 +273,8 @@ void ALDevice::close() DECL_THUNK1(String, Device, getName, const, PlaybackName) DECL_THUNK1(bool, Device, queryExtension, const, const String&) -DECL_THUNK0(ALCuint, Device, getALCVersion, const) -DECL_THUNK0(ALCuint, Device, getEFXVersion, const) +DECL_THUNK0(Version, Device, getALCVersion, const) +DECL_THUNK0(Version, Device, getEFXVersion, const) DECL_THUNK0(ALCuint, Device, getFrequency, const) DECL_THUNK0(ALCuint, Device, getMaxAuxiliarySends, const) DECL_THUNK0(Vector, Device, enumerateHRTFNames, const) diff --git a/src/device.h b/src/device.h index a63b234..f523534 100644 --- a/src/device.h +++ b/src/device.h @@ -53,8 +53,8 @@ public: String getName(PlaybackName type) const; bool queryExtension(const String &name) const; - ALCuint getALCVersion() const; - ALCuint getEFXVersion() const; + Version getALCVersion() const; + Version getEFXVersion() const; ALCuint getFrequency() const; -- 2.11.4.GIT