lsst.afw  17.0.1-26-ga1fda76f0
Public Types | Public Member Functions | Protected Types | Protected Member Functions | List of all members
lsst::afw::typehandling::GenericMap< K > Class Template Referenceabstract

Interface for a heterogeneous map. More...

#include <GenericMap.h>

Inheritance diagram for lsst::afw::typehandling::GenericMap< K >:
lsst::afw::typehandling::MutableGenericMap< K > lsst::afw::typehandling::SimpleGenericMap< K >

Public Types

using key_type = K
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 

Public Member Functions

virtual ~GenericMap () noexcept=default
 
virtual size_type size () const noexcept=0
 Return the number of key-value pairs in the map. More...
 
virtual bool empty () const noexcept=0
 Return true if this map contains no key-value pairs. More...
 
virtual size_type max_size () const noexcept=0
 Return the maximum number of elements the container is able to hold due to system or library implementation limitations. More...
 
template<typename T >
size_type count (Key< K, T > const &key) const
 Return the number of elements mapped to the specified key. More...
 
virtual bool contains (K const &key) const =0
 Return true if this map contains a mapping whose key has the specified label. More...
 
virtual std::vector< K > keys () const =0
 Return the set of all keys, without type information. More...
 
template<typename T , typename std::enable_if_t<!IS_SMART_PTR< T >, int > = 0>
T & at (Key< K, T > const &key)
 Return a reference to the mapped value of the element with key equal to key. More...
 
template<typename T , typename std::enable_if_t< std::is_fundamental< T >::value||std::is_base_of< std::string, T >::value, int > = 0>
T const & at (Key< K, T > const &key) const
 Return a reference to the mapped value of the element with key equal to key. More...
 
template<typename T , typename std::enable_if_t< std::is_base_of< Storable, T >::value, int > = 0>
T const & at (Key< K, T > const &key) const
 Return a reference to the mapped value of the element with key equal to key. More...
 
template<typename T , typename std::enable_if_t< std::is_base_of< Storable, T >::value, int > = 0>
std::shared_ptr< T > at (Key< K, std::shared_ptr< T >> const &key) const
 Return a reference to the mapped value of the element with key equal to key. More...
 
template<typename T , typename std::enable_if_t< std::is_fundamental< T >::value||std::is_base_of< std::string, T >::value, int > = 0>
bool contains (Key< K, T > const &key) const
 Return true if this map contains a mapping for the specified key. More...
 
template<typename T , typename std::enable_if_t< std::is_base_of< Storable, T >::value, int > = 0>
bool contains (Key< K, T > const &key) const
 Return true if this map contains a mapping for the specified key. More...
 
template<typename T , typename std::enable_if_t< std::is_base_of< Storable, T >::value, int > = 0>
bool contains (Key< K, std::shared_ptr< T >> const &key) const
 Return true if this map contains a mapping for the specified key. More...
 
virtual bool operator== (GenericMap const &other) const
 Test for map equality. More...
 
bool operator!= (GenericMap const &other) const
 Test for map equality. More...
 

Protected Types

using ValueReference = boost::variant< bool const &, std::int32_t const &, std::int64_t const &, float const &, double const &, std::string const &, PolymorphicValue const &, std::shared_ptr< Storable > const & >
 A type-agnostic reference to the value stored inside the map. More...
 
using StorableType = decltype(_referenceToType(std::declval< ValueReference >()))
 The types that can be stored in a map. More...
 

Protected Member Functions

virtual ValueReference unsafeLookup (K key) const =0
 Return a reference to the mapped value of the element with key equal to key. More...
 

Detailed Description

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

Interface for a heterogeneous map.

Objects of type GenericMap cannot necessarily have keys added or removed, although mutable values can be modified as usual. In Python, a GenericMap behaves like a collections.abc.Mapping. See MutableGenericMap for a GenericMap that must allow insertions and deletions.

Template Parameters
Kthe key type of the map.

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 an integer labeled "value", for example, will report no such integer if instead there is a string labeled "value". For Python compatibility, a GenericMap does not store type information internally, instead relying on RTTI for type checking.

All subclasses must guarantee, as a class invariant, that every value in the map is implicitly nothrow-convertible to the type indicated by its key. For example, MutableGenericMap ensures this by appropriately templating all operations that create new key-value pairs.

A GenericMap may contain primitive types, strings, Storable, and shared pointers to Storable as values. It does not support unique pointers to Storable because such pointers are read destructively. For safety reasons, it may not contain references, C-style pointers, or arrays to any type. Due to implementation restrictions, const types (particularly pointers to const Storable) are not currently supported.

Definition at line 229 of file GenericMap.h.

Member Typedef Documentation

◆ difference_type

Definition at line 233 of file GenericMap.h.

◆ key_type

template<typename K>
using lsst::afw::typehandling::GenericMap< K >::key_type = K

