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 GenericMap that allows element addition and removal. 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 | ~MutableGenericMap () noexcept=default |
virtual void | clear () noexcept=0 |
Remove all of the mappings from this map. | |
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. | |
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. | |
template<typename T > | |
bool | erase (Key< K, T > const &key) |
Remove the mapping for a key from this map, if it exists. | |
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 bool | unsafeInsert (K key, StorableType &&value)=0 |
Create a new mapping with key equal to key and value equal to value . | |
virtual bool | unsafeErase (K key)=0 |
Remove the mapping for a key from this map, if it exists. | |
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 GenericMap that allows element addition and removal.
In Python, a MutableGenericMap behaves like a collections.abc.MutableMapping
.
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(). Definition at line 597 of file GenericMap.h.
|
protectedinherited |
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.
|
inherited |
Definition at line 83 of file GenericMap.h.
|
inherited |
Definition at line 81 of file GenericMap.h.
|
inherited |
Definition at line 82 of file GenericMap.h.
|
protectedinherited |
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.
|
protectedinherited |
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 |
|
inlineinherited |
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.
|
inlineinherited |
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.
|
inlineinherited |
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.
|
inlineinherited |
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.
|
inlineinherited |
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 virtualnoexcept |
Remove all of the mappings from this map.
After this call, the map will be empty.
Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.
|
pure virtualinherited |
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 >.
|
inlineinherited |
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.
|
inlineinherited |
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 virtualnoexceptinherited |
Return true
if this map contains no key-value pairs.
Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.
|
inline |
Remove the mapping for a key from this map, if it exists.
T | the type of value the key maps to |
key | the key to remove |
true
if key
was removed, false
if it was not presentDefinition at line 676 of file GenericMap.h.
|
inline |
Insert an element into the map, if the map doesn't already contain a mapping with a conflicting key.
T | the type of value to insert |
key | key to insert |
value | value to insert |
true
if the insertion took place and false
otherwiseDefinition at line 654 of file GenericMap.h.
|
inline |
Insert an element into the map, if the map doesn't already contain a mapping with the same or a conflicting key.
T | the type of value to insert |
key | key to insert |
value | value to insert |
true
if the insertion took place, false
otherwiseT
to prevent insertion. Callers can safely assume this->contains(key.getId())
as a postcondition, but not this->contains(key)
.Definition at line 630 of file GenericMap.h.
|
pure virtualnoexceptinherited |
Return the set of all keys, without type information.
Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.
|
pure virtualnoexceptinherited |
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 >.
|
inlineinherited |
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.
|
inlinevirtualnoexceptinherited |
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 virtualnoexceptinherited |
Return the number of key-value pairs in the map.
Implemented in lsst::afw::typehandling::SimpleGenericMap< K >.
|
protectedpure virtual |
Remove the mapping for a key from this map, if it exists.
key | the key to remove |
true
if key
was removed, false
if it was not presentImplemented in lsst::afw::typehandling::SimpleGenericMap< K >.
|
protectedpure virtual |
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.
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. |
true
if the insertion took place, false
otherwiseImplemented in lsst::afw::typehandling::SimpleGenericMap< K >.
|
inlineprotectedinherited |
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 virtualinherited |
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 >.