NVIDIA Iray API Home  Up
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
iuser_class.h
Go to the documentation of this file.
1 //*****************************************************************************
2 // Copyright 1986, 2016 NVIDIA Corporation. All rights reserved.
3 //*****************************************************************************
6 //*****************************************************************************
7 
8 #ifndef MI_NEURAYLIB_IUSER_CLASS_H
9 #define MI_NEURAYLIB_IUSER_CLASS_H
10 
13 #include <mi/base/lock.h>
15 #include <mi/neuraylib/version.h>
16 
17 namespace mi {
18 
19 class IArray;
20 
21 namespace neuraylib {
22 
23 class IDeserializer;
24 class ITransaction;
25 
30 class IUser_class : public
37  mi::base::Interface_declare<0xa8bbfac5,0xf1b0,0x4ab5,0x99,0x18,0x9a,0x46,0xf8,0xb8,0x32,0x2b,
38  neuraylib::ISerializable>
39 {
40 public:
50  virtual IUser_class* copy() const = 0;
51 
59  virtual const char* get_class_name() const = 0;
60 
72  virtual IArray* get_references( ITransaction* transaction) const = 0;
73 
74  // Sets the embedded pointer.
75  //
76  // The embedded pointer is used for internal purposes. Users must not use this method.
77  virtual bool set_pointer( const base::IInterface* pointer) = 0;
78 
79  // Returns the embedded pointer.
80  //
81  // The embedded pointer is used for internal purposes. Users must not use this method.
82  virtual const base::IInterface* get_pointer() const = 0;
83 };
84 
89 template <Uint32 id1, Uint16 id2, Uint16 id3
90  , Uint8 id4, Uint8 id5, Uint8 id6, Uint8 id7
91  , Uint8 id8, Uint8 id9, Uint8 id10, Uint8 id11
92  , class I = IUser_class>
94 {
95 public:
98 
100  User_class() : m_pointer( 0) { }
101 
103  User_class( const User_class& other) : base::Interface_implement<I>( other), m_pointer( 0) { }
104 
107  {
109  return *this;
110  }
111 
114  {
115  mi_base_assert( m_pointer == 0);
116  }
117 
119  virtual const char* get_class_name() const
120  {
121  return "User class";
122  }
123 
125  virtual base::Uuid get_class_id() const
126  {
127  return IID();
128  }
129 
130  // Overrides the standard release() implementation.
131  //
132  // If the release count drops to 1, and the embedded pointer is set, release it.
133  virtual Uint32 release() const
134  {
135  base::Lock::Block block( &m_pointer_lock);
138  if( count == 1) {
139  block.release();
141  }
142  if(( count == 2) && m_pointer) {
143  m_pointer->release();
144  m_pointer = 0;
145  }
147  }
148 
149  // Sets the embedded pointer.
150  //
151  // The embedded pointer is used for internal purposes. Users must not use this method.
152  virtual bool set_pointer( const base::IInterface* pointer)
153  {
154  base::Lock::Block block( &m_pointer_lock);
155  if( m_pointer)
156  return false;
157  m_pointer = pointer;
158  if( m_pointer)
159  m_pointer->retain();
160  return true;
161  }
162 
163  // Returns the embedded pointer.
164  //
165  // The embedded pointer is used for internal purposes. Users must not use this method.
166  virtual const base::IInterface* get_pointer() const
167  {
168  base::Lock::Block block( &m_pointer_lock);
169  if( m_pointer)
170  m_pointer->retain();
171  return m_pointer;
172  }
173 
174 private:
175  // The embedded pointer.
176  //
177  // The embedded pointer is used for internal purposes. Users must not access the pointer.
178  mutable const base::IInterface* m_pointer;
179 
180  // The lock that protects the embedded pointer.
181  mutable base::Lock m_pointer_lock;
182 };
183  // end group mi_neuray_plugins
185 
186 } // namespace neuraylib
187 
188 #ifdef MI_NEURAYLIB_DEPRECATED_NAMESPACE_MI_TRANSITION
189 using neuraylib::IDeserializer;
190 using neuraylib::ISerializable;
191 #endif // MI_NEURAYLIB_DEPRECATED_NAMESPACE_MI_TRANSITION
192 
193 } // namespace mi
194 
195 #endif // MI_NEURAYLIB_IUSER_CLASS_H