Diligent Engine API Reference: D:/GitHub/DiligentEngine/DiligentCore/Common/interface/ObjectBase.h Source File

Diligent Engine API Reference

ObjectBase.h
1 /* Copyright 2015-2018 Egor Yusov
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
12 *
13 * In no event and under no legal theory, whether in tort (including negligence),
14 * contract, or otherwise, unless required by applicable law (such as deliberate
15 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
16 * liable for any damages, including any direct, indirect, special, incidental,
17 * or consequential damages of any character arising as a result of this License or
18 * out of the use or inability to use the software (including but not limited to damages
19 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
20 * all other commercial damages or losses), even if such Contributor has been advised
21 * of the possibility of such damages.
22 */
23
24 #pragma once
25
28
29 #include "Object.h"
30 #include "RefCountedObjectImpl.h"
31
32 namespace Diligent
33 {
34
35
36 #define IMPLEMENT_QUERY_INTERFACE_BODY(InterfaceID, ParentClassName) \
37 { \
38 if( ppInterface == nullptr ) \
39 return; \
40 if( IID == InterfaceID ) \
41 { \
42 *ppInterface = this; \
43 (*ppInterface)->AddRef(); \
44 } \
45 else \
46 { \
47 ParentClassName::QueryInterface( IID, ppInterface ); \
48 } \
49 }
50
51 #define IMPLEMENT_QUERY_INTERFACE(ClassName, InterfaceID, ParentClassName) \
52 void ClassName :: QueryInterface(const Diligent::INTERFACE_ID &IID, IObject **ppInterface) \
53 IMPLEMENT_QUERY_INTERFACE_BODY(InterfaceID, ParentClassName)
54
55 #define IMPLEMENT_QUERY_INTERFACE_IN_PLACE(InterfaceID, ParentClassName) \
56 virtual void QueryInterface(const Diligent::INTERFACE_ID &IID, IObject **ppInterface)override \
57 IMPLEMENT_QUERY_INTERFACE_BODY(InterfaceID, ParentClassName)
58
59
61 template<typename BaseInterface>
62 class ObjectBase : public RefCountedObject<BaseInterface>
63 {
64 public:
65 ObjectBase(IReferenceCounters *pRefCounters) :
66 RefCountedObject<BaseInterface>( pRefCounters )
67 {}
68
69 virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )
70 {
71 if( ppInterface == nullptr )
72 return;
73
74 *ppInterface = nullptr;
75 if( IID == Diligent::IID_Unknown )
76 {
77 *ppInterface = this;
78 (*ppInterface)->AddRef();
79 }
80 }
81 };
82
83 }
Diligent::ObjectBase
Template class implementing base functionality for an object.
Definition: ObjectBase.h:62
Diligent
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Diligent::RefCountedObject
Base class for all reference counting objects.
Definition: RefCountedObjectImpl.h:470