A wrapper around the interface for MDL function definitions. More...
#include <definition_wrapper.h>
Public Member Functions | |
General methods | |
Definition_wrapper (ITransaction *transaction, const char *name, IMdl_factory *mdl_factory) | |
Constructs an MDL definition wrapper for a fixed material or function definition. More... | |
bool | is_valid () const |
Indicates whether the definition wrapper is in a valid state. More... | |
bool | is_valid_definition (IMdl_execution_context *context) const |
Indicates whether the material or function definition referenced by this definition wrapper matches a definition in its owner module. More... | |
Element_type | get_type () const |
Indicates whether the definition wrapper acts on a material definition or on a function definition. More... | |
const char * | get_mdl_definition () const |
Returns the MDL name of the material or function definition. More... | |
const char * | get_module () const |
Returns the DB name of the corresponding module. More... | |
bool | is_exported () const |
Indicates whether the material or function definition is exported by its module. More... | |
bool | is_declarative () const |
Indicates whether the material or function definition is declarative. More... | |
bool | is_material () const |
Indicates whether the definition represents a material. More... | |
Size | get_parameter_count () const |
Returns the number of parameters. More... | |
const char * | get_parameter_name (Size index) const |
Returns the name of the parameter at index . More... | |
Size | get_parameter_index (const char *name) const |
Returns the index position of a parameter. More... | |
const IType_list * | get_parameter_types () const |
Returns the types of all parameters. More... | |
const IType * | get_return_type () const |
Returns the return type. More... | |
const char * | get_thumbnail () const |
Returns the resolved file name of the thumbnail image for this MDL definition. More... | |
Methods related to argument defaults | |
const IExpression_list * | get_defaults () const |
Returns the defaults of all parameters. More... | |
template<class T> | |
Sint32 | get_default (Size index, T &value) const |
Returns the default of a non-array parameter. More... | |
template<class T> | |
Sint32 | get_default (const char *name, T &value) const |
Returns the default of a non-array parameter. More... | |
Methods related to annotations | |
const IAnnotation_block * | get_annotations () const |
Returns the annotations for a material or function definition. More... | |
const IAnnotation_list * | get_parameter_annotations () const |
Returns the annotations of all parameters. More... | |
const IAnnotation_block * | get_return_annotations () const |
Returns the annotations of the return type. More... | |
const IExpression_list * | get_enable_if_conditions () const |
Returns the enable_if conditions of all parameters. More... | |
Size | get_enable_if_users (Size index) const |
Returns the number of other parameters whose enable_if condition might depend on the argument of the given parameter. More... | |
Size | get_enable_if_user (Size index, Size u_index) const |
Returns the index of a parameter whose enable_if condition might depend on the argument of the given parameter. More... | |
Methods related to instantiation of definitions | |
IFunction_call * | create_instance (const IExpression_list *arguments=0, Sint32 *errors=0) const |
Creates an instance of the material or function definition. More... | |
template<class T> | |
T * | create_instance (const IExpression_list *arguments=0, Sint32 *errors=0) const |
Creates an instance of the material or function definition. More... | |
Methods related to member access. | |
ITransaction * | get_transaction () const |
Get the transaction. More... | |
IMdl_factory * | get_mdl_factory () const |
Get the MDL factory. More... | |
const IFunction_definition * | get_scene_element () const |
Get the MDL function or material definition. More... | |
Element_type | get_element_type () const |
Get the element type. More... | |
const std::string & | get_name () const |
Get the DB name of the MDL function or material definition. More... | |
A wrapper around the interface for MDL function definitions.
The purpose of the MDL definition wrapper is to simplify common working with MDL function definitions. The key benefit is that it wraps API call sequences occurring in typical tasks into one single method call, e.g., instance creation or obtaining the default values (as long as their type is not too complex).
See mi::neuraylib::IFunction_definition for the underlying interface. See also mi::neuraylib::Argument_editor for a similar wrapper for MDL function calls.
|
inline |
Constructs an MDL definition wrapper for a fixed material or function definition.
transaction | The transaction to be used. |
name | The name of the wrapped material or function definition. |
mdl_factory | A pointer to the API component mi::neuraylib::IMdl_factory. Needed only by create_instance() if called with NULL as first argument, can be NULL otherwise. |
|
inline |
Creates an instance of the material or function definition.
arguments | If not NULL , then these arguments are used for the material instance or function call. If an argument is missing, then the default for that parameter is used. If there is no default, range annotations are used to obtain a suitable value, or the argument is default-constructed as last resort. Must not be NULL (or missing any arguments) in case of Template-like function definitions. | |
[out] | errors | An optional pointer to an mi::Sint32 to which an error code will be written. The error codes have the following meaning:
|
NULL
in case of errors.
|
inline |
Creates an instance of the material or function definition.
This template wrapper exists only for backwards compatibility with older code. In new code, use the non-template overload instead.
|
inline |
Returns the annotations for a material or function definition.
Sint32 mi::neuraylib::Definition_wrapper::get_default | ( | const char * | name, |
T & | value | ||
) | const |
Returns the default of a non-array parameter.
name | The name of the parameter in question. | |
[out] | value | The default of the specified parameter. |
false
.name
is invalid, or there is no default for this parameter.T
. Sint32 mi::neuraylib::Definition_wrapper::get_default | ( | Size | index, |
T & | value | ||
) | const |
Returns the default of a non-array parameter.
If a literal 0
is passed for index
, the call is ambiguous. You need to explicitly cast the value to mi::Size.
index | The index the parameter in question. | |
[out] | value | The default of the specified parameter. |
false
.index
is out of range, or there is no default for this parameter.T
.
|
inline |
Returns the defaults of all parameters.
|
inline |
Get the element type.
|
inline |
Returns the enable_if
conditions of all parameters.
|
inline |
Returns the index of a parameter whose enable_if
condition might depend on the argument of the given parameter.
index | The index of the parameter. |
u_index | The index of the enable_if user. |
enable_if
condition depends on this parameter argument, or ~0 if indexes are out of range. Returns the number of other parameters whose enable_if
condition might depend on the argument of the given parameter.
index | The index of the parameter. |
enable_if
condition depends on this parameter argument.
|
inline |
Returns the MDL name of the material or function definition.
|
inline |
Get the MDL factory.
|
inline |
Returns the DB name of the corresponding module.
|
inline |
Get the DB name of the MDL function or material definition.
|
inline |
Returns the annotations of all parameters.
|
inline |
Returns the number of parameters.
|
inline |
Returns the index position of a parameter.
name | The name of the parameter. |
name
is invalid.
|
inline |
Returns the name of the parameter at index
.
index | The index of the parameter. |
NULL
if index
is out of range.
|
inline |
Returns the types of all parameters.
|
inline |
Returns the annotations of the return type.
|
inline |
Returns the return type.
|
inline |
Get the MDL function or material definition.
|
inline |
Returns the resolved file name of the thumbnail image for this MDL definition.
The function first checks for a thumbnail annotation. If the annotation is provided, it uses the 'name' argument of the annotation and resolves that in the MDL search path. If the annotation is not provided or file resolution fails, it checks for a file module_name.material_name.png next to the MDL module. In case this cannot be found either NULL
is returned.
|
inline |
Get the transaction.
|
inline |
Indicates whether the definition wrapper acts on a material definition or on a function definition.
false
.
|
inline |
Indicates whether the material or function definition is declarative.
|
inline |
Indicates whether the material or function definition is exported by its module.
|
inline |
Indicates whether the definition represents a material.
|
inline |
Indicates whether the definition wrapper is in a valid state.
The definition wrapper is valid if and only if the name passed in the constructor identifies a material or function definition. This method should be immediately called after invoking the constructor. If it returns false
, no other methods of this class should be called.
|
inline |
Indicates whether the material or function definition referenced by this definition wrapper matches a definition in its owner module.
Definitions might become invalid due to a module reload of the owner module itself or another module imported by the owner module.
context | Execution context that can be queried for error messages after the operation has finished. Can be NULL . |
True
, if the definition is valid, false
otherwise.