Skip to content

Commit 9a42546

Browse files
IObject: added convenience template version of QueryInterface
1 parent 0004b56 commit 9a42546

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Primitives/interface/Object.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,6 +33,10 @@
3333
#include "InterfaceID.h"
3434
#include "ReferenceCounters.h"
3535

36+
#if DILIGENT_CPP_INTERFACE
37+
# include <type_traits>
38+
#endif
39+
3640
DILIGENT_BEGIN_NAMESPACE(Diligent)
3741

3842
#if DILIGENT_CPP_INTERFACE
@@ -77,6 +81,12 @@ struct IObject
7781
/// reference counters object. The method does *NOT* increment
7882
/// the number of strong references to the returned object.
7983
virtual IReferenceCounters* DILIGENT_CALL_TYPE GetReferenceCounters() const = 0;
84+
85+
template <typename DerivedType, typename = typename std::enable_if<std::is_base_of<IObject, DerivedType>::value>::type>
86+
void QueryInterface(const INTERFACE_ID& IID, DerivedType** ppInterface)
87+
{
88+
QueryInterface(IID, reinterpret_cast<IObject**>(ppInterface));
89+
}
8090
};
8191

8292
#else

0 commit comments

Comments
 (0)