LSST Applications g0265f82a02+c6dfa2ddaf,g1162b98a3f+ffe7eabc7e,g2079a07aa2+1b2e822518,g2bbee38e9b+c6dfa2ddaf,g337abbeb29+c6dfa2ddaf,g36da64cc00+ea84795170,g3ddfee87b4+955a963fd8,g50ff169b8f+2eb0e556e8,g52b1c1532d+90ebb246c7,g555ede804d+955a963fd8,g591dd9f2cf+bac198a2cb,g5ec818987f+420292cfeb,g858d7b2824+d6c9a0a3b8,g876c692160+aabc49a3c3,g8a8a8dda67+90ebb246c7,g8cdfe0ae6a+4fd9e222a8,g99cad8db69+e6cd765486,g9ddcbc5298+a1346535a5,ga1e77700b3+df8f93165b,ga8c6da7877+acd47f83f4,gae46bcf261+c6dfa2ddaf,gb0e22166c9+8634eb87fb,gb3f2274832+12c8382528,gba4ed39666+1ac82b564f,gbb8dafda3b+0574160a1f,gbeb006f7da+dea2fbb49f,gc28159a63d+c6dfa2ddaf,gc86a011abf+d6c9a0a3b8,gcf0d15dbbd+955a963fd8,gdaeeff99f8+1cafcb7cd4,gdc0c513512+d6c9a0a3b8,ge79ae78c31+c6dfa2ddaf,geb67518f79+ba1859f325,gee10cc3b42+90ebb246c7,gf1cff7945b+d6c9a0a3b8,w.2024.13
LSST Data Management Base Package
Loading...
Searching...
No Matches
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 &&) noexcept=default
 
 SimpleGenericMap (GenericMap< K > const &other)
 Convert another GenericMap into a SimpleGenericMap.
 
virtual ~SimpleGenericMap () noexcept=default
 
SimpleGenericMapoperator= (SimpleGenericMap const &other)
 
SimpleGenericMapoperator= (SimpleGenericMap &&) noexcept=default
 
SimpleGenericMapoperator= (GenericMap< K > const &other)
 
GenericMap< K >::size_type size () const noexcept override
 Return the number of key-value pairs in the map.
 
bool empty () const noexcept override
 Return true if this map contains no key-value pairs.
 
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.
 
bool contains (K const &key) const override
 Return true if this map contains a mapping whose key has the specified label.
 
std::vector< K > const & keys () const noexcept override
 Return the set of all keys, without type information.
 
void clear () noexcept override
 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.
 
template<typename T >
size_type count (Key< K, T > const &key) const
 Return the number of elements mapped to the specified key.
 
template<typename T >
bool contains (Key< K, T > const &key) const
 Return true if this map contains a mapping for the specified key.
 
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

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

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. In particular, it will iterate over keys in the order they were added.

Template Parameters
Kthe key type of the map. Must be hashable.

Definition at line 49 of file SimpleGenericMap.h.

Member Typedef Documentation

◆ ConstValueReference

template<typename K >
using lsst::afw::typehandling::GenericMap< K >::ConstValueReference = decltype(_typeToConstRef(std::declval<StorableType>()))
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.

◆ difference_type

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

Definition at line 83 of file GenericMap.h.

◆ key_type

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

Definition at line 81 of file GenericMap.h.

◆ size_type

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

Definition at line 82 of file GenericMap.h.

◆ StorableType

template<typename K >
using lsst::afw::typehandling::GenericMap< K >::StorableType
protectedinherited
Initial value:
std::variant<bool, int, long, long long, float, double, std::string,

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.

◆ ValueReference

template<typename K >
using lsst::afw::typehandling::GenericMap< K >::ValueReference = decltype(_typeToRef(std::declval<StorableType>()))
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.

Constructor & Destructor Documentation

◆ SimpleGenericMap() [1/4]

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

◆ SimpleGenericMap() [2/4]

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

◆ SimpleGenericMap() [3/4]

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

◆ SimpleGenericMap() [4/4]

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

Convert another GenericMap into a SimpleGenericMap.

This constructor will insert key-value pairs following other's iteration order. This may not be the order in which they were inserted into the original map.

Definition at line 65 of file SimpleGenericMap.h.

65: _storage(_convertStorage(other)), _keyView(other.keys()) {}

◆ ~SimpleGenericMap()

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

Member Function Documentation

◆ apply() [1/2]

template<typename K >
template<class Visitor >
auto lsst::afw::typehandling::GenericMap< K >::apply ( Visitor && visitor)
inlineinherited

Apply a modifying operation to each key-value pair in the map.

