MDL SDK API nvidia_logo_transpbg.gif Up
iinterface.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2024 NVIDIA Corporation. All rights reserved.
3 **************************************************************************************************/
6
7#ifndef MI_BASE_IINTERFACE_H
8#define MI_BASE_IINTERFACE_H
9
10#include <mi/base/types.h>
11#include <mi/base/uuid.h>
12
13namespace mi {
14
15namespace base {
16
36// Forward declaration, see below for definition
37class IInterface;
38
103{
104public:
105
113
117 static bool compare_iid( const Uuid& iid)
118 {
119 return ( iid == IID());
120 }
121
128 virtual Uint32 retain() const = 0;
129
137 virtual Uint32 release() const = 0;
138
151 virtual const IInterface* get_interface( const Uuid& interface_id ) const = 0;
152
168 template <class T>
169 const T* get_interface() const
170 {
171 return static_cast<const T*>( get_interface( typename T::IID()));
172 }
173
186 virtual IInterface* get_interface( const Uuid& interface_id ) = 0;
187
203 template <class T>
205 {
206 return static_cast<T*>( get_interface( typename T::IID()));
207 }
208
210 virtual Uuid get_iid() const = 0;
211
212protected:
213 // Acquires a const interface.
214 //
215 // Static helper function for implementing #get_interface(const Uuid&). On #IInterface, the
216 // method terminates the recursive call chain.
217 //
218 // \param iinterface The interface to act on.
219 // \param interface_id Interface ID of the interface to acquire.
220 static const IInterface* get_interface_static(
221 const IInterface* iinterface, const Uuid& interface_id)
222 {
223 if( interface_id == IID()) {
224 iinterface->retain();
225 return iinterface;
226 }
227 return 0;
228 }
229
230 // Acquires a mutable interface.
231 //
232 // Static helper function for implementing #get_interface(const Uuid&). On #IInterface, the
233 // method terminates the recursive call chain.
234 //
235 // \param iinterface The interface to act on.
236 // \param interface_id Interface ID of the interface to acquire.
237 static IInterface* get_interface_static(
238 IInterface* iinterface, const Uuid& interface_id)
239 {
240 if( interface_id == IID()) {
241 iinterface->retain();
242 return iinterface;
243 }
244 return 0;
245 }
246
247};
248 // end group mi_base_iinterface
250
251} // namespace base
252
253} // namespace mi
254
255#endif // MI_BASE_IINTERFACE_H
The basic extensible interface.
Definition: iinterface.h:103
Class template for a compile-time representation of universally unique identifiers (UUIDs or GUIDs).
Definition: uuid.h:122
virtual const IInterface * get_interface(const Uuid &interface_id) const =0
Acquires a const interface from another.
virtual Uuid get_iid() const =0
Returns the interface ID of the most derived interface.
Uuid_t<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> IID
Declares the interface ID (IID) of this interface.
Definition: iinterface.h:112
virtual Uint32 retain() const =0
Increments the reference count.
T * get_interface()
Acquires a mutable interface from another.
Definition: iinterface.h:204
const T * get_interface() const
Acquires a const interface from another.
Definition: iinterface.h:169
virtual IInterface * get_interface(const Uuid &interface_id)=0
Acquires a mutable interface from another.
virtual Uint32 release() const =0
Decrements the reference count.
static bool compare_iid(const Uuid &iid)
Compares the interface ID iid against the interface ID of this interface.
Definition: iinterface.h:117
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:49
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: example_derivatives.dox:5
A 128 bit representation of a universally unique identifier (UUID or GUID).
Definition: uuid.h:26
Basic types.
A 128 bit representation of a universally unique identifier (UUID or GUID).