LSPMap Class

class localsolver.modeler.LSPMap

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 LSPMap.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, 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 enumerators returned by the method GetEnumerator() follow the fail-fast convention: if the map is structurally modified after the creation of an enumerator (by using the methods Add, Set, Unset or Clear), the enumerator will throw an exception. In other words, you can’t modify a map while you are iterating over it.

Since

10.0

Summary

Methods

Count

Returns the number of elements in the map.

Clear

Erases all elements from the map.

AddValue

Adds the given value in the map.

AddInt

Adds the given integer value in the map.

AddDouble

Adds the given double value in the map.

AddBool

Adds the given boolean value in the map.

AddExpression

Adds the given expression in the map.

AddString

Adds the given string value in the map.

AddMap

Adds the given map in the map.

AddFunction

Adds the given function in the map.

AddModule

Adds the given module in the map.

GetValue

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

GetInt

Returns the integer value associated with the given key.

GetDouble

Returns the double value associated with the given key.

GetBool

Returns the boolean value associated with the given key.

GetString

Returns the string value associated with the given key.

GetExpression

Returns the LSExpression associated with the given key.

GetMap

Returns the map associated with the given key.

GetFunction

Returns the function associated with the given key.

GetModule

Returns the module associated with the given key.

SetValue

Associates the LSPValue to the given key in the map.

SetInt

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

SetDouble

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

SetBool

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

SetString

Associates the string value to the given key in the map.

SetExpression

Associates the expression to the given key in the map.

SetMap

Associates the map to the given key in the map.

SetFunction

Associates the function to the given key in the map.

SetModule

Associates the module to 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.

AsValue

Returns the map as a LSPValue.

GetEnumerator

Returns an iterator to the elements of this map.

Instance methods

long Count()

Returns the number of elements in the map.

void Clear()

Erases all elements from the map. After this call, LSPMap.Count() returns zero.

void AddValue(LSPValue value)

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

Arguments

value (LSPValue) – Value to add in the map.

void AddInt(long value)

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

Arguments

value (long) – Value to add in the map.

void AddDouble(double value)

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

Arguments

value (double) – Value to add in the map.

void AddBool(bool value)

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

Arguments

value (bool) – Value to add in the map.

void AddExpression(LSExpression expr)

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

Arguments

expr (LSExpression) – Value to add in the map.

void AddString(string value)

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

Arguments

value (string) – Value to add in the map.

void AddMap(LSPMap map)

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

Arguments

map (LSPMap) – Map to add in the map.

void AddFunction(LSPFunction function)

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

Arguments

function (LSPFunction) – Function to add in the map.

void AddModule(LSPModule module)

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

Arguments

module (LSPModule) – Module to add in the map.

LSPValue GetValue(long key)
LSPValue GetValue(string key)
LSPValue GetValue(LSPValue key)

Returns the value associated with the given key as a LSPValue. If no value is associated with the key, an LSPValue representing nil is returned.

Arguments

key (long, string or LSPValue) – Key searched.

Returns

LSPValue associated with the key.

Return type

LSPValue

long GetInt(long key)
long GetInt(string key)
long GetInt(LSPValue key)

Returns the integer value associated with the given key. The value must exist and must be an integer.

Arguments

key (long, string or LSPValue) – Key searched.

Returns

Integer value associated with the key.

Return type

long

double GetDouble(long key)
double GetDouble(string key)
double GetDouble(LSPValue key)

Returns the double value associated with the given key. The value must exist and must be a double.

Arguments

key (long, string or LSPValue) – Key searched.

Returns

Double value associated with the key.

Return type

double

bool GetBool(long key)
bool GetBool(string key)
bool GetBool(LSPValue key)

Returns the boolean value associated with the given key. The value must exist and must be a boolean.

Arguments

key (long, string or LSPValue) – Key searched.

Returns

Boolean value associated with the key.

Return type

bool

string GetString(long key)
string GetString(string key)
string GetString(LSPValue key)

Returns the string value associated with the given key. The value must exist and must be a string.

Arguments

key (long, string or LSPValue) – Key searched.

Returns

String value associated with the key.

Return type

string

