This page is for an old version of Hexaly Optimizer. We recommend that you update your version and read the documentation for the latest stable release.

LSPMap Class

class

An LSPMap is a data structure mapping keys to values.

A map is both an associative table and an array. Setting a value to an existing key will overwrite any value previously set for that key.

When used as an array-like structure, adding a new unkeyed element to an LSPMap with addValue automatically assigns an integer key to the element equal to the largest integer key already present plus one, or zero if no integer key exists.

Most of the functions below exist in multiple versions: Values and keys can be manipulated through their native type (like int, double, std::string, LSPMap, LSPFunction, …) or manipulated with an 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.

The iterators returned by the method iterator follow the fail-fast convention: if the map is structurally modified after the creation of an iterator (by using the methods add, set, unset or clear), the iterator will throw an exception. In other words, you can’t modify a map while you are iterating over it.

Since:10.0

Summary

Functions
count Returns the number of elements in the map.
clear Erases all elements from the map.
addValue Adds the given value to the map.
addExpression Adds the given LSExpression to the map.
addFunction Adds the given LSPFunction to the map.
addMap Adds the given LSPMap to the map.
addModule Adds the given LSPModule to the map.
addString Adds the given string to the map.
addDouble Adds the given double value to the map.
addInt Adds the given integer value to the map.
addBool Adds the given boolean value to the map.
getValue Returns the value associated with the given key as an LSPValue.
getMap Returns the LSPMap associated with the given key.
getModule Returns the LSPModule associated with the given key.
getFunction Returns the LSPFunction associated with the given key.
getExpression Returns the LSExpression associated with the given key.
getString Returns the string associated with the given key.
getDouble Returns the double value associated with the given key.
getInt Returns the integer value associated with the given key.
getBool Returns the boolean value associated with the given key.
setValue Associates the LSPValue with the given key in the map.
setMap Associates the LSPMap with the given key in the map.
setModule Associates the LSPModule with the given key in the map.
setFunction Associates the LSPFunction with the given key in the map.
setExpression Associates the LSExpression with the given key in the map.
setString Associates the string with the given key in the map.
setDouble Associates the double value with the given key in the map.
setInt Associates the integer value with the given key in the map.
setBool Associates the boolean value with the given key in the map.
unset Unsets the given key in the map if present.
isDefined Returns true if the given key is defined in the map.
iterator Returns a new iterator to the elements of this map.
asValue Gets the map as an LSPValue.

Functions

lsint localsolver::modeler::LSPMap::count()
const

Returns the number of elements in the map.

void localsolver::modeler::LSPMap::clear()
const

Erases all elements from the map.

After this call, count returns zero.

void localsolver::modeler::LSPMap::addValue(const LSPValue &value)

Adds the given value to the map.

The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.

Parameters:value - Value to add in the map.

void localsolver::modeler::LSPMap::addExpression(const LSExpression &expr)

Adds the given LSExpression to the map.

The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.

Parameters:expr - LSExpression to add in the map.

void localsolver::modeler::LSPMap::addFunction(const LSPFunction &func)

Adds the given LSPFunction to the map.

The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.

Parameters:func - LSPFunction to add in the map.

void localsolver::modeler::LSPMap::addMap(const LSPMap &map)

Adds the given LSPMap to the map.

The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.

Parameters:map - LSPMap to add in the map.

void localsolver::modeler::LSPMap::addModule(const LSPModule &module)

Adds the given LSPModule to the map.

The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.

Parameters:module - LSPModule to add in the map.

void localsolver::modeler::LSPMap::addString(const std::string &str)

Adds the given string to the map.

The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.

Parameters:str - String to add in the map.

void localsolver::modeler::LSPMap::addDouble(lsdouble value)

Adds the given double value to the map.

The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.

Parameters:value - Double value to add in the map.

void localsolver::modeler::LSPMap::addInt(lsint value)

Adds the given integer value to the map.

The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.

Parameters:value - Integer value to add in the map.

void localsolver::modeler::LSPMap::addBool(bool value)

Adds the given boolean value to the map.

The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.

Parameters:value - Boolean value to add in the map.

LSPValue localsolver::modeler::LSPMap::getValue(const std::string &key)
const

