HxmMap Class

class HxmMap

An HxmMap 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 HxmMap 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, HxmMap, HxmFunction, …) or manipulated with an HxmValue 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. HxmValue 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.

addInt

Adds the given integer value to the map.

addDouble

Adds the given double value to the map.

addBool

Adds the given boolean value to the map.

addExpression

Adds the given HxExpression to the map.

addString

Adds the given string to the map.

addMap

Adds the given HxmMap to the map.

addFunction

Adds the given HxmFunction to the map.

addModule

Adds the given HxmModule to the map.

getValue

Gets the HxmValue associated with the given key.

getValue

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

getValue

Gets the HxmValue associated with the given key.

getInt

Gets the integer value associated with the given key.

getInt

Returns the integer value associated with the given key.

getInt

Returns the integer value associated with the given key.

getDouble

Gets the double value associated with the given key.

getDouble

Returns the double value associated with the given key.

getDouble

Returns the double value associated with the given key.

getBool

Gets the boolean value associated with the given key.

getBool

Returns the boolean value associated with the given key.

getBool

Returns the boolean value associated with the given key.

getString

Gets the string associated with the given key.

getString

Returns the string associated with the given key.

getString

Returns the string associated with the given key.

getExpression

Gets the HxExpression associated with the given key.

getExpression

Returns the HxExpression associated with the given key.

getExpression

Gets the HxExpression associated with the given key.

getMap

Gets the HxmMap associated with the given key.

getMap

Returns the HxmMap associated with the given key.

getMap

Gets the HxmMap associated with the given key.

getFunction

Gets the HxmFunction associated with the given key.

getFunction

Returns the HxmFunction associated with the given key.

getFunction

Gets the HxmFunction associated with the given key.

getModule

Gets the HxmModule associated with the given key.

getModule

Returns the HxmModule associated with the given key.

getModule

Gets the HxmModule associated with the given key.

setValue

Associates the HxmValue with the given key.

setValue

Associates the HxmValue with the given key in the map.

setValue

Associates an HxmValue with the given key.

setInt

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

setInt

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

setInt

Associates an integer value with the given key.

setDouble

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

setDouble

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

setDouble

Associates a double value with the given key.

setBool

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

setBool

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

setBool

Associates a boolean value with the given key.

setString

Associates the string with the given key in the map.

setString

Associates the string with the given key in the map.

setString

Associates a string with the given key.

setExpression

Associates the HxExpression with the given key in the map.

setExpression

Associates the HxExpression with the given key in the map.

setExpression

Associates an HxExpression with the given key.

setMap

Associates the HxmMap with the given key in the map.

setMap

Associates the HxmMap with the given key in the map.

setMap

Associates an HxmMap with the given key.

setFunction

Associates the HxmFunction with the given key in the map.

setFunction

Associates the HxmFunction with the given key in the map.

setFunction

Associates an HxmFunction with the given key.

setModule

Associates the HxmModule with the given key in the map.

setModule

Associates the HxmModule with the given key in the map.

setModule

Associates an HxmModule with the given key.

unset

Unsets the given key in the map if present.

unset

Unsets the given key in the map if present.

unset

Unsets the given key in the map if present.

isDefined

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

isDefined

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

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 HxmValue.

Overloaded operators

HxmValue

Returns the map as an HxmValue.

Functions

hxint HxmMap::count() const

Returns the number of elements in the map.

void HxmMap::clear() const

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

