neuray API Programmer's Manual

iexpression.h File Reference

Description

Expressions of the MDL type system.

Code Example

iexpression.h

‎/***************************************************************************************************
 * Copyright 2022 NVIDIA Corporation. All rights reserved.
 **************************************************************************************************/

#ifndef MI_NEURAYLIB_IEXPRESSION_H
#define MI_NEURAYLIB_IEXPRESSION_H

#include <mi/neuraylib/ivalue.h>

namespace mi {

class IString;

namespace neuraylib {

class IAnnotation;
class IAnnotation_block;
class IExpression_list;


enum Mdl_version {
    MDL_VERSION_1_0,                       
    MDL_VERSION_1_1,                       
    MDL_VERSION_1_2,                       
    MDL_VERSION_1_3,                       
    MDL_VERSION_1_4,                       
    MDL_VERSION_1_5,                       
    MDL_VERSION_1_6,                       
    MDL_VERSION_1_7,                       
    MDL_VERSION_LATEST = MDL_VERSION_1_7,  
    MDL_VERSION_INVALID = 0xffffffffU,     
    MDL_VERSION_FORCE_32_BIT = 0xffffffffU // Undocumented, for alignment only
};

class IExpression : public
    mi::base::Interface_declare<0x0f4a7542,0x9b27,0x4924,0xbd,0x8d,0x82,0xe3,0xa9,0xa7,0xa9,0xd6>
{
public:
    enum Kind {
        EK_CONSTANT,
        EK_CALL,
        EK_PARAMETER,
        EK_DIRECT_CALL,
        EK_TEMPORARY,
        //  Undocumented, for alignment only.
        EK_FORCE_32_BIT = 0xffffffffU
    };

    virtual Kind 
               get_kind() const = 0;

    virtual const IType* get_type() const = 0;

    template <class T>
    const T* get_type() const
    {
        const IType* ptr_type = get_type();
        if( !ptr_type)
            return 0;
        const T* ptr_T = static_cast<const T*>( ptr_type->get_interface( typename T::IID()));
        ptr_type->release();
        return ptr_T;
    }
};

mi_static_assert( sizeof( IExpression::Kind) == sizeof( Uint32));

class IExpression_constant : public
    mi::base::Interface_declare<0x9da8d465,0x4058,0x46cb,0x83,0x6e,0x0e,0x38,0xa6,0x7f,0xcd,0xef,
                                neuraylib::IExpression>
{
public:
    static const Kind 
               s_kind = EK_CONSTANT;

    virtual const IValue* get_value() const = 0;

    template <class T>
    const T* get_value() const
    {
        const IValue* ptr_value = get_value();
        if( !ptr_value)
            return 0;
        const T* ptr_T = static_cast<const T*>( ptr_value->get_interface( typename T::IID()));
        ptr_value->release();
        return ptr_T;
    }

    virtual IValue* get_value() = 0;

    template <class T>
    T* get_value()
    {
        IValue* ptr_value = get_value();
        if( !ptr_value)
            return 0;
        T* ptr_T = static_cast<T*>( ptr_value->get_interface( typename T::IID()));
        ptr_value->release();
        return ptr_T;
    }

    virtual Sint32 
               set_value( IValue* value) = 0;
};

class IExpression_call : public
    mi::base::Interface_declare<0xcf625aec,0x8eb8,0x4743,0x9f,0xf6,0x76,0x82,0x2c,0x02,0x54,0xa3,
                                neuraylib::IExpression>
{
public:
    static const Kind 
               s_kind = EK_CALL;

    virtual const char* get_call() const = 0;

    virtual Sint32 
               set_call( const char* name) = 0;
};

class IExpression_parameter : public
    mi::base::Interface_declare<0x206c4319,0x0b53,0x45a7,0x86,0x07,0x29,0x98,0xb3,0x44,0x7f,0xaa,
                               neuraylib::IExpression>
{
public:
    static const Kind 
               s_kind = EK_PARAMETER;

    virtual Size 
               get_index() const = 0;

    virtual void set_index( Size index) = 0;
};

class IExpression_direct_call : public
    mi::base::Interface_declare<0x9253c9d6,0xe162,0x4234,0xab,0x91,0x54,0xc1,0xe4,0x87,0x39,0x66,
                                neuraylib::IExpression>
{
public:
    static const Kind 
               s_kind = EK_DIRECT_CALL;

    virtual const char* get_definition() const = 0;

    virtual const IExpression_list* get_arguments() const = 0;
};

class IExpression_temporary : public
    mi::base::Interface_declare<0xd91f484b,0xdbf8,0x4585,0x9d,0xab,0xba,0xd9,0x91,0x7f,0xe1,0x4c,
                                neuraylib::IExpression>
{
public:
    static const Kind 
               s_kind = EK_TEMPORARY;

    virtual Size 
               get_index() const = 0;

    virtual void set_index( Size index) = 0;
};

class IExpression_list : public
    mi::base::Interface_declare<0x98ce8e89,0x9f23,0x45ec,0xa7,0xce,0x85,0x78,0x48,0x14,0x85,0x23>
{
public:
    virtual Size 
               get_size() const = 0;

    virtual Size 
               get_index( const char* name) const = 0;

    virtual const char* get_name( Size index) const = 0;

    virtual const IExpression* get_expression( Size index) const = 0;

    template <class T>
    const T* get_expression( Size index) const
    {
        const IExpression* ptr_expression = get_expression( index);
        if( !ptr_expression)
            return 0;
        const T* ptr_T = static_cast<const T*>( ptr_expression->get_interface( typename T::IID()));
        ptr_expression->release();
        return ptr_T;
    }

    virtual const IExpression* get_expression( const char* name) const = 0;

    template <class T>
    const T* get_expression( const char* name) const
    {
        const IExpression* ptr_expression = get_expression( name);
        if( !ptr_expression)
            return 0;
        const T* ptr_T = static_cast<const T*>( ptr_expression->get_interface( typename T::IID()));
        ptr_expression->release();
        return ptr_T;
    }

    virtual Sint32 
               set_expression( Size index, const IExpression* expression) = 0;

    virtual Sint32 
               set_expression( const char* name, const IExpression* expression) = 0;

    virtual Sint32 
               add_expression( const char* name, const IExpression* expression) = 0;
};

class IAnnotation_definition : public
    mi::base::Interface_declare<0xa453318b,0xe056,0x4521,0x9f,0x3c,0x9d,0x5c,0x3,0x23,0x5f,0xb7>
{
public:

    enum Semantics
    {
        AS_UNKNOWN = 0,                          

        AS_INTRINSIC_ANNOTATION = 0x0100,
        AS_ANNOTATION_FIRST = AS_INTRINSIC_ANNOTATION,
        AS_THROWS_ANNOTATION,                    
        AS_SINCE_ANNOTATION,                     
        AS_REMOVED_ANNOTATION,                   
        AS_CONST_EXPR_ANNOTATION,                
        AS_DERIVABLE_ANNOTATION,                 
        AS_NATIVE_ANNOTATION,                    

        AS_UNUSED_ANNOTATION,                    
        AS_NOINLINE_ANNOTATION,                  
        AS_SOFT_RANGE_ANNOTATION,                
        AS_HARD_RANGE_ANNOTATION,                
        AS_HIDDEN_ANNOTATION,                    
        AS_DEPRECATED_ANNOTATION,                
        AS_VERSION_NUMBER_ANNOTATION,            
        AS_VERSION_ANNOTATION,                   
        AS_DEPENDENCY_ANNOTATION,                
        AS_UI_ORDER_ANNOTATION,                  
        AS_USAGE_ANNOTATION,                     
        AS_ENABLE_IF_ANNOTATION,                 
        AS_THUMBNAIL_ANNOTATION,                 
        AS_DISPLAY_NAME_ANNOTATION,              
        AS_IN_GROUP_ANNOTATION,                  
        AS_DESCRIPTION_ANNOTATION,               
        AS_AUTHOR_ANNOTATION,                    
        AS_CONTRIBUTOR_ANNOTATION,               
        AS_COPYRIGHT_NOTICE_ANNOTATION,          
        AS_CREATED_ANNOTATION,                   
        AS_MODIFIED_ANNOTATION,                  
        AS_KEYWORDS_ANNOTATION,                  
        AS_ORIGIN_ANNOTATION,                    

        AS_ANNOTATION_LAST = AS_ORIGIN_ANNOTATION,
        AS_FORCE_32_BIT = 0xffffffffU            //   Undocumented, for alignment only.
    };

    virtual const char* get_module() const = 0;

    virtual const char* get_name() const = 0;

    virtual const char* get_mdl_module_name() const = 0;

    virtual const char* get_mdl_simple_name() const = 0;

    virtual const char* get_mdl_parameter_type_name( Size index) const = 0;

    virtual Semantics 
               get_semantic() const = 0;

    virtual bool is_exported() const = 0;

    virtual void get_mdl_version( Mdl_version& since, Mdl_version& removed) const = 0;

    virtual Size 
               get_parameter_count() const = 0;

    virtual const char* get_parameter_name( Size index) const = 0;

    virtual Size 
               get_parameter_index( const char* name) const = 0;

    virtual const IType_list* get_parameter_types() const = 0;

    virtual const IExpression_list* get_defaults() const = 0;

    virtual const IAnnotation_block* get_annotations() const = 0;

    virtual const IAnnotation* create_annotation( const IExpression_list* arguments) const = 0;
};

mi_static_assert( sizeof( IAnnotation_definition::Semantics) == sizeof( Uint32));

class IAnnotation : public
    mi::base::Interface_declare<0xa9c652e7,0x952e,0x4887,0x93,0xb4,0x55,0xc8,0x66,0xd0,0x1a,0x1f>
{
public:
    virtual const char* get_name() const = 0;

    virtual void set_name( const char* name) = 0;

    virtual const IExpression_list* get_arguments() const = 0;

    virtual const IAnnotation_definition* get_definition() const = 0;
};

class IAnnotation_block : public
    mi::base::Interface_declare<0x57b0ae97,0x0815,0x41e8,0x89,0xe7,0x16,0xa1,0x23,0x86,0x80,0x6e>
{
public:
    virtual Size 
               get_size() const = 0;

    virtual const IAnnotation* get_annotation( Size index) const = 0;

    virtual Sint32 
               set_annotation( Size index, const IAnnotation* annotation) = 0;

    virtual Sint32 
               add_annotation( IAnnotation* annotation) = 0;
};

class IAnnotation_list : public
    mi::base::Interface_declare<0x6c4663c2,0x112f,0x4eeb,0x81,0x60,0x41,0xa5,0xa6,0xfb,0x74,0x3c>
{
public:
    virtual Size 
               get_size() const = 0;

    virtual Size 
               get_index( const char* name) const = 0;

    virtual const char* get_name( Size index) const = 0;

    virtual const IAnnotation_block* get_annotation_block( Size index) const = 0;

    virtual const IAnnotation_block* get_annotation_block( const char* name) const = 0;

    virtual Sint32 
               set_annotation_block( Size index, const IAnnotation_block* block) = 0;

    virtual Sint32 
               set_annotation_block( const char* name, const IAnnotation_block* block) = 0;

    virtual Sint32 
               add_annotation_block( const char* name, const IAnnotation_block* block) = 0;
};

class IExpression_factory : public
    mi::base::Interface_declare<0x9fd3b2d4,0xb5b8,0x4ccd,0x9b,0x5f,0x7b,0xd9,0x9d,0xeb,0x62,0x64>
{
public:
    virtual IValue_factory* get_value_factory() const = 0;

    virtual IExpression_constant* create_constant( IValue* value) const = 0;

    virtual const IExpression_constant* create_constant( const IValue* value) const = 0;

    virtual IExpression_call* create_call( const char* name) const = 0;

    virtual IExpression_parameter* create_parameter( const IType* type, Size index) const = 0;

    virtual IExpression_direct_call* create_direct_call(
        const char* name, IExpression_list* arguments, Sint32* errors = 0) const = 0;

    virtual IExpression_list* create_expression_list() const = 0;

    virtual IAnnotation* create_annotation(
        const char* name, const IExpression_list* arguments) const = 0;

    virtual IAnnotation_block* create_annotation_block() const = 0;

    virtual IAnnotation_list* create_annotation_list() const = 0;

    virtual IExpression* clone( const IExpression* expr) const = 0;

    template <class T>
    T* clone( const T* expr) const
    {
        IExpression* ptr_expr = clone( static_cast<const IExpression*>( expr));
        if( !ptr_expr)
            return 0;
        T* ptr_T = static_cast<T*>( ptr_expr->get_interface( typename T::IID()));
        ptr_expr->release();
        return ptr_T;
    }

    virtual IExpression_list* clone( const IExpression_list* expression_list) const = 0;

    enum Comparison_options {
        DEFAULT_OPTIONS      = 0,
        DEEP_CALL_COMPARISONS           = 1,
        SKIP_TYPE_ALIASES               = 2,
        // Undocumented, for alignment only
        COMPARISON_OPTIONS_FORCE_32_BIT = 0xffffffffU
    };

    mi_static_assert( sizeof( Comparison_options) == sizeof( mi::Uint32));

    virtual Sint32 
               compare(
        const IExpression* lhs,
        const IExpression* rhs,
        Uint32 flags = 0,
        Float64 epsilon = 0.0) const = 0;

    virtual Sint32 
               compare(
        const IExpression_list* lhs,
        const IExpression_list* rhs,
        Uint32 flags = 0,
        Float64 epsilon = 0.0) const = 0;

    virtual const IString* dump(
        const IExpression* expr, const char* name, Size depth = 0) const = 0;

    virtual const IString* dump(
        const IExpression_list* list, const char* name, Size depth = 0) const = 0;

    virtual const IString* dump(
        const IAnnotation* annotation, const char* name, Size depth = 0) const = 0;

    virtual const IString* dump( const IAnnotation_block* block, const char* name, Size depth = 0)
        const = 0;

    virtual const IString* dump( const IAnnotation_list* list, const char* name, Size depth = 0)
        const = 0;

    virtual IExpression* create_cast(
        IExpression* src_expr,
        const IType* target_type,
        const char* cast_db_name,
        bool force_cast,
        Sint32 *errors = 0) const = 0;
};
 // end group mi_neuray_mdl_types

}  // namespace neuraylib

}  // namespace mi

#endif // MI_NEURAYLIB_IEXPRESSION_H

Namespaces

namespace 
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH. More...
namespace 
Namespace for the neuray API. More...

Classes

class 
An annotation is similar to a direct call expression, but without return type. More...
class 
An annotation block is an array of annotations. More...
class 
An annotation definition. More...
class 
An ordered collection of annotation blocks identified by name or index. More...
class 
The interface to MDL expressions. More...
class 
An indirect call expression. More...
class 
A constant expression. More...
class 
A direct call expression. More...
class 
The interface for creating expressions. More...
class 
An ordered collection of expressions identified by name or index. More...
class 
A parameter reference expression. More...
class 
A temporary reference expression. More...

Enumerations

enum  {MDL_VERSION_1_0, MDL_VERSION_1_1, MDL_VERSION_1_2, MDL_VERSION_1_3, MDL_VERSION_1_4, MDL_VERSION_1_5, MDL_VERSION_1_6, MDL_VERSION_1_7, MDL_VERSION_LATEST = MDL_VERSION_1_7, MDL_VERSION_INVALID = 0xffffffffU, MDL_VERSION_FORCE_32_BIT = 0xffffffffU }
The MDL version. More...