summaryrefslogtreecommitdiffstats
path: root/Primitives/interface
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-01-28 20:30:39 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-01-28 20:30:39 +0000
commitde9b8692d538f4249e30dd979c3ebac45120be41 (patch)
tree2a0c65090d858680c3767d4dc974fd483f923294 /Primitives/interface
parentFixed few issues in C interface (diff)
downloadDiligentCore-de9b8692d538f4249e30dd979c3ebac45120be41.tar.gz
DiligentCore-de9b8692d538f4249e30dd979c3ebac45120be41.zip
Reworked interface definitions to use DILIGENT_BEGIN_INTERFACE/DILIGENT_END_INTERFACE pair
Diffstat (limited to 'Primitives/interface')
-rw-r--r--Primitives/interface/CommonDefinitions.h10
-rw-r--r--Primitives/interface/DataBlob.h8
-rw-r--r--Primitives/interface/DefineInterfaceHelperMacros.h9
-rw-r--r--Primitives/interface/FileStream.h8
-rw-r--r--Primitives/interface/UndefInterfaceHelperMacros.h1
5 files changed, 21 insertions, 15 deletions
diff --git a/Primitives/interface/CommonDefinitions.h b/Primitives/interface/CommonDefinitions.h
index bfd5102c..ac916642 100644
--- a/Primitives/interface/CommonDefinitions.h
+++ b/Primitives/interface/CommonDefinitions.h
@@ -55,14 +55,18 @@
# define DILIGENT_GLOBAL_FUNCTION(FuncName) Diligent_##FuncName
-# define DILIGENT_INTERFACE(Name, Base) \
- struct Name; \
+# define DILIGENT_BEGIN_INTERFACE(Name, Base) \
+ struct Name; \
struct Name##Methods
# define DEFAULT_VALUE(x)
# define CALL_IFACE_METHOD(Iface, Method, This, ...) (This)->pVtbl->Iface.Method((I##Iface*)(This), ##__VA_ARGS__)
+// Two levels of indirection are required to concatenate expanded macros
+# define DILIGENT_CONCATENATE(X, Y) X##Y
+# define DILIGENT_VTBL_NAME(Iface) DILIGENT_CONCATENATE(Iface, Vtbl)
+
#else
# define DILIGENT_BEGIN_NAMESPACE(Name) \
@@ -80,7 +84,7 @@
# define DILIGENT_GLOBAL_FUNCTION(FuncName) FuncName
-# define DILIGENT_INTERFACE(Name, Base) struct Name : public Base
+# define DILIGENT_BEGIN_INTERFACE(Name, Base) struct Name : public Base
# define DEFAULT_VALUE(x) = x
diff --git a/Primitives/interface/DataBlob.h b/Primitives/interface/DataBlob.h
index 52bcca10..76d276ae 100644
--- a/Primitives/interface/DataBlob.h
+++ b/Primitives/interface/DataBlob.h
@@ -47,7 +47,7 @@ static const struct INTERFACE_ID IID_DataBlob =
/// Base interface for a file stream
-DILIGENT_INTERFACE(IDataBlob, IObject)
+DILIGENT_BEGIN_INTERFACE(IDataBlob, IObject)
{
/// Sets the size of the internal data buffer
VIRTUAL void METHOD(Resize)(THIS_
@@ -59,6 +59,7 @@ DILIGENT_INTERFACE(IDataBlob, IObject)
/// Returns the pointer to the internal data buffer
VIRTUAL void* METHOD(GetDataPtr)(THIS) PURE;
};
+DILIGENT_END_INTERFACE
#include "UndefInterfaceHelperMacros.h"
@@ -73,11 +74,6 @@ struct IDataBlobVtbl
struct IDataBlobMethods DataBlob;
};
-typedef struct IDataBlob
-{
- struct IDataBlobVtbl* pVtbl;
-} IDataBlob;
-
// clang-format off
# define IDataBlob_Resize(This, ...) CALL_IFACE_METHOD(DataBlob, Resize, This, __VA_ARGS__)
diff --git a/Primitives/interface/DefineInterfaceHelperMacros.h b/Primitives/interface/DefineInterfaceHelperMacros.h
index 9114fb5e..794eb37e 100644
--- a/Primitives/interface/DefineInterfaceHelperMacros.h
+++ b/Primitives/interface/DefineInterfaceHelperMacros.h
@@ -57,6 +57,14 @@
# define REF *
# define METHOD(Name) (*Name)
+// clang-format off
+# define DILIGENT_END_INTERFACE\
+ typedef struct DILIGENT_INTERFACE_NAME \
+ { \
+ struct DILIGENT_VTBL_NAME(DILIGENT_INTERFACE_NAME)* pVtbl;\
+ } DILIGENT_INTERFACE_NAME;
+// clang-format on
+
#else
# define THIS
@@ -66,5 +74,6 @@
# define PURE = 0
# define REF &
# define METHOD(Name) Name
+# define DILIGENT_END_INTERFACE
#endif
diff --git a/Primitives/interface/FileStream.h b/Primitives/interface/FileStream.h
index 4bef7123..6e29d3fe 100644
--- a/Primitives/interface/FileStream.h
+++ b/Primitives/interface/FileStream.h
@@ -47,7 +47,7 @@ static const struct INTERFACE_ID IID_FileStream =
/// Base interface for a file stream
-DILIGENT_INTERFACE(IFileStream, IObject)
+DILIGENT_BEGIN_INTERFACE(IFileStream, IObject)
{
/// Reads data from the stream
VIRTUAL bool METHOD(Read)(THIS_
@@ -66,6 +66,7 @@ DILIGENT_INTERFACE(IFileStream, IObject)
VIRTUAL bool METHOD(IsValid)(THIS) PURE;
};
+DILIGENT_END_INTERFACE
#include "UndefInterfaceHelperMacros.h"
@@ -81,11 +82,6 @@ struct IFileStreamVtbl
struct IFileStreamMethods FileStream;
};
-typedef struct IFileStream
-{
- struct IFileStreamVtbl* pVtbl;
-} IFileStream;
-
// clang-format off
# define IFileStream_Read(This, ...) CALL_IFACE_METHOD(FileStream, Read, This, __VA_ARGS__)
diff --git a/Primitives/interface/UndefInterfaceHelperMacros.h b/Primitives/interface/UndefInterfaceHelperMacros.h
index 6b90e049..a997f1bb 100644
--- a/Primitives/interface/UndefInterfaceHelperMacros.h
+++ b/Primitives/interface/UndefInterfaceHelperMacros.h
@@ -34,3 +34,4 @@
#pragma pop_macro("METHOD")
#undef DILIGENT_INTERFACE_NAME
+#undef DILIGENT_END_INTERFACE