LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | Related Functions | List of all members
lsst::afw::typehandling::Key< K, V > Class Template Referencefinal

Key for type-safe lookup in a GenericMap. More...

#include <Key.h>

Public Types

using KeyType = K
 
using ValueType = V
 

Public Member Functions

constexpr Key (K id)
 Construct a new key. More...
 
 Key (Key const &)=default
 
 Key (Key &&)=default
 
Keyoperator= (Key const &)=default
 
Keyoperator= (Key &&)=default
 
template<typename U >
 Key (Key< K, U > other)
 Convert a key to a different key that could retrieve the same values. More...
 
constexpr K const & getId () const noexcept
 Return the identifier of this field. More...
 
template<typename U >
constexpr bool operator< (Key< K, U > const &other) const noexcept
 Define sort order for Keys. More...
 
std::size_t hash_value () const noexcept
 Return a hash of this object. More...
 
constexpr bool operator== (Key< K, V > const &other) const noexcept
 Test for key equality. More...
 
template<typename U >
constexpr std::enable_if_t<!std::is_same< U, V >::value, bool > operator== (Key< K, U > const &) const noexcept
 Test for key equality. More...
 
template<typename U >
constexpr bool operator!= (Key< K, U > const &other) const noexcept
 Test for key equality. More...
 

Related Functions

(Note that these are not member functions.)

template<typename V , typename K >
constexpr Key< K, V > makeKey (K const &id)
 Factory function for Key, to enable type parameter inference. More...
 
template<typename K , typename V >
std::ostreamoperator<< (std::ostream &os, Key< K, V > const &key)
 Output operator for Key. More...
 

Detailed Description

template<typename K, typename V>
class lsst::afw::typehandling::Key< K, V >

Key for type-safe lookup in a GenericMap.

Template Parameters
Kthe logical type of the key (e.g., a string)
Vthe type of the value mapped to this key

Key objects are equality-comparable, hashable, sortable, or printable if and only if K is comparable, hashable, sortable, or printable, respectively. Key can be used in compile-time expressions if and only if K can (in particular, Key<std::string, V> cannot).

Definition at line 52 of file Key.h.

Member Typedef Documentation

◆ KeyType

template<typename K , typename V >
using lsst::afw::typehandling::Key< K, V >::KeyType = K

Definition at line 54 of file Key.h.

◆ ValueType

template<typename K , typename V >
using lsst::afw::typehandling::Key< K, V >::ValueType = V

Definition at line 55 of file Key.h.

Constructor & Destructor Documentation

◆ Key() [1/4]

template<typename K , typename V >
constexpr lsst::afw::typehandling::Key< K, V >::Key ( id)
inlineexplicitconstexpr

Construct a new key.

Parameters
idthe identifier of the field. For most purposes, this value is the actual key; it can be retrieved by calling getId().
Exception Safety
Provides the same exception safety as the copy-constructor of K.
See also
makeKey

Definition at line 68 of file Key.h.

68 : id(id) {}

◆ Key() [2/4]

template<typename K , typename V >
lsst::afw::typehandling::Key< K, V >::Key ( Key< K, V > const &  )
default

◆ Key() [3/4]

template<typename K , typename V >
lsst::afw::typehandling::Key< K, V >::Key ( Key< K, V > &&  )
default

◆ Key() [4/4]

template<typename K , typename V >
template<typename U >
lsst::afw::typehandling::Key< K, V >::Key ( Key< K, U >  other)
inline

Convert a key to a different key that could retrieve the same values.

Template Parameters
UThe value type being converted from. Smart pointer keys are convertible if and only if the corresponding pointers are; other keys are convertible if and only if their value references are (consistent with pointers being retrieved by value and other types by reference).
Parameters
other
Note
This constructor is intended to support implicit conversions.

Definition at line 89 of file Key.h.

