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

A GenericMap that allows insertion and deletion of arbitrary values. More...

#include <SimpleGenericMap.h>

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

Public Types

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

Public Member Functions

 SimpleGenericMap ()=default
 
 SimpleGenericMap (SimpleGenericMap const &other)=default
 
 SimpleGenericMap (SimpleGenericMap &&)=default
 
virtual ~SimpleGenericMap () noexcept=default
 
SimpleGenericMap & operator= (SimpleGenericMap const &other)=default
 
SimpleGenericMap & operator= (SimpleGenericMap &&)=default
 
GenericMap< K >::size_type size () const noexcept override
 Return the number of key-value pairs in the map. More...
 
bool empty () const noexcept override
 Return true if this map contains no key-value pairs. More...
 
GenericMap< K >::size_type max_size () const noexcept override
 Return the maximum number of elements the container is able to hold due to system or library implementation limitations. More...
 
bool contains (K const &key) const override
 Return true if this map contains a mapping whose key has the specified label. More...
 
std::vector< K > keys () const override
 Return the set of all keys, without type information. More...
 
void clear () noexcept override
 Remove all of the mappings from this map. More...
 
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. More...
 
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. More...
 
template<typename T >
bool erase (Key< K, T > const &key)
 Remove the mapping for a key from this map, if it exists. More...
 
template<typename T >
size_type count (Key< K, T > const &key) const
 Return the number of elements mapped to the specified key. 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, 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

ValueReference unsafeLookup (K key) const override
 Return a reference to the mapped value of the element with key equal to key. More...
 
bool unsafeInsert (K key, StorableType &&value) override
 Create a new mapping with key equal to key and value equal to value. More...
 
bool unsafeErase (K key) override
 Remove the mapping for a key from this map, if it exists. More...
 

Detailed Description

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

A GenericMap that allows insertion and deletion of arbitrary values.

In Python, a SimpleGenericMap behaves like a dict.

Template Parameters
Kthe key type of the map. Must be hashable.
Note
This class offers no guarantees, such as thread-safety, beyond those provided by MutableGenericMap.

Definition at line 52 of file SimpleGenericMap.h.

Member Typedef Documentation

◆ difference_type

template<typename K>
using lsst::afw::typehandling::GenericMap< K >::difference_type = std::ptrdiff_t
inherited

Definition at line 233 of file GenericMap.h.

◆ key_type

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

Definition at line 231 of file GenericMap.h.

◆ size_type

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

Definition at line 232 of file GenericMap.h.

◆ StorableType

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

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&>
protectedinherited

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

◆ SimpleGenericMap() [1/3]

template<typename K >
lsst::afw::typehandling::SimpleGenericMap< K >::SimpleGenericMap ( )
default

◆ SimpleGenericMap() [2/3]

template<typename K >
lsst::afw::typehandling::SimpleGenericMap< K >::SimpleGenericMap ( SimpleGenericMap< K > const &  other)
default

◆ SimpleGenericMap() [3/3]

template<typename K >
lsst::afw::typehandling::SimpleGenericMap< K >::SimpleGenericMap ( SimpleGenericMap< K > &&  )
default

◆ ~SimpleGenericMap()

template<typename K >
virtual lsst::afw::typehandling::SimpleGenericMap< K >::~SimpleGenericMap ( )
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)
inlineinherited

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
inlineinherited

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
inlineinherited

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
inlineinherited

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.

◆ clear()

template<typename K >
void lsst::afw::typehandling::SimpleGenericMap< K >::clear ( )
inlineoverridevirtualnoexcept

Remove all of the mappings from this map.

After this call, the map will be empty.

Implements lsst::afw::typehandling::MutableGenericMap< K >.

Definition at line 83 of file SimpleGenericMap.h.

◆ contains() [1/3]

template<typename K >
bool lsst::afw::typehandling::SimpleGenericMap< K >::contains ( K const &  key) const
inlineoverridevirtual

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.

Implements lsst::afw::typehandling::GenericMap< K >.

Definition at line 72 of file SimpleGenericMap.h.

◆ contains() [2/3]

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
inlineinherited

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/3]

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
inlineinherited

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
inlineinherited

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 >
bool lsst::afw::typehandling::SimpleGenericMap< K >::empty ( ) const
inlineoverridevirtualnoexcept

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

Implements lsst::afw::typehandling::GenericMap< K >.

Definition at line 68 of file SimpleGenericMap.h.

◆ erase()

