Template Class MutableGenericMap

Inheritance Relationships

Base Type

Derived Type

Class Documentation

template<typename K>
class MutableGenericMap : public lsst::afw::typehandling::GenericMap<K>

Interface for a GenericMap that allows element addition and removal.

In Python, a MutableGenericMap behaves like a collections.abc.MutableMapping.

Note

Unlike standard library maps, this class does not support operator[] or insert_or_assign. This is because these operations would have surprising behavior when dealing with keys of different types but the same Key::getId().

Subclassed by lsst::afw::typehandling::SimpleGenericMap< K >

Public Functions

virtual ~MutableGenericMap()
virtual void clear() = 0

Remove all of the mappings from this map.

After this call, the map will be empty.

template<typename T>
bool insert(Key<K, T> const &key, T const &value)

Insert an element into the map, if the map doesn’t already contain a mapping with the same or a conflicting key.

Provides strong exception safety.

Return

true if the insertion took place, false otherwise

Template Parameters
  • T: the type of value to insert

Parameters
  • key: key to insert

  • value: value to insert

Note

It is possible for a key with a value type other than T to prevent insertion. Callers can safely assume this->contains(key.getId()) as a postcondition, but not this->contains(key).

Note

This implementation calls contains, then calls unsafeInsert if there is no conflicting key.

template<typename T>
std::pair<Key<K, T>, bool> insert(K const &key, T const &value)

Insert an element into the map, if the map doesn’t already contain a mapping with a conflicting key.

Provides strong exception safety.

Return

a pair consisting of a strongly-typed key for the value and a flag that is true if the insertion took place and false otherwise

Template Parameters
  • T: the type of value to insert

Parameters
  • key: key to insert

  • value: value to insert

Warning

the type of the compiler-generated key may not always be what you expect. Callers should save the returned key if they wish to retrieve the value later.

template<typename T>
bool erase(Key<K, T> const &key)

Remove the mapping for a key from this map, if it exists.

Provides strong exception safety.

Return

true if key was removed, false if it was not present

Template Parameters
  • T: the type of value the key maps to

Parameters
  • key: the key to remove

Note

This implementation calls contains, then calls unsafeErase if the key is present.

Protected Functions

virtual bool unsafeInsert(K key, StorableType &&value) = 0

Create a new mapping with key equal to key and value equal to value.

This method is the primary way to implement the MutableGenericMap interface.

Must provide strong exception safety.

Return

true if the insertion took place, false otherwise

Parameters
  • key: the key of the element to insert. The method may assume that the map does not contain key.

  • value: a reference to the value to insert.

virtual bool unsafeErase(K key) = 0

Remove the mapping for a key from this map, if it exists.

Must provide strong exception safety.

Return

true if key was removed, false if it was not present

Parameters
  • key: the key to remove