NVIDIA Iray API
 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 1986, 2014 NVIDIA Corporation. All rights reserved.
3 //*****************************************************************************
6 //*****************************************************************************
7 
8 #ifndef MI_BASE_INTERFACE_IMPLEMENT_H
9 #define MI_BASE_INTERFACE_IMPLEMENT_H
10 
11 #include <mi/base/types.h>
12 #include <mi/base/uuid.h>
13 #include <mi/base/atom.h>
14 
15 namespace mi {
16 namespace base {
17 
22 // Forward declaration
23 class IInterface;
24 
40 template <class I>
41 class Interface_implement : public I
42 {
43 public:
48  : m_refcnt( initial)
49  {
50  }
51 
56  : m_refcnt( 1)
57  {
58  // avoid warning
59  (void) other;
60  }
61 
66  {
67  // Note: no call of operator= on m_refcount
68  // avoid warning
69  (void) other;
70  return *this;
71  }
72 
77  virtual Uint32 retain() const
78  {
79  return ++m_refcnt;
80  }
81 
87  virtual Uint32 release() const
88  {
89  Uint32 cnt = --m_refcnt;
90  if( !cnt)
91  delete this;
92  return cnt;
93  }
94 
105  virtual const IInterface* get_interface( const Uuid& interface_id) const
106  {
107  return I::get_interface_static( this, interface_id);
108  }
109 
120  virtual IInterface* get_interface( const Uuid& interface_id)
121  {
122  return I::get_interface_static( this, interface_id);
123  }
124 
125  using I::get_interface;
126 
128  Uuid get_iid() const
129  {
130  return typename I::IID();
131  }
132 
133 protected:
134  virtual ~Interface_implement() {}
135 
136 private:
137  mutable Atom32 m_refcnt;
138 };
139 
140 
158 template <class I1, class I2>
159 class Interface_implement_2 : public I1, public I2
160 {
161 public:
166  : m_refcnt( initial)
167  {
168  }
169 
174  : m_refcnt( 1)
175  {
176  // avoid warning
177  (void) other;
178  }
179 
184  {
185  // Note: no call of operator= on m_refcount
186  // avoid warning
187  (void) other;
188  return *this;
189  }
190 
195  virtual Uint32 retain() const
196  {
197  return ++m_refcnt;
198  }
199 
205  virtual Uint32 release() const
206  {
207  Uint32 cnt = --m_refcnt;
208  if( !cnt)
209  delete this;
210  return cnt;
211  }
212 
223  virtual const IInterface* get_interface( const Uuid& interface_id) const
224  {
225  const IInterface* iptr = I1::get_interface_static( static_cast<const I1*>(this),
226  interface_id);
227  if ( iptr == 0)
228  iptr = I2::get_interface_static( static_cast<const I2*>(this), interface_id);
229  return iptr;
230  }
231 
242  virtual IInterface* get_interface( const Uuid& interface_id)
243  {
244  IInterface* iptr = I1::get_interface_static(static_cast<I1*>(this),interface_id);
245  if ( iptr == 0)
246  iptr = I2::get_interface_static( static_cast<I2*>(this), interface_id);
247  return iptr;
248  }
249 
250  using I1::get_interface;
251 
253  Uuid get_iid() const
254  {
255  return typename I1::IID();
256  }
257 
258 protected:
259  virtual ~Interface_implement_2() {}
260 
261 private:
262  mutable Atom32 m_refcnt;
263 };
264 
265 
282 template <class I>
284 {
285 public:
290  virtual Uint32 retain() const
291  {
292  return 1;
293  }
294 
299  virtual Uint32 release() const
300  {
301  return 1;
302  }
303 
314  virtual const IInterface* get_interface( const Uuid& interface_id) const
315  {
316  return I::get_interface_static( this, interface_id);
317  }
318 
329  virtual IInterface* get_interface( const Uuid& interface_id)
330  {
331  return I::get_interface_static( this, interface_id);
332  }
333 
334  using I::get_interface;
335 
337  Uuid get_iid() const
338  {
339  return typename I::IID();
340  }
341 
342 protected:
343  virtual ~Interface_implement_singleton() {}
344 };
345 
346  // end group mi_base_iinterface
348 
349 } // namespace base
350 } // namespace mi
351 
352 #endif // MI_BASE_INTERFACE_IMPLEMENT_H