summaryrefslogtreecommitdiff
path: root/slang.h
diff options
context:
space:
mode:
Diffstat (limited to 'slang.h')
-rw-r--r--slang.h24
1 files changed, 18 insertions, 6 deletions
diff --git a/slang.h b/slang.h
index d5630660b..5dd2cb550 100644
--- a/slang.h
+++ b/slang.h
@@ -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`,