NVIDIA Iray API
 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 1986, 2014 NVIDIA Corporation. All rights reserved.
3 //*****************************************************************************
6 //*****************************************************************************
7 
8 #ifndef MI_NEURAYLIB_SET_GET_H
9 #define MI_NEURAYLIB_SET_GET_H
10 
11 #include <mi/base/config.h>
12 #include <mi/base/handle.h>
15 #include <mi/neuraylib/ibbox.h>
16 #include <mi/neuraylib/icolor.h>
17 #include <mi/neuraylib/ienum.h>
18 #include <mi/neuraylib/imatrix.h>
19 #include <mi/neuraylib/iparameter.h>
20 #include <mi/neuraylib/iref.h>
21 #include <mi/neuraylib/ispectrum.h>
22 #include <mi/neuraylib/istring.h>
23 #include <mi/neuraylib/itemporary.h>
24 #include <mi/neuraylib/iuuid.h>
25 #include <mi/neuraylib/ivalue.h>
26 #include <mi/neuraylib/ivector.h>
28 
29 namespace mi {
30 
35 template<class T>
72 mi::Sint32 set_value( mi::IData* data, const T& value)
73 {
75  if( v.is_valid_interface()) {
76  v->set_value( value);
77  return 0;
78  }
80  if( a.is_valid_interface()) {
81  a->set_reference( static_cast<const char*>( 0));
83  return set_value( d.get(), value);
84  }
86  if( e.is_valid_interface()) {
87  mi::Sint32 result = e->set_value( static_cast<mi::Sint32>( value));
88  return result == 0 ? 0 : -2;
89  }
91  if( p.is_valid_interface()) {
92  p->set_value( static_cast<mi::Uint32>( value));
93  return 0;
94  }
96  if( t.is_valid_interface()) {
97  t->set_value( static_cast<mi::Uint32>( value));
98  return 0;
99  }
100  return -1;
101 }
102 
106 inline mi::Sint32 set_value( mi::IData* data, const char* value)
107 {
109  if( s.is_valid_interface()) {
110  s->set_c_str( value);
111  return 0;
112  }
114  if( r.is_valid_interface()) {
115  mi::Sint32 result = r->set_reference( value);
116  return result == 0 ? 0 : -2;
117  }
119  if( a.is_valid_interface()) {
121  if( s.is_valid_interface()) {
122  a->set_reference( static_cast<const char*>( 0));
123  s->set_c_str( value);
124  return 0;
125  } else {
126  mi::Sint32 result = a->set_reference( value);
127  return result == 0 ? 0 : -2;
128  }
129  }
131  if( e.is_valid_interface()) {
132  mi::Sint32 result = e->set_value_by_name( value);
133  return result == 0 ? 0 : -2;
134  }
135  return -1;
136 }
137 
141 inline mi::Sint32 set_value( mi::IData* data, const mi::base::Uuid& value)
142 {
144  if( u.is_valid_interface()) {
145  u->set_uuid( value);
146  return 0;
147  }
148  return -1;
149 }
150 
162 template <class T, Size DIM>
164 {
165  typedef typename mi::Vector_type_traits<T,DIM>::Interface_type Vector_interface_type;
166  mi::base::Handle<Vector_interface_type> v( data->get_interface<Vector_interface_type>());
167  if( v.is_valid_interface()) {
168  v->set_value( value);
169  return 0;
170  }
172  if( a.is_valid_interface()) {
173  a->set_reference( static_cast<const char*>( 0));
175  return set_value( d.get(), value);
176  }
177  return -1;
178 }
179 
191 template <class T, Size ROW, Size COL>
193 {
194  typedef typename mi::Matrix_type_traits<T,ROW,COL>::Interface_type Matrix_interface_type;
195  mi::base::Handle<Matrix_interface_type> m( data->get_interface<Matrix_interface_type>());
196  if( m.is_valid_interface()) {
197  m->set_value( value);
198  return 0;
199  }
201  if( a.is_valid_interface()) {
202  a->set_reference( static_cast<const char*>( 0));
204  return set_value( d.get(), value);
205  }
206  return -1;
207 }
208 
212 inline mi::Sint32 set_value( mi::IData* data, const mi::Color& value)
213 {
215  if( c.is_valid_interface()) {
216  c->set_value( value);
217  return 0;
218  }
220  if( c3.is_valid_interface()) {
221  c3->set_value( value);
222  return 0;
223  }
225  if( a.is_valid_interface()) {
226  a->set_reference( static_cast<const char*>( 0));
228  return set_value( d.get(), value);
229  }
230  return -1;
231 }
232 
236 inline mi::Sint32 set_value( mi::IData* data, const mi::Spectrum& value)
237 {
239  if( s.is_valid_interface()) {
240  s->set_value( value);
241  return 0;
242  }
244  if( a.is_valid_interface()) {
245  a->set_reference( static_cast<const char*>( 0));
247  return set_value( d.get(), value);
248  }
249  return -1;
250 }
251 
255 inline mi::Sint32 set_value( mi::IData* data, const mi::Bbox3& value)
256 {
258  if( b.is_valid_interface()) {
259  b->set_value( value);
260  return 0;
261  }
262  return -1;
263 }
264 
276 template<class T>
277 mi::Sint32 set_value( mi::IData* data, mi::Size index, const T& value)
278 {
280  if( c.is_valid_interface()) {
282  if( !d.is_valid_interface())
283  return -3;
284  return set_value( d.get(), value);
285  }
286  return -1;
287 }
288 
300 template<class T>
301 mi::Sint32 set_value( mi::IData* data, const char* key, const T& value)
302 {
304  if( c.is_valid_interface()) {
306  if( !d.is_valid_interface())
307  return -3;
308  return set_value( d.get(), value);
309  }
310  return -1;
311 }
312 
348 template<class T>
349 mi::Sint32 get_value( const mi::IData* data, T& value)
350 {
352  if( v.is_valid_interface()) {
353  v->get_value( value);
354  return 0;
355  }
357  if( a.is_valid_interface()) {
359  if( i.is_valid_interface())
360  return -1;
362  return get_value( v.get(), value);
363  }
364 // disable C4800: 'mi::Sint32' : forcing value to bool 'true' or 'false' (performance warning)
365 // disable C4800: 'mi::Uint32' : forcing value to bool 'true' or 'false' (performance warning)
366 #ifdef MI_COMPILER_MSC
367 #pragma warning( push )
368 #pragma warning( disable : 4800 )
369 #endif
371  if( e.is_valid_interface()) {
372  value = static_cast<T>( e->get_value());
373  return 0;
374  }
376  if( p.is_valid_interface()) {
377  value = static_cast<T>( p->get_value());
378  return 0;
379  }
381  if( t.is_valid_interface()) {
382  value = static_cast<T>( t->get_value());
383  return 0;
384  }
385 #ifdef MI_COMPILER_MSC
386 #pragma warning( pop )
387 #endif
388  return -1;
389 }
390 
394 inline mi::Sint32 get_value( const mi::IData* data, const char*& value)
395 {
397  if( i.is_valid_interface()) {
398  value = i->get_c_str();
399  return 0;
400  }
402  if( r.is_valid_interface()) {
403  value = r->get_reference_name();
404  return 0;
405  }
407  if( a.is_valid_interface()) {
409  if( s.is_valid_interface())
410  value = s->get_c_str();
411  else
412  value = a->get_reference_name();
413  return 0;
414  }
416  if( e.is_valid_interface()) {
417  value = e->get_value_by_name();
418  return 0;
419  }
420  return -1;
421 }
422 
426 inline mi::Sint32 get_value( const mi::IData* data, mi::base::Uuid& value)
427 {
429  if( u.is_valid_interface()) {
430  value = u->get_uuid();
431  return 0;
432  }
433  return -1;
434 }
435 
447 template <class T, Size DIM>
449 {
450  typedef typename mi::Vector_type_traits<T,DIM>::Interface_type Vector_interface_type;
451  mi::base::Handle<const Vector_interface_type> v( data->get_interface<Vector_interface_type>());
452  if( v.is_valid_interface()) {
453  value = v->get_value();
454  return 0;
455  }
457  if( a.is_valid_interface()) {
459  if( i.is_valid_interface())
460  return -1;
462  return get_value( v.get(), value);
463  }
464  return -1;
465 }
466 
478 template <class T, Size ROW, Size COL>
480 {
481  typedef typename mi::Matrix_type_traits<T,ROW,COL>::Interface_type Matrix_interface_type;
482  mi::base::Handle<const Matrix_interface_type> m( data->get_interface<Matrix_interface_type>());
483  if( m.is_valid_interface()) {
484  value = m->get_value();
485  return 0;
486  }
488  if( a.is_valid_interface()) {
490  if( i.is_valid_interface())
491  return -1;
493  return get_value( v.get(), value);
494  }
495  return -1;
496 }
497 
501 inline mi::Sint32 get_value( const mi::IData* data, mi::Color& value)
502 {
504  if( c.is_valid_interface()) {
505  value = c->get_value();
506  return 0;
507  }
509  if( c3.is_valid_interface()) {
510  value = c3->get_value();
511  return 0;
512  }
514  if( a.is_valid_interface()) {
516  if( i.is_valid_interface())
517  return -1;
519  return get_value( v.get(), value);
520  }
521  return -1;
522 }
523 
527 inline mi::Sint32 get_value( const mi::IData* data, mi::Spectrum& value)
528 {
530  if( s.is_valid_interface()) {
531  value = s->get_value();
532  return 0;
533  }
535  if( a.is_valid_interface()) {
537  if( i.is_valid_interface())
538  return -1;
540  return get_value( v.get(), value);
541  }
542  return -1;
543 }
544 
548 inline mi::Sint32 get_value( const mi::IData* data, mi::Bbox3& value)
549 {
551  if( b.is_valid_interface()) {
552  value = b->get_value();
553  return 0;
554  }
555  return -1;
556 }
557 
568 template<class T>
569 mi::Sint32 get_value( const mi::IData* data, mi::Size index, T& value)
570 {
572  if( c.is_valid_interface()) {
574  if( !d.is_valid_interface())
575  return -3;
576  return get_value( d.get(), value);
577  }
578  return -1;
579 }
580 
591 template<class T>
592 mi::Sint32 get_value( const mi::IData* data, const char* key, T& value)
593 {
595  if( c.is_valid_interface()) {
597  if( !d.is_valid_interface())
598  return -3;
599  return get_value( d.get(), value);
600  }
601  return -1;
602 }
603  // end group mi_neuray_types
605 
610 template<class T>
623 mi::Sint32 set_value( mi::IAttribute_set* attribute_set, const char* name, const T& value)
624 {
625  mi::base::Handle<mi::IData> data( attribute_set->edit_attribute<mi::IData>( name));
626  if( !data.is_valid_interface())
627  return -4;
628  return set_value( data.get(), value);
629 }
630 
645 template<class T>
647  mi::IAttribute_set* attribute_set, const char* name, mi::Size index, const T& value)
648 {
649  mi::base::Handle<mi::IData> data( attribute_set->edit_attribute<mi::IData>( name));
650  if( !data.is_valid_interface())
651  return -4;
652  return set_value( data.get(), index, value);
653 }
654 
669 template<class T>
671  mi::IAttribute_set* attribute_set, const char* name, const char* key, const T& value)
672 {
673  mi::base::Handle<mi::IData> data( attribute_set->edit_attribute<mi::IData>( name));
674  if( !data.is_valid_interface())
675  return -4;
676  return set_value( data.get(), key, value);
677 }
678 
690 template<class T>
691 mi::Sint32 get_value( const mi::IAttribute_set* attribute_set, const char* name, T& value)
692 {
693  mi::base::Handle<const mi::IData> data( attribute_set->access_attribute<mi::IData>( name));
694  if( !data.is_valid_interface())
695  return -4;
696  return get_value( data.get(), value);
697 }
698 
712 template<class T>
714  const mi::IAttribute_set* attribute_set, const char* name, mi::Size index, T& value)
715 {
716  mi::base::Handle<const mi::IData> data( attribute_set->access_attribute<mi::IData>( name));
717  if( !data.is_valid_interface())
718  return -4;
719  return get_value( data.get(), index, value);
720 }
721 
735 template<class T>
737  const mi::IAttribute_set* attribute_set, const char* name, const char* key, T& value)
738 {
739  mi::base::Handle<const mi::IData> data( attribute_set->access_attribute<mi::IData>( name));
740  if( !data.is_valid_interface())
741  return -4;
742  return get_value( data.get(), key, value);
743 }
744  // end group mi_neuray_types
746 
747 } // namespace mi
748 
749 #endif // MI_NEURAYLIB_SET_GET_H