Returns the value associated with the given key as an LSPValue.

If no value is associated with the key, an LSPValue representing nil is returned.

Return:LSPValue associated with the key.
Parameters:key - String key.

LSPMap localsolver::modeler::LSPMap::getMap(const std::string &key)
const

Returns the LSPMap associated with the given key.

The value must exist and must be an LSPMap.

Return:LSPMap associated with the key.
Parameters:key - String key.

LSPModule localsolver::modeler::LSPMap::getModule(const std::string &key)
const

Returns the LSPModule associated with the given key.

The value must exist and must be an LSPModule.

Return:LSPModule associated with the key.
Parameters:key - String key

LSPFunction localsolver::modeler::LSPMap::getFunction(const std::string &key)
const

Returns the LSPFunction associated with the given key.

The value must must exist and must be an LSPFunction.

Return:LSPFunction associated with the key.
Parameters:key - String key.

LSExpression localsolver::modeler::LSPMap::getExpression(const std::string &key)
const

Returns the LSExpression associated with the given key.

The value must exist and must be an LSExpression.

Return:LSExpression associated with the key.
Parameters:key - String key.

std::string localsolver::modeler::LSPMap::getString(const std::string &key)
const

Returns the string associated with the given key.

The value must exist and must be a string.

Return:String value associated with the key.
Parameters:key - String key.

lsdouble localsolver::modeler::LSPMap::getDouble(const std::string &key)
const

Returns the double value associated with the given key.

The value must exist and must be a double.

Return:Double value associated with the key.
Parameters:key - String key.

lsint localsolver::modeler::LSPMap::getInt(const std::string &key)
const

Returns the integer value associated with the given key.

The value must exist and must be an integer.

Return:Integer value associated with the key.
Parameters:key - String key.

bool localsolver::modeler::LSPMap::getBool(const std::string &key)
const

Returns the boolean value associated with the given key.

The value must exist and must be a boolean.

Return:Boolean value associated with the key.
Parameters:key - String key.

void localsolver::modeler::LSPMap::setValue(const std::string &key, const LSPValue &value)

Associates the LSPValue with the given key in the map.

If the value is nil, this has the same effect as unset. If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - String key.
  • value - LSPValue to set.

void localsolver::modeler::LSPMap::setMap(const std::string &key, const LSPMap &map)

Associates the LSPMap with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - String key.
  • map - LSPMap to set.

void localsolver::modeler::LSPMap::setModule(const std::string &key, const LSPModule &module)

Associates the LSPModule with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - String key.
  • module - LSPModule to set.

void localsolver::modeler::LSPMap::setFunction(const std::string &key, const LSPFunction &func)

Associates the LSPFunction with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:

void localsolver::modeler::LSPMap::setExpression(const std::string &key, const LSExpression &expr)

Associates the LSExpression with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:

void localsolver::modeler::LSPMap::setString(const std::string &key, const std::string &value)

Associates the string with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - String key.
  • value - String value to set.

void localsolver::modeler::LSPMap::setDouble(const std::string &key, lsdouble value)

Associates the double value with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - String key.
  • value - Double value to set.

void localsolver::modeler::LSPMap::setInt(const std::string &key, lsint value)

Associates the integer value with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - String key.
  • value - Integer value to set.

void localsolver::modeler::LSPMap::setBool(const std::string &key, bool value)

Associates the boolean value with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - String kye.
  • value - Boolean value to set.

LSPValue localsolver::modeler::LSPMap::getValue(lsint key)
const

Gets the LSPValue associated with the given key.

If the key is not present in the map, an LSPValue representing nil is returned.

Return:LSPValue associated with the key.
Parameters:key - Integer key.

LSPMap localsolver::modeler::LSPMap::getMap(lsint key)
const

Gets the LSPMap associated with the given key.

The value must exist and must be an LSPMap.

Return:LSPMap associated with the key.
Parameters:key - Integer key.

LSPModule localsolver::modeler::LSPMap::getModule(lsint key)
const

Gets the LSPModule associated with the given key.

The value must exist and must be an LSPModule.

Return:LSPModule associated with the key.
Parameters:key - Integer key.

