Iray SDK API nvidia_logo_transpbg.gif Up
iuser_class.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2024 NVIDIA Corporation. All rights reserved.
3 **************************************************************************************************/
6
7#ifndef MI_NEURAYLIB_IUSER_CLASS_H
8#define MI_NEURAYLIB_IUSER_CLASS_H
9
12#include <mi/base/lock.h>
14
15namespace mi {
16
17class IArray;
18
19namespace neuraylib {
20
21class IDeserializer;
22class ITransaction;
23
34class IUser_class : public
35 mi::base::Interface_declare<0xa8bbfac5,0xf1b0,0x4ab5,0x99,0x18,0x9a,0x46,0xf8,0xb8,0x32,0x2b,
36 neuraylib::ISerializable>
37{
38public:
48 virtual IUser_class* copy() const = 0;
49
57 virtual const char* get_class_name() const = 0;
58
70 virtual IArray* get_references( ITransaction* transaction) const = 0;
71
72 // Sets the embedded pointer.
73 //
74 // The embedded pointer is used for internal purposes. Users must not use this method.
75 virtual bool set_pointer( const base::IInterface* pointer) = 0;
76
77 // Returns the embedded pointer.
78 //
79 // The embedded pointer is used for internal purposes. Users must not use this method.
80 virtual const base::IInterface* get_pointer() const = 0;
81};
82
87template <Uint32 id1, Uint16 id2, Uint16 id3
88 , Uint8 id4, Uint8 id5, Uint8 id6, Uint8 id7
89 , Uint8 id8, Uint8 id9, Uint8 id10, Uint8 id11
90 , class I = IUser_class>
92{
93public:
96
98 User_class() : m_pointer( 0) { }
99
101 User_class( const User_class& other) : base::Interface_implement<I>( other), m_pointer( 0) { }
102
105 {
107 return *this;
108 }
109
112 {
113 mi_base_assert( m_pointer == 0);
114 }
115
117 virtual const char* get_class_name() const
118 {
119 return "User class";
120 }
121
123 virtual base::Uuid get_class_id() const
124 {
125 return IID();
126 }
127
128 // Overrides the standard release() implementation.
129 //
130 // If the release count drops to 1, and the embedded pointer is set, release it.
131 virtual Uint32 release() const
132 {
133 base::Lock::Block block( &m_pointer_lock);
136 if( count == 1) {
137 block.release();
139 }
140 if(( count == 2) && m_pointer) {
141 m_pointer->release();
142 m_pointer = 0;
143 }
145 }
146
147 // Sets the embedded pointer.
148 //
149 // The embedded pointer is used for internal purposes. Users must not use this method.
150 virtual bool set_pointer( const base::IInterface* pointer)
151 {
152 base::Lock::Block block( &m_pointer_lock);
153 if( m_pointer)
154 return false;
155 m_pointer = pointer;
156 if( m_pointer)
157 m_pointer->retain();
158 return true;
159 }
160
161 // Returns the embedded pointer.
162 //
163 // The embedded pointer is used for internal purposes. Users must not use this method.
164 virtual const base::IInterface* get_pointer() const
165 {
166 base::Lock::Block block( &m_pointer_lock);
167 if( m_pointer)
168 m_pointer->retain();
169 return m_pointer;
170 }
171
172private:
173 // The embedded pointer.
174 //
175 // The embedded pointer is used for internal purposes. Users must not access the pointer.
176 mutable const base::IInterface* m_pointer;
177
178 // The lock that protects the embedded pointer.
179 mutable base::Lock m_pointer_lock;
180};
181 // end group mi_neuray_plugins
183
184} // namespace neuraylib
185
186} // namespace mi
187
188#endif // MI_NEURAYLIB_IUSER_CLASS_H
This interface represents static arrays, i.e., arrays with a fixed number of elements.
Definition: iarray.h:37
The basic extensible interface.
Definition: iinterface.h:103
Mixin class template for deriving new interface declarations.
Definition: interface_declare.h:43
Mixin class template for deriving interface implementations.
Definition: interface_implement.h:41
Utility class to acquire a lock that is released by the destructor.
Definition: lock.h:61
Class template for a compile-time representation of universally unique identifiers (UUIDs or GUIDs).
Definition: uuid.h:122
A transaction provides a consistent view on the database.
Definition: itransaction.h:81
Abstract interface for user-defined classes.
Definition: iuser_class.h:37
virtual IArray * get_references(ITransaction *transaction) const =0
Returns the list of elements referenced by this element.
virtual IUser_class * copy() const =0
Creates a copy of the database element.
virtual const char * get_class_name() const =0
Returns a human readable identifier for the class this database element belongs to.
This mixin class should be used to implement the IUser_class interface.
Definition: iuser_class.h:92
base::Uuid_t< id1, ... > IID
Declares the class ID.
Definition: iuser_class.h:95
~User_class()
Destructor.
Definition: iuser_class.h:111
User_class()
Default constructor.
Definition: iuser_class.h:98
virtual Uint32 release() const
Decrements the reference count.
Definition: iuser_class.h:131
virtual base::Uuid get_class_id() const
Returns the class ID corresponding to the template parameters of this mixin class.
Definition: iuser_class.h:123
User_class & operator=(const User_class &other)
Assignment operator.
Definition: iuser_class.h:104
virtual const char * get_class_name() const
Returns a human readable class name.
Definition: iuser_class.h:117
User_class(const User_class &other)
Copy constructor.
Definition: iuser_class.h:101
#define mi_base_assert(expr)
Base API assertion macro (without message).
Definition: assert.h:94
virtual Uint32 release() const
Decrements the reference count.
Definition: interface_implement.h:103
virtual Uint32 retain() const =0
Increments the reference count.
Interface_implement<I> & operator=(const Interface_implement<I> &other)
Assignment operator.
Definition: interface_implement.h:66
Interface_implement(Uint32 initial=1)
Constructor.
Definition: interface_implement.h:48
virtual Uint32 release() const =0
Decrements the reference count.
virtual Uint32 retain() const
Increments the reference count.
Definition: interface_implement.h:93
void release()
Releases the lock.
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:49
unsigned char Uint8
8-bit unsigned integer.
Definition: types.h:47
unsigned short Uint16
16-bit unsigned integer.
Definition: types.h:48
Mixin class template for deriving new interface declarations.
Mixin class template for deriving interface implementations.
Serialization of objects to a byte stream.
Multithreading locks.
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: neuraylib.h:179
A 128 bit representation of a universally unique identifier (UUID or GUID).
Definition: uuid.h:26