Iray SDK API nvidia_logo_transpbg.gif Up
set_get.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2024 NVIDIA Corporation. All rights reserved.
3 **************************************************************************************************/
6
7#ifndef MI_NEURAYLIB_SET_GET_H
8#define MI_NEURAYLIB_SET_GET_H
9
10#include <mi/base/config.h>
11#include <mi/base/handle.h>
13#include <mi/neuraylib/ibbox.h>
14#include <mi/neuraylib/icolor.h>
15#include <mi/neuraylib/ienum.h>
18#include <mi/neuraylib/iref.h>
21#include <mi/neuraylib/iuuid.h>
24
25namespace mi {
26
51template<class T>
52mi::Sint32 set_value( mi::IData* data, const T& value)
53{
55 if( v.is_valid_interface()) {
56 v->set_value( value);
57 return 0;
58 }
60 if( e.is_valid_interface()) {
61 mi::Sint32 result = e->set_value( static_cast<mi::Sint32>( value));
62 return result == 0 ? 0 : -2;
63 }
64 return -1;
65}
66
70inline mi::Sint32 set_value( mi::IData* data, const char* value)
71{
73 if( s.is_valid_interface()) {
74 s->set_c_str( value);
75 return 0;
76 }
78 if( r.is_valid_interface()) {
79 mi::Sint32 result = r->set_reference( value);
80 return result == 0 ? 0 : -2;
81 }
83 if( e.is_valid_interface()) {
84 mi::Sint32 result = e->set_value_by_name( value);
85 return result == 0 ? 0 : -2;
86 }
87 return -1;
88}
89
93inline mi::Sint32 set_value( mi::IData* data, const std::string& value)
94{
95 return set_value(data,value.c_str());
96}
97
101inline mi::Sint32 set_value( mi::IData* data, const mi::base::Uuid& value)
102{
104 if( u.is_valid_interface()) {
105 u->set_uuid( value);
106 return 0;
107 }
108 return -1;
109}
110
121template <class T, Size DIM>
123{
124 typedef typename mi::Vector_type_traits<T,DIM>::Interface_type Vector_interface_type;
125 mi::base::Handle<Vector_interface_type> v( data->get_interface<Vector_interface_type>());
126 if( v.is_valid_interface()) {
127 v->set_value( value);
128 return 0;
129 }
130 return -1;
131}
132
143template <class T, Size ROW, Size COL>
145{
146 typedef typename mi::Matrix_type_traits<T,ROW,COL>::Interface_type Matrix_interface_type;
147 mi::base::Handle<Matrix_interface_type> m( data->get_interface<Matrix_interface_type>());
148 if( m.is_valid_interface()) {
149 m->set_value( value);
150 return 0;
151 }
152 return -1;
153}
154
158inline mi::Sint32 set_value( mi::IData* data, const mi::Color& value)
159{
161 if( c.is_valid_interface()) {
162 c->set_value( value);
163 return 0;
164 }
166 if( c3.is_valid_interface()) {
167 c3->set_value( value);
168 return 0;
169 }
170 return -1;
171}
172
176inline mi::Sint32 set_value( mi::IData* data, const mi::Spectrum& value)
177{
179 if( s.is_valid_interface()) {
180 s->set_value( value);
181 return 0;
182 }
183 return -1;
184}
185
189inline mi::Sint32 set_value( mi::IData* data, const mi::Bbox3& value)
190{
192 if( b.is_valid_interface()) {
193 b->set_value( value);
194 return 0;
195 }
196 return -1;
197}
198
210template<class T>
211mi::Sint32 set_value( mi::IData* data, mi::Size index, const T& value)
212{
214 if( c.is_valid_interface()) {
215 mi::base::Handle<mi::IData> d( c->get_value<mi::IData>( index));
216 if( !d.is_valid_interface())
217 return -3;
218 return set_value( d.get(), value);
219 }
220 return -1;
221}
222
234template<class T>
235mi::Sint32 set_value( mi::IData* data, const char* key, const T& value)
236{
238 if( c.is_valid_interface()) {
239 mi::base::Handle<mi::IData> d( c->get_value<mi::IData>( key));
240 if( !d.is_valid_interface())
241 return -3;
242 return set_value( d.get(), value);
243 }
244 return -1;
245}
246
266template<class T>
267mi::Sint32 get_value( const mi::IData* data, T& value)
268{
270 if( v.is_valid_interface()) {
271 v->get_value( value);
272 return 0;
273 }
274// disable C4800: 'mi::Sint32' : forcing value to bool 'true' or 'false' (performance warning)
275// disable C4800: 'mi::Uint32' : forcing value to bool 'true' or 'false' (performance warning)
276#ifdef MI_COMPILER_MSC
277#pragma warning( push )
278#pragma warning( disable : 4800 )
279#endif
281 if( e.is_valid_interface()) {
282 value = static_cast<T>( e->get_value());
283 return 0;
284 }
285#ifdef MI_COMPILER_MSC
286#pragma warning( pop )
287#endif
288 return -1;
289}
290
294inline mi::Sint32 get_value( const mi::IData* data, const char*& value)
295{
297 if( i.is_valid_interface()) {
298 value = i->get_c_str();
299 return 0;
300 }
302 if( r.is_valid_interface()) {
303 value = r->get_reference_name();
304 return 0;
305 }
307 if( e.is_valid_interface()) {
308 value = e->get_value_by_name();
309 return 0;
310 }
311 return -1;
312}
313
317inline mi::Sint32 get_value( const mi::IData* data, mi::base::Uuid& value)
318{
320 if( u.is_valid_interface()) {
321 value = u->get_uuid();
322 return 0;
323 }
324 return -1;
325}
326
337template <class T, Size DIM>
339{
340 typedef typename mi::Vector_type_traits<T,DIM>::Interface_type Vector_interface_type;
341 mi::base::Handle<const Vector_interface_type> v( data->get_interface<Vector_interface_type>());
342 if( v.is_valid_interface()) {
343 value = v->get_value();
344 return 0;
345 }
346 return -1;
347}
348
359template <class T, Size ROW, Size COL>
361{
362 typedef typename mi::Matrix_type_traits<T,ROW,COL>::Interface_type Matrix_interface_type;
363 mi::base::Handle<const Matrix_interface_type> m( data->get_interface<Matrix_interface_type>());
364 if( m.is_valid_interface()) {
365 value = m->get_value();
366 return 0;
367 }
368 return -1;
369}
370
374inline mi::Sint32 get_value( const mi::IData* data, mi::Color& value)
375{
377 if( c.is_valid_interface()) {
378 value = c->get_value();
379 return 0;
380 }
382 if( c3.is_valid_interface()) {
383 value = c3->get_value();
384 return 0;
385 }
386 return -1;
387}
388
392inline mi::Sint32 get_value( const mi::IData* data, mi::Spectrum& value)
393{
395 if( s.is_valid_interface()) {
396 value = s->get_value();
397 return 0;
398 }
399 return -1;
400}
401
405inline mi::Sint32 get_value( const mi::IData* data, mi::Bbox3& value)
406{
408 if( b.is_valid_interface()) {
409 value = b->get_value();
410 return 0;
411 }
412 return -1;
413}
414
425template<class T>
426mi::Sint32 get_value( const mi::IData* data, mi::Size index, T& value)
427{
429 if( c.is_valid_interface()) {
430 mi::base::Handle<const mi::IData> d( c->get_value<mi::IData>( index));
431 if( !d.is_valid_interface())
432 return -3;
433 return get_value( d.get(), value);
434 }
435 return -1;
436}
437
448template<class T>
449mi::Sint32 get_value( const mi::IData* data, const char* key, T& value)
450{
452 if( c.is_valid_interface()) {
453 mi::base::Handle<const mi::IData> d( c->get_value<mi::IData>( key));
454 if( !d.is_valid_interface())
455 return -3;
456 return get_value( d.get(), value);
457 }
458 return -1;
459}
460 // end group mi_neuray_types
462
479template<class T>
481 mi::neuraylib::IAttribute_set* attribute_set, const char* name, const T& value)
482{
483 mi::base::Handle<mi::IData> data( attribute_set->edit_attribute<mi::IData>( name));
484 if( !data.is_valid_interface())
485 return -4;
486 return set_value( data.get(), value);
487}
488
503template<class T>
505 mi::neuraylib::IAttribute_set* attribute_set, const char* name, mi::Size index, const T& value)
506{
507 mi::base::Handle<mi::IData> data( attribute_set->edit_attribute<mi::IData>( name));
508 if( !data.is_valid_interface())
509 return -4;
510 return set_value( data.get(), index, value);
511}
512
527template<class T>
529 mi::neuraylib::IAttribute_set* attribute_set, const char* name, const char* key, const T& value)
530{
531 mi::base::Handle<mi::IData> data( attribute_set->edit_attribute<mi::IData>( name));
532 if( !data.is_valid_interface())
533 return -4;
534 return set_value( data.get(), key, value);
535}
536
548template<class T>
550 const mi::neuraylib::IAttribute_set* attribute_set, const char* name, T& value)
551{
553 if( !data.is_valid_interface())
554 return -4;
555 return get_value( data.get(), value);
556}
557
571template<class T>
573 const mi::neuraylib::IAttribute_set* attribute_set, const char* name, mi::Size index, T& value)
574{
576 if( !data.is_valid_interface())
577 return -4;
578 return get_value( data.get(), index, value);
579}
580
594template<class T>
596 const mi::neuraylib::IAttribute_set* attribute_set, const char* name, const char* key, T& value)
597{
599 if( !data.is_valid_interface())
600 return -4;
601 return get_value( data.get(), key, value);
602}
603 // end group mi_neuray_types
605
606} // namespace mi
607
608#endif // MI_NEURAYLIB_SET_GET_H
This interface represents bounding boxes.
Definition: ibbox.h:28
This interface represents RGB colors.
Definition: icolor.h:52
This interface represents RGBA colors.
Definition: icolor.h:28
This interface represents collections.
Definition: idata.h:350
This interface is the base interface of all types.
Definition: idata.h:297
This interface represents enums.
Definition: ienum.h:39
This interface represents simple numeric types.
Definition: inumber.h:25
A reference is an object that acts as a pointer to other database elements.
Definition: iref.h:25
This interface represents spectrums.
Definition: ispectrum.h:28
A simple string class.
Definition: istring.h:22
This interface represents UUIDs.
Definition: iuuid.h:24
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
Axis-aligned N-dimensional bounding box class template of fixed dimension.
Definition: bbox.h:74
Standard RGBA color class with floating point elements and operations.
Definition: color.h:81
NxM-dimensional matrix class template of fixed dimensions.
Definition: matrix.h:367
Spectrum with floating point elements and operations.
Definition: spectrum.h:53
Fixed-size math vector class template with generic operations.
Definition: vector.h:286
The attribute set comprises all attributes attached to a database element.
Definition: iattribute_set.h:332
virtual IData * edit_attribute(const char *name)=0
Returns a mutable pointer to the attribute name.
virtual const IData * access_attribute(const char *name) const =0
Returns a const pointer to the attribute name.
Configuration of the Base API.
virtual const IInterface * get_interface(const Uuid &interface_id) const =0
Acquires a const interface from another.
Interface * get() const
Access to the interface. Returns 0 for an invalid interface.
Definition: handle.h:294
bool is_valid_interface() const
Returns true if the interface is valid.
Definition: handle.h:291
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
signed int Sint32
32-bit signed integer.
Definition: types.h:46
mi::Sint32 set_value(mi::IData *data, const T &value)
Simplifies setting the value of mi::IData from the corresponding classes from the base and math API.
Definition: set_get.h:52
mi::Sint32 get_value(const mi::IData *data, T &value)
Simplifies reading the value of mi::IData into the corresponding classes from the base and math API.
Definition: set_get.h:267
Smart-pointer handle class for interfaces, const and non-const version.
Base class for database elements with attributes.
Bounding box type.
Color type.
Numeric types.
Matrix types.
Numeric types.
Type that holds a reference to a database element.
Spectrum type.
String type.
UUID type.
Vector types.
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
Type traits.