template<typename K >
template<typename T >
bool lsst::afw::typehandling::MutableGenericMap< K >::erase ( Key< K, T > const &  key)
inlineinherited

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

Template Parameters
Tthe type of value the key maps to
Parameters
keythe key to remove
Returns
true if key was removed, false if it was not present
Exception Safety
Provides strong exception safety.
Note
This implementation calls contains, then calls unsafeErase if the key is present.

Definition at line 641 of file GenericMap.h.

◆ insert() [1/2]

template<typename K >
template<typename T >
bool lsst::afw::typehandling::MutableGenericMap< K >::insert ( Key< K, T > const &  key,
T const &  value 
)
inlineinherited

Insert an element into the map, if the map doesn't already contain a mapping with the same or a conflicting key.

Template Parameters
Tthe type of value to insert
Parameters
keykey to insert
valuevalue to insert
Returns
true if the insertion took place, false otherwise
Exception Safety
Provides strong exception safety.
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).
This implementation calls contains, then calls unsafeInsert if there is no conflicting key.

Definition at line 595 of file GenericMap.h.

◆ insert() [2/2]

template<typename K >
template<typename T >
std::pair<Key<K, T>, bool> lsst::afw::typehandling::MutableGenericMap< K >::insert ( K const &  key,
T const &  value 
)
inlineinherited

Insert an element into the map, if the map doesn't already contain a mapping with a conflicting key.

Template Parameters
Tthe type of value to insert
Parameters
keykey to insert
valuevalue to insert
Returns
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
Exception Safety
Provides strong exception safety.
Warning
the type of the compiler-generated key may not always be what you expect. Callers should save the returned key if they wish to retrieve the value later.

Definition at line 619 of file GenericMap.h.

◆ keys()

template<typename K >
std::vector<K> lsst::afw::typehandling::SimpleGenericMap< K >::keys ( ) const
inlineoverridevirtual

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.

Implements lsst::afw::typehandling::GenericMap< K >.

Definition at line 74 of file SimpleGenericMap.h.

◆ max_size()

template<typename K >
GenericMap<K>::size_type lsst::afw::typehandling::SimpleGenericMap< K >::max_size ( ) const
inlineoverridevirtualnoexcept

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.

Implements lsst::afw::typehandling::GenericMap< K >.

Definition at line 70 of file SimpleGenericMap.h.

◆ operator!=()

template<typename K>
bool lsst::afw::typehandling::GenericMap< K >::operator!= ( GenericMap< K > const &  other) const
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.

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=() [1/2]

template<typename K >
SimpleGenericMap& lsst::afw::typehandling::SimpleGenericMap< K >::operator= ( SimpleGenericMap< K > const &  other)
default

◆ operator=() [2/2]

template<typename K >
SimpleGenericMap& lsst::afw::typehandling::SimpleGenericMap< K >::operator= ( SimpleGenericMap< K > &&  )
default

◆ operator==()

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

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 >
GenericMap<K>::size_type lsst::afw::typehandling::SimpleGenericMap< K >::size ( ) const
inlineoverridevirtualnoexcept

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

Implements lsst::afw::typehandling::GenericMap< K >.

Definition at line 66 of file SimpleGenericMap.h.

◆ unsafeErase()

template<typename K >
bool lsst::afw::typehandling::SimpleGenericMap< K >::unsafeErase ( K  key)
inlineoverrideprotectedvirtual

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

Parameters
keythe key to remove
Returns
true if key was removed, false if it was not present
Exception Safety
Must provide strong exception safety.

Implements lsst::afw::typehandling::MutableGenericMap< K >.

Definition at line 100 of file SimpleGenericMap.h.

◆ unsafeInsert()

template<typename K >
bool lsst::afw::typehandling::SimpleGenericMap< K >::unsafeInsert ( K  key,
StorableType &&  value 
)
inlineoverrideprotectedvirtual

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.

Parameters
keythe key of the element to insert. The method may assume that the map does not contain key.
valuea reference to the value to insert.
Returns
true if the insertion took place, false otherwise
Exception Safety
Must provide strong exception safety.

Implements lsst::afw::typehandling::MutableGenericMap< K >.

Definition at line 96 of file SimpleGenericMap.h.

◆ unsafeLookup()

template<typename K >
ValueReference lsst::afw::typehandling::SimpleGenericMap< K >::unsafeLookup ( K  key) const
inlineoverrideprotectedvirtual

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.

Implements lsst::afw::typehandling::GenericMap< K >.

Definition at line 86 of file SimpleGenericMap.h.


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