File GenericMap.h¶
-
namespace
lsst
Class for a simple mapping implementing a generic AstrometryTransform.
Remove all non-astronomical counts from the Chunk Exposure’s pixels.
Forward declarations for lsst::utils::Cache
For details on the Cache class, see the Cache.h file.
It uses a template rather than a pointer so that the derived classes can use the specifics of the transform. The class simplePolyMapping overloads a few routines.
A base class for image defects
Numeric constants used by the Integrate.h integrator routines.
Compute Image Statistics
- Note
Gauss-Kronrod-Patterson quadrature coefficients for use in quadpack routine qng. These coefficients were calculated with 101 decimal digit arithmetic by L. W. Fullerton, Bell Labs, Nov 1981.
- Note
The Statistics class itself can only handle lsst::afw::image::MaskedImage() types. The philosophy has been to handle other types by making them look like lsst::afw::image::MaskedImage() and reusing that code. Users should have no need to instantiate a Statistics object directly, but should use the overloaded makeStatistics() factory functions.
-
namespace
afw
-
namespace
typehandling
¶ -
template<typename
K
>
classGenericMap
- #include <GenericMap.h>
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.A
Key for the map is parameterized by both the key typeK
and a corresponding value typeV
. The map is indexed uniquely by a value of typeK
; no two entries in the map may have identical values of Key::getId().- Template Parameters
K
: the key type of the map.
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 toconst
Storable) are not currently supported.Subclassed by lsst::afw::typehandling::MutableGenericMap< K >
Unnamed Group
-
template<typename T, typename std::enable_if_t<!detail::IS_SMART_PTR< T >, int > = 0>T& lsst::afw::typehandling::GenericMap::at(Key < K, T > const & key)
Return a reference to the mapped value of the element with key equal to
key
.- Return
a reference to the
T
mapped tokey
, if one exists- Note
This implementation calls unsafeLookup once, then uses templates and RTTI to determine if the value is of the expected type.
- Template Parameters
T
: the type of the element mapped tokey
. 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 anint
withT=long
.
- Parameters
key
: the key of the element to find
- Exceptions
pex::exceptions::OutOfRangeError
: Thrown if the map does not have aT
with the specified key Provides strong exception safety.
-
template<typename T, typename std::enable_if_t<!detail::IS_SMART_PTR< T >, int > = 0>T const& lsst::afw::typehandling::GenericMap::at(Key < K, T > const & key) const
-
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::at(Key < K, std::shared_ptr< T >> const & key) const
Unnamed Group
-
virtual bool
operator==
(GenericMap const &other) const 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.
-
bool
operator!=
(GenericMap const &other) const
Unnamed Group
-
template<>
usingConstValueReference
= decltype(_typeToConstRef(std::declval<StorableType>())) A type-agnostic reference to the value stored inside the map.
These are the reference equivalents (
T const&
orT&
) of StorableType.
-
template<>
usingValueReference
= decltype(_typeToRef(std::declval<StorableType>()))
Unnamed Group
-
virtual ConstValueReference
unsafeLookup
(K key) const = 0 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.
- Return
the value mapped to
key
, if one exists- Parameters
key
: the key of the element to find
- Exceptions
pex::exceptions::OutOfRangeError
: Thrown if the map does not have a value with the specified key Must provide strong exception safety.
-
ValueReference
unsafeLookup
(K key)
Public Types
-
template<>
usingkey_type
= K
-
template<>
usingsize_type
= std::size_t
-
template<>
usingdifference_type
= std::ptrdiff_t
Public Functions
-
virtual
~GenericMap
()
-
virtual size_type
size
() const = 0 Return the number of key-value pairs in the map.
-
virtual bool
empty
() const = 0 Return
true
if this map contains no key-value pairs.
-
virtual size_type
max_size
() const = 0 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.
-
template<typename
T
>
size_typecount
(Key<K, T> const &key) const Return the number of elements mapped to the specified key.
Provides strong exception safety.
- Return
number of
T
with keykey
, that is, either 1 or 0.- Template Parameters
T
: the value corresponding tokey
- Parameters
key
: key value of the elements to count
- Note
This implementation calls contains.
-
virtual bool
contains
(K const &key) const = 0 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 keyk
such thatk.getId() == key
. There can be at most one such mapping.Provides strong exception safety.
- Return
true
if this map contains a mapping forkey
, regardless of value type.- Parameters
key
: the weakly-typed key to search for
-
template<typename
T
>
boolcontains
(Key<K, T> const &key) const Return
true
if this map contains a mapping for the specified key.This is equivalent to testing whether
at(key)
would succeed.Provides strong exception safety.
- Return
true
if this map contains a mapping from the specified key to aT
- Template Parameters
T
: the value corresponding tokey
- Parameters
key
: the key to search for
- 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&).
-
virtual std::vector<K> const &
keys
() const = 0 Return the set of all keys, without type information.
- Return
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.
- Warning
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.
-
template<class
Visitor
>
autoapply
(Visitor &&visitor) const Apply an operation to each key-value pair in the map.
Provides the same level of exception safety as
Visitor
, or strong exception safety ifVisitor
cannot throw.- Return
if
Visitor
has a return value, astd::vector
of values returned from applyingvisitor
to each key in keys, in that order. Otherwise,void
.- Template Parameters
Visitor
: a callable that takes a key and a value. See below for exact requirements.
- Parameters
visitor
: the visitor to apply
A
Visitor
must define one or moreoperator()
that take a weakly-typed key and a value. Eachoperator()
must return the same type (which may bevoid
). Through any combination of overloading or templates, the visitor must accept values of the following types:either
bool
orbool const&
either
int
orint const&
either
long
orlong const&
either
long long
orlong long const&
either
float
orfloat const&
either
double
ordouble const&
std::string const&
Storable const&
std::shared_ptr<Storable const>
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"); } } };
- Note
This implementation calls keys, then calls unsafeLookup for each key before passing the result to
visitor
.
-
template<class
Visitor
>
autoapply
(Visitor &&visitor) Apply a modifying operation to each key-value pair in the map.
Provides basic exception safety if
Visitor
is exception-safe.- Return
if
Visitor
has a return value, astd::vector
of values returned from applyingvisitor
to each key in keys, in that order. Otherwise,void
.- Template Parameters
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.
- Parameters
visitor
: the visitor to apply
- Note
This implementation calls keys, then calls unsafeLookup for each key before passing the result to
visitor
.
Protected Types
-
template<>
usingStorableType
= boost::variant<bool, int, long, long long, float, double, std::string, PolymorphicValue, std::shared_ptr<Storable const>> The types that can be stored in a map.
Keys of any subclass of Storable are implemented using PolymorphicValue to preserve type.
Private Functions
-
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::_at(Key < K, T > const & key) const
-
template<typename T, typename std::enable_if_t< std::is_base_of< Storable, T >::value, int > = 0>T const& lsst::afw::typehandling::GenericMap::_at(Key < K, T > const & key) const
-
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::_at(Key < K, std::shared_ptr< T >> const & key) const
-
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::_contains(Key < K, T > const & key) const
-
template<typename T, typename std::enable_if_t< std::is_base_of< Storable, T >::value, int > = 0>bool lsst::afw::typehandling::GenericMap::_contains(Key < K, T > const & key) const
-
template<typename T, typename std::enable_if_t< std::is_base_of< Storable, T >::value, int > = 0>bool lsst::afw::typehandling::GenericMap::_contains(Key < K, std::shared_ptr< T >> const & key) const
-
template<class Visitor, typename std::enable_if_t< std::is_void< _VisitorResult< Visitor >>::value, int > = 0>void lsst::afw::typehandling::GenericMap::_apply(Visitor && visitor) const
-
template<class Visitor, typename std::enable_if_t<!std::is_void< _VisitorResult< Visitor >>::value, int > = 0>auto lsst::afw::typehandling::GenericMap::_apply(Visitor && visitor) const
-
template<class Visitor, typename std::enable_if_t< std::is_void< _VisitorResult< Visitor >>::value, int > = 0>void lsst::afw::typehandling::GenericMap::_apply(Visitor && visitor)
-
template<class Visitor, typename std::enable_if_t<!std::is_void< _VisitorResult< Visitor >>::value, int > = 0>auto lsst::afw::typehandling::GenericMap::_apply(Visitor && visitor)
-
template<typename
K
>
classMutableGenericMap
: public lsst::afw::typehandling::GenericMap<K> - #include <GenericMap.h>
Interface for a GenericMap that allows element addition and removal.
In Python, a MutableGenericMap behaves like a
collections.abc.MutableMapping
.- Note
Unlike standard library maps, this class does not support
operator[]
orinsert_or_assign
. This is because these operations would have surprising behavior when dealing with keys of different types but the same Key::getId().
Subclassed by lsst::afw::typehandling::SimpleGenericMap< K >
Public Functions
-
virtual
~MutableGenericMap
()
-
virtual void
clear
() = 0 Remove all of the mappings from this map.
After this call, the map will be empty.
-
template<typename
T
>
boolinsert
(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.
Provides strong exception safety.
- Return
true
if the insertion took place,false
otherwise- Template Parameters
T
: the type of value to insert
- Parameters
key
: key to insertvalue
: value to insert
- Note
It is possible for a key with a value type other than
T
to prevent insertion. Callers can safely assumethis->contains(key.getId())
as a postcondition, but notthis->contains(key)
.- Note
This implementation calls contains, then calls unsafeInsert if there is no 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.
Provides strong exception safety.
- Return
a pair consisting of a strongly-typed key for the value and a flag that is
true
if the insertion took place andfalse
otherwise- Template Parameters
T
: the type of value to insert
- Parameters
key
: key to insertvalue
: value to insert
- 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.
-
template<typename
T
>
boolerase
(Key<K, T> const &key) Remove the mapping for a key from this map, if it exists.
Provides strong exception safety.
- Return
true
ifkey
was removed,false
if it was not present- Template Parameters
T
: the type of value the key maps to
- Parameters
key
: the key to remove
- Note
This implementation calls contains, then calls unsafeErase if the key is present.
Protected Functions
-
virtual bool
unsafeInsert
(K key, StorableType &&value) = 0 Create a new mapping with key equal to
key
and value equal tovalue
.This method is the primary way to implement the MutableGenericMap interface.
Must provide strong exception safety.
- Return
true
if the insertion took place,false
otherwise- Parameters
key
: the key of the element to insert. The method may assume that the map does not containkey
.value
: a reference to the value to insert.
-
virtual bool
unsafeErase
(K key) = 0 Remove the mapping for a key from this map, if it exists.
Must provide strong exception safety.
- Return
true
ifkey
was removed,false
if it was not present- Parameters
key
: the key to remove
-
template<typename
-
namespace