LSExpression GetExpression(long key)
LSExpression GetExpression(string key)
LSExpression GetExpression(LSPValue key)

Returns the LSExpression associated with the given key. The value must exist and must be an expression.

Arguments

key (long, string or LSPValue) – Key searched.

Returns

Expression associated with the key.

Return type

LSExpression

LSPMap GetMap(long key)
LSPMap GetMap(string key)
LSPMap GetMap(LSPValue key)

Returns the map associated with the given key. The value must exist and must be a map.

Arguments

key (long, string or LSPValue) – Key searched.

Returns

Map associated with the key.

Return type

LSPMap

LSPFunction GetFunction(long key)
LSPFunction GetFunction(string key)
LSPFunction GetFunction(LSPValue key)

Returns the function associated with the given key. The value must exist and must be a function.

Arguments

key (long, string or LSPValue) – Key searched.

Returns

Function associated with the key.

Return type

LSPFunction

LSPModule GetModule(long key)
LSPModule GetModule(string key)
LSPModule GetModule(LSPValue key)

Returns the module associated with the given key. The value must exist and must be a module.

Arguments

key (long, string or LSPValue) – Key searched.

Returns

Module associated with the key.

Return type

LSPModule

void SetValue(long key, LSPValue value)
void SetValue(string key, LSPValue value)
void SetValue(LSPValue key, LSPValue value)

Associates the LSPValue to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as Unset().

Arguments
  • key (long, string or LSPValue) – Key to set.

  • value (LSPValue) – Value to set.

void SetInt(long key, long value)
void SetInt(string key, long value)
void SetInt(LSPValue key, long value)

Associates the integer value to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as Unset().

Arguments
  • key (long, string or LSPValue) – Key to set.

  • value (long) – Value to set.

void SetDouble(long key, double value)
void SetDouble(string key, double value)
void SetDouble(LSPValue key, double value)

Associates the double value to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as Unset().

Arguments
  • key (long, string or LSPValue) – Key to set.

  • value (double) – Value to set.

void SetBool(long key, bool value)
void SetBool(string key, bool value)
void SetBool(LSPValue key, bool value)

Associates the boolean value to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as Unset().

Arguments
  • key (long, string or LSPValue) – Key to set.

  • value (bool) – Value to set.

void SetString(long key, string value)
void SetString(string key, string value)
void SetString(LSPValue key, string value)

Associates the string value to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as Unset().

Arguments
  • key (long, string or LSPValue) – Key to set.

  • value (string) – Value to set.

void SetExpression(long key, LSExpression expr)
void SetExpression(string key, LSExpression expr)
void SetExpression(LSPValue key, LSExpression expr)

Associates the expression to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as Unset().

Arguments
void SetMap(long key, LSPMap map)
void SetMap(string key, LSPMap map)
void SetMap(LSPValue key, LSPMap map)

Associates the map to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as Unset().

Arguments
  • key (long, string or LSPValue) – Key to set.

  • value (LSPMap) – Map to set.

void SetFunction(long key, LSPFunction function)
void SetFunction(string key, LSPFunction function)
void SetFunction(LSPValue key, LSPFunction function)

Associates the function to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as Unset().

Arguments
void SetModule(long key, LSPModule module)
void SetModule(string key, LSPModule module)
void SetModule(LSPValue key, LSPModule module)

Associates the module to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as Unset().

Arguments
  • key (long, string or LSPValue) – Key to set.

  • value (LSPModule) – Module to set.

void Unset(long key)
void Unset(string key)
void Unset(LSPValue key)

Unsets the given key in the map if present. If the key doesn’t exist in the map do nothing. The key must not be nil.

Arguments

key (long, string or LSPValue) – Key to unset.

bool IsDefined(long key)
bool IsDefined(string key)
bool IsDefined(LSPValue key)

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

Arguments

key (long, string or LSPValue) – Key to search.

LSPValue AsValue()

Returns the map as a LSPValue.

Returns

The map as an LSPValue.

Return type

LSPValue

IEnumerator<KeyValuePair<LSPValue, GetEnumerator()

Returns an iterator to the elements of this map.

Returns

Iterator to the elements of this map.

Return type

IEnumerator