LSPFunction localsolver::modeler::LSPMap::getFunction(lsint key)
const

Gets the LSPFunction associated with the given key.

The value must exist and must be an LSPFunction.

Return:LSPFunction associated with the key.
Parameters:key - Integer key.

LSExpression localsolver::modeler::LSPMap::getExpression(lsint key)
const

Gets the LSExpression associated with the given key.

The value must exist and must be an LSExpression.

Return:LSExpression associated with the key.
Parameters:key - Integer key.

std::string localsolver::modeler::LSPMap::getString(lsint key)
const

Gets the string associated with the given key.

The value must exist and must be a string.

Return:String associated with the key.
Parameters:key - Integer key.

lsdouble localsolver::modeler::LSPMap::getDouble(lsint key)
const

Gets the double value associated with the given key.

The value must exist and must be a double.

Return:Double value associated with the key.
Parameters:key - Integer key.

lsint localsolver::modeler::LSPMap::getInt(lsint key)
const

Gets the integer value associated with the given key.

The value must exist and must be a integer.

Return:Integer value associated with the key.
Parameters:key - Integer key.

bool localsolver::modeler::LSPMap::getBool(lsint key)
const

Gets the boolean value associated with the given key.

The value must exist and must be a boolean.

Return:Boolean value associated with the key.
Parameters:key - Integer key.

void localsolver::modeler::LSPMap::setValue(lsint key, const LSPValue &value)

Associates the LSPValue with the given key.

If the value is nil, this has the same effect as unset. If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - Integer key.
  • value - LSPValue to set.

void localsolver::modeler::LSPMap::setMap(lsint key, const LSPMap &map)

Associates the LSPMap with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - Integer key.
  • map - LSPMap to set.

void localsolver::modeler::LSPMap::setModule(lsint key, const LSPModule &module)

Associates the LSPModule with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - Integer key.
  • module - LSPModule to set.

void localsolver::modeler::LSPMap::setFunction(lsint key, const LSPFunction &func)

Associates the LSPFunction with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:

void localsolver::modeler::LSPMap::setExpression(lsint key, const LSExpression &expr)

Associates the LSExpression with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:

void localsolver::modeler::LSPMap::setString(lsint key, const std::string &value)

Associates the string with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - Integer key.
  • value - String to set.

void localsolver::modeler::LSPMap::setDouble(lsint key, lsdouble value)

Associates the double value with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - Integer key.
  • value - Double value to set.

void localsolver::modeler::LSPMap::setInt(lsint key, lsint value)

Associates the integer value with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - Integer key.
  • value - Integer value to set.

void localsolver::modeler::LSPMap::setBool(lsint key, bool value)

Associates the boolean value with the given key in the map.

If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - Integer key.
  • value - Boolean value to set.

LSPValue localsolver::modeler::LSPMap::getValue(const LSPValue &key)
const

Gets the LSPValue associated with the given key.

The key must not be nil. If the key is not present in the map, an LSPValue representing nil is returned.

Return:LSPValue associated with the key.
Parameters:key - LSPValue key.

LSPMap localsolver::modeler::LSPMap::getMap(const LSPValue &key)
const

Gets the LSPMap associated with the given key.

The key must not be nil. The value must exist and must be an LSPMap.

Return:LSPMap associated with the key.
Parameters:key - LSPValue key.

LSPModule localsolver::modeler::LSPMap::getModule(const LSPValue &key)
const

Gets the LSPModule associated with the given key.

The key must not be nil. The value must exist and must be an LSPModule.

Return:LSPModule associated with the key.
Parameters:key - LSPValue key.

LSPFunction localsolver::modeler::LSPMap::getFunction(const LSPValue &key)
const

Gets the LSPFunction associated with the given key.

The key must not be nil. The value must exist and must be an LSPFunction.

Return:LSPFunction associated with the key.
Parameters:key - LSPValue key.

LSExpression localsolver::modeler::LSPMap::getExpression(const LSPValue &key)
const

Gets the LSExpression associated with the given key.

The key must not be nil. The value must exist and must be an LSExpression.

Return:LSExpression associated with the key.
Parameters:key - LSPValue key.

std::string localsolver::modeler::LSPMap::getString(const LSPValue &key)
const

