Material Definition Language API nvidia_logo_transpbg.gif Up
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
set_get.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  * Copyright 2019 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>
16 #include <mi/neuraylib/imatrix.h>
17 #include <mi/neuraylib/inumber.h>
18 #include <mi/neuraylib/iref.h>
19 #include <mi/neuraylib/ispectrum.h>
20 #include <mi/neuraylib/istring.h>
21 #include <mi/neuraylib/iuuid.h>
22 #include <mi/neuraylib/ivector.h>
24 
25 namespace mi {
26 
31 template<class T>
52 mi::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 
70 inline 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 
93 inline mi::Sint32 set_value( mi::IData* data, const mi::base::Uuid& value)
94 {
96  if( u.is_valid_interface()) {
97  u->set_uuid( value);
98  return 0;
99  }
100  return -1;
101 }
102 
113 template <class T, Size DIM>
115 {
116  typedef typename mi::Vector_type_traits<T,DIM>::Interface_type Vector_interface_type;
117  mi::base::Handle<Vector_interface_type> v( data->get_interface<Vector_interface_type>());
118  if( v.is_valid_interface()) {
119  v->set_value( value);
120  return 0;
121  }
122  return -1;
123 }
124 
135 template <class T, Size ROW, Size COL>
137 {
138  typedef typename mi::Matrix_type_traits<T,ROW,COL>::Interface_type Matrix_interface_type;
139  mi::base::Handle<Matrix_interface_type> m( data->get_interface<Matrix_interface_type>());
140  if( m.is_valid_interface()) {
141  m->set_value( value);
142  return 0;
143  }
144  return -1;
145 }
146 
150 inline mi::Sint32 set_value( mi::IData* data, const mi::Color& value)
151 {
153  if( c.is_valid_interface()) {
154  c->set_value( value);
155  return 0;
156  }
158  if( c3.is_valid_interface()) {
159  c3->set_value( value);
160  return 0;
161  }
162  return -1;
163 }
164 
168 inline mi::Sint32 set_value( mi::IData* data, const mi::Spectrum& value)
169 {
171  if( s.is_valid_interface()) {
172  s->set_value( value);
173  return 0;
174  }
175  return -1;
176 }
177 
181 inline mi::Sint32 set_value( mi::IData* data, const mi::Bbox3& value)
182 {
184  if( b.is_valid_interface()) {
185  b->set_value( value);
186  return 0;
187  }
188  return -1;
189 }
190 
202 template<class T>
203 mi::Sint32 set_value( mi::IData* data, mi::Size index, const T& value)
204 {
206  if( c.is_valid_interface()) {
208  if( !d.is_valid_interface())
209  return -3;
210  return set_value( d.get(), value);
211  }
212  return -1;
213 }
214 
226 template<class T>
227 mi::Sint32 set_value( mi::IData* data, const char* key, const T& value)
228 {
230  if( c.is_valid_interface()) {
232  if( !d.is_valid_interface())
233  return -3;
234  return set_value( d.get(), value);
235  }
236  return -1;
237 }
238 
258 template<class T>
259 mi::Sint32 get_value( const mi::IData* data, T& value)
260 {
262  if( v.is_valid_interface()) {
263  v->get_value( value);
264  return 0;
265  }
266 // disable C4800: 'mi::Sint32' : forcing value to bool 'true' or 'false' (performance warning)
267 // disable C4800: 'mi::Uint32' : forcing value to bool 'true' or 'false' (performance warning)
268 #ifdef MI_COMPILER_MSC
269 #pragma warning( push )
270 #pragma warning( disable : 4800 )
271 #endif
273  if( e.is_valid_interface()) {
274  value = static_cast<T>( e->get_value());
275  return 0;
276  }
277 #ifdef MI_COMPILER_MSC
278 #pragma warning( pop )
279 #endif
280  return -1;
281 }
282 
286 inline mi::Sint32 get_value( const mi::IData* data, const char*& value)
287 {
289  if( i.is_valid_interface()) {
290  value = i->get_c_str();
291  return 0;
292  }
294  if( r.is_valid_interface()) {
295  value = r->get_reference_name();
296  return 0;
297  }
299  if( e.is_valid_interface()) {
300  value = e->get_value_by_name();
301  return 0;
302  }
303  return -1;
304 }
305 
309 inline mi::Sint32 get_value( const mi::IData* data, mi::base::Uuid& value)
310 {
312  if( u.is_valid_interface()) {
313  value = u->get_uuid();
314  return 0;
315  }
316  return -1;
317 }
318 
329 template <class T, Size DIM>
331 {
332  typedef typename mi::Vector_type_traits<T,DIM>::Interface_type Vector_interface_type;
333  mi::base::Handle<const Vector_interface_type> v( data->get_interface<Vector_interface_type>());
334  if( v.is_valid_interface()) {
335  value = v->get_value();
336  return 0;
337  }
338  return -1;
339 }
340 
351 template <class T, Size ROW, Size COL>
353 {
354  typedef typename mi::Matrix_type_traits<T,ROW,COL>::Interface_type Matrix_interface_type;
355  mi::base::Handle<const Matrix_interface_type> m( data->get_interface<Matrix_interface_type>());
356  if( m.is_valid_interface()) {
357  value = m->get_value();
358  return 0;
359  }
360  return -1;
361 }
362 
366 inline mi::Sint32 get_value( const mi::IData* data, mi::Color& value)
367 {
369  if( c.is_valid_interface()) {
370  value = c->get_value();
371  return 0;
372  }
374  if( c3.is_valid_interface()) {
375  value = c3->get_value();
376  return 0;
377  }
378  return -1;
379 }
380 
384 inline mi::Sint32 get_value( const mi::IData* data, mi::Spectrum& value)
385 {
387  if( s.is_valid_interface()) {
388  value = s->get_value();
389  return 0;
390  }
391  return -1;
392 }
393 
397 inline mi::Sint32 get_value( const mi::IData* data, mi::Bbox3& value)
398 {
400  if( b.is_valid_interface()) {
401  value = b->get_value();
402  return 0;
403  }
404  return -1;
405 }
406 
417 template<class T>
418 mi::Sint32 get_value( const mi::IData* data, mi::Size index, T& value)
419 {
421  if( c.is_valid_interface()) {
423  if( !d.is_valid_interface())
424  return -3;
425  return get_value( d.get(), value);
426  }
427  return -1;
428 }
429 
440 template<class T>
441 mi::Sint32 get_value( const mi::IData* data, const char* key, T& value)
442 {
444  if( c.is_valid_interface()) {
446  if( !d.is_valid_interface())
447  return -3;
448  return get_value( d.get(), value);
449  }
450  return -1;
451 }
452  // end group mi_neuray_types
454 
459 template<class T>
473  mi::neuraylib::IAttribute_set* attribute_set, const char* name, const T& value)
474 {
475  mi::base::Handle<mi::IData> data( attribute_set->edit_attribute<mi::IData>( name));
476  if( !data.is_valid_interface())
477  return -4;
478  return set_value( data.get(), value);
479 }
480 
495 template<class T>
497  mi::neuraylib::IAttribute_set* attribute_set, const char* name, mi::Size index, const T& value)
498 {
499  mi::base::Handle<mi::IData> data( attribute_set->edit_attribute<mi::IData>( name));
500  if( !data.is_valid_interface())
501  return -4;
502  return set_value( data.get(), index, value);
503 }
504 
519 template<class T>
521  mi::neuraylib::IAttribute_set* attribute_set, const char* name, const char* key, const T& value)
522 {
523  mi::base::Handle<mi::IData> data( attribute_set->edit_attribute<mi::IData>( name));
524  if( !data.is_valid_interface())
525  return -4;
526  return set_value( data.get(), key, value);
527 }
528 
540 template<class T>
542  const mi::neuraylib::IAttribute_set* attribute_set, const char* name, T& value)
543 {
544  mi::base::Handle<const mi::IData> data( attribute_set->access_attribute<mi::IData>( name));
545  if( !data.is_valid_interface())
546  return -4;
547  return get_value( data.get(), value);
548 }
549 
563 template<class T>
565  const mi::neuraylib::IAttribute_set* attribute_set, const char* name, mi::Size index, T& value)
566 {
567  mi::base::Handle<const mi::IData> data( attribute_set->access_attribute<mi::IData>( name));
568  if( !data.is_valid_interface())
569  return -4;
570  return get_value( data.get(), index, value);
571 }
572 
586 template<class T>
588  const mi::neuraylib::IAttribute_set* attribute_set, const char* name, const char* key, T& value)
589 {
590  mi::base::Handle<const mi::IData> data( attribute_set->access_attribute<mi::IData>( name));
591  if( !data.is_valid_interface())
592  return -4;
593  return get_value( data.get(), key, value);
594 }
595  // end group mi_neuray_types
597 
598 } // namespace mi
599 
600 #endif // MI_NEURAYLIB_SET_GET_H