LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
LSST Data Management Base Package
|
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. | |
virtual bool | empty () const noexcept=0 |
Return true if this map contains no key-value pairs. | |
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. | |
template<typename T > | |
size_type | count (Key< K, T > const &key) const |
Return the number of elements mapped to the specified key. | |
virtual bool | contains (K const &key) const =0 |
Return true if this map contains a mapping whose key has the specified label. | |
template<typename T > | |
bool | contains (Key< K, T > const &key) const |
Return true if this map contains a mapping for the specified key. | |
virtual std::vector< K > const & | keys () const noexcept=0 |
Return the set of all keys, without type information. | |
template<class Visitor > | |
auto | apply (Visitor &&visitor) const |
Apply an operation to each key-value pair in the map. | |
template<class Visitor > | |
auto | apply (Visitor &&visitor) |
Apply a modifying operation to each key-value pair in the map. | |
template<typename T , typename std::enable_if_t<!detail::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 . | |
template<typename T , typename std::enable_if_t<!detail::IS_SMART_PTR< T >, 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 . | |
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 . | |
virtual bool | operator== (GenericMap const &other) const noexcept |
Test for map equality. | |
bool | operator!= (GenericMap const &other) const |
Test for map equality. | |
Protected Types | |
using | StorableType |
The types that can be stored in a map. | |
using | ConstValueReference = decltype(_typeToConstRef(std::declval<StorableType>())) |
A type-agnostic reference to the value stored inside the map. | |
using | ValueReference = decltype(_typeToRef(std::declval<StorableType>())) |
A type-agnostic reference to the value stored inside the map. | |
Protected Member Functions | |
virtual ConstValueReference | unsafeLookup (K key) const =0 |
Return a reference to the mapped value of the element with key equal to key . | |
ValueReference | unsafeLookup (K key) |
Return a reference to the mapped value of the element with key equal to key . | |
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 (except pointers to const
Storable) are not currently supported.
Definition at line 79 of file GenericMap.h.
|
protected |
A type-agnostic reference to the value stored inside the map.
These are the reference equivalents (T const&
or T&
) of StorableType.
Definition at line 369 of file GenericMap.h.
using lsst::afw::typehandling::GenericMap< K >::difference_type = std::ptrdiff_t |
Definition at line 83 of file GenericMap.h.
using lsst::afw::typehandling::GenericMap< K >::key_type = K |
Definition at line 81 of file GenericMap.h.
using lsst::afw::typehandling::GenericMap< K >::size_type = std::size_t |
Definition at line 82 of file GenericMap.h.
|
protected |
The types that can be stored in a map.
Keys of any subclass of Storable are implemented using PolymorphicValue to preserve type.
Definition at line 359 of file GenericMap.h.
|
protected |
A type-agnostic reference to the value stored inside the map.
These are the reference equivalents (T const&
or T&
) of StorableType.
Definition at line 370 of file GenericMap.h.
|
virtualdefaultnoexcept |
|
inline |
Apply a modifying operation to each key-value pair in the map.
Visitor | a callable that takes a key and a value. Requirements as for apply(Visitor&&) const, except that it may take non-const references to values. |
visitor | the visitor to apply |
Visitor
has a return value, a std::vector
of values returned from applying visitor
to each key in keys, in that order. Otherwise, void
.Visitor
is exception-safe.visitor
. Definition at line 331 of file GenericMap.h.
|
inline |
Apply an operation to each key-value pair in the map.
Visitor | a callable that takes a key and a value. See below for exact requirements. |
visitor | the visitor to apply |
Visitor
has a return value, a std::vector
of values returned from applying visitor
to each key in keys, in that order. Otherwise, void
.Visitor
, or strong exception safety if Visitor
cannot throw.A Visitor
must define one or more operator()
that take a weakly-typed key and a value. Each operator()
must return the same type (which may be void
). Through any combination of overloading or templates, the visitor must accept values of the following types:
bool
or bool const&
int
or int const&
long
or long const&
long long
or long long const&
float
or float const&
double
or double const&
std::string const&
Storable const&
std::shared_ptr<Storable const>
visitor
.An example visitor that prints each key-value pair to standard output:
template <typename K> class Printer { public: template <typename V> void operator()(K const& key, V const& value) { std::cout << key << ": " << value << "," << std::endl; } void operator()(K const& key, Storable const& value) { std::cout << key << ": "; try { std::cout << value; } catch (UnsupportedOperationException const&) { std::cout << "[unprintable]"; } std::cout << "," << std::endl; } void operator()(K const& key, std::shared_ptr<Storable const> value) { if (value != nullptr) { operator()(key, *value); } else { operator()(key, "null"); } } };
Definition at line 309 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 . It may be the exact type of the element, if known, or any type to which its references or pointers can be implicitly converted (e.g., a superclass). For example, references to built-in types are not convertible, so you can't retrieve an int with T=long . |
key | the key of the element to find |
T
mapped to key
, if one existspex::exceptions::OutOfRangeError | Thrown if the map does not have a T with the specified key |
Definition at line 121 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 . It may be the exact type of the element, if known, or any type to which its references or pointers can be implicitly converted (e.g., a superclass). For example, references to built-in types are not convertible, so you can't retrieve an int with T=long . |
key | the key of the element to find |
T
mapped to key
, if one existspex::exceptions::OutOfRangeError | Thrown if the map does not have a T with the specified key |
Definition at line 109 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 . It may be the exact type of the element, if known, or any type to which its references or pointers can be implicitly converted (e.g., a superclass). For example, references to built-in types are not convertible, so you can't retrieve an int with T=long . |
key | the key of the element to find |
T
mapped to key
, if one existspex::exceptions::OutOfRangeError | Thrown if the map does not have a T with the specified key |
Definition at line 115 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 T
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 194 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 157 of file GenericMap.h.
|
pure virtualnoexcept |
Return true
if this map contains no key-value pairs.
Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.
|
pure virtualnoexcept |
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 245 of file GenericMap.h.
|
inlinevirtualnoexcept |
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 229 of file GenericMap.h.
|
pure virtualnoexcept |
Return the number of key-value pairs in the map.
Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.
|
inlineprotected |
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 existspex::exceptions::OutOfRangeError | Thrown if the map does not have a value with the specified key |
Definition at line 391 of file GenericMap.h.
|
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 existspex::exceptions::OutOfRangeError | Thrown if the map does not have a value with the specified key |
Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.