neuray Services API Programmer's Manual

User Types

[Types]

Description

The neuray Services API allows the user to register custom data types which can be used as arguments and results in service commands. mi::nservices::IUser_type provides the core for this functionality and it simply extends mi::IStructure. As it is derived from mi::IStructure it's elements are fixed and strictly typed. neuray Services extends on the data types supported by structures by adding the following additional types:

  • "Data" represents any data type

  • "Array" an mi::IDynamic_array containing any data type

  • "Map" an mi::IMap containing any data type

Defining user types

User types are defined with mi::nservices::IUser_type_definition which can be created off the factory: mi::nservices::IFactory::create("User_type_definition"). The name of the user type is set with IUser_type_definition::set_name( const char *name) and IUser_type_definition::add_element( const char *name, const char *type_name) is then called repeatedly to specify the elements of the user type. EG:

‎IFactory *factory = ...;
IUser_type_definition *def = factory->create("User_type_definition");
if (def) {
    def->set_name("Matrix22");
    def->add_element("xx","Float32");
    def->add_element("xy","Float32");
    def->add_element("yx","Float32");
    def->add_element("yy","Float32");
}

Using user types

Once registered, user types can be specified as command arguments or results simply by using it's name in the command implementation. EG:

‎class Example_command : public IService_command {
    virtual bool get_argument_description(
                IFactory *factory,
                const char *argument_name,
                IArgument_description *argument) const {
            if (strcmp(argument_name,"value") == 0) {
                ...
                argument->set_type_name("Matrix22");
                ...
                return true;
            };
            ...
            return false;
        };
    virtual const char *get_return_type_name() const { return "Matrix22"; };
};
And they can be created from mi::nservices::IFactory in the same manner as any other type. EG:
‎IFactory *factory;
IUser_type *mat22 = factory->create<IUser_type>("Matrix22");
if (mat22) {
    mi::IFloat32 *xx = mat22->get_value<mi::IFloat32>("xx");
    if (xx) {
        xx->set_value(1.234);
    }
    ....
}

Classes

class 
This interface represents user defined objects. More...
class 
A definition of a user type. More...