The basic extensible interface. More...
Public Types | |
typedef Uuid_t< 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 > | IID |
Declares the interface ID (IID) of this interface. More... |
|
Public Member Functions | |
virtual Uint32 | retain () const =0 |
Increments the reference count. More... |
|
virtual Uint32 | release () const =0 |
Decrements the reference count. More... |
|
virtual const IInterface * | get_interface (const Uuid &interface_id) const =0 |
Acquires a const interface from another. More... |
|
template<class T > | |
const T * | get_interface () const |
Acquires a const interface from another. More... |
|
virtual IInterface * | get_interface (const Uuid &interface_id)=0 |
Acquires a mutable interface from another. More... |
|
template<class T > | |
T * | get_interface () |
Acquires a mutable interface from another. More... |
|
virtual Uuid | get_iid () const =0 |
Returns the interface ID of the most derived interface. More... |
|
Static Public Member Functions | |
static bool | compare_iid (const Uuid &iid) |
Compares the interface ID iid against the interface ID of this interface. More... |
|
The basic extensible interface.
The mi::base::IInterface class is a pure virtual class with no members, a so-called interface. It is used as the common base class of interface hierarchies. The purpose of this class is the management of object lifetime through reference counting, see mi::base::IInterface::retain() and mi::base::IInterface::release(), and the proper dynamic-cast like access to derived and otherwise related interfaces, see mi::base::IInterface::get_interface(const Uuid&).
In addition to these methods, the class mi::base::IInterface has an inner type mi::base::IInterface::IID, which is readily convertible to the type mi::base::Uuid. The type mi::base::IInterface::IID has a default constructor which creates a value that contains the universally unique identifier (UUID a.k.a. GUID) of this interface. Each interface has such a local type mi::base::IInterface::IID with a distinct and unique value. The value can be passed to the mi::base::IInterface::get_interface(const Uuid&) methods, introduced below, and this is the mode in which it is normally used.
#include <mi/base/iinterface.h>
iptr
for an allocator object with the corresponding interface mi::base::IAllocator. You cannot directly cast the pointer to the corresponding interface pointer. Instead you need to use the mi::base::IInterface::get_interface(const Uuid&) method with the corresponding interface ID (IID) value of type mi::base::Uuid, cast the result and release the interface after you are done using it. You can obtain the necessary IID value by instantiating the IID
type that is locally embedded in each interface.iptr
refers to an object supporting an mi::base::IAllocator interface you must check that the result of the mi::base::IInterface::get_interface(const Uuid&) method call is not NULL
.Alternatively, you can use the more convenient and type-safe template version that eliminates the need for the subsequent static_cast
.
typedef Uuid_t<0,0,0,0,0,0,0,0,0,0,0> mi::base::IInterface::IID |
Declares the interface ID (IID) of this interface.
A local type in each interface type, which is distinct and unique for each interface. The type has a default constructor and the constructed value represents the universally unique identifier (UUID) for this interface. The local type is readily convertible to a mi::base::Uuid.
|
inlinestatic |
Compares the interface ID iid
against the interface ID of this interface.
true
if iid
== mi::base::IInterface::IID(), and false
otherwise.
|
pure virtual |
Returns the interface ID of the most derived interface.
Implemented in mi::base::Interface_implement_singleton< IAllocator >.
|
pure virtual |
Acquires a const interface from another.
If this interface supports the interface with the passed interface_id
, then the method returns a non-NULL
const
mi::base::IInterface* that can be casted via static_cast
to an interface pointer of the interface type corresponding to the passed interface_id
. Otherwise, the method returns NULL
.
In the case of a non-NULL
return value, the caller receives ownership of the new interface pointer, whose reference count has been retained once. The caller must release the returned interface pointer at the end to prevent a memory leak.
interface_id | Interface ID of the interface to acquire. |
Implemented in mi::base::Interface_implement_singleton< IAllocator >.
|
inline |
Acquires a const interface from another.
If this interface supports the interface T
, then the method returns a non-NULL
const
pointer to the interface T
. Otherwise, the method returns NULL
.
In the case of a non-NULL
return value, the caller receives ownership of the new interface pointer, whose reference count has been retained once. The caller must release the returned interface pointer at the end to prevent a memory leak.
This templated member function is a wrapper of the non-template variant for the user's convenience. It eliminates the need to apply static_cast
to the returned pointer, since the return type already is a const pointer to the type T
specified as template parameter.
T | The requested interface type. |
|
pure virtual |
Acquires a mutable interface from another.
If this interface supports the interface with the passed interface_id
, then the methods returns a non-NULL
mi::base::IInterface* that can be casted via static_cast
to an interface pointer of the interface type corresponding to the passed interface_id
. Otherwise, the method returns NULL
.
In the case of a non-NULL
return value, the caller receives ownership of the new interface pointer, whose reference count has been retained once. The caller must release the returned interface pointer at the end to prevent a memory leak.
interface_id | Interface ID of the interface to acquire. |
Implemented in mi::base::Interface_implement_singleton< IAllocator >.
|
inline |
Acquires a mutable interface from another.
If this interface supports the interface T
, then the method returns a non-NULL
pointer to the interface T
. Otherwise, the method returns NULL
.
In the case of a non-NULL
return value, the caller receives ownership of the new interface pointer, whose reference count has been retained once. The caller must release the returned interface pointer at the end to prevent a memory leak.
This templated member function is a wrapper of the non-template variant for the user's convenience. It eliminates the need to apply static_cast
to the returned pointer, since the return type already is a pointer to the type T
specified as template parameter.
T | The requested interface type. |
|
pure virtual |
Decrements the reference count.
Decrements the reference count of the object referenced through this interface and returns the new reference count. If the reference count dropped to zero, the object will be deleted. The operation is thread-safe.
Implemented in mi::base::Interface_implement_singleton< IAllocator >.
|
pure virtual |
Increments the reference count.
Increments the reference count of the object referenced through this interface and returns the new reference count. The operation is thread-safe.
Implemented in mi::base::Interface_implement_singleton< IAllocator >.