HexalyModeler Class

class HexalyModeler

Modeler environment. Main class of the modeler library which enables the creation and manipulation of a virtual machine that can load and execute programs written in the Hexaly Modeling Language.

See:

HexalyOptimizer

See:

HxmModule

Since:

10.0

Summary

Functions

HexalyModeler

Constructs a complete modeler environment.

~HexalyModeler

Deletes this modeler environment and all associated objects.

createOptimizer

Returns a new Hexaly Optimizer instance that can be used to launch a module with the method HxmModule::run().

getModule

Returns the module with the given name.

addModuleLookupPath

Adds a new lookup path for modules.

clearModuleLookupPaths

Deletes all paths used to search for modules.

loadModule

Loads the module written in Hexaly modeling language at the indicated location.

createModule

Creates an empty module with the given name.

createFunction

Creates an external HxmFunction.

createFunction

Creates an external HxmFunction.

createMap

Creates an HxmMap.

createNil

Creates a nil value.

createInt

Creates an integer value.

createDouble

Creates a double value.

createBool

Creates a boolean value.

createString

Creates a string value.

Functions

HexalyModeler::HexalyModeler()

Constructs a complete modeler environment.

See:

HexalyOptimizer

HexalyModeler::~HexalyModeler()

Deletes this modeler environment and all associated objects. This also includes optimizers created using the HexalyModeler::createOptimizer() method.

HexalyOptimizer HexalyModeler::createOptimizer()

Returns a new Hexaly Optimizer instance that can be used to launch a module with the method HxmModule::run().

Returns:

Optimizer.

See:

HexalyOptimizer

HxmModule HexalyModeler::getModule(const std::string &moduleName)

Returns the module with the given name. User modules can be accessed as well as builtin modules like the JSON module or the CSV module. If the module is not loaded, this method attempts to load it from the paths specified by HxmModule::addModuleLookupPath().

The variables of the module can then be manipulated through the associated HxmModule object.

Parameters:

moduleName – Module name.

Returns:

Module loaded.

See:

HxmModule

void HexalyModeler::addModuleLookupPath(const std::string &path)

Adds a new lookup path for modules. The paths specified when calling this method are taken into account when the modeling virtual machine loads a module, either by a direct call to the HxmModule::getModule() method, or indirectly when loading a dependency to another module. By default, the lookup path contains at least the current runtime folder.

Parameters:

path – New path to consider for modules.

void HexalyModeler::clearModuleLookupPaths()

Deletes all paths used to search for modules. This method deletes all the paths previously added by HxmModule::addModuleLookupPath() method, as well as the default location(s) (including the current execution folder).

__Important note:__ after calling this method, you must at least add a path with HxmModule::addModuleLookupPath(). Without a path, you won’t be able to load any modules other than the native ones supplied by the virtual machine.

HxmModule HexalyModeler::loadModule(const std::string &moduleName, const std::string &filePath)

Loads the module written in Hexaly modeling language at the indicated location. The loaded module will take the name specified in parameter. Unlike HxmModule::getModule(), this method ignores all paths indicated by HxmModule::addModuleLookupPath(), and if a module with a similar name is already loaded, an exception will be thrown.

Once loaded, the variables of the module can be manipulated through the associated HxmModule object.

Parameters:
  • moduleName – Name taken by the module once loaded.

  • filePath – Path to the module file.

Returns:

Module created.

See:

HxmModule

HxmModule HexalyModeler::createModule(const std::string &moduleName)

Creates an empty module with the given name. The variables of the module can then be manipulated through the associated HxmModule object.

Parameters:

moduleName – Module name.

Returns:

Module created.

See:

HxmModule

HxmFunction HexalyModeler::createFunction(HxmFunctor *functor)

Creates an external HxmFunction. The argument must be derived from HxmFunctor. When the function is called, the modeler instance will be made accessible to the function, as well as the arguments.

For instance, the following example creates a simple function that accepts two arguments and returns the sum of both values. The generated function is then exposed in a module under the name “myCustomFunction”:

class MyCustomFunction : public HxmFunctor {
    HxmValue call(HexalyModeler& modeler, const HxmValue* args, int nbArgs) override {
        return modeler.createDouble(arguments[0].asDouble() + arguments[1].asDouble());
    }
};

MyCustomFunction customFunctor;
module.setFunction("myCustomFunction", modeler.createFunction(&customFunctor));

Note: This method should only be used to expose functions used during the modeling process. You should not use this method to create a function that will be used during the resolution as anexternal function. In this case, you should instead use the optimizer API directly (see HxExternalFunction)

Parameters:

functor – Implementation of the external function.

Returns:

Function created.

See:

HxmFunctor

See:

HxmFunction

HxmFunction HexalyModeler::createFunction(const std::string &name, HxmFunctor *functor)

Creates an external HxmFunction. The argument must be derived from HxmFunctor. When the function is called, the modeler instance will be made accessible to the function, as well as the arguments.

For instance, the following example creates a simple function that accepts two arguments and returns the sum of both values. The generated function is then exposed in a module under the name “myCustomFunction”:

class MyCustomFunction : public HxmFunctor {
    HxmValue call(HexalyModeler& modeler, const HxmValue* arguments, int nbArguments) override {
        return modeler.createDouble(arguments[0].asDouble() + arguments[1].asDouble());
    }
};

MyCustomFunction customFunctor;
module.setFunction("myCustomFunction", modeler.createFunction("myCustomFunction", &customFunctor));

Note: This method should only be used to expose functions used during the modeling process. You should not use this method to create a function that will be used during the resolution as an external function. In this case, you should instead use the optimizer API directly (see HxExternalFunction)

Parameters:
  • name – Name of the function. The name is only used to identify the function in the generated stack trace when an exception occurs. Once created, the function can be associated with any variable in any module, regardless of its name.

  • functor – Implementation of the external function.

Returns:

Function created.

See:

HxmFunctor

See:

HxmFunction

HxmMap HexalyModeler::createMap()

Creates an HxmMap. A map is a data structure mapping keys to values that can also be used as an array-like structure. Keys and values can be of any type except nil. The map can be assigned to any variable in a module with HxmModule::setMap() or can be part of another map with HxmMap::setMap().

Returns:

Map created.

See:

HxmMap

HxmValue HexalyModeler::createNil()

Creates a nil value.

Returns:

Created nil value.

See:

HxmValue

HxmValue HexalyModeler::createInt(hxint value)

Creates an integer value. The value can be assigned to any variable in a module with HxmModule::setValue() or can be part of a map as key or value.

Returns:

Created integer value.

See:

HxmValue

HxmValue HexalyModeler::createDouble(hxdouble value)

Creates a double value. The value can be assigned to any variable in a module with HxmModule::setValue() or can be part of a map as key or value.

Returns:

Created double value.

See:

HxmValue

HxmValue HexalyModeler::createBool(bool value)

Creates a boolean value. Please note that there is no dedicated type for booleans in the modeler. They are simulated with integers: 1 denotes true and 0 denotes false. The created value can be assigned to any variable in a module with HxmModule::setValue() or can be part of a map as key or value.

Returns:

Created boolean value.

See:

HxmValue

HxmValue HexalyModeler::createString(const std::string &value)

Creates a string value. The value can be assigned to any variable in a module with HxmModule::setValue() or can be part of a map as key or value.

Returns:

Created string value.

See:

HxmValue