diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-04-08 01:11:27 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-07 10:11:27 -0700 |
| commit | 0468cd0d1a8a1cff1d838a741b050ef11f6d7461 (patch) | |
| tree | e2e9e5731a20f46d524562c932a2371b191fd4e6 /slang.h | |
| parent | 7bbe7b4780345181cb586b03504ff63f9b8d5c4c (diff) | |
Add SLANG_IID_PPV_ARGS (#2784)
* Add SLANG_IID_PPV_ARGS
To mirror IID_PPV_ARGS from the COM Coding Practices: https://learn.microsoft.com/en-us/windows/win32/LearnWin32/com-coding-practices#the-iid_ppv_args-macro
* Make getTypeGuid constexpr
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'slang.h')
| -rw-r--r-- | slang.h | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -932,21 +932,33 @@ extern "C" // It is not necessary to use the multiple parameters (we can wrap in parens), but this is simple. #define SLANG_COM_INTERFACE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \ public: \ - SLANG_FORCE_INLINE static const SlangUUID& getTypeGuid() \ + SLANG_FORCE_INLINE constexpr static SlangUUID getTypeGuid() \ { \ - static const SlangUUID guid = { a, b, c, d0, d1, d2, d3, d4, d5, d6, d7 }; \ - return guid; \ + return { a, b, c, d0, d1, d2, d3, d4, d5, d6, d7 }; \ } // Sometimes it's useful to associate a guid with a class to identify it. This macro can used for this, // and the guid extracted via the getTypeGuid() function defined in the type #define SLANG_CLASS_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \ - SLANG_FORCE_INLINE static const SlangUUID& getTypeGuid() \ + SLANG_FORCE_INLINE constexpr static SlangUUID getTypeGuid() \ { \ - static const SlangUUID guid = { a, b, c, d0, d1, d2, d3, d4, d5, d6, d7 }; \ - return guid; \ + return { a, b, c, d0, d1, d2, d3, d4, d5, d6, d7 }; \ } +// Helper to fill in pairs of GUIDs and return pointers. This ensures that the +// type of the GUID passed matches the pointer type, and that it is derived +// from ISlangUnknown, +// TODO(c++20): would is_derived_from be more appropriate here for private inheritance of ISlangUnknown? +// +// with : void createFoo(SlangUUID, void**); +// Slang::ComPtr<Bar> myBar; +// call with: createFoo(SLANG_IID_PPV_ARGS(myBar.writeRef())) +// to call : createFoo(Bar::getTypeGuid(), (void**)(myBar.writeRef())) +#define SLANG_IID_PPV_ARGS(ppType) \ + std::decay_t<decltype(**(ppType))>::getTypeGuid(), \ + ((void)[]{static_assert(std::is_base_of_v<ISlangUnknown, std::decay_t<decltype(**(ppType))>>);}, reinterpret_cast<void**>(ppType)) + + /** Base interface for components exchanged through the API. This interface definition is compatible with the COM `IUnknown`, |