89  : id(other.getId()) {
90  static_assert((!detail::IS_SMART_PTR<U> && !detail::IS_SMART_PTR<V> &&
92  (detail::IS_SMART_PTR<U> && detail::IS_SMART_PTR<V> &&
94  "Implicit conversion of Keys whose types are not implicitly convertible.");
95  }

Member Function Documentation

◆ getId()

template<typename K , typename V >
constexpr K const& lsst::afw::typehandling::Key< K, V >::getId ( ) const
inlineconstexprnoexcept

Return the identifier of this field.

The identifier serves as the "key" for the map abstraction represented by GenericMap.

Returns
the unique key defining this field

Definition at line 105 of file Key.h.

105 { return id; }

◆ hash_value()

template<typename K , typename V >
std::size_t lsst::afw::typehandling::Key< K, V >::hash_value ( ) const
inlinenoexcept

Return a hash of this object.

Definition at line 149 of file Key.h.

149 { return std::hash<K>()(id); }

◆ operator!=()

template<typename K , typename V >
template<typename U >
constexpr bool lsst::afw::typehandling::Key< K, V >::operator!= ( Key< K, U > const &  other) const
inlineconstexprnoexcept

Test for key equality.

A key is considered equal to another key if and only if their getId() are equal and their value types are exactly the same (including const/volatile qualifications).

Definition at line 123 of file Key.h.

123  {
124  return !(*this == other);
125  }

◆ operator<()

template<typename K , typename V >
template<typename U >
constexpr bool lsst::afw::typehandling::Key< K, V >::operator< ( Key< K, U > const &  other) const
inlineconstexprnoexcept

Define sort order for Keys.

This must be expressed as operator< instead of std::less because only std::less<void> supports arguments of mixed types, and it cannot be specialized.

Parameters
otherthe key, possibly of a different type, to compare to
Returns
equivalent to this->getId() < other.getId()
Warning
this comparison operator provides a strict weak ordering so long as K does, but is not consistent with equality. In particular, keys with the same value of getId() but different types will be equivalent but not equal.

Definition at line 143 of file Key.h.

143  {
144  const std::less<K> comparator;
145  return comparator(this->getId(), other.getId());
146  }
constexpr K const & getId() const noexcept
Return the identifier of this field.
Definition: Key.h:105

◆ operator=() [1/2]

template<typename K , typename V >
Key& lsst::afw::typehandling::Key< K, V >::operator= ( Key< K, V > &&  )
default

◆ operator=() [2/2]

template<typename K , typename V >
Key& lsst::afw::typehandling::Key< K, V >::operator= ( Key< K, V > const &  )
default

◆ operator==() [1/2]

template<typename K , typename V >
template<typename U >
constexpr std::enable_if_t<!std::is_same<U, V>::value, bool> lsst::afw::typehandling::Key< K, V >::operator== ( Key< K, U > const &  ) const
inlineconstexprnoexcept

Test for key equality.

A key is considered equal to another key if and only if their getId() are equal and their value types are exactly the same (including const/volatile qualifications).

Definition at line 118 of file Key.h.

118  {
119  return false;
120  }

◆ operator==() [2/2]

template<typename K , typename V >
constexpr bool lsst::afw::typehandling::Key< K, V >::operator== ( Key< K, V > const &  other) const
inlineconstexprnoexcept

Test for key equality.

A key is considered equal to another key if and only if their getId() are equal and their value types are exactly the same (including const/volatile qualifications).

Definition at line 115 of file Key.h.

115 { return this->id == other.id; }

Friends And Related Function Documentation

◆ makeKey()

template<typename V , typename K >
constexpr Key< K, V > makeKey ( K const &  id)
related

Factory function for Key, to enable type parameter inference.

Parameters
idthe key ID to create.
Returns
a key of the desired type
Exception Safety
Provides the same exception safety as the copy-constructor of K.

Calling this function prevents you from having to explicitly name the key type:

auto key = makeKey<int>("foo");

Definition at line 173 of file Key.h.

173  {
174  return Key<K, V>(id);
175 }

◆ operator<<()

template<typename K , typename V >
std::ostream & operator<< ( std::ostream os,
Key< K, V > const &  key 
)
related

Output operator for Key.

The output will use C++ template notation for the key; for example, a key "foo" pointing to an int may print as "foo<int>".

Parameters
osthe desired output stream
keythe key to print
Returns
a reference to os
Exception Safety
Provides basic exception safety if the output operator of K is exception-safe.
Warning
the type name is compiler-specific and may be mangled or unintuitive; for example, some compilers say "i" instead of "int"

Definition at line 196 of file Key.h.

196  {
197  static const std::string typeStr = boost::core::demangle(typeid(V).name());
198  static const std::string constStr = std::is_const<V>::value ? " const" : "";
199  static const std::string volatileStr = std::is_volatile<V>::value ? " volatile" : "";
200  os << key.getId() << "<" << typeStr << constStr << volatileStr << ">";
201  return os;
202 }
table::Key< std::string > name
Definition: Amplifier.cc:116
std::ostream * os
Definition: Schema.cc:557

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