Template Parameters
Visitora callable that takes a key and a value. Requirements as for apply(Visitor&&) const, except that it may take non-const references to values.
Parameters
visitorthe visitor to apply
Returns
if Visitor has a return value, a std::vector of values returned from applying visitor to each key in keys, in that order. Otherwise, void.
Exception Safety
Provides basic exception safety if Visitor is exception-safe.
Note
This implementation calls keys, then calls unsafeLookup for each key before passing the result to visitor.

Definition at line 331 of file GenericMap.h.

331 {
332 // Delegate to private methods to hide special-casing of Visitor
333 return _apply(visitor);
334 }

◆ apply() [2/2]

template<typename K >
template<class Visitor >
auto lsst::afw::typehandling::GenericMap< K >::apply ( Visitor && visitor) const
inlineinherited

Apply an operation to each key-value pair in the map.

Template Parameters
Visitora callable that takes a key and a value. See below for exact requirements.
Parameters
visitorthe visitor to apply
Returns
if Visitor has a return value, a std::vector of values returned from applying visitor to each key in keys, in that order. Otherwise, void.
Exception Safety
Provides the same level of exception safety as 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:

  • either bool or bool const&
  • either int or int const&
  • either long or long const&
  • either long long or long long const&
  • either float or float const&
  • either double or double const&
  • std::string const&
  • Storable const&
  • std::shared_ptr<Storable const>
Note
This implementation calls keys, then calls unsafeLookup for each key before passing the result to 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.

309 {
310 // Delegate to private methods to hide special-casing of Visitor
311 return _apply(visitor);
312 }

◆ at() [1/3]

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. 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.
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 121 of file GenericMap.h.

121 {
122 // Delegate to private methods to hide further special-casing of T
123 return _at(key);
124 }

◆ at() [2/3]

template<typename K >
template<typename T , typename std::enable_if_t<!detail::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. 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.
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 109 of file GenericMap.h.

109 {
110 // Both casts are safe; see Effective C++, Item 3
111 return const_cast<T&>(static_cast<const GenericMap&>(*this).at(key));
112 }

◆ at() [3/3]

template<typename K >
template<typename T , typename std::enable_if_t<!detail::IS_SMART_PTR< T >, 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. 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.
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 115 of file GenericMap.h.

115 {
116 // Delegate to private methods to hide further special-casing of T
117 return _at(key);
118 }

◆ 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 99 of file SimpleGenericMap.h.

99 {
100 _storage.clear();
101 _keyView.clear();
102 }
T clear(T... args)

◆ contains() [1/2]

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 95 of file SimpleGenericMap.h.

95{ return _storage.count(key) > 0; }
T count(T... args)

◆ contains() [2/2]

template<typename K >
template<typename T >
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 194 of file GenericMap.h.

194 {
195 // Delegate to private methods to hide special-casing of T
196 return _contains(key);
197 }

◆ 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 157 of file GenericMap.h.

157 {
158 return contains(key) ? 1 : 0;
159 }
virtual bool contains(K const &key) const =0
Return true if this map contains a mapping whose key has the specified label.

◆ 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 89 of file SimpleGenericMap.h.

89{ return _storage.empty(); }
T empty(T... args)

◆ 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 676 of file GenericMap.h.

676 {
677 if (this->contains(key)) {
678 return unsafeErase(key.getId());
679 } else {
680 return false;
681 }
682 }
virtual bool unsafeErase(K key)=0
Remove the mapping for a key from this map, if it exists.

