Iray SDK API nvidia_logo_transpbg.gif Up
iuser_class.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2025 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
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
88template <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{
94public:
97
99 User_class() = default;
100
102 User_class( const User_class& other) : base::Interface_implement<I>( other) { }
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 = nullptr;
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
173private:
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 = nullptr;
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
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:67
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:82
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:93
~User_class()
Destructor.
Definition: iuser_class.h:112
base::Uuid_t< id1, ... > IID
Declares the class ID.
Definition: iuser_class.h:96
User_class()=default
Default constructor.
virtual base::Uuid get_class_id() const
Returns the class ID corresponding to the template parameters of this mixin class.
Definition: iuser_class.h:124
User_class & operator=(const User_class &other)
Assignment operator.
Definition: iuser_class.h:105
virtual const char * get_class_name() const
Returns a human readable class name.
Definition: iuser_class.h:118
User_class(const User_class &other)
Copy constructor.
Definition: iuser_class.h:102
#define mi_base_assert(expr)
Base API assertion macro (without message).
Definition: assert.h:86
Uint32 release() const override
Decrements the reference count.
Definition: interface_implement.h:101
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.
Uint32 retain() const override
Increments the reference count.
Definition: interface_implement.h:91
unsigned char Uint8
8-bit unsigned integer.
Definition: types.h:47
unsigned short Uint16
16-bit unsigned integer.
Definition: types.h:48
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:49
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