Definition at line 231 of file GenericMap.h.

◆ size_type

template<typename K>
using lsst::afw::typehandling::GenericMap< K >::size_type = std::size_t

Definition at line 232 of file GenericMap.h.

◆ StorableType

template<typename K>
using lsst::afw::typehandling::GenericMap< K >::StorableType = decltype(_referenceToType(std::declval<ValueReference>()))
protected

The types that can be stored in a map.

These are the pass-by-value equivalents (using std::decay) of ValueReference.

Definition at line 522 of file GenericMap.h.

◆ ValueReference

template<typename K>
using lsst::afw::typehandling::GenericMap< K >::ValueReference = boost::variant<bool const&, std::int32_t const&, std::int64_t const&, float const&, double const&, std::string const&, PolymorphicValue const&, std::shared_ptr<Storable> const&>
protected

A type-agnostic reference to the value stored inside the map.

Keys of any subclass of Storable are implemented using PolymorphicValue to preserve type.

Definition at line 514 of file GenericMap.h.

Constructor & Destructor Documentation

◆ ~GenericMap()

template<typename K>
virtual lsst::afw::typehandling::GenericMap< K >::~GenericMap ( )
virtualdefaultnoexcept

Member Function Documentation

◆ at() [1/4]

template<typename K>
template<typename T , typename std::enable_if_t<!IS_SMART_PTR< T >, int > = 0>
T& lsst::afw::typehandling::GenericMap< K >::at ( Key< K, T > const &  key)
inline

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

Template Parameters
Tthe type of the element mapped to key
Parameters
keythe key of the element to find
Returns
a reference to the T mapped to key, if one exists
Exceptions
pex::exceptions::OutOfRangeErrorThrown if the map does not have a T with the specified key
Exception Safety
Provides strong exception safety.
Note
This implementation calls unsafeLookup once, then uses templates and RTTI to determine if the value is of the expected type.

Definition at line 255 of file GenericMap.h.

◆ at() [2/4]

template<typename K>
template<typename T , typename std::enable_if_t< std::is_fundamental< T >::value||std::is_base_of< std::string, T >::value, int > = 0>
T const& lsst::afw::typehandling::GenericMap< K >::at ( Key< K, T > const &  key) const
inline

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

Template Parameters
Tthe type of the element mapped to key
Parameters
keythe key of the element to find
Returns
a reference to the T mapped to key, if one exists
Exceptions
pex::exceptions::OutOfRangeErrorThrown if the map does not have a T with the specified key
Exception Safety
Provides strong exception safety.
Note
This implementation calls unsafeLookup once, then uses templates and RTTI to determine if the value is of the expected type.

Definition at line 264 of file GenericMap.h.

◆ at() [3/4]

template<typename K>
template<typename T , typename std::enable_if_t< std::is_base_of< Storable, T >::value, int > = 0>
T const& lsst::afw::typehandling::GenericMap< K >::at ( Key< K, T > const &  key) const
inline

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

Template Parameters
Tthe type of the element mapped to key
Parameters
keythe key of the element to find
Returns
a reference to the T mapped to key, if one exists
Exceptions
pex::exceptions::OutOfRangeErrorThrown if the map does not have a T with the specified key
Exception Safety
Provides strong exception safety.
Note
This implementation calls unsafeLookup once, then uses templates and RTTI to determine if the value is of the expected type.

Definition at line 278 of file GenericMap.h.

◆ at() [4/4]

template<typename K>
template<typename T , typename std::enable_if_t< std::is_base_of< Storable, T >::value, int > = 0>
std::shared_ptr<T> lsst::afw::typehandling::GenericMap< K >::at ( Key< K, std::shared_ptr< T >> const &  key) const
inline

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

Template Parameters
Tthe type of the element mapped to key
Parameters
keythe key of the element to find
Returns
a reference to the T mapped to key, if one exists
Exceptions
pex::exceptions::OutOfRangeErrorThrown if the map does not have a T with the specified key
Exception Safety
Provides strong exception safety.
Note
This implementation calls unsafeLookup once, then uses templates and RTTI to determine if the value is of the expected type.

Definition at line 301 of file GenericMap.h.

◆ contains() [1/4]

template<typename K>
virtual bool lsst::afw::typehandling::GenericMap< K >::contains ( K const &  key) const
pure virtual

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.

Parameters
keythe weakly-typed key to search for
Returns
true if this map contains a mapping for key, regardless of value type.
Exception Safety
Provides strong exception safety.

Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.

◆ contains() [2/4]

template<typename K>
template<typename T , typename std::enable_if_t< std::is_fundamental< T >::value||std::is_base_of< std::string, T >::value, int > = 0>
bool lsst::afw::typehandling::GenericMap< K >::contains ( Key< K, T > const &  key) const
inline

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

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