void HxmMap::addValue(const HxmValue &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 HxmMap::addInt(hxint 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 HxmMap::addDouble(hxdouble 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 HxmMap::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.

void HxmMap::addExpression(const HxExpression &expr)

Adds the given HxExpression 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 – HxExpression to add in the map.

void HxmMap::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 HxmMap::addMap(const HxmMap &map)

Adds the given HxmMap 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 – HxmMap to add in the map.

void HxmMap::addFunction(const HxmFunction &func)

Adds the given HxmFunction 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 – HxmFunction to add in the map.

void HxmMap::addModule(const HxmModule &module)

Adds the given HxmModule 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 – HxmModule to add in the map.

HxmValue HxmMap::getValue(hxint key) const

Gets the HxmValue associated with the given key. If the key is not present in the map, an HxmValue representing nil is returned.

Parameters:

key – Integer key.

Returns:

HxmValue associated with the key.

HxmValue HxmMap::getValue(const std::string &key) const

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

Parameters:

key – String key.

Returns:

HxmValue associated with the key.

HxmValue HxmMap::getValue(const HxmValue &key) const

Gets the HxmValue associated with the given key. The key must not be nil. If the key is not present in the map, an HxmValue representing nil is returned.

Parameters:

key – HxmValue key.

Returns:

HxmValue associated with the key.

hxint HxmMap::getInt(hxint key) const

Gets the integer value associated with the given key. The value must exist and must be a integer.

Parameters:

key – Integer key.

Returns:

Integer value associated with the key.

hxint HxmMap::getInt(const std::string &key) const

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

Parameters:

key – String key.

Returns:

Integer value associated with the key.

hxint HxmMap::getInt(const HxmValue &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.

Parameters:

key – HxmValue key.

Returns:

Integer value associated with the key.

hxdouble HxmMap::getDouble(hxint key) const

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

Parameters:

key – Integer key.

Returns:

Double value associated with the key.

hxdouble HxmMap::getDouble(const std::string &key) const

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

Parameters:

key – String key.

Returns:

Double value associated with the key.

hxdouble HxmMap::getDouble(const HxmValue &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.

Parameters:

key – HxmValue key.

Returns:

Double value associated with the key.

bool HxmMap::getBool(hxint key) const

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

Parameters:

key – Integer key.

Returns:

Boolean value associated with the key.

bool HxmMap::getBool(const std::string &key) const

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

Parameters:

key – String key.

Returns:

Boolean value associated with the key.

bool HxmMap::getBool(const HxmValue &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.

Parameters:

key – HxmValue key.

Returns:

Boolean value associated with the key.

std::string HxmMap::getString(hxint key) const

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

Parameters:

key – Integer key.

Returns:

String associated with the key.

std::string HxmMap::getString(const std::string &key) const

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

Parameters:

key – String key.

Returns:

String value associated with the key.

std::string HxmMap::getString(const HxmValue &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.

Parameters:

key – HxmValue key.

Returns:

String associated with the key.

HxExpression HxmMap::getExpression(hxint key) const

Gets the HxExpression associated with the given key. The value must exist and must be an HxExpression.

Parameters:

key – Integer key.

Returns:

HxExpression associated with the key.

HxExpression HxmMap::getExpression(const std::string &key) const

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

Parameters:

key – String key.

Returns:

HxExpression associated with the key.

HxExpression HxmMap::getExpression(const HxmValue &key) const

Gets the HxExpression associated with the given key. The key must not be nil. The value must exist and must be an HxExpression.

Parameters:

key – HxmValue key.

Returns:

HxExpression associated with the key.

HxmMap HxmMap::getMap(hxint key) const

Gets the HxmMap associated with the given key. The value must exist and must be an HxmMap.

Parameters:

key – Integer key.

Returns:

HxmMap associated with the key.

HxmMap HxmMap::getMap(const std::string &key) const

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

Parameters:

key – String key.

Returns:

HxmMap associated with the key.

HxmMap HxmMap::getMap(const HxmValue &key) const

Gets the HxmMap associated with the given key. The key must not be nil. The value must exist and must be an HxmMap.

Parameters:

key – HxmValue key.

Returns:

HxmMap associated with the key.

HxmFunction HxmMap::getFunction(hxint key) const

Gets the HxmFunction associated with the given key. The value must exist and must be an HxmFunction.

Parameters:

key – Integer key.

Returns:

HxmFunction associated with the key.

HxmFunction HxmMap::getFunction(const std::string &key) const

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

Parameters:

key – String key.

Returns:

HxmFunction associated with the key.

HxmFunction HxmMap::getFunction(const HxmValue &key) const

Gets the HxmFunction associated with the given key. The key must not be nil. The value must exist and must be an HxmFunction.

Parameters:

key – HxmValue key.

Returns:

HxmFunction associated with the key.

HxmModule HxmMap::getModule(hxint key) const

Gets the HxmModule associated with the given key. The value must exist and must be an HxmModule.

Parameters:

key – Integer key.

Returns:

HxmModule associated with the key.

HxmModule HxmMap::getModule(const std::string &key) const

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

HxmModule HxmMap::getModule(const HxmValue &key) const

Gets the HxmModule associated with the given key. The key must not be nil. The value must exist and must be an HxmModule.

Parameters:

key – HxmValue key.

Returns:

HxmModule associated with the key.

void HxmMap::setValue(hxint key, const HxmValue &value)

Associates the HxmValue with the given key. If the value is nil, this has the same effect as HxmMap::unset(). If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key – Integer key.

  • value – HxmValue to set.

void HxmMap::setValue(const std::string &key, const HxmValue &value)

Associates the HxmValue with the given key in the map. If the value is nil, this has the same effect as HxmMap::unset(). If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key – String key.

  • value – HxmValue to set.

void HxmMap::setValue(const HxmValue &key, const HxmValue &value)

Associates an HxmValue with the given key. The key must not be nil. If the value is nil, this has the same effect as HxmMap::unset(). If the map already contained an association for the key, the previous value is replaced.

Parameters:
  • key – HxmValue key.

  • value – HxmValue value.

void HxmMap::setInt(hxint key, hxint 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 HxmMap::setInt(const std::string &key, hxint 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 HxmMap::setInt(const HxmValue &key, hxint 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 – HxmValue key.

  • value – Integer value.

void HxmMap::setDouble(hxint key, hxdouble 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 HxmMap::setDouble(const std::string &key, hxdouble 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 HxmMap::setDouble(const HxmValue &key, hxdouble 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 – HxmValue key.

  • value – Double value.

void HxmMap::setBool(hxint 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.

void HxmMap::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 key.

  • value – Boolean value to set.

void HxmMap::setBool(const HxmValue &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 – HxmValue key.

  • value – Boolean value.

void HxmMap::setString(hxint 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 HxmMap::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 HxmMap::setString(const HxmValue &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 s replaced.

Parameters:
  • key – HxmValue key.

  • value – String value.

void HxmMap::setExpression(hxint key, const HxExpression &expr)

Associates the HxExpression 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.

  • expr – HxExpression to set.

void HxmMap::setExpression(const std::string &key, const HxExpression &expr)

Associates the HxExpression 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.

  • expr – HxExpression to set.

void HxmMap::setExpression(const HxmValue &key, const HxExpression &expr)

Associates an HxExpression 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 – HxmValue key.

  • expr – HxExpression value.

void HxmMap::setMap(hxint key, const HxmMap &map)

Associates the HxmMap 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 – HxmMap to set.

void HxmMap::setMap(const std::string &key, const HxmMap &map)

Associates the HxmMap 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 – HxmMap to set.

void HxmMap::setMap(const HxmValue &key, const HxmMap &map)

Associates an HxmMap 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 – HxmValue key.

  • map – HxmMap value.

void HxmMap::setFunction(hxint key, const HxmFunction &func)

Associates the HxmFunction 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.

  • func – HxmFunction to set.

void HxmMap::setFunction(const std::string &key, const HxmFunction &func)

Associates the HxmFunction 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.

  • func – HxmFunction to set.

void HxmMap::setFunction(const HxmValue &key, const HxmFunction &func)

Associates an HxmFunction 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 – HxmValue key.

  • func – HxmFunction value.

void HxmMap::setModule(hxint key, const HxmModule &module)

Associates the HxmModule 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 – HxmModule to set.

void HxmMap::setModule(const std::string &key, const HxmModule &module)

Associates the HxmModule 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 – HxmModule to set.

void HxmMap::setModule(const HxmValue &key, const HxmModule &module)

Associates an HxmModule 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 – HxmValue key.

  • module – HxmModule value.

void HxmMap::unset(hxint 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 HxmMap::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 HxmMap::unset(const HxmValue &key)

Unsets the given key in the map if present. If the key doesn’t exist in the map, does nothing.

Parameters:

key – HxmValue key.

bool HxmMap::isDefined(hxint key) const

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

Parameters:

key – Integer key.

bool HxmMap::isDefined(const std::string &key) const

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

Parameters:

key – String key.

bool HxmMap::isDefined(const HxmValue &key) const

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

Parameters:

key – HxmValue key.

HxmMapIterator HxmMap::iterator() const

Returns a new iterator to the elements of this map.

HxmValue HxmMap::asValue() const

Gets the map as an HxmValue.

Returns:

The map as HxmValue.

Overloaded operators

explicit operator HxmMap::HxmValue() const

Returns the map as an HxmValue.

See:

HxmValue