Material Definition Language API nvidia_logo_transpbg.gif Up
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
interface_merger.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  * Copyright 2020 NVIDIA Corporation. All rights reserved.
3  **************************************************************************************************/
6 
7 #ifndef MI_BASE_INTERFACE_MERGER_H
8 #define MI_BASE_INTERFACE_MERGER_H
9 
10 #include <mi/base/iinterface.h>
11 
12 namespace mi {
13 namespace base {
14 
19 template <typename MAJOR, typename MINOR>
55  : public MAJOR,
56  public MINOR
57 {
58 public:
60  typedef MAJOR MAJOR_BASE;
61 
63  typedef MINOR MINOR_BASE;
64 
69  static bool compare_iid( const Uuid& iid) {
70  if( MAJOR::compare_iid( iid))
71  return true;
72  return MINOR::compare_iid( iid);
73  }
74 
79  const IInterface* get_interface( const Uuid& interface_id) const;
80 
84  template <class T>
85  const T* get_interface() const {
86  return static_cast<const T*>( get_interface( typename T::IID()));
87  }
88 
93  IInterface* get_interface( const Uuid& interface_id);
94 
98  template <class T>
100  return static_cast<T*>( get_interface( typename T::IID()));
101  }
102 
106  Uuid get_iid() const {
107  return MAJOR::get_iid();
108  }
109 
113  mi::Uint32 retain() const {
114  return MAJOR::retain();
115  }
116 
120  mi::Uint32 release() const {
121  return MAJOR::release();
122  }
123 
134  const MAJOR* cast_to_major() const {
135  return static_cast<const MAJOR*>( this);
136  }
137 
148  MAJOR* cast_to_major() {
149  return static_cast<MAJOR*>( this);
150  }
151 };
152 
153 template <typename MAJOR, typename MINOR>
155  const Uuid& interface_id) const
156 {
157  const IInterface* iinterface = MAJOR::get_interface( interface_id);
158  if( iinterface)
159  return iinterface;
160  return MINOR::get_interface_static( static_cast<const MINOR*>( this), interface_id);
161 }
162 
163 template <typename MAJOR, typename MINOR>
165  const Uuid& interface_id)
166 {
167  IInterface* iinterface = MAJOR::get_interface( interface_id);
168  if( iinterface)
169  return iinterface;
170  return MINOR::get_interface_static( static_cast<MINOR*>( this), interface_id);
171 }
172  // end group mi_base_iinterface
174 
175 } // namespace base
176 } // namespace mi
177 
178 #endif // MI_BASE_INTERFACE_MERGER_H