From b0e75f077d9001cb6b4205cd51ffde3d491aa01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 6 Mar 2018 23:25:38 +0100 Subject: [PATCH] Audio: manual indices for extensions. Again to remove the ugly `#line` hack and make KDevelop highlight happily again. Also added a test for all this. --- src/Magnum/Audio/Context.h | 6 +++++- src/Magnum/Audio/Extensions.h | 25 +++++++++++------------ src/Magnum/Audio/Test/ContextTest.cpp | 29 ++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/Magnum/Audio/Context.h b/src/Magnum/Audio/Context.h index 5ae1dfd15..9190e3e3e 100644 --- a/src/Magnum/Audio/Context.h +++ b/src/Magnum/Audio/Context.h @@ -50,6 +50,10 @@ typedef struct ALCcontext_struct ALCcontext; namespace Magnum { namespace Audio { +namespace Implementation { + enum: std::size_t { ExtensionCount = 16 }; +} + /** @brief Run-time information about OpenAL extension @@ -315,7 +319,7 @@ class MAGNUM_AUDIO_EXPORT Context { ALCdevice* _device; ALCcontext* _context; - std::bitset<64> _extensionStatus; + std::bitset _extensionStatus; std::vector _supportedExtensions; }; diff --git a/src/Magnum/Audio/Extensions.h b/src/Magnum/Audio/Extensions.h index 8252a61cf..c14500bf2 100644 --- a/src/Magnum/Audio/Extensions.h +++ b/src/Magnum/Audio/Extensions.h @@ -66,37 +66,36 @@ See @ref building and @ref cmake for more information. namespace Extensions { #ifndef DOXYGEN_GENERATING_OUTPUT -#define _extension(prefix, vendor, extension) \ +#define _extension(index, prefix, vendor, extension) \ struct extension { \ - enum: std::size_t { Index = __LINE__-1 }; \ + enum: std::size_t { Index = index }; \ constexpr static const char* string() { return #prefix "_" #vendor "_" #extension; } \ }; -#define _extension_rev(prefix, vendor, extension) \ +#define _extension_rev(index, prefix, vendor, extension) \ struct extension { \ - enum: std::size_t { Index = __LINE__-1 }; \ + enum: std::size_t { Index = index }; \ constexpr static const char* string() { return #prefix "_" #extension "_" #vendor; } \ }; /* IMPORTANT: don't forget to add new extensions also in Context.cpp */ namespace AL { - #line 1 namespace EXT { - _extension(AL,EXT,FLOAT32) // #??? - _extension(AL,EXT,DOUBLE) // #??? - _extension(AL,EXT,ALAW) // #??? - _extension(AL,EXT,MULAW) // #??? - _extension(AL,EXT,MCFORMATS) // #??? + _extension(1,AL,EXT,FLOAT32) // #??? + _extension(2,AL,EXT,DOUBLE) // #??? + _extension(3,AL,EXT,ALAW) // #??? + _extension(4,AL,EXT,MULAW) // #??? + _extension(5,AL,EXT,MCFORMATS) // #??? } } namespace ALC { namespace EXT { - _extension_rev(ALC,EXT,ENUMERATION) // #??? + _extension_rev(6,ALC,EXT,ENUMERATION) // #??? } namespace SOFTX { - _extension(ALC,SOFTX,HRTF) // #??? + _extension(7,ALC,SOFTX,HRTF) // #??? } namespace SOFT { - _extension(ALC,SOFT,HRTF) // #??? + _extension(8,ALC,SOFT,HRTF) // #??? } } #undef _extension diff --git a/src/Magnum/Audio/Test/ContextTest.cpp b/src/Magnum/Audio/Test/ContextTest.cpp index 58fe69f6e..bbfa70a99 100644 --- a/src/Magnum/Audio/Test/ContextTest.cpp +++ b/src/Magnum/Audio/Test/ContextTest.cpp @@ -34,11 +34,38 @@ namespace Magnum { namespace Audio { namespace Test { struct ContextTest: TestSuite::Tester { explicit ContextTest(); + void extensions(); + void debugHrtfStatus(); }; ContextTest::ContextTest() { - addTests({&ContextTest::debugHrtfStatus}); + addTests({&ContextTest::extensions, + + &ContextTest::debugHrtfStatus}); +} + +void ContextTest::extensions() { + const char* used[Implementation::ExtensionCount]{}; + + /* Check that all extension indices are unique */ + for(const Extension& e: Extension::extensions()) { + if(e.index() >= Implementation::ExtensionCount) { + Error{} << "Index" << e.index() << "used by" << e.string() + << "larger than" << Implementation::ExtensionCount; + CORRADE_VERIFY(false); + } + + if(used[e.index()]) { + Error{} << "Index" << e.index() << "used by both" + << used[e.index()] << "and" << e.string(); + CORRADE_VERIFY(false); + } + + used[e.index()] = e.string(); + } + + CORRADE_VERIFY(true); } void ContextTest::debugHrtfStatus() {