Template Parameters
Tthe value corresponding to key
Parameters
keythe key to search for
Returns
true if this map contains a mapping from the specified key to a T
Exception Safety
Provides strong exception safety.
Note
This implementation calls contains(K const&) const. If the call returns true, it calls unsafeLookup, then uses templates and RTTI to determine if the value is of the expected type. The performance of this method depends strongly on the performance of contains(K const&).

Definition at line 397 of file GenericMap.h.

◆ contains() [3/4]

template<typename K>
template<typename T , typename std::enable_if_t< std::is_base_of< Storable, T >::value, int > = 0>
bool lsst::afw::typehandling::GenericMap< K >::contains ( Key< K, T > const &  key) const
inline

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

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

Template Parameters
Tthe value corresponding to key
Parameters
keythe key to search for
Returns
true if this map contains a mapping from the specified key to a T
Exception Safety
Provides strong exception safety.
Note
This implementation calls contains(K const&) const. If the call returns true, it calls unsafeLookup, then uses templates and RTTI to determine if the value is of the expected type. The performance of this method depends strongly on the performance of contains(K const&).

Definition at line 414 of file GenericMap.h.

◆ contains() [4/4]

template<typename K>
template<typename T , typename std::enable_if_t< std::is_base_of< Storable, T >::value, int > = 0>
bool lsst::afw::typehandling::GenericMap< K >::contains ( Key< K, std::shared_ptr< T >> const &  key) const
inline

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

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

Template Parameters
Tthe value corresponding to key
Parameters
keythe key to search for
Returns
true if this map contains a mapping from the specified key to a T
Exception Safety
Provides strong exception safety.
Note
This implementation calls contains(K const&) const. If the call returns true, it calls unsafeLookup, then uses templates and RTTI to determine if the value is of the expected type. The performance of this method depends strongly on the performance of contains(K const&).

Definition at line 432 of file GenericMap.h.

◆ count()

template<typename K>
template<typename T >
size_type lsst::afw::typehandling::GenericMap< K >::count ( Key< K, T > const &  key) const
inline

Return the number of elements mapped to the specified key.

Template Parameters
Tthe value corresponding to key
Parameters
keykey value of the elements to count
Returns
number of T with key key, that is, either 1 or 0.
Exception Safety
Provides strong exception safety.
Note
This implementation calls contains.

Definition at line 355 of file GenericMap.h.

◆ empty()

template<typename K>
virtual bool lsst::afw::typehandling::GenericMap< K >::empty ( ) const
pure virtualnoexcept

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

Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.

◆ keys()

template<typename K>
virtual std::vector<K> lsst::afw::typehandling::GenericMap< K >::keys ( ) const
pure virtual

Return the set of all keys, without type information.

Returns
a copy of all keys currently in the map, in the same iteration order as this object. The set will not be updated as this object changes, or vice versa.
Note
The keys are returned as a list, rather than a set, so that subclasses can give them a well-defined iteration order.
Exception Safety
Provides strong exception safety.

Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.

◆ max_size()

template<typename K>
virtual size_type lsst::afw::typehandling::GenericMap< K >::max_size ( ) const
pure virtualnoexcept

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.

Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.

◆ operator!=()

template<typename K>
bool lsst::afw::typehandling::GenericMap< K >::operator!= ( GenericMap< K > const &  other) const
inline

Test for map equality.

Two GenericMap objects are considered equal if they map the same keys to the same values. The two objects do not need to have the same implementation class. If either class orders its keys, the order is ignored.

Note
This implementation calls keys on both objects and compares the results. If the two objects have the same keys, it calls unsafeLookup for each key and compares the values.

Definition at line 493 of file GenericMap.h.

◆ operator==()

template<typename K>
virtual bool lsst::afw::typehandling::GenericMap< K >::operator== ( GenericMap< K > const &  other) const
inlinevirtual

Test for map equality.

Two GenericMap objects are considered equal if they map the same keys to the same values. The two objects do not need to have the same implementation class. If either class orders its keys, the order is ignored.

Note
This implementation calls keys on both objects and compares the results. If the two objects have the same keys, it calls unsafeLookup for each key and compares the values.

Definition at line 479 of file GenericMap.h.

◆ size()

template<typename K>
virtual size_type lsst::afw::typehandling::GenericMap< K >::size ( ) const
pure virtualnoexcept

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

Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.

◆ unsafeLookup()

template<typename K>
virtual ValueReference lsst::afw::typehandling::GenericMap< K >::unsafeLookup ( K  key) const
protectedpure virtual

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

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

Parameters
keythe key of the element to find
Returns
the value mapped to key, if one exists
Exceptions
pex::exceptions::OutOfRangeErrorThrown if the map does not have a value with the specified key
Exception Safety
Must provide strong exception safety.

Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.


The documentation for this class was generated from the following file: