LSPModule Class

class LSPModule

A module is a collection of global variables. As LSP is a dynamically typed language, global variable can contain any value (including functions and other modules). Each LSP file is a module.

Global variables can be modified and accessed by their name specified as a string. Most of the functions below exist in multiple versions: values of the global variables can be manipulated through their native type (like int, float, std::string, LSPMap, LSPFunction…) or manipulated through LSPValue which is a container that can hold any type of value. Using the native type is more convenient and results in less overhead most of the time. LSPValue should only be used when you don’t know the type of the manipulated value.

Since

10.0

Summary

Functions

parseArguments

Parses the list of arguments and imports them in the module.

parseArguments

Parses the list of arguments and imports them in the module.

run

Entry point to the execution of a module.

run

Entry point to the execution of a module.

run

Entry point to the execution of a module.

getType

Returns the type of the variable with the given name.

getValue

Returns the LSPValue with the given name.

getInt

Returns the integer variable with the given name.

getDouble

Returns the double variable with the given name.

getBool

Returns the boolean variable with the given name.

getExpression

Returns the LSExpression with the given name.

getString

Returns the string with the given name.

getMap

Returns the LSPMap with the given name.

getFunction

Returns the LSPFunction with the given name.

getModule

Returns the LSPModule with the given name.

setValue

Sets the value associated with the variable with the given name.

setNil

Unsets the variable with the given name.

setInt

Sets the integer value associated with the variable with the given name.

setDouble

Sets the double value associated with the variable with the given name.

setBool

Sets the boolean value associated with the variable with the given name.

setExpression

Sets the LSExpression associated with the variable with the given name.

setString

Sets the string associated with the variable with the given name.

setMap

Sets the map associated with the variable with the given name.

setFunction

Sets the function associated with the variable with the given name.

setModule

Sets the module associated with the variable with the given name.

unset

Unsets the variable with the given name.

isNil

Returns true if no variable with this name exists in the module or if the variable holds a nil value.

isInt

Returns true if the variable with the given name exists and holds an integer value.

isDouble

Returns true if the variable with the given name exists and holds a double value.

isBool

Returns true if the variable with the given name exists and holds a boolean value.

isExpression

Returns true if the variable with the given name exists and holds an LSExpression.

isString

Returns true if the variable with the given name exists and holds a string value.

isMap

Returns true if the variable with the given name exists and holds an LSPMap.

isFunction

Returns true if the variable with the given name exists and holds an LSPFunction.

isModule

Returns true if the variable with the given name exists and holds an LSPModule.

asValue

Returns the module as an LSPValue.

Overloaded operators

LSPValue

Returns the module as an LSPValue.

Functions

void LSPModule::parseArguments(const std::vector<std::string> &args)

Parses the list of arguments and imports them in the module. Each argument must be of the form argName=argValue.

Parameters

args – List of arguments.

void LSPModule::parseArguments(int argc, const char *const *argv)

Parses the list of arguments and imports them in the module. Each argument must be of the form argName=argValue.

Parameters
  • argc – Number of arguments.

  • argv – Pointer to the first argument in the list.

void LSPModule::run()

Entry point to the execution of a module. Such execution is defined by the following steps:

  • The input function is executed if it exists in the module.

  • The model function is executed. It must be declared in the module.

  • The localsolver::LSModel is then closed.

  • The param function is executed if it exists in the module.

  • The function localsolver::LocalSolver::solve() is called on the corresponding solver instance. If the display function is defined, it will be called during the resolution process.

  • The output function is executed if it exists in the module.

void LSPModule::run(const std::vector<std::string> &arguments)

Entry point to the execution of a module. This is a shortcut to parsing arguments with parseArguments() before calling run().

Parameters

arguments – List of arguments

See

LSPModule::parseArguments()

See

LSPModule::run()

void LSPModule::run(int argc, const char *const *argv)

Entry point to the execution of a module. This is a shortcut to parsing arguments with parseArguments() before calling run().

Parameters
  • argc – Number of arguments.

  • argv – Point to the first arguments in the list.

See

LSPModule::parseArguments()

See

LSPModule::run()

LSPType LSPModule::getType(const std::string &varName) const

Returns the type of the variable with the given name. If the variable does not exist in the module, LSP_Nil is returned.

Parameters

varName – Name of the variable.

Returns

Type of the variable.

See

LSPType

LSPValue LSPModule::getValue(const std::string &varName) const

Returns the LSPValue with the given name. If the variable does not exist in the module, an LSPValue representing a nil value is returned.

Parameters

varName – Name of the variable.

Returns

LSPValue associated with the given name.

See

LSPValue

lsint LSPModule::getInt(const std::string &varName) const

Returns the integer variable with the given name. The variable must exist and must hold an integer value.

Parameters

varName – Name of the variable.

Returns

Integer value associated with the given name.

lsdouble LSPModule::getDouble(const std::string &varName) const

Returns the double variable with the given name. The variable must exist and must hold a double value.

Parameters

varName – Name of the variable.

Returns

Double value associated with the given name.

bool LSPModule::getBool(const std::string &varName) const

Returns the boolean variable with the given name. The variable must exist and must hold a boolean value.

Parameters

varName – Name of the variable.

Returns

Boolean value associated with the given name.

LSExpression LSPModule::getExpression(const std::string &varName) const

Returns the LSExpression with the given name. The variable must exist and must hold a value of type LSP_Expression.

Parameters

varName – Name of the variable.

Returns

LSExpression associated with the given name.

std::string LSPModule::getString(const std::string &varName) const

Returns the string with the given name. The variable must exist and must hold a string value.

Parameters

varName – Name of the variable.

Returns

String associated with the given name.

LSPMap LSPModule::getMap(const std::string &varName) const

Returns the LSPMap with the given name. The variable must exist and must hold a map.

Parameters

varName – Name of the variable.

Returns

LSPMap associated with the given name.

LSPFunction LSPModule::getFunction(const std::string &varName) const

Returns the LSPFunction with the given name. The variable must exist and must hold a function.

Parameters

varName – Name of the variable.

Returns

LSPFunction associated with the given name.

LSPModule LSPModule::getModule(const std::string &varName) const

Returns the LSPModule with the given name. The variable must exist and must hold a module.

Parameters

varName – Name of the variable.

Returns

LSPModule associated with the given name.

void LSPModule::setValue(const std::string &varName, const LSPValue &value)

Sets the value associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.

Parameters
  • varName – Name of the variable.

  • value – Value of the variable.

void LSPModule::setNil(const std::string &varName)

Unsets the variable with the given name. Do nothing it the variable does not exist.

Parameters

varName – Name of the variable.

void LSPModule::setInt(const std::string &varName, lsint value)

Sets the integer value associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.

Parameters
  • varName – Name of the variable.

  • value – Value of the variable.

void LSPModule::setDouble(const std::string &varName, lsdouble value)

Sets the double value associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.

Parameters
  • varName – Name of the variable.

  • value – Value of the variable.

void LSPModule::setBool(const std::string &varName, bool value)

Sets the boolean value associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.

Parameters
  • varName – Name of the variable.

  • value – Value of the variable.

void LSPModule::setExpression(const std::string &varName, const LSExpression &expr)

Sets the LSExpression associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.

Parameters
  • varName – Name of the variable.

  • expr – Value of the variable.

void LSPModule::setString(const std::string &varName, const std::string &value)

Sets the string associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.

Parameters
  • varName – Name of the variable.

  • value – Value of the variable.

void LSPModule::setMap(const std::string &varName, const LSPMap &map)

Sets the map associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.

Parameters
  • varName – Name of the variable.

  • map – Value of the variable.

void LSPModule::setFunction(const std::string &varName, const LSPFunction &function)

Sets the function associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.

Parameters
  • varName – Name of the variable.

  • function – Value of the variable.

void LSPModule::setModule(const std::string &varName, const LSPModule &module)

Sets the module associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.

Parameters
  • varName – Name of the variable.

  • module – Value of the variable.

void LSPModule::unset(const std::string &varName)

Unsets the variable with the given name. Do nothing it the variable does not exist.

Parameters

varName – Name of the variable.

bool LSPModule::isNil(const std::string &varName) const

Returns true if no variable with this name exists in the module or if the variable holds a nil value.

Parameters

varName – Name of the variable.

bool LSPModule::isInt(const std::string &varName) const

Returns true if the variable with the given name exists and holds an integer value.

Parameters

varName – Name of the variable.

bool LSPModule::isDouble(const std::string &varName) const

Returns true if the variable with the given name exists and holds a double value.

Parameters

varName – Name of the variable.

bool LSPModule::isBool(const std::string &varName) const

Returns true if the variable with the given name exists and holds a boolean value.

Parameters

varName – Name of the variable.

bool LSPModule::isExpression(const std::string &varName) const

Returns true if the variable with the given name exists and holds an LSExpression.

Parameters

varName – Name of the variable.

bool LSPModule::isString(const std::string &varName) const

Returns true if the variable with the given name exists and holds a string value.

Parameters

varName – Name of the variable.

bool LSPModule::isMap(const std::string &varName) const

Returns true if the variable with the given name exists and holds an LSPMap.

Parameters

varName – Name of the variable.

bool LSPModule::isFunction(const std::string &varName) const

Returns true if the variable with the given name exists and holds an LSPFunction.

Parameters

varName – Name of the variable.

bool LSPModule::isModule(const std::string &varName) const

Returns true if the variable with the given name exists and holds an LSPModule.

Parameters

varName – Name of the variable.

LSPValue LSPModule::asValue() const

Returns the module as an LSPValue.

Overloaded operators

explicit operator LSPModule::LSPValue() const

Returns the module as an LSPValue.

See

LSPValue