MDL SDK API nvidia_logo_transpbg.gif Up
annotation_wrapper.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2024 NVIDIA Corporation. All rights reserved.
3 **************************************************************************************************/
6
7#ifndef MI_NEURAYLIB_ANNOTATION_WRAPPER_H
8#define MI_NEURAYLIB_ANNOTATION_WRAPPER_H
9
10#include <mi/base/handle.h>
11#include <mi/neuraylib/assert.h>
17#include <mi/neuraylib/itype.h>
18#include <mi/neuraylib/ivalue.h>
19
20namespace mi {
21
22namespace neuraylib {
23
37{
38public:
39
41
42
47
52
57 const char* get_annotation_name(mi::Size anno_index) const;
58
68 const char* anno_name,
69 mi::Size offset = 0) const;
70
76
82 const char* get_annotation_param_name(mi::Size anno_index, mi::Size param_index) const;
83
89 const IType* get_annotation_param_type(mi::Size anno_index, mi::Size param_index) const;
90
97 mi::Size anno_index, mi::Size param_index) const;
98
105 const char* anno_name, mi::Size param_index ) const;
106
116 template <class T>
118 mi::Size anno_index, mi::Size param_index, T& value) const;
119
129 template <class T>
131 const char* anno_name, mi::Size param_index, T& value ) const;
132
133private:
135};
136 // end group mi_neuray_mdl_elements
138
140 const mi::neuraylib::IAnnotation_block* anno_block)
141{
142 // anno_block == null is valid and will result in an annotation count of zero
143 m_anno_block = make_handle_dup(anno_block);
144}
145
147{
148 if (!m_anno_block)
149 return 0;
150
151 return m_anno_block->get_size();
152}
153
154inline const char* Annotation_wrapper::get_annotation_name(mi::Size anno_index) const
155{
156 if (!m_anno_block || m_anno_block->get_size() <= anno_index)
157 return 0;
158
160 m_anno_block->get_annotation(anno_index));
161 if (!anno)
162 return 0;
163
164 return anno->get_name();
165}
166
168 const char* anno_name,
169 mi::Size offset) const
170{
171 if (!anno_name || !m_anno_block)
172 return static_cast<mi::Size>(-1);
173
174 for (mi::Size i = offset, n = get_annotation_count(); i < n; ++i)
175 if (strcmp(anno_name, get_annotation_name(i)) == 0) //-V575 PVS
176 return i;
177
178 return static_cast<mi::Size>(-1);
179}
180
182{
183 if (!m_anno_block || m_anno_block->get_size() <= anno_index)
184 return 0;
185
187 m_anno_block->get_annotation(anno_index));
188 if (!anno)
189 return 0;
190
191 mi::base::Handle<const mi::neuraylib::IExpression_list> expr_list(anno->get_arguments());
192 if (!expr_list)
193 return 0;
194
195 return expr_list->get_size();
196}
197
199 mi::Size anno_index, mi::Size param_index) const
200{
201 if (!m_anno_block || m_anno_block->get_size() <= anno_index)
202 return 0;
203
205 m_anno_block->get_annotation(anno_index));
206 if (!anno)
207 return 0;
208
209 mi::base::Handle<const mi::neuraylib::IExpression_list> expr_list(anno->get_arguments());
210 if (!expr_list)
211 return 0;
212
213 if (expr_list->get_size() <= param_index)
214 return 0;
215
216 return expr_list->get_name(param_index);
217}
218
220 mi::Size anno_index, mi::Size param_index) const
221{
222 if (!m_anno_block || m_anno_block->get_size() <= anno_index)
223 return 0;
224
226 m_anno_block->get_annotation(anno_index));
227 if (!anno)
228 return 0;
229
230 mi::base::Handle<const mi::neuraylib::IExpression_list> expr_list(anno->get_arguments());
231 if (!expr_list)
232 return 0;
233
234 if (expr_list->get_size() <= param_index)
235 return 0;
236
237 mi::base::Handle<const mi::neuraylib::IExpression> expr(expr_list->get_expression(param_index));
238 if (!expr)
239 return 0;
240
241 return expr->get_type();
242}
243
245 mi::Size anno_index, mi::Size param_index) const
246{
247 if (!m_anno_block || m_anno_block->get_size() <= anno_index)
248 return 0;
249
251 m_anno_block->get_annotation(anno_index));
252 if (!anno)
253 return 0;
254
255 mi::base::Handle<const mi::neuraylib::IExpression_list> expr_list(anno->get_arguments());
256 if (!expr_list)
257 return 0;
258
259 if (expr_list->get_size() <= param_index)
260 return 0;
261
262 mi::base::Handle<const mi::neuraylib::IExpression> expr(expr_list->get_expression(param_index));
263 if (!expr)
264 return 0;
265
268 if (!c)
269 return 0;
270
271 return c->get_value();
272}
273
275 const char* anno_name, mi::Size param_index) const
276{
277 mi::Size anno_index = get_annotation_index(anno_name);
278 if (anno_index == static_cast<mi::Size>(-1))
279 return 0;
280
281 return get_annotation_param_value(anno_index, param_index);
282}
283
284template <class T>
286 mi::Size anno_index, mi::Size param_index, T& value) const
287{
289 anno_index, param_index));
290 if (!v)
291 return -3;
292
293 return mi::neuraylib::get_value(v.get(), value);
294}
295
296template <class T>
298 const char* anno_name, mi::Size param_index, T& value) const
299{
301 anno_name, param_index));
302 if (!v)
303 return -3;
304
305 return mi::neuraylib::get_value(v.get(), value);
306}
307
308} // namespace neuraylib
309
310} // namespace mi
311
312#endif // MI_NEURAYLIB_ANNOTATION_WRAPPER_H
A wrapper around the interfaces for MDL annotations.
Definition: annotation_wrapper.h:37
mi::Size get_annotation_count() const
Get the number of the annotations.
Definition: annotation_wrapper.h:146
mi::Size get_annotation_index(const char *anno_name, mi::Size offset=0) const
Get the index of an annotation based on its name for one of the annotations.
Definition: annotation_wrapper.h:167
const char * get_annotation_param_name(mi::Size anno_index, mi::Size param_index) const
Get the name of one of the parameters of one of the annotations.
Definition: annotation_wrapper.h:198
const IType * get_annotation_param_type(mi::Size anno_index, mi::Size param_index) const
Get the type of one of the parameters of one of the annotations.
Definition: annotation_wrapper.h:219
mi::Size get_annotation_param_count(mi::Size anno_index) const
Get the number of parameters of an annotation.
Definition: annotation_wrapper.h:181
Annotation_wrapper(const mi::neuraylib::IAnnotation_block *anno_block)
Constructs a helper that provides convenience methods for annotations.
Definition: annotation_wrapper.h:139
const char * get_annotation_name(mi::Size anno_index) const
Get the name of the annotation for one of the annotations.
Definition: annotation_wrapper.h:154
const IValue * get_annotation_param_value_by_name(const char *anno_name, mi::Size param_index) const
Get the value of one of the parameters of one of the annotations.
Definition: annotation_wrapper.h:274
const IValue * get_annotation_param_value(mi::Size anno_index, mi::Size param_index) const
Get the value of one of the parameters of one of the annotations.
Definition: annotation_wrapper.h:244
An annotation block is an array of annotations.
Definition: iexpression.h:575
virtual const IAnnotation * get_annotation(Size index) const =0
Returns the annotation for index, or NULL if index is out of bounds.
virtual Size get_size() const =0
Returns the number of annotations in this block.
A constant expression.
Definition: iexpression.h:96
The interface to MDL types.
Definition: itype.h:151
The interface to MDL values.
Definition: ivalue.h:33
Handle<Interface> make_handle_dup(Interface *iptr)
Converts passed-in interface pointer to a handle, without taking interface over.
Definition: handle.h:439
Handle<New_interface> get_interface() const
Returns a new handle for a possibly different interface type, similar to a dynamic cast,...
Definition: handle.h:353
Interface * get() const
Access to the interface. Returns 0 for an invalid interface.
Definition: handle.h:294
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 get_value(const mi::neuraylib::IValue *value, T &v)
Simplifies reading the value of mi::neuraylib::IValue into the corresponding classes from the base an...
Definition: ivalue.h:1254
Smart-pointer handle class for interfaces, const and non-const version.
Expressions of the MDL type system.
Scene element Function_call.
Scene element Material_instance.
API component that gives access to some MDL functionality.
Database transactions.
Types of the MDL type system.
Values of the MDL type system.
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: example_derivatives.dox:5
Assertions and compile-time assertions.