|
lsst.afw
17.0.1-24-g0055ebd3c+3
|
Interface for a heterogeneous map. More...
#include <GenericMap.h>
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... | |
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.
| K | the 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.
| using lsst::afw::typehandling::GenericMap< K >::difference_type = std::ptrdiff_t |
Definition at line 233 of file GenericMap.h.
| using lsst::afw::typehandling::GenericMap< K >::key_type = K |
Definition at line 231 of file GenericMap.h.
| using lsst::afw::typehandling::GenericMap< K >::size_type = std::size_t |
Definition at line 232 of file GenericMap.h.
|
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.
|
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.
|
virtualdefaultnoexcept |
|
inline |
Return a reference to the mapped value of the element with key equal to key.
| T | the type of the element mapped to key |
| key | the key of the element to find |
T mapped to key, if one exists| pex::exceptions::OutOfRangeError | Thrown if the map does not have a T with the specified key |
Definition at line 255 of file GenericMap.h.
|
inline |
Return a reference to the mapped value of the element with key equal to key.
| T | the type of the element mapped to key |
| key | the key of the element to find |
T mapped to key, if one exists| pex::exceptions::OutOfRangeError | Thrown if the map does not have a T with the specified key |
Definition at line 264 of file GenericMap.h.
|
inline |
Return a reference to the mapped value of the element with key equal to key.
| T | the type of the element mapped to key |
| key | the key of the element to find |
T mapped to key, if one exists| pex::exceptions::OutOfRangeError | Thrown if the map does not have a T with the specified key |
Definition at line 278 of file GenericMap.h.
|
inline |
Return a reference to the mapped value of the element with key equal to key.
| T | the type of the element mapped to key |
| key | the key of the element to find |
T mapped to key, if one exists| pex::exceptions::OutOfRangeError | Thrown if the map does not have a T with the specified key |
Definition at line 301 of file GenericMap.h.
|
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.
| key | the weakly-typed key to search for |
true if this map contains a mapping for key, regardless of value type.Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.
|
inline |
Return true if this map contains a mapping for the specified key.
This is equivalent to testing whether at(key) would succeed.
| T | the value corresponding to key |
| key | the key to search for |
true if this map contains a mapping from the specified key to a Ttrue, 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.
|
inline |
Return true if this map contains a mapping for the specified key.
This is equivalent to testing whether at(key) would succeed.
| T | the value corresponding to key |
| key | the key to search for |
true if this map contains a mapping from the specified key to a Ttrue, 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.
|
inline |
Return true if this map contains a mapping for the specified key.
This is equivalent to testing whether at(key) would succeed.
| T | the value corresponding to key |
| key | the key to search for |
true if this map contains a mapping from the specified key to a Ttrue, 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.
|
inline |
Return the number of elements mapped to the specified key.
| T | the value corresponding to key |
| key | key value of the elements to count |
T with key key, that is, either 1 or 0.Definition at line 355 of file GenericMap.h.
|
pure virtualnoexcept |
Return true if this map contains no key-value pairs.
Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.
|
pure virtual |
Return the set of all keys, without type information.
Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.
|
pure virtualnoexcept |
Return the maximum number of elements the container is able to hold due to system or library implementation limitations.
Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.
|
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.
Definition at line 493 of file GenericMap.h.
|
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.
Definition at line 479 of file GenericMap.h.
|
pure virtualnoexcept |
Return the number of key-value pairs in the map.
Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.
|
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.
| key | the key of the element to find |
key, if one exists| pex::exceptions::OutOfRangeError | Thrown if the map does not have a value with the specified key |
Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.
1.8.13