Material Definition Language API nvidia_logo_transpbg.gif Up
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
interface_implement.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  * Copyright 2019 NVIDIA Corporation. All rights reserved.
3  **************************************************************************************************/
6 
7 #ifndef MI_BASE_INTERFACE_IMPLEMENT_H
8 #define MI_BASE_INTERFACE_IMPLEMENT_H
9 
10 #include <mi/base/types.h>
11 #include <mi/base/uuid.h>
12 #include <mi/base/atom.h>
13 
14 namespace mi {
15 namespace base {
16 
21 // Forward declaration
22 class IInterface;
23 
39 template <class I>
40 class Interface_implement : public I
41 {
42 public:
47  : m_refcnt( initial)
48  {
49  }
50 
55  : m_refcnt( 1)
56  {
57  // avoid warning
58  (void) other;
59  }
60 
65  {
66  // Note: no call of operator= on m_refcount
67  // avoid warning
68  (void) other;
69  return *this;
70  }
71 
76  virtual Uint32 retain() const
77  {
78  return ++m_refcnt;
79  }
80 
86  virtual Uint32 release() const
87  {
88  Uint32 cnt = --m_refcnt;
89  if( !cnt)
90  delete this;
91  return cnt;
92  }
93 
104  virtual const IInterface* get_interface( const Uuid& interface_id) const
105  {
106  return I::get_interface_static( this, interface_id);
107  }
108 
119  virtual IInterface* get_interface( const Uuid& interface_id)
120  {
121  return I::get_interface_static( this, interface_id);
122  }
123 
124  using I::get_interface;
125 
127  Uuid get_iid() const
128  {
129  return typename I::IID();
130  }
131 
132 protected:
133  virtual ~Interface_implement() {}
134 
135 private:
136  mutable Atom32 m_refcnt;
137 };
138 
139 
157 template <class I1, class I2>
158 class Interface_implement_2 : public I1, public I2
159 {
160 public:
165  : m_refcnt( initial)
166  {
167  }
168 
173  : m_refcnt( 1)
174  {
175  // avoid warning
176  (void) other;
177  }
178 
183  {
184  // Note: no call of operator= on m_refcount
185  // avoid warning
186  (void) other;
187  return *this;
188  }
189 
194  virtual Uint32 retain() const
195  {
196  return ++m_refcnt;
197  }
198 
204  virtual Uint32 release() const
205  {
206  Uint32 cnt = --m_refcnt;
207  if( !cnt)
208  delete this;
209  return cnt;
210  }
211 
222  virtual const IInterface* get_interface( const Uuid& interface_id) const
223  {
224  const IInterface* iptr = I1::get_interface_static( static_cast<const I1*>(this),
225  interface_id);
226  if ( iptr == 0)
227  iptr = I2::get_interface_static( static_cast<const I2*>(this), interface_id);
228  return iptr;
229  }
230 
241  virtual IInterface* get_interface( const Uuid& interface_id)
242  {
243  IInterface* iptr = I1::get_interface_static(static_cast<I1*>(this),interface_id);
244  if ( iptr == 0)
245  iptr = I2::get_interface_static( static_cast<I2*>(this), interface_id);
246  return iptr;
247  }
248 
249  using I1::get_interface;
250 
252  Uuid get_iid() const
253  {
254  return typename I1::IID();
255  }
256 
257 protected:
258  virtual ~Interface_implement_2() {}
259 
260 private:
261  mutable Atom32 m_refcnt;
262 };
263 
264 
281 template <class I>
283 {
284 public:
289  virtual Uint32 retain() const
290  {
291  return 1;
292  }
293 
298  virtual Uint32 release() const
299  {
300  return 1;
301  }
302 
313  virtual const IInterface* get_interface( const Uuid& interface_id) const
314  {
315  return I::get_interface_static( this, interface_id);
316  }
317 
328  virtual IInterface* get_interface( const Uuid& interface_id)
329  {
330  return I::get_interface_static( this, interface_id);
331  }
332 
333  using I::get_interface;
334 
336  Uuid get_iid() const
337  {
338  return typename I::IID();
339  }
340 
341 protected:
342  virtual ~Interface_implement_singleton() {}
343 };
344 
345  // end group mi_base_iinterface
347 
348 } // namespace base
349 } // namespace mi
350 
351 #endif // MI_BASE_INTERFACE_IMPLEMENT_H