diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-01-27 20:04:26 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-01-27 20:04:26 +0000 |
| commit | 3ed4072f25c4c08f2be2deea41f67c3988458038 (patch) | |
| tree | 0944ba58679a2d0191da16fa266c61124303dabf /Primitives/interface | |
| parent | Reworked C interfaces to share declaration with c++ (diff) | |
| download | DiligentCore-3ed4072f25c4c08f2be2deea41f67c3988458038.tar.gz DiligentCore-3ed4072f25c4c08f2be2deea41f67c3988458038.zip | |
Guarded interface definitions by define-undef macro helper include pairs to avoid macro conflicts
Diffstat (limited to 'Primitives/interface')
| -rw-r--r-- | Primitives/interface/CommonDefinitions.h | 13 | ||||
| -rw-r--r-- | Primitives/interface/DataBlob.h | 14 | ||||
| -rw-r--r-- | Primitives/interface/DefineInterfaceHelperMacros.h | 70 | ||||
| -rw-r--r-- | Primitives/interface/FileStream.h | 14 | ||||
| -rw-r--r-- | Primitives/interface/UndefInterfaceHelperMacros.h | 36 |
5 files changed, 120 insertions, 27 deletions
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 |
