interface_merger.h File Reference
Description
Mixin class template to merge an interface with an implementation.
Code Example
interface_merger.h
/***************************************************************************************************
* Copyright 2024 NVIDIA Corporation. All rights reserved.
**************************************************************************************************/
#ifndef MI_BASE_INTERFACE_MERGER_H
#define MI_BASE_INTERFACE_MERGER_H
#include <mi/base/iinterface.h>
namespace mi {
namespace base {
template <typename MAJOR, typename MINOR>
class Interface_merger
: public MAJOR,
public MINOR
{
public:
typedef MAJOR MAJOR_BASE;
typedef MINOR MINOR_BASE;
typedef Interface_merger< MAJOR, MINOR>
Self;
#if __cplusplus >= 201103L
using MAJOR::MAJOR;
#endif
static bool compare_iid( const Uuid& iid)
{
if( MAJOR::compare_iid( iid))
return true;
return MINOR::compare_iid( iid);
}
const IInterface* get_interface( const Uuid& interface_id) const;
template <class T>
const T* get_interface() const
{
return static_cast<const T*>( get_interface( typename T::IID()));
}
IInterface* get_interface( const Uuid& interface_id);
template <class T>
T* get_interface()
{
return static_cast<T*>( get_interface( typename T::IID()));
}
Uuid
get_iid() const { return MAJOR::get_iid(); }
mi::Uint32
retain() const { return MAJOR::retain(); }
mi::Uint32
release() const { return MAJOR::release(); }
const MAJOR* cast_to_major() const { return static_cast<const MAJOR*>( this); }
MAJOR* cast_to_major() { return static_cast<MAJOR*>( this); }
};
template <typename MAJOR, typename MINOR>
const IInterface* Interface_merger< MAJOR, MINOR>::get_interface(
const Uuid& interface_id) const
{
const IInterface* iinterface = MAJOR::get_interface( interface_id);
if( iinterface)
return iinterface;
return MINOR::get_interface_static( static_cast<const MINOR*>( this), interface_id);
}
template <typename MAJOR, typename MINOR>
IInterface* Interface_merger< MAJOR, MINOR>::get_interface(
const Uuid& interface_id)
{
IInterface* iinterface = MAJOR::get_interface( interface_id);
if( iinterface)
return iinterface;
return MINOR::get_interface_static( static_cast<MINOR*>( this), interface_id);
}
// end group mi_base_iinterface
} // namespace base
} // namespace mi
#endif // MI_BASE_INTERFACE_MERGER_H
Namespaces
- namespace
- Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH. More...
- namespace
- Namespace for the Base API. More...
Classes
- class
- This mixin merges the implementation of one interface with a second interface. More...