summaryrefslogtreecommitdiffstats
path: root/Primitives/interface
diff options
context:
space:
mode:
Diffstat (limited to 'Primitives/interface')
-rw-r--r--Primitives/interface/CommonDefinitions.h25
-rw-r--r--Primitives/interface/DataBlob.h43
-rw-r--r--Primitives/interface/FileStream.h53
-rw-r--r--Primitives/interface/InterfaceID.h3
-rw-r--r--Primitives/interface/Object.h15
-rw-r--r--Primitives/interface/ReferenceCounters.h2
6 files changed, 111 insertions, 30 deletions
diff --git a/Primitives/interface/CommonDefinitions.h b/Primitives/interface/CommonDefinitions.h
index 690127e4..c8303641 100644
--- a/Primitives/interface/CommonDefinitions.h
+++ b/Primitives/interface/CommonDefinitions.h
@@ -55,6 +55,17 @@
# define DILIGENT_GLOBAL_FUNCTION(FuncName) Diligent_##FuncName
+# define DILIGENT_INTERFACE(Name, Base) \
+ struct Name; \
+ struct Name##Methods
+
+# define VIRTUAL
+# define CONST
+# define PURE
+# define REF *
+# define METHOD(Name) (*Name)
+# define DEFAULT_VALUE(x)
+
#else
# define DILIGENT_BEGIN_NAMESPACE(Name) \
@@ -72,10 +83,18 @@
# define DILIGENT_GLOBAL_FUNCTION(FuncName) FuncName
-#endif
+# define DILIGENT_INTERFACE(Name, Base) struct Name : public Base
+
+# define THIS
+# define THIS_
+# define VIRTUAL virtual
+# define CONST const
+# define PURE = 0
+# define REF &
+# define METHOD(Name) Name
+# define DEFAULT_VALUE(x) = x
+
-#ifndef __cplusplus
-# define class struct
#endif
#if DILIGENT_C_INTERFACE
diff --git a/Primitives/interface/DataBlob.h b/Primitives/interface/DataBlob.h
index aa284a6f..af78d20d 100644
--- a/Primitives/interface/DataBlob.h
+++ b/Primitives/interface/DataBlob.h
@@ -39,23 +39,52 @@ DILIGENT_BEGIN_NAMESPACE(Diligent)
static const struct INTERFACE_ID IID_DataBlob =
{0xf578ff0d, 0xabd2, 0x4514, {0x9d, 0x32, 0x7c, 0xb4, 0x54, 0xd4, 0xa7, 0x3b}};
-#if DILIGENT_CPP_INTERFACE
+// clang-format off
+
+#if DILIGENT_C_INTERFACE
+# define THIS struct IDataBlob*
+# define THIS_ struct IDataBlob*,
+#endif
/// Base interface for a file stream
-class IDataBlob : public IObject
+DILIGENT_INTERFACE(IDataBlob, IObject)
{
-public:
/// Sets the size of the internal data buffer
- virtual void Resize(size_t NewSize) = 0;
+ VIRTUAL void METHOD(Resize)(THIS_
+ size_t NewSize) PURE;
/// Returns the size of the internal data buffer
- virtual size_t GetSize() = 0;
+ VIRTUAL size_t METHOD(GetSize)(THIS) PURE;
/// Returns the pointer to the internal data buffer
- virtual void* GetDataPtr() = 0;
+ VIRTUAL void* METHOD(GetDataPtr)(THIS) PURE;
+};
+
+ // clang-format on
+
+#if DILIGENT_C_INTERFACE
+
+# undef THIS
+# undef THIS_
+
+struct IDataBlobVtbl
+{
+ struct IObjectMethods Object;
+ struct IDataBlobMethods DataBlob;
};
-#else
+typedef struct IDataBlob
+{
+ struct IDataBlobVtbl* pVtbl;
+} IDataBlob;
+
+// clang-format off
+
+# define IDataBlob_Resize(This, ...) (This)->pVtbl->DataBlob.Resize ((IDataBlob*)(This), __VA_ARGS__)
+# define IDataBlob_GetSize(This) (This)->pVtbl->DataBlob.GetSize ((IDataBlob*)(This))
+# define IDataBlob_GetDataPtr(This) (This)->pVtbl->DataBlob.GetDataPtr((IDataBlob*)(This))
+
+// clang-format on
#endif
diff --git a/Primitives/interface/FileStream.h b/Primitives/interface/FileStream.h
index 91ca581e..e09722ab 100644
--- a/Primitives/interface/FileStream.h
+++ b/Primitives/interface/FileStream.h
@@ -35,33 +35,66 @@
DILIGENT_BEGIN_NAMESPACE(Diligent)
-
/// IFileStream interface unique identifier
// {E67F386C-6A5A-4A24-A0CE-C66435465D41}
static const struct INTERFACE_ID IID_FileStream =
{0xe67f386c, 0x6a5a, 0x4a24, {0xa0, 0xce, 0xc6, 0x64, 0x35, 0x46, 0x5d, 0x41}};
+// clang-format off
-#if DILIGENT_CPP_INTERFACE
+#if DILIGENT_C_INTERFACE
+# define THIS struct IFileStream*
+# define THIS_ struct IFileStream*,
+#endif
/// Base interface for a file stream
-class IFileStream : public IObject
+DILIGENT_INTERFACE(IFileStream, IObject)
{
-public:
/// Reads data from the stream
- virtual bool Read(void* Data, size_t BufferSize) = 0;
+ VIRTUAL bool METHOD(Read)(THIS_
+ void* Data,
+ size_t BufferSize) PURE;
- virtual void Read(IDataBlob* pData) = 0;
+ VIRTUAL void METHOD(ReadBlob)(THIS_
+ IDataBlob* pData) PURE;
/// Writes data to the stream
- virtual bool Write(const void* Data, size_t Size) = 0;
+ VIRTUAL bool METHOD(Write)(THIS_
+ const void* Data,
+ size_t Size) PURE;
+
+ VIRTUAL size_t METHOD(GetSize)(THIS) PURE;
+
+ VIRTUAL bool METHOD(IsValid)(THIS) PURE;
+};
+
+ // clang-format on
- virtual size_t GetSize() = 0;
+#if DILIGENT_C_INTERFACE
- virtual bool IsValid() = 0;
+# undef THIS
+# undef THIS_
+
+struct IFileStreamVtbl
+{
+ struct IObjectMethods Object;
+ struct IFileStreamMethods FileStream;
};
-#else
+typedef struct IFileStream
+{
+ struct IFileStreamVtbl* pVtbl;
+} IFileStream;
+
+// clang-format off
+
+# define IFileStream_Read(This, ...) (This)->pVtbl->FileStream.Read ((IFileStream*)(This), __VA_ARGS__)
+# define IFileStream_ReadBlob(This, ...) (This)->pVtbl->FileStream.ReadBlob((IFileStream*)(This), __VA_ARGS__)
+# define IFileStream_Write(This, ...) (This)->pVtbl->FileStream.Write ((IFileStream*)(This), __VA_ARGS__)
+# define IFileStream_GetSize(This) (This)->pVtbl->FileStream.GetSize ((IFileStream*)(This))
+# define IFileStream_IsValid(This) (This)->pVtbl->FileStream.IsValid ((IFileStream*)(This))
+
+// clang-format on
#endif
diff --git a/Primitives/interface/InterfaceID.h b/Primitives/interface/InterfaceID.h
index 1924c331..7f07996c 100644
--- a/Primitives/interface/InterfaceID.h
+++ b/Primitives/interface/InterfaceID.h
@@ -51,8 +51,9 @@ struct INTERFACE_ID
}
#endif
};
+typedef struct INTERFACE_ID INTERFACE_ID;
/// Unknown interface
-static const struct INTERFACE_ID IID_Unknown = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
+static const INTERFACE_ID IID_Unknown = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
DILIGENT_END_NAMESPACE // namespace Diligent
diff --git a/Primitives/interface/Object.h b/Primitives/interface/Object.h
index 931020ab..d328eb64 100644
--- a/Primitives/interface/Object.h
+++ b/Primitives/interface/Object.h
@@ -38,9 +38,8 @@ DILIGENT_BEGIN_NAMESPACE(Diligent)
#if DILIGENT_CPP_INTERFACE
/// Base interface for all dynamic objects in the engine
-class IObject
+struct IObject
{
-public:
/// Queries the specific interface.
/// \param [in] IID - Unique identifier of the requested interface.
@@ -88,10 +87,10 @@ struct IObject;
struct IObjectMethods
{
- void (*QueryInterface) (struct IObject*, const struct INTERFACE_ID* IID, struct IObject** ppInterface);
- ReferenceCounterValueType (*AddRef) (struct IObject*);
- ReferenceCounterValueType (*Release) (struct IObject*);
- class IReferenceCounters* (*GetReferenceCounters)(struct IObject*);
+ void (*QueryInterface) (struct IObject*, const struct INTERFACE_ID* IID, struct IObject** ppInterface);
+ ReferenceCounterValueType (*AddRef) (struct IObject*);
+ ReferenceCounterValueType (*Release) (struct IObject*);
+ struct IReferenceCounters* (*GetReferenceCounters)(struct IObject*);
};
struct IObjectVtbl
@@ -101,10 +100,10 @@ struct IObjectVtbl
// clang-format on
-struct IObject
+typedef struct IObject
{
struct IObjectVtbl* pVtbl;
-};
+} IObject;
// clang-format off
diff --git a/Primitives/interface/ReferenceCounters.h b/Primitives/interface/ReferenceCounters.h
index 793761a7..1f6a77c5 100644
--- a/Primitives/interface/ReferenceCounters.h
+++ b/Primitives/interface/ReferenceCounters.h
@@ -97,7 +97,7 @@ public:
/// will be stored. In this case, the number of strong references to the object
/// will be incremented by 1.\n
/// The method is thread-safe and does not require explicit synchronization.
- virtual void GetObject(class IObject** ppObject) = 0;
+ virtual void GetObject(struct IObject** ppObject) = 0;
/// Returns the number of outstanding strong references.