From 3ed4072f25c4c08f2be2deea41f67c3988458038 Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 27 Jan 2020 12:04:26 -0800 Subject: Guarded interface definitions by define-undef macro helper include pairs to avoid macro conflicts --- Graphics/GraphicsEngine/interface/Buffer.h | 11 ++-- Graphics/GraphicsEngine/interface/BufferView.h | 13 ++-- Graphics/GraphicsEngine/interface/DeviceContext.h | 12 ++-- Graphics/GraphicsEngine/interface/DeviceObject.h | 11 ++-- Graphics/GraphicsEngine/interface/EngineFactory.h | 12 ++-- Graphics/GraphicsEngine/interface/Fence.h | 11 ++-- Graphics/GraphicsEngine/interface/PipelineState.h | 12 ++-- Graphics/GraphicsEngine/interface/Query.h | 12 ++-- Graphics/GraphicsEngine/interface/RenderDevice.h | 11 ++-- .../GraphicsEngine/interface/ResourceMapping.h | 11 ++-- Graphics/GraphicsEngine/interface/Sampler.h | 5 ++ Graphics/GraphicsEngine/interface/Shader.h | 25 ++++---- .../interface/ShaderResourceBinding.h | 13 ++-- .../interface/ShaderResourceVariable.h | 12 ++-- Graphics/GraphicsEngine/interface/SwapChain.h | 10 +--- Graphics/GraphicsEngine/interface/Texture.h | 13 ++-- Graphics/GraphicsEngine/interface/TextureView.h | 13 ++-- Primitives/CMakeLists.txt | 2 + Primitives/interface/CommonDefinitions.h | 13 ---- Primitives/interface/DataBlob.h | 14 ++--- Primitives/interface/DefineInterfaceHelperMacros.h | 70 ++++++++++++++++++++++ Primitives/interface/FileStream.h | 14 ++--- Primitives/interface/UndefInterfaceHelperMacros.h | 36 +++++++++++ 23 files changed, 205 insertions(+), 151 deletions(-) create mode 100644 Primitives/interface/DefineInterfaceHelperMacros.h create mode 100644 Primitives/interface/UndefInterfaceHelperMacros.h diff --git a/Graphics/GraphicsEngine/interface/Buffer.h b/Graphics/GraphicsEngine/interface/Buffer.h index 1a1f79d1..a7a999a1 100644 --- a/Graphics/GraphicsEngine/interface/Buffer.h +++ b/Graphics/GraphicsEngine/interface/Buffer.h @@ -173,10 +173,8 @@ struct BufferData }; typedef struct BufferData BufferData; -#if DILIGENT_C_INTERFACE -# define THIS struct IBuffer* -# define THIS_ struct IBuffer*, -#endif +#define DILIGENT_INTERFACE_NAME IBuffer +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" /// Buffer interface @@ -238,10 +236,9 @@ DILIGENT_INTERFACE(IBuffer, IDeviceObject) VIRTUAL RESOURCE_STATE METHOD(GetState)(THIS) CONST PURE; }; -#if DILIGENT_C_INTERFACE +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" -#undef THIS -#undef THIS_ +#if DILIGENT_C_INTERFACE // clang-format on diff --git a/Graphics/GraphicsEngine/interface/BufferView.h b/Graphics/GraphicsEngine/interface/BufferView.h index fbdb6636..613f552b 100644 --- a/Graphics/GraphicsEngine/interface/BufferView.h +++ b/Graphics/GraphicsEngine/interface/BufferView.h @@ -139,12 +139,8 @@ struct BufferViewDesc DILIGENT_DERIVE(DeviceObjectAttribs) }; typedef struct BufferViewDesc BufferViewDesc; - - -#if DILIGENT_C_INTERFACE -# define THIS struct IBufferView* -# define THIS_ struct IBufferView*, -#endif +#define DILIGENT_INTERFACE_NAME IBufferView +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" /// Buffer view interface @@ -166,10 +162,9 @@ DILIGENT_INTERFACE(IBufferView, IDeviceObject) VIRTUAL struct IBuffer* METHOD(GetBuffer)(THIS) PURE; }; -#if DILIGENT_C_INTERFACE +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" -# undef THIS -# undef THIS_ +#if DILIGENT_C_INTERFACE // clang-format on diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index 8484be67..38cbfa61 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -609,11 +609,8 @@ struct CopyTextureAttribs }; typedef struct CopyTextureAttribs CopyTextureAttribs; - -#if DILIGENT_C_INTERFACE -# define THIS struct IDeviceContext* -# define THIS_ struct IDeviceContext*, -#endif +#define DILIGENT_INTERFACE_NAME IDeviceContext +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" /// Device context interface. @@ -1317,10 +1314,9 @@ DILIGENT_INTERFACE(IDeviceContext, IObject) const ResolveTextureSubresourceAttribs REF ResolveAttribs) PURE; }; -#if DILIGENT_C_INTERFACE +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" -# undef THIS -# undef THIS_ +#if DILIGENT_C_INTERFACE // clang-format on diff --git a/Graphics/GraphicsEngine/interface/DeviceObject.h b/Graphics/GraphicsEngine/interface/DeviceObject.h index 3feba088..98d7f26f 100644 --- a/Graphics/GraphicsEngine/interface/DeviceObject.h +++ b/Graphics/GraphicsEngine/interface/DeviceObject.h @@ -40,10 +40,8 @@ DILIGENT_BEGIN_NAMESPACE(Diligent) static const INTERFACE_ID IID_DeviceObject = {0x5b4cca0b, 0x5075, 0x4230, {0x97, 0x59, 0xf4, 0x87, 0x69, 0xee, 0x55, 0x2}}; -#if DILIGENT_C_INTERFACE -# define THIS struct IDeviceObject* -# define THIS_ struct IDeviceObject*, -#endif +#define DILIGENT_INTERFACE_NAME IDeviceObject +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" /// Base interface for all objects created by the render device Diligent::IRenderDevice DILIGENT_INTERFACE(IDeviceObject, IObject) @@ -71,10 +69,9 @@ DILIGENT_INTERFACE(IDeviceObject, IObject) VIRTUAL Int32 METHOD(GetUniqueID)(THIS) CONST PURE; }; -#if DILIGENT_C_INTERFACE +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" -# undef THIS -# undef THIS_ +#if DILIGENT_C_INTERFACE // clang-format off diff --git a/Graphics/GraphicsEngine/interface/EngineFactory.h b/Graphics/GraphicsEngine/interface/EngineFactory.h index 829e9ccd..7e401b37 100644 --- a/Graphics/GraphicsEngine/interface/EngineFactory.h +++ b/Graphics/GraphicsEngine/interface/EngineFactory.h @@ -41,10 +41,9 @@ struct IShaderSourceInputStreamFactory; static const INTERFACE_ID IID_EngineFactory = {0xd932b052, 0x4ed6, 0x4729, {0xa5, 0x32, 0xf3, 0x1d, 0xee, 0xc1, 0x0, 0xf3}}; -#if DILIGENT_C_INTERFACE -# define THIS struct IEngineFactory* -# define THIS_ struct IEngineFactory*, -#endif +#define DILIGENT_INTERFACE_NAME IEngineFactory +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" + // clang-format off @@ -73,10 +72,9 @@ DILIGENT_INTERFACE(IEngineFactory, IObject) #endif }; -#if DILIGENT_C_INTERFACE +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" -# undef THIS -# undef THIS_ +#if DILIGENT_C_INTERFACE // clang-format on diff --git a/Graphics/GraphicsEngine/interface/Fence.h b/Graphics/GraphicsEngine/interface/Fence.h index b1fe06c1..7387495c 100644 --- a/Graphics/GraphicsEngine/interface/Fence.h +++ b/Graphics/GraphicsEngine/interface/Fence.h @@ -46,10 +46,9 @@ typedef struct FenceDesc FenceDesc; // clang-format off -#if DILIGENT_C_INTERFACE -# define THIS struct IFence* -# define THIS_ struct IFence*, -#endif +#define DILIGENT_INTERFACE_NAME IFence +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" + /// Fence interface @@ -76,12 +75,10 @@ DILIGENT_INTERFACE(IFence, IDeviceObject) Uint64 Value) PURE; }; +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" #if DILIGENT_C_INTERFACE -# undef THIS -# undef THIS_ - // clang-format on struct IFenceVtbl diff --git a/Graphics/GraphicsEngine/interface/PipelineState.h b/Graphics/GraphicsEngine/interface/PipelineState.h index 95f42972..de24d071 100644 --- a/Graphics/GraphicsEngine/interface/PipelineState.h +++ b/Graphics/GraphicsEngine/interface/PipelineState.h @@ -254,11 +254,8 @@ typedef struct PipelineStateDesc PipelineStateDesc; static const struct INTERFACE_ID IID_PipelineState = {0x6084ae5, 0x6a71, 0x4fe8, {0x84, 0xb9, 0x39, 0x5d, 0xd4, 0x89, 0xa2, 0x8c}}; - -#if DILIGENT_C_INTERFACE -# define THIS struct IPipelineState* -# define THIS_ struct IPipelineState*, -#endif +#define DILIGENT_INTERFACE_NAME IPipelineState +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" // clang-format off @@ -350,10 +347,9 @@ DILIGENT_INTERFACE(IPipelineState, IDeviceObject) const struct IPipelineState* pPSO) CONST PURE; }; -#if DILIGENT_C_INTERFACE +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" -# undef THIS -# undef THIS_ +#if DILIGENT_C_INTERFACE // clang-format on diff --git a/Graphics/GraphicsEngine/interface/Query.h b/Graphics/GraphicsEngine/interface/Query.h index 61834232..4f4cfd98 100644 --- a/Graphics/GraphicsEngine/interface/Query.h +++ b/Graphics/GraphicsEngine/interface/Query.h @@ -172,10 +172,9 @@ struct QueryDesc DILIGENT_DERIVE(DeviceObjectAttribs) }; typedef struct QueryDesc QueryDesc; -#if DILIGENT_C_INTERFACE -# define THIS struct IQuery* -# define THIS_ struct IQuery*, -#endif +#define DILIGENT_INTERFACE_NAME IQuery +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" + // clang-format off @@ -218,10 +217,9 @@ DILIGENT_INTERFACE(IQuery, IDeviceObject) VIRTUAL void METHOD(Invalidate)(THIS) PURE; }; -#if DILIGENT_C_INTERFACE +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" -# undef THIS -# undef THIS_ +#if DILIGENT_C_INTERFACE // clang-format on diff --git a/Graphics/GraphicsEngine/interface/RenderDevice.h b/Graphics/GraphicsEngine/interface/RenderDevice.h index 93d70a83..71d0bff3 100644 --- a/Graphics/GraphicsEngine/interface/RenderDevice.h +++ b/Graphics/GraphicsEngine/interface/RenderDevice.h @@ -57,10 +57,9 @@ DILIGENT_BEGIN_NAMESPACE(Diligent) static const INTERFACE_ID IID_RenderDevice = {0xf0e9b607, 0xae33, 0x4b2b, {0xb1, 0xaf, 0xa8, 0xb2, 0xc3, 0x10, 0x40, 0x22}}; -#if DILIGENT_C_INTERFACE -# define THIS struct IRenderDevice* -# define THIS_ struct IRenderDevice*, -#endif +#define DILIGENT_INTERFACE_NAME IRenderDevice +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" + // clang-format off @@ -238,12 +237,10 @@ DILIGENT_INTERFACE(IRenderDevice, IObject) VIRTUAL IEngineFactory* METHOD(GetEngineFactory)(THIS) CONST PURE; }; +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" #if DILIGENT_C_INTERFACE -# undef THIS -# undef THIS - // clang-format on struct IRenderDeviceVtbl diff --git a/Graphics/GraphicsEngine/interface/ResourceMapping.h b/Graphics/GraphicsEngine/interface/ResourceMapping.h index 5de0e935..3078cf13 100644 --- a/Graphics/GraphicsEngine/interface/ResourceMapping.h +++ b/Graphics/GraphicsEngine/interface/ResourceMapping.h @@ -90,11 +90,9 @@ struct ResourceMappingDesc }; typedef struct ResourceMappingDesc ResourceMappingDesc; +#define DILIGENT_INTERFACE_NAME IResourceMapping +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" -#if DILIGENT_C_INTERFACE -# define THIS struct IResourceMapping* -# define THIS_ struct IResourceMapping*, -#endif // clang-format off @@ -167,10 +165,9 @@ DILIGENT_INTERFACE(IResourceMapping, IObject) VIRTUAL size_t METHOD(GetSize)(THIS) PURE; }; -#if DILIGENT_C_INTERFACE +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" -# undef THIS -# undef THIS_ +#if DILIGENT_C_INTERFACE // clang-format on diff --git a/Graphics/GraphicsEngine/interface/Sampler.h b/Graphics/GraphicsEngine/interface/Sampler.h index 97d4b99c..b265ff8e 100644 --- a/Graphics/GraphicsEngine/interface/Sampler.h +++ b/Graphics/GraphicsEngine/interface/Sampler.h @@ -171,6 +171,8 @@ struct SamplerDesc DILIGENT_DERIVE(DeviceObjectAttribs) }; typedef struct SamplerDesc SamplerDesc; +#define DILIGENT_INTERFACE_NAME ISampler +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" #if DILIGENT_CPP_INTERFACE @@ -191,6 +193,9 @@ DILIGENT_INTERFACE(ISampler, IDeviceObject) #endif + +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" + #if DILIGENT_C_INTERFACE // clang-format on diff --git a/Graphics/GraphicsEngine/interface/Shader.h b/Graphics/GraphicsEngine/interface/Shader.h index 971302af..63c788d9 100644 --- a/Graphics/GraphicsEngine/interface/Shader.h +++ b/Graphics/GraphicsEngine/interface/Shader.h @@ -85,10 +85,9 @@ static const INTERFACE_ID IID_IShaderSourceInputStreamFactory = // clang-format off -#if DILIGENT_C_INTERFACE -# define THIS struct IShaderSourceInputStreamFactory* -# define THIS_ struct IShaderSourceInputStreamFactory*, -#endif +#define DILIGENT_INTERFACE_NAME IShaderSourceInputStreamFactory +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" + /// Shader source stream factory interface DILIGENT_INTERFACE(IShaderSourceInputStreamFactory, IObject) @@ -99,10 +98,9 @@ DILIGENT_INTERFACE(IShaderSourceInputStreamFactory, IObject) }; -#if DILIGENT_C_INTERFACE +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" -# undef THIS -# undef THIS_ +#if DILIGENT_C_INTERFACE // clang-format on @@ -318,11 +316,8 @@ struct ShaderResourceDesc }; typedef struct ShaderResourceDesc ShaderResourceDesc; - -#if DILIGENT_C_INTERFACE -# define THIS struct IShader* -# define THIS_ struct IShader*, -#endif +#define DILIGENT_INTERFACE_NAME IShader +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" // clang-format off @@ -343,10 +338,10 @@ DILIGENT_INTERFACE(IShader, IDeviceObject) ShaderResourceDesc REF ResourceDesc) CONST PURE; }; -#if DILIGENT_C_INTERFACE -# undef THIS -# undef THIS_ +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" + +#if DILIGENT_C_INTERFACE // clang-format on diff --git a/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h b/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h index d18c8060..11889a86 100644 --- a/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h +++ b/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h @@ -44,10 +44,10 @@ static const INTERFACE_ID IID_ShaderResourceBinding = {0x61f8774, 0x9a09, 0x48e8, {0x84, 0x11, 0xb5, 0xbd, 0x20, 0x56, 0x1, 0x4}}; -#if DILIGENT_C_INTERFACE -# define THIS struct IShaderResourceBinding* -# define THIS_ struct IShaderResourceBinding*, -#endif +#define DILIGENT_INTERFACE_NAME IShaderResourceBinding +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" + + // clang-format off @@ -128,10 +128,9 @@ DILIGENT_INTERFACE(IShaderResourceBinding, IObject) const struct IPipelineState* pPipelineState DEFAULT_VALUE(nullptr)) PURE; }; -#if DILIGENT_C_INTERFACE +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" -# undef THIS -# undef THIS_ +#if DILIGENT_C_INTERFACE // clang-format on diff --git a/Graphics/GraphicsEngine/interface/ShaderResourceVariable.h b/Graphics/GraphicsEngine/interface/ShaderResourceVariable.h index 6001f99b..889ecce0 100644 --- a/Graphics/GraphicsEngine/interface/ShaderResourceVariable.h +++ b/Graphics/GraphicsEngine/interface/ShaderResourceVariable.h @@ -104,10 +104,10 @@ DILIGENT_TYPED_ENUM(BIND_SHADER_RESOURCES_FLAGS, Uint32) // clang-format on -#if DILIGENT_C_INTERFACE -# define THIS struct IShaderResourceVariable* -# define THIS_ struct IShaderResourceVariable*, -#endif +#define DILIGENT_INTERFACE_NAME IShaderResourceVariable +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" + + // clang-format off @@ -154,12 +154,10 @@ DILIGENT_INTERFACE(IShaderResourceVariable, IObject) Uint32 ArrayIndex) CONST PURE; }; +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" #if DILIGENT_C_INTERFACE -# undef THIS -# undef THIS_ - // clang-format on struct IShaderResourceVariableVtbl diff --git a/Graphics/GraphicsEngine/interface/SwapChain.h b/Graphics/GraphicsEngine/interface/SwapChain.h index b1d435e6..c73800d3 100644 --- a/Graphics/GraphicsEngine/interface/SwapChain.h +++ b/Graphics/GraphicsEngine/interface/SwapChain.h @@ -41,11 +41,9 @@ DILIGENT_BEGIN_NAMESPACE(Diligent) static const INTERFACE_ID IID_SwapChain = {0x1c703b77, 0x6607, 0x4eec, {0xb1, 0xfe, 0x15, 0xc8, 0x2d, 0x3b, 0x41, 0x30}}; +#define DILIGENT_INTERFACE_NAME ISwapChain +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" -#if DILIGENT_C_INTERFACE -# define THIS struct ISwapChain* -# define THIS_ struct ISwapChain*, -#endif // clang-format off @@ -97,12 +95,10 @@ DILIGENT_INTERFACE(ISwapChain, IObject) VIRTUAL ITextureView* METHOD(GetDepthBufferDSV)(THIS) PURE; }; +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" #if DILIGENT_C_INTERFACE -# undef THIS -# undef THIS_ - // clang-format on struct ISwapChainVtbl diff --git a/Graphics/GraphicsEngine/interface/Texture.h b/Graphics/GraphicsEngine/interface/Texture.h index e5bd316c..261664bf 100644 --- a/Graphics/GraphicsEngine/interface/Texture.h +++ b/Graphics/GraphicsEngine/interface/Texture.h @@ -308,10 +308,10 @@ struct MappedTextureSubresource }; typedef struct MappedTextureSubresource MappedTextureSubresource; -#if DILIGENT_C_INTERFACE -# define THIS struct ITexture* -# define THIS_ struct ITexture*, -#endif +#define DILIGENT_INTERFACE_NAME ITexture +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" + + /// Texture inteface DILIGENT_INTERFACE(ITexture, IDeviceObject) @@ -376,10 +376,9 @@ DILIGENT_INTERFACE(ITexture, IDeviceObject) VIRTUAL RESOURCE_STATE METHOD(GetState)(THIS) CONST PURE; }; -#if DILIGENT_C_INTERFACE +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" -# undef THIS -# undef THIS_ +#if DILIGENT_C_INTERFACE // clang-format on diff --git a/Graphics/GraphicsEngine/interface/TextureView.h b/Graphics/GraphicsEngine/interface/TextureView.h index 4182d85d..21e8b6f8 100644 --- a/Graphics/GraphicsEngine/interface/TextureView.h +++ b/Graphics/GraphicsEngine/interface/TextureView.h @@ -184,10 +184,10 @@ typedef struct TextureViewDesc TextureViewDesc; // clang-format on -#if DILIGENT_C_INTERFACE -# define THIS struct ITextureView* -# define THIS_ struct ITextureView*, -#endif +#define DILIGENT_INTERFACE_NAME ITextureView +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" + + /// Texture view interface @@ -224,10 +224,9 @@ DILIGENT_INTERFACE(ITextureView, IDeviceObject) VIRTUAL struct ITexture* METHOD(GetTexture)(THIS) PURE; }; -#if DILIGENT_C_INTERFACE +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" -# undef THIS -# undef THIS_ +#if DILIGENT_C_INTERFACE // clang-format on diff --git a/Primitives/CMakeLists.txt b/Primitives/CMakeLists.txt index f69f2da2..4b4f49ff 100644 --- a/Primitives/CMakeLists.txt +++ b/Primitives/CMakeLists.txt @@ -12,6 +12,7 @@ set(INTERFACE interface/CommonDefinitions.h interface/DataBlob.h interface/DebugOutput.h + interface/DefineInterfaceHelperMacros.h interface/FlagEnum.h interface/Errors.hpp interface/FileStream.h @@ -20,6 +21,7 @@ set(INTERFACE interface/MemoryAllocator.h interface/Object.h interface/ReferenceCounters.h + interface/UndefInterfaceHelperMacros.h ) # This should be an interface library. However, CMake does not show diff --git a/Primitives/interface/CommonDefinitions.h b/Primitives/interface/CommonDefinitions.h index c8303641..7c719267 100644 --- a/Primitives/interface/CommonDefinitions.h +++ b/Primitives/interface/CommonDefinitions.h @@ -59,11 +59,6 @@ struct Name; \ struct Name##Methods -# define VIRTUAL -# define CONST -# define PURE -# define REF * -# define METHOD(Name) (*Name) # define DEFAULT_VALUE(x) #else @@ -85,16 +80,8 @@ # 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 - #endif #if DILIGENT_C_INTERFACE diff --git a/Primitives/interface/DataBlob.h b/Primitives/interface/DataBlob.h index af78d20d..24d87544 100644 --- a/Primitives/interface/DataBlob.h +++ b/Primitives/interface/DataBlob.h @@ -41,10 +41,10 @@ static const struct INTERFACE_ID IID_DataBlob = // clang-format off -#if DILIGENT_C_INTERFACE -# define THIS struct IDataBlob* -# define THIS_ struct IDataBlob*, -#endif +#define DILIGENT_INTERFACE_NAME IDataBlob +#include "DefineInterfaceHelperMacros.h" + + /// Base interface for a file stream DILIGENT_INTERFACE(IDataBlob, IObject) @@ -60,12 +60,12 @@ DILIGENT_INTERFACE(IDataBlob, IObject) VIRTUAL void* METHOD(GetDataPtr)(THIS) PURE; }; - // clang-format on +#include "UndefInterfaceHelperMacros.h" #if DILIGENT_C_INTERFACE -# undef THIS -# undef THIS_ + +// clang-format on struct IDataBlobVtbl { diff --git a/Primitives/interface/DefineInterfaceHelperMacros.h b/Primitives/interface/DefineInterfaceHelperMacros.h new file mode 100644 index 00000000..9114fb5e --- /dev/null +++ b/Primitives/interface/DefineInterfaceHelperMacros.h @@ -0,0 +1,70 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "CommonDefinitions.h" + +#ifndef DILIGENT_INTERFACE_NAME +# error Interface name is undefined +#endif + +#pragma push_macro("THIS") +#pragma push_macro("THIS_") +#pragma push_macro("VIRTUAL") +#pragma push_macro("CONST") +#pragma push_macro("PURE") +#pragma push_macro("REF") +#pragma push_macro("METHOD") + +#undef THIS +#undef THIS_ +#undef VIRTUAL +#undef CONST +#undef PURE +#undef REF +#undef METHOD + +#if DILIGENT_C_INTERFACE + +# define THIS struct DILIGENT_INTERFACE_NAME* +# define THIS_ struct DILIGENT_INTERFACE_NAME*, +# define VIRTUAL +# define CONST +# define PURE +# define REF * +# define METHOD(Name) (*Name) + +#else + +# define THIS +# define THIS_ +# define VIRTUAL virtual +# define CONST const +# define PURE = 0 +# define REF & +# define METHOD(Name) Name + +#endif diff --git a/Primitives/interface/FileStream.h b/Primitives/interface/FileStream.h index e09722ab..1f3ccad3 100644 --- a/Primitives/interface/FileStream.h +++ b/Primitives/interface/FileStream.h @@ -42,10 +42,9 @@ static const struct INTERFACE_ID IID_FileStream = // clang-format off -#if DILIGENT_C_INTERFACE -# define THIS struct IFileStream* -# define THIS_ struct IFileStream*, -#endif +#define DILIGENT_INTERFACE_NAME IFileStream +#include "DefineInterfaceHelperMacros.h" + /// Base interface for a file stream DILIGENT_INTERFACE(IFileStream, IObject) @@ -68,12 +67,13 @@ DILIGENT_INTERFACE(IFileStream, IObject) VIRTUAL bool METHOD(IsValid)(THIS) PURE; }; - // clang-format on +#include "UndefInterfaceHelperMacros.h" + #if DILIGENT_C_INTERFACE -# undef THIS -# undef THIS_ + +// clang-format on struct IFileStreamVtbl { diff --git a/Primitives/interface/UndefInterfaceHelperMacros.h b/Primitives/interface/UndefInterfaceHelperMacros.h new file mode 100644 index 00000000..6b90e049 --- /dev/null +++ b/Primitives/interface/UndefInterfaceHelperMacros.h @@ -0,0 +1,36 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma pop_macro("THIS") +#pragma pop_macro("THIS_") +#pragma pop_macro("VIRTUAL") +#pragma pop_macro("CONST") +#pragma pop_macro("PURE") +#pragma pop_macro("REF") +#pragma pop_macro("METHOD") + +#undef DILIGENT_INTERFACE_NAME -- cgit v1.2.3