◆ insert() [1/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 654 of file GenericMap.h.

654 {
655 auto strongKey = makeKey<T>(key);
656 // Construct return value in advance, so that exception from copying/moving Key is atomic
657 auto result = make_pair(strongKey, false);
658 result.second = insert(strongKey, value);
659 return result;
660 }
py::object result
Definition _schema.cc:429
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 confl...
Definition GenericMap.h:630
T make_pair(T... args)

◆ insert() [2/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 630 of file GenericMap.h.

630 {
631 if (this->contains(key.getId())) {
632 return false;
633 }
634
635 return unsafeInsert(key.getId(), StorableType(value));
636 }
std::variant< bool, int, long, long long, float, double, std::string, PolymorphicValue, std::shared_ptr< Storable const > > StorableType
The types that can be stored in a map.
Definition GenericMap.h:359
virtual bool unsafeInsert(K key, StorableType &&value)=0
Create a new mapping with key equal to key and value equal to value.

◆ keys()

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

Return the set of all keys, without type information.

Returns
a read-only view of all keys currently in the map, in the same iteration order as this object. The view will be updated by changes to the underlying map.
Warning
Do not modify this map while iterating over its keys.
Do not store the returned reference in variables that outlive the map; destroying the map will invalidate the reference.
Note
The keys are returned as a list, rather than a set, so that subclasses can give them a well-defined iteration order.

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

Definition at line 97 of file SimpleGenericMap.h.

97{ return _keyView; }

◆ 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 91 of file SimpleGenericMap.h.

91 {
92 return std::min(_storage.max_size(), _keyView.max_size());
93 }
T max_size(T... args)
T min(T... args)

◆ 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 245 of file GenericMap.h.

245{ return !(*this == other); }

◆ operator=() [1/3]

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

Definition at line 77 of file SimpleGenericMap.h.

77 {
78 std::vector<K> newKeys = other.keys();
79 // strong exception safety: unordered_map is nothrow move-assignable and
80 // vector is nothrow swappable, so no exceptions can occur after _convertStorage returns
81 _storage = _convertStorage(other);
82 using std::swap;
83 swap(_keyView, newKeys);
84 return *this;
85 }
void swap(PolymorphicValue &lhs, PolymorphicValue &rhs) noexcept
Swap specialization for PolymorphicValue.
T swap(T... args)

◆ operator=() [2/3]

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

◆ operator=() [3/3]

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

Definition at line 68 of file SimpleGenericMap.h.

68 {
69 std::vector<K> newKeys = other._keyView;
70 _storage = other._storage;
71 // strong exception safety because no exceptions can occur past this point
72 using std::swap;
73 swap(_keyView, newKeys);
74 return *this;
75 }

◆ operator==()

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

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 229 of file GenericMap.h.

229 {
230 auto keys1 = this->keys();
231 auto keys2 = other.keys();
232 if (!std::is_permutation(keys1.begin(), keys1.end(), keys2.begin(), keys2.end())) {
233 return false;
234 }
235 for (K const& key : keys1) {
236 // Can't use std::variant::operator== here because
237 // std::reference_wrapper isn't equality-comparable.
238 if (!detail::refwrap_equals()(this->unsafeLookup(key), other.unsafeLookup(key))) {
239 return false;
240 }
241 }
242 return true;
243 }
virtual ConstValueReference unsafeLookup(K key) const =0
Return a reference to the mapped value of the element with key equal to key.
virtual std::vector< K > const & keys() const noexcept=0
Return the set of all keys, without type information.
T is_permutation(T... args)

◆ 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 87 of file SimpleGenericMap.h.

87{ return _storage.size(); }
T size(T... args)

◆ 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 131 of file SimpleGenericMap.h.

131 {
132 std::vector<K> newKeys = _keyView;
133 for (auto it = newKeys.cbegin(); it != newKeys.cend();) {
134 if (*it == key) {
135 it = newKeys.erase(it);
136 } else {
137 ++it;
138 }
139 }
140 // strong exception safety because no exceptions can occur past this point
141 bool erased = _storage.erase(key) > 0;
142 if (erased) {
143 using std::swap;
144 swap(_keyView, newKeys);
145 }
146 return erased;
147 }
T cbegin(T... args)
T cend(T... args)
T erase(T... args)

◆ 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 118 of file SimpleGenericMap.h.

118 {
119 std::vector<K> newKeys = _keyView;
120 newKeys.emplace_back(key);
121 bool inserted = _storage.emplace(key, std::move(value)).second;
122 // strong exception safety because no exceptions can occur past this point
123 if (inserted) {
124 // _storage did not previously include key, so the key appended to newKeys is unique
125 using std::swap;
126 swap(_keyView, newKeys);
127 }
128 return inserted;
129 }
T emplace_back(T... args)
T emplace(T... args)
T move(T... args)

◆ unsafeLookup() [1/2]

template<typename K >
ValueReference lsst::afw::typehandling::GenericMap< K >::unsafeLookup ( K key)
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.

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.

Definition at line 391 of file GenericMap.h.

391 {
392 ConstValueReference constRef = static_cast<const GenericMap&>(*this).unsafeLookup(key);
393 return std::visit(
394 [](auto const & v) { return ValueReference(detail::refwrap_const_cast(v)); },
395 constRef
396 );
397 }
decltype(_typeToRef(std::declval< StorableType >())) ValueReference
A type-agnostic reference to the value stored inside the map.
Definition GenericMap.h:370
decltype(_typeToConstRef(std::declval< StorableType >())) ConstValueReference
A type-agnostic reference to the value stored inside the map.
Definition GenericMap.h:369
std::reference_wrapper< T > refwrap_const_cast(std::reference_wrapper< T const > const &r)

◆ unsafeLookup() [2/2]

template<typename K >
ConstValueReference 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 105 of file SimpleGenericMap.h.

105 {
106 try {
107 return std::visit(
108 [](auto const & v) { return ConstValueReference(std::cref(v)); },
109 _storage.at(key)
110 );
111 } catch (std::out_of_range& e) {
112 std::stringstream message;
113 message << "Key not found: " << key;
114 std::throw_with_nested(LSST_EXCEPT(pex::exceptions::OutOfRangeError, message.str()));
115 }
116 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
T at(T... args)
T cref(T... args)
T str(T... args)
T throw_with_nested(T... args)

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