summaryrefslogtreecommitdiffstats
path: root/ComLightLib/server/interfaceMap.h
diff options
context:
space:
mode:
authorKonstantin <const@const.me>2023-01-16 14:52:43 +0100
committerKonstantin <const@const.me>2023-01-16 14:52:43 +0100
commit8c4603c73675958efc960fbd4bb599a2909d106a (patch)
tree714dc6fc9a1672d5fd7f89676b97e10959662abc /ComLightLib/server/interfaceMap.h
parent990a8d0dbaefc996244097397259e92758b15cce (diff)
Source codes
Diffstat (limited to 'ComLightLib/server/interfaceMap.h')
-rw-r--r--ComLightLib/server/interfaceMap.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/ComLightLib/server/interfaceMap.h b/ComLightLib/server/interfaceMap.h
new file mode 100644
index 0000000..605ed33
--- /dev/null
+++ b/ComLightLib/server/interfaceMap.h
@@ -0,0 +1,31 @@
+#pragma once
+#include "../utils/typeTraits.hpp"
+
+// Unlike ATL, the interface map is optional for ComLight.
+// If you won't declare a map, the object will support 2 interfaces: IUnknown, and whatever template argument was passed to ObjectRoot class.
+#define BEGIN_COM_MAP() \
+protected: \
+bool implQueryInterface( REFIID iid, void** ppvObject ) {
+
+#define END_COM_MAP() return false; }
+
+namespace ComLight
+{
+ namespace details
+ {
+ template<typename I, typename C>
+ inline bool tryReturnInterface( REFIID iid, C* pThis, void** ppvResult )
+ {
+ static_assert( pointersAssignable<IUnknown, I>(), "Trying to implement an interface that doesn't derive from IUnknown" );
+ static_assert( pointersAssignable<I, C>(), "Declared support for an interface, but the class doesn't implement it" );
+ if( I::iid() != iid )
+ return false;
+ I* const result = pThis;
+ result->AddRef();
+ *ppvResult = result;
+ return true;
+ }
+ }
+}
+
+#define COM_INTERFACE_ENTRY( I ) if( ComLight::details::tryReturnInterface<I>( iid, this, ppvObject ) ) return true; \ No newline at end of file