Class StorableMap

Class Documentation

class StorableMap

A map of Storable supporting strongly-typed access.

A Key for the map is parameterized by both the key type K and a corresponding value type V. The map is indexed uniquely by a value of type K; no two entries in the map may have identical values of Key::getId().

All operations are sensitive to the value type of the key: a contains call requesting a SkyWcs labeled “value”, for example, will report no such object if instead there is a Psf labeled “value”. At present, a StorableMap does not store type information internally, instead relying on RTTI for type checking.

Unnamed Group

bool operator==(StorableMap const &other) const

Test for map equality.

Two StorableMap objects are considered equal if they map the same keys to the same values.

bool operator!=(StorableMap const &other) const

Unnamed Group

iterator begin()

Return an iterator to the first element of the map.

Return

An iterator that dereferences to a value_type, i.e. a pair of const Key and shared pointer to const Storable.

const_iterator begin() const
const_iterator cbegin() const

Unnamed Group

iterator end()

Return an iterator to the element past the end of the map.

Return

An iterator that dereferences to a value_type, i.e. a pair of const Key and shared pointer to const Storable.

const_iterator end() const
const_iterator cend() const

Public Types

using mapped_type = std::shared_ptr<typehandling::Storable const>
using key_type = typehandling::Key<std::string, mapped_type>
using value_type = std::pair<key_type const, mapped_type>
using size_type = std::size_t
using difference_type = std::ptrdiff_t
using reference = value_type&
using const_reference = value_type const&
using pointer = value_type *
using const_pointer = value_type const *
using const_iterator = _Impl::const_iterator
using iterator = _Impl::iterator
using reverse_iterator = std::reverse_iterator<iterator>
using const_reverse_iterator = std::reverse_iterator<const_iterator>
using Key = lsst::afw::typehandling::Key<std::string, V>
using Storable = lsst::afw::typehandling::Storable

Public Functions

StorableMap()
StorableMap(StorableMap const &other)
StorableMap(StorableMap &&other)
StorableMap &operator=(StorableMap const &other)
StorableMap &operator=(StorableMap &&other)
~StorableMap()
StorableMap(std::initializer_list<value_type> init)

Construct a map from an initializer list.

Note

If init contains any keys with the same ID, it is unspecified which will be inserted.

See

std::map::map

Parameters
  • init: an initializer list of key-value pairs. The keys and values may be of any type that can be converted to std::shared_ptr<typehandling::Storable const>.

template<typename T>
std::shared_ptr<T> at(Key<std::shared_ptr<T>> const &key) const

Return a the mapped value of the element with key equal to key.

Return

a pointer to the T mapped to key, if one exists

Template Parameters
  • T: the type of the element mapped to key. It may be the exact type of the element, if known, or any type to which its pointers can be implicitly converted (e.g., a superclass).

Parameters
  • key: the key of the element to find

Exceptions
  • pex::exceptions::OutOfRangeError: Thrown if the map does not have a T with the specified key. Provides strong exception safety.

size_type size() const

Return the number of key-value pairs in the map.

bool empty() const

Return true if this map contains no key-value pairs.

size_type max_size() const

Return the maximum number of elements the container is able to hold due to system or library implementation limitations.

Note

This value typically reflects the theoretical limit on the size of the container. At runtime, the size of the container may be limited to a value smaller than max_size() by the amount of RAM available.

bool contains(std::string const &key) const

Return true if this map contains a mapping whose key has the specified label.

More formally, this method returns true if and only if this map contains a mapping with a key k such that k.getId() == key. There can be at most one such mapping.

Provides strong exception safety.

Return

true if this map contains a mapping for key, regardless of value type.

Parameters
  • key: the weakly-typed key to search for

template<typename T>
bool contains(Key<std::shared_ptr<T>> const &key) const

Return true if this map contains a mapping for the specified key.

This is equivalent to testing whether at(key) would succeed.

Provides strong exception safety.

Return

true if this map contains a mapping from the specified key to a T.

Template Parameters
  • T: the type of element being tested for

Parameters
  • key: the key to search for

void clear()

Remove all of the mappings from this map.

After this call, the map will be empty.

template<typename T>
bool insert(Key<std::shared_ptr<T>> const &key, std::shared_ptr<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: the key to insert

  • value: the 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).

template<typename T>
std::pair<Key<T>, bool> insert(std::string 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 (will not compile unless shared pointer to a subclass of Storable)

Parameters
  • key: the key to insert

  • value: the value to insert

Warning

The type of the compiler-generated key may be surprising. Callers should save the returned key if they wish to retrieve the value later.

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

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

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