Skip to content

Commit 17d601e

Browse files
IObject: Add templated QueryInterface to avoid manual casts
1 parent d3066de commit 17d601e

File tree

94 files changed

+160
-190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+160
-190
lines changed

Common/interface/BasicFileStream.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -51,7 +51,7 @@ class BasicFileStream : public ObjectBase<IFileStream>
5151
const Char* Path,
5252
EFileAccessMode Access = EFileAccessMode::Read);
5353

54-
virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override;
54+
IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_FileStream, TBase)
5555

5656
/// Reads data from the stream
5757
virtual void DILIGENT_CALL_TYPE ReadBlob(IDataBlob* pData) override;

Common/interface/DataBlobImpl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class DataBlobImpl final : public ObjectBase<IDataBlob>
5555

5656
~DataBlobImpl() override;
5757

58-
virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override;
58+
IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_DataBlob, TBase);
5959

6060
/// Sets the size of the internal data buffer
6161
virtual void DILIGENT_CALL_TYPE Resize(size_t NewSize) override;

Common/interface/MemoryFileStream.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -47,7 +47,7 @@ class MemoryFileStream final : public ObjectBase<IFileStream>
4747
MemoryFileStream(IReferenceCounters* pRefCounters,
4848
IDataBlob* pData);
4949

50-
virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final;
50+
IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_FileStream, TBase)
5151

5252
/// Reads data from the stream
5353
virtual void DILIGENT_CALL_TYPE ReadBlob(IDataBlob* pData) override final;

Common/interface/ObjectBase.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -56,10 +56,12 @@ namespace Diligent
5656
void ClassName::QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) \
5757
IMPLEMENT_QUERY_INTERFACE_BODY(InterfaceID, ParentClassName)
5858

59+
// clang-format off
5960
#define IMPLEMENT_QUERY_INTERFACE_IN_PLACE(InterfaceID, ParentClassName) \
6061
virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override \
61-
IMPLEMENT_QUERY_INTERFACE_BODY(InterfaceID, ParentClassName)
62-
62+
IMPLEMENT_QUERY_INTERFACE_BODY(InterfaceID, ParentClassName) \
63+
using IObject::QueryInterface;
64+
// clang-format on
6365

6466
#define IMPLEMENT_QUERY_INTERFACE2_BODY(InterfaceID1, InterfaceID2, ParentClassName) \
6567
{ \
@@ -80,9 +82,12 @@ namespace Diligent
8082
void ClassName::QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) \
8183
IMPLEMENT_QUERY_INTERFACE2_BODY(InterfaceID1, InterfaceID2, ParentClassName)
8284

85+
// clang-format off
8386
#define IMPLEMENT_QUERY_INTERFACE2_IN_PLACE(InterfaceID1, InterfaceID2, ParentClassName) \
8487
virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override \
85-
IMPLEMENT_QUERY_INTERFACE2_BODY(InterfaceID1, InterfaceID2, ParentClassName)
88+
IMPLEMENT_QUERY_INTERFACE2_BODY(InterfaceID1, InterfaceID2, ParentClassName) \
89+
using IObject::QueryInterface;
90+
// clang-format on
8691

8792
/// Template class implementing base functionality for an object
8893
template <typename BaseInterface>

