MDL SDK API nvidia_logo_transpbg.gif Up
annotation_wrapper.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2026 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 nullptr;
158
160 m_anno_block->get_annotation(anno_index));
161 if (!anno)
162 return nullptr;
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 const char* s = get_annotation_name(i);
176 if (s && strcmp(anno_name, s) == 0)
177 return i;
178 }
179
180 return static_cast<mi::Size>(-1);
181}
182
184{
185 if (!m_anno_block || m_anno_block->get_size() <= anno_index)
186 return 0;
187
189 m_anno_block->get_annotation(anno_index));
190 if (!anno)
191 return 0;
192
193 mi::base::Handle<const mi::neuraylib::IExpression_list> expr_list(anno->get_arguments());
194 if (!expr_list)
195 return 0;
196
197 return expr_list->get_size();
198}
199
201 mi::Size anno_index, mi::Size param_index) const
202{
203 if (!m_anno_block || m_anno_block->get_size() <= anno_index)
204 return nullptr;
205
207 m_anno_block->get_annotation(anno_index));
208 if (!anno)
209 return nullptr;
210
211 mi::base::Handle<const mi::neuraylib::IExpression_list> expr_list(anno->get_arguments());
212 if (!expr_list)
213 return nullptr;
214
215 if (expr_list->get_size() <= param_index)
216 return nullptr;
217
218 return expr_list->get_name(param_index);
219}
220
222 mi::Size anno_index, mi::Size param_index) const
223{
224 if (!m_anno_block || m_anno_block->get_size() <= anno_index)
225 return nullptr;
226
228 m_anno_block->get_annotation(anno_index));
229 if (!anno)
230 return nullptr;
231
232 mi::base::Handle<const mi::neuraylib::IExpression_list> expr_list(anno->get_arguments());
233 if (!expr_list)
234 return nullptr;
235
236 if (expr_list->get_size() <= param_index)
237 return nullptr;
238
239 mi::base::Handle<const mi::neuraylib::IExpression> expr(expr_list->get_expression(param_index));
240 if (!expr)
241 return nullptr;
242
243 return expr->get_type();
244}
245
247 mi::Size anno_index, mi::Size param_index) const
248{
249 if (!m_anno_block || m_anno_block->get_size() <= anno_index)
250 return nullptr;
251
253 m_anno_block->get_annotation(anno_index));
254 if (!anno)
255 return nullptr;
256
257 mi::base::Handle<const mi::neuraylib::IExpression_list> expr_list(anno->get_arguments());
258 if (!expr_list)
259 return nullptr;
260
261 if (expr_list->get_size() <= param_index)
262 return nullptr;
263
264 mi::base::Handle<const mi::neuraylib::IExpression> expr(expr_list->get_expression(param_index));
265 if (!expr)
266 return nullptr;
267
270 if (!c)
271 return nullptr;
272
273 return c->get_value();
274}
275
277 const char* anno_name, mi::Size param_index) const
278{
279 mi::Size anno_index = get_annotation_index(anno_name);
280 if (anno_index == static_cast<mi::Size>(-1))
281 return nullptr;
282
283 return get_annotation_param_value(anno_index, param_index);
284}
285
286template <class T>
288 mi::Size anno_index, mi::Size param_index, T& value) const
289{
291 anno_index, param_index));
292 if (!v)
293 return -3;
294
295 return mi::neuraylib::get_value(v.get(), value);
296}
297
298template <class T>
300 const char* anno_name, mi::Size param_index, T& value) const
301{
303 anno_name, param_index));
304 if (!v)
305 return -3;
306
307 return mi::neuraylib::get_value(v.get(), value);
308}
309
310} // namespace neuraylib
311
312} // namespace mi
313
314#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:200
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:221
mi::Size get_annotation_param_count(mi::Size anno_index) const
Get the number of parameters of an annotation.
Definition: annotation_wrapper.h:183
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:276
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:246
An annotation block is an array of annotations.
Definition: iexpression.h:576
virtual const IAnnotation * get_annotation(Size index) const =0
Returns the annotation for index, or nullptr 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:95
The interface to MDL types.
Definition: itype.h:153
The interface to MDL values.
Definition: ivalue.h:34
Handle<Interface> make_handle_dup(Interface *iptr)
Converts passed-in interface pointer to a handle, without taking interface over.
Definition: handle.h:434
Handle<New_interface> get_interface() const
Returns a new handle for a possibly different interface type, similar to a dynamic cast,...
Definition: handle.h:348
Interface * get() const
Access to the interface. Returns nullptr for an invalid interface.
Definition: handle.h:289
int Sint32
32-bit signed integer.
Definition: types.h:46
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:103
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:1253
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.