Added C API for IReferenceCounters
assiduous
2 years ago
119 | 119 | |
120 | 120 | #else |
121 | 121 | |
122 | struct IObject; | |
123 | struct IReferenceCounters; | |
124 | ||
125 | // clang-format off | |
126 | ||
127 | typedef struct IReferenceCountersMethods | |
128 | { | |
129 | ReferenceCounterValueType (*AddStrongRef) (struct IReferenceCounters*); | |
130 | ReferenceCounterValueType (*ReleaseStrongRef) (struct IReferenceCounters*); | |
131 | ReferenceCounterValueType (*AddWeakRef) (struct IReferenceCounters*); | |
132 | ReferenceCounterValueType (*ReleaseWeakRef) (struct IReferenceCounters*); | |
133 | void (*GetObject) (struct IReferenceCounters*, struct IObject** ppObject); | |
134 | ReferenceCounterValueType (*GetNumStrongRefs) (struct IReferenceCounters*); | |
135 | ReferenceCounterValueType (*GetNumWeakRefs) (struct IReferenceCounters*); | |
136 | } IReferenceCountersMethods; | |
137 | ||
138 | typedef struct IReferenceCountersVtbl | |
139 | { | |
140 | IReferenceCountersMethods ReferenceCounters; | |
141 | } IReferenceCountersVtbl; | |
142 | ||
143 | // clang-format on | |
144 | ||
145 | typedef struct IReferenceCounters | |
146 | { | |
147 | struct IReferenceCountersVtbl* pVtbl; | |
148 | } IReferenceCounters; | |
149 | ||
150 | // clang-format off | |
151 | ||
152 | # define IReferenceCounters_AddStrongRef(This) CALL_IFACE_METHOD(ReferenceCounters, AddStrongRef, This) | |
153 | # define IReferenceCounters_ReleaseStrongRef(This) CALL_IFACE_METHOD(ReferenceCounters, ReleaseStrongRef, This) | |
154 | # define IReferenceCounters_AddWeakRef(This) CALL_IFACE_METHOD(ReferenceCounters, AddWeakRef, This) | |
155 | # define IReferenceCounters_ReleaseWeakRef(This) CALL_IFACE_METHOD(ReferenceCounters, ReleaseWeakRef, This) | |
156 | # define IReferenceCounters_GetObject(This, ...) CALL_IFACE_METHOD(ReferenceCounters, GetObject, This, __VA_ARGS__) | |
157 | # define IReferenceCounters_GetNumStrongRefs(This) CALL_IFACE_METHOD(ReferenceCounters, GetNumStrongRefs, This) | |
158 | # define IReferenceCounters_GetNumWeakRefs(This) CALL_IFACE_METHOD(ReferenceCounters, GetNumWeakRefs, This) | |
159 | ||
160 | // clang-format on | |
161 | ||
122 | 162 | #endif |
123 | 163 | |
124 | 164 | DILIGENT_END_NAMESPACE // namespace Diligent |
0 | /* | |
1 | * Copyright 2019-2020 Diligent Graphics LLC | |
2 | * Copyright 2015-2019 Egor Yusov | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | * | |
16 | * In no event and under no legal theory, whether in tort (including negligence), | |
17 | * contract, or otherwise, unless required by applicable law (such as deliberate | |
18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be | |
19 | * liable for any damages, including any direct, indirect, special, incidental, | |
20 | * or consequential damages of any character arising as a result of this License or | |
21 | * out of the use or inability to use the software (including but not limited to damages | |
22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and | |
23 | * all other commercial damages or losses), even if such Contributor has been advised | |
24 | * of the possibility of such damages. | |
25 | */ | |
26 | ||
27 | #include "DiligentCore/Primitives/interface/ReferenceCounters.h" | |
28 | #include "DiligentCore/Primitives/interface/Object.h" | |
29 | ||
30 | void TestReferenceCounters_CInterface(IReferenceCounters* pRefCounters) | |
31 | { | |
32 | ReferenceCounterValueType rc = 0; | |
33 | ||
34 | rc = IReferenceCounters_AddStrongRef(pRefCounters); | |
35 | rc = IReferenceCounters_ReleaseStrongRef(pRefCounters); | |
36 | rc = IReferenceCounters_AddWeakRef(pRefCounters); | |
37 | rc = IReferenceCounters_ReleaseWeakRef(pRefCounters); | |
38 | ||
39 | struct IObject* pObject = NULL; | |
40 | IReferenceCounters_GetObject(pRefCounters, &pObject); | |
41 | IObject_Release(pObject); | |
42 | ||
43 | rc = IReferenceCounters_GetNumStrongRefs(pRefCounters); | |
44 | rc = IReferenceCounters_GetNumWeakRefs(pRefCounters); | |
45 | } |
0 | /* | |
1 | * Copyright 2019-2020 Diligent Graphics LLC | |
2 | * Copyright 2015-2019 Egor Yusov | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | * | |
16 | * In no event and under no legal theory, whether in tort (including negligence), | |
17 | * contract, or otherwise, unless required by applicable law (such as deliberate | |
18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be | |
19 | * liable for any damages, including any direct, indirect, special, incidental, | |
20 | * or consequential damages of any character arising as a result of this License or | |
21 | * out of the use or inability to use the software (including but not limited to damages | |
22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and | |
23 | * all other commercial damages or losses), even if such Contributor has been advised | |
24 | * of the possibility of such damages. | |
25 | */ | |
26 | ||
27 | #include "DiligentCore/Primitives/interface/ReferenceCounters.h" |