NVIDIA Iray API
 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, 2014 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 
16 namespace mi {
17 
18 class IArray;
19 class IDeserializer;
20 
21 namespace neuraylib {
22 
23 class ITransaction;
24 
29 class IUser_class : public
36  mi::base::Interface_declare<0xa8bbfac5,0xf1b0,0x4ab5,0x99,0x18,0x9a,0x46,0xf8,0xb8,0x32,0x2b,
37  ISerializable>
38 {
39 public:
49  virtual IUser_class* copy() const = 0;
50 
58  virtual const char* get_class_name() const = 0;
59 
71  virtual IArray* get_references( ITransaction* transaction) const = 0;
72 
73  // Sets the embedded pointer.
74  //
75  // The embedded pointer is used for internal purposes. Users must not use this method.
76  virtual bool set_pointer( const base::IInterface* pointer) = 0;
77 
78  // Returns the embedded pointer.
79  //
80  // The embedded pointer is used for internal purposes. Users must not use this method.
81  virtual const base::IInterface* get_pointer() const = 0;
82 };
83 
88 template <Uint32 id1, Uint16 id2, Uint16 id3
89  , Uint8 id4, Uint8 id5, Uint8 id6, Uint8 id7
90  , Uint8 id8, Uint8 id9, Uint8 id10, Uint8 id11
91  , class I = IUser_class>
93 {
94 public:
97 
99  User_class() : m_pointer( 0) { }
100 
102  User_class( const User_class& other) : base::Interface_implement<I>( other), m_pointer( 0) { }
103 
106  {
108  return *this;
109  }
110 
113  {
114  mi_base_assert( m_pointer == 0);
115  }
116 
118  virtual const char* get_class_name() const
119  {
120  return "User class";
121  }
122 
124  virtual base::Uuid get_class_id() const
125  {
126  return IID();
127  }
128 
129  // Overrides the standard release() implementation.
130  //
131  // If the release count drops to 1, and the embedded pointer is set, release it.
132  virtual Uint32 release() const
133  {
134  base::Lock::Block block( &m_pointer_lock);
137  if( count == 1) {
138  block.release();
140  }
141  if(( count == 2) && m_pointer) {
142  m_pointer->release();
143  m_pointer = 0;
144  }
146  }
147 
148  // Sets the embedded pointer.
149  //
150  // The embedded pointer is used for internal purposes. Users must not use this method.
151  virtual bool set_pointer( const base::IInterface* pointer)
152  {
153  base::Lock::Block block( &m_pointer_lock);
154  if( m_pointer)
155  return false;
156  m_pointer = pointer;
157  if( m_pointer)
158  m_pointer->retain();
159  return true;
160  }
161 
162  // Returns the embedded pointer.
163  //
164  // The embedded pointer is used for internal purposes. Users must not use this method.
165  virtual const base::IInterface* get_pointer() const
166  {
167  base::Lock::Block block( &m_pointer_lock);
168  if( m_pointer)
169  m_pointer->retain();
170  return m_pointer;
171  }
172 
173 private:
174  // The embedded pointer.
175  //
176  // The embedded pointer is used for internal purposes. Users must not access the pointer.
177  mutable const base::IInterface* m_pointer;
178 
179  // The lock that protects the embedded pointer.
180  mutable base::Lock m_pointer_lock;
181 };
182  // end group mi_neuray_plugins
184 
185 } // namespace neuraylib
186 
187 } // namespace mi
188 
189 #endif // MI_NEURAYLIB_IUSER_CLASS_H