LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
LSSTDataManagementBasePackage
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 <GenericMap.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 &)=delete
 
Keyoperator= (Key &&)=delete
 
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).

Note
Objects of this type are immutable.

Definition at line 63 of file GenericMap.h.

Member Typedef Documentation

◆ KeyType

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

Definition at line 65 of file GenericMap.h.

◆ ValueType

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

Definition at line 66 of file GenericMap.h.

Constructor & Destructor Documentation

◆ Key() [1/3]

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

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

79 : id(id) {}
table::Key< int > id
Definition: Detector.cc:166

◆ Key() [2/3]

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

◆ Key() [3/3]

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

Member Function Documentation

◆ getId()

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

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

94 { return id; }
table::Key< int > id
Definition: Detector.cc:166

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

138 { 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
inlinenoexcept

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

112  {
113  return !(*this == other);
114  }
ItemVariant const * other
Definition: Schema.cc:56

◆ operator<()

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

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

132  {
133  const std::less<K> comparator;
134  return comparator(this->getId(), other.getId());
135  }
ItemVariant const * other
Definition: Schema.cc:56
constexpr K const & getId() const noexcept
Return the identifier of this field.
Definition: GenericMap.h:94

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ operator==() [1/2]

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

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

104 { return this->id == other.id; }
ItemVariant const * other
Definition: Schema.cc:56

◆ operator==() [2/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
inlinenoexcept

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

107  {
108  return false;
109  }

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

162  {
163  return Key<K, V>(id);
164 }
table::Key< int > id
Definition: Detector.cc:166

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

185  {
186  static const std::string typeStr = boost::core::demangle(typeid(V).name());
187  static const std::string constStr = std::is_const<V>::value ? " const" : "";
188  static const std::string volatileStr = std::is_volatile<V>::value ? " volatile" : "";
189  os << key.getId() << "<" << typeStr << constStr << volatileStr << ">";
190  return os;
191 }
STL class.
Key< U > key
Definition: Schema.cc:281
std::ostream * os
Definition: Schema.cc:746

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