Returns the string associated with the given key.

The key must not be nil. The value must exist and must be a string.

Return:String associated with the key.
Parameters:key - LSPValue key.

lsdouble localsolver::modeler::LSPMap::getDouble(const LSPValue &key)
const

Returns the double value associated with the given key.

The key must not be nil. The value must exist and must be a double.

Return:Double value associated with the key.
Parameters:key - LSPValue key.

lsint localsolver::modeler::LSPMap::getInt(const LSPValue &key)
const

Returns the integer value associated with the given key.

The key must not be nil. The value must exist and must be an integer.

Return:Integer value associated with the key.
Parameters:key - LSPValue key.

bool localsolver::modeler::LSPMap::getBool(const LSPValue &key)
const

Returns the boolean value associated with the given key.

The key must not be nil. The value must exist and must be a boolean.

Return:Boolean value associated with the key.
Parameters:key - LSPValue key.

void localsolver::modeler::LSPMap::setValue(const LSPValue &key, const LSPValue &value)

Associates an LSPValue with the given key.

The key must not be nil. If the value is nil, this has the same effect as unset. If the map already contained an association for the key, the previous value is replaced.

Parameters:

void localsolver::modeler::LSPMap::setMap(const LSPValue &key, const LSPMap &map)

Associates an LSPMap with the given key.

The key must not be nil. If the map already contained an association for the key, the previous value is replaced.

Parameters:

void localsolver::modeler::LSPMap::setModule(const LSPValue &key, const LSPModule &module)

Associates an LSPModule with the given key.

The key must not be nil. If the map already contained an association for the key, the previous value is replaced.

Parameters:

void localsolver::modeler::LSPMap::setFunction(const LSPValue &key, const LSPFunction &func)

Associates an LSPFunction with the given key.

The key must not be nil. If the map already contained an association for the key, the previous value is replaced.

Parameters:

void localsolver::modeler::LSPMap::setExpression(const LSPValue &key, const LSExpression &expr)

Associates an LSExpression with the given key.

The key must not be nil. If the map already contained an association for the key, the previous value is replaced.

Parameters:

void localsolver::modeler::LSPMap::setString(const LSPValue &key, const std::string &value)

Associates a string with the given key.

The key must not be nil. If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - LSPValue key.
  • value - String value.

void localsolver::modeler::LSPMap::setDouble(const LSPValue &key, lsdouble value)

Associates a double value with the given key.

The key must not be nil. If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - LSPValue key.
  • value - Double value.

void localsolver::modeler::LSPMap::setInt(const LSPValue &key, lsint value)

Associates an integer value with the given key.

The key must not be nil. If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - LSPValue key.
  • value - Integer value.

void localsolver::modeler::LSPMap::setBool(const LSPValue &key, bool value)

Associates a boolean value with the given key.

The key must not be nil. If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key - LSPValue key.
  • value - Boolean value.

void localsolver::modeler::LSPMap::unset(lsint key)

Unsets the given key in the map if present.

If the key doesn’t exist in the map, does nothing.

Parameters:key - Integer key.

void localsolver::modeler::LSPMap::unset(const std::string &key)

Unsets the given key in the map if present.

If the key doesn’t exist in the map, does nothing.

Parameters:key - String key.

void localsolver::modeler::LSPMap::unset(const LSPValue &key)

Unsets the given key in the map if present.

If the key doesn’t exist in the map, does nothing.

Parameters:key - LSPValue key.

bool localsolver::modeler::LSPMap::isDefined(lsint key)
const

Returns true if the given key is defined in the map.

Parameters:key - Integer key.

bool localsolver::modeler::LSPMap::isDefined(const std::string &key)
const

Returns true if the given key is defined in the map.

Parameters:key - String key.

bool localsolver::modeler::LSPMap::isDefined(const LSPValue &key)
const

Returns true if the given key is defined in the map.

Parameters:key - LSPValue key.

LSPMapIterator localsolver::modeler::LSPMap::iterator()
const

Returns a new iterator to the elements of this map.

LSPValue localsolver::modeler::LSPMap::asValue()
const

Gets the map as an LSPValue.

Return:The map as LSPValue.