Common/src/BasicFileStream.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -50,8 +50,6 @@ BasicFileStream::BasicFileStream(IReferenceCounters* pRefCounters,
5050
{
5151
}
5252

53-
IMPLEMENT_QUERY_INTERFACE(BasicFileStream, IID_FileStream, TBase)
54-
5553
bool BasicFileStream::Read(void* Data, size_t Size)
5654
{
5755
return m_FileWrpr->Read(Data, Size);

Common/src/DataBlobImpl.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ const void* DataBlobImpl::GetConstDataPtr(size_t Offset) const
106106
return !m_DataBuff.empty() ? &m_DataBuff[Offset] : nullptr;
107107
}
108108

109-
IMPLEMENT_QUERY_INTERFACE(DataBlobImpl, IID_DataBlob, TBase)
110-
111-
112109
void* DataBlobAllocatorAdapter::Allocate(size_t Size, const Char* dbgDescription, const char* dbgFileName, const Int32 dbgLineNumber)
113110
{
114111
VERIFY(!m_pDataBlob, "The data blob has already been created. The allocator does not support more than one blob.");

Common/src/GeometryPrimitives.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Diligent Graphics LLC
2+
* Copyright 2024-2025 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -90,7 +90,7 @@ void CreateCubeGeometryInternal(Uint32 NumSubdivisions,
9090
{
9191
pVertexData = DataBlobImpl::Create(VertexDataSize);
9292
DEV_CHECK_ERR(*ppVertices == nullptr, "*ppVertices is not null, which may cause memory leak");
93-
pVertexData->QueryInterface(IID_DataBlob, reinterpret_cast<IObject**>(ppVertices));
93+
pVertexData->QueryInterface(IID_DataBlob, ppVertices);
9494
pVert = pVertexData->GetDataPtr<Uint8>();
9595
}
9696

@@ -100,7 +100,7 @@ void CreateCubeGeometryInternal(Uint32 NumSubdivisions,
100100
{
101101
pIndexData = DataBlobImpl::Create(IndexDataSize);
102102
DEV_CHECK_ERR(*ppIndices == nullptr, "*ppIndices is not null, which may cause memory leak");
103-
pIndexData->QueryInterface(IID_DataBlob, reinterpret_cast<IObject**>(ppIndices));
103+
pIndexData->QueryInterface(IID_DataBlob, ppIndices);
104104
pIdx = pIndexData->GetDataPtr<Uint32>();
105105
}
106106

Common/src/MemoryFileStream.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ MemoryFileStream::MemoryFileStream(IReferenceCounters* pRefCounters,
4545
{
4646
}
4747

48-
IMPLEMENT_QUERY_INTERFACE(MemoryFileStream, IID_FileStream, TBase)
49-
5048
bool MemoryFileStream::Read(void* Data, size_t Size)
5149
{
5250
if (Size == 0)

Graphics/GraphicsEngine/include/EngineFactoryBase.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class EngineFactoryBase : public BaseInterface
8080
}
8181
}
8282

83+
using IObject::QueryInterface;
84+
8385
virtual ReferenceCounterValueType DILIGENT_CALL_TYPE AddRef() override final
8486
{
8587
return m_RefCounters.AddStrongRef();
@@ -103,7 +105,7 @@ class EngineFactoryBase : public BaseInterface
103105
virtual void DILIGENT_CALL_TYPE CreateDataBlob(size_t InitialSize, const void* pData, IDataBlob** ppDataBlob) const override final
104106
{
105107
if (RefCntAutoPtr<DataBlobImpl> pDataBlob = DataBlobImpl::Create(InitialSize, pData))
106-
pDataBlob->QueryInterface(IID_DataBlob, reinterpret_cast<IObject**>(ppDataBlob));
108+
pDataBlob->QueryInterface(IID_DataBlob, ppDataBlob);
107109
}
108110

109111
virtual void DILIGENT_CALL_TYPE CreateDefaultShaderSourceStreamFactory(const Char* SearchDirectories,

Graphics/GraphicsEngine/src/DearchiverBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ void DearchiverBase::UnpackShader(const ShaderUnpackInfo& UnpackInfo,
804804
if (!pShader)
805805
return;
806806

807-
pShader->QueryInterface(IID_Shader, reinterpret_cast<IObject**>(ppShader));
807+
pShader->QueryInterface(IID_Shader, ppShader);
808808
}
809809

810810
void DearchiverBase::UnpackResourceSignature(const ResourceSignatureUnpackInfo& DeArchiveInfo,

0 commit comments

Comments
 (0)