LSCollection Class

class

Value type for collection expressions (lists or sets).

Such value is obtained with LSExpression::getCollectionValue() or LSSolution::getCollectionValue(const LSExpression). It represents a reference to the value of a variable and the value of this variable is modified when the LSCollection object is modified.

See:LSSolution
See:LSExpression
Since:5.5

Summary

Functions
add Adds the given value to this collection.
clear Removes all values of this collection.
count Returns the number of values in the collection.
get Gets the value at the given position.
contains Returns true if the collection contains the given value, false otherwise.
toString Returns a string representation of the values in the collection in the format \u201c{ val0, val1, \u2026, valN }\u201d.
Overloaded operators
operator[] Operator overloading for get.

Functions

void localsolver::LSCollection::add(lsint val)

Adds the given value to this collection.

Only allowed in state S_Stopped. This function will fail if the given value is outside of the domain of the list/set or if this value is already included in this list/set (keep in mind that a list or a set cannot contain twice the same value).

Parameters:val - The value to be added.

void localsolver::LSCollection::clear()

Removes all values of this collection.

Only allowed in state S_Stopped.

int localsolver::LSCollection::count()
const

Returns the number of values in the collection.

Values in collections are indexed from 0 to count()-1.

lsint localsolver::LSCollection::get(int position)
const

Gets the value at the given position.

Parameters:position - The considered position (must be non negative and strictly smaller than the number of values in the collection).

bool localsolver::LSCollection::contains(lsint value)
const

Returns true if the collection contains the given value, false otherwise.

Parameters:value - element whose presence in this collection is to be tested

lsint localsolver::LSCollection::operator[](int position)
const

Operator overloading for get.

Parameters:position - The considered position (must be non negative and strictly smaller than the number of values in the collection).

std::string localsolver::LSCollection::toString()
const

Returns a string representation of the values in the collection in the format “{ val0, val1, …, valN }”.

Return:String representation.