LSSTApplications  19.0.0-14-gb0260a2+6db932c395,20.0.0+235c3eae2c,20.0.0+448775ce90,20.0.0+5f56aa8f28,20.0.0+b40eaeb6a0,20.0.0+d006f05c5d,20.0.0+dbd2281351,20.0.0+dc1acf7baf,20.0.0+e2e26847c2,20.0.0+f48bb53858,20.0.0-1-g10df615+4b67200b40,20.0.0-1-g253301a+d006f05c5d,20.0.0-1-g2b7511a+f48bb53858,20.0.0-1-g4d801e7+68c50072dc,20.0.0-1-g5b95a8c+d1beabf16b,20.0.0-1-g660595b+f45b7d88f4,20.0.0-1-gc96f8cb+4df7bab894,20.0.0-1-gd1c87d7+add1f556b4,20.0.0-1-gedffbd8+eb23c4e4f2,20.0.0-11-g13aeee2+1a7c0f1887,20.0.0-14-g199c894+e853f797a7,20.0.0-15-gf5872d0+4df7bab894,20.0.0-16-g6fe20a1+b7072f60df,20.0.0-2-g4dae9ad+4df7bab894,20.0.0-2-g5ad0983+1a7c0f1887,20.0.0-2-g7818986+add1f556b4,20.0.0-2-gb095acb+63636aeed8,20.0.0-2-gdaeb0e8+7d7ca508c5,20.0.0-2-gec03fae+de92faa26f,20.0.0-23-g8d4de91b+950b69a445,20.0.0-4-gfea843c+f45b7d88f4,20.0.0-46-g00fa051+1467b54e00,20.0.0-5-g357b56b+f45b7d88f4,20.0.0-5-gfcebe35+a6a1a2f802,20.0.0-7-gc818c6e6+57cf537add,20.0.0-7-gcda7bf1+738fa57269,20.0.0-9-g61a2a9a3d+7fa50e000d,w.2020.38
LSSTDataManagementBasePackage
Public Member Functions | Friends | List of all members
lsst::afw::table::Key< T > Class Template Reference

A class used as a handle to a particular field in a table. More...

#include <fwd.h>

Public Member Functions

template<typename OtherT >
bool operator== (Key< OtherT > const &other) const noexcept
 Equality comparison. More...
 
template<typename OtherT >
bool operator!= (Key< OtherT > const &other) const noexcept
 
bool operator== (Key const &other) const noexcept
 
bool operator!= (Key const &other) const noexcept
 
std::size_t hash_value () const noexcept
 Return a hash of this object. More...
 
int getOffset () const noexcept
 Return the offset (in bytes) of this field within a record. More...
 
bool isValid () const noexcept
 Return true if the key was initialized to valid offset. More...
 
 Key () noexcept
 Default construct a field. More...
 
 Key (Key const &) noexcept=default
 
 Key (Key &&) noexcept=default
 
Keyoperator= (Key const &) noexcept=default
 
Keyoperator= (Key &&) noexcept=default
 
 ~Key () noexcept=default
 

Friends

class detail::Access
 
class BaseRecord
 
std::ostreamoperator<< (std::ostream &os, Key< T > const &key)
 Stringification. More...
 

Detailed Description

template<typename T>
class lsst::afw::table::Key< T >

A class used as a handle to a particular field in a table.

All access to table data ultimately goes through Key objects, which know (via an internal offset) how to address and cast the internal data buffer of a record or table.

Keys can be obtained from a Schema by name:

schema.find("myfield").key

and are also returned when a new field is added. Compound and array keys also provide accessors to retrieve scalar keys to their elements (see the documentation for the KeyBase specializations), even though these element keys do not correspond to a field that exists in any Schema. For example:

Schema schema;
Key< Array<float> > arrayKey = schema.addField< Array<float> >("array", "docs for array", 5);
Key< Point<int> > pointKey = schema.addField< Point<int> >("point", "docs for point");
Key<float> elementKey = arrayKey[3];
Key<int> xKey = pointKey.getX();
std::shared_ptr<BaseTable> table = BaseTable::make(schema);
std::shared_ptr<BaseRecord> record = table.makeRecord();
assert(&record[arrayKey][3] == &record[elementKey3]);
assert(record.get(pointKey).getX() == record[xKey]);

Key inherits from FieldBase to allow a key for a dynamically-sized field to know its size without needing to specialize Key itself or hold a full Field object.

Definition at line 45 of file fwd.h.

Constructor & Destructor Documentation

◆ Key() [1/3]

template<typename T >
lsst::afw::table::Key< T >::Key ( )
inlinenoexcept

Default construct a field.

The new field will be invalid until a valid Key is assigned to it.

Definition at line 104 of file Key.h.

104 : FieldBase<T>(FieldBase<T>::makeDefault()), _offset(-1) {}

◆ Key() [2/3]

template<typename T >
lsst::afw::table::Key< T >::Key ( Key< T > const &  )
defaultnoexcept

◆ Key() [3/3]

template<typename T >
lsst::afw::table::Key< T >::Key ( Key< T > &&  )
defaultnoexcept

◆ ~Key()

template<typename T >
lsst::afw::table::Key< T >::~Key ( )
defaultnoexcept

Member Function Documentation

◆ getOffset()

template<typename T >
int lsst::afw::table::Key< T >::getOffset ( ) const
inlinenoexcept

Return the offset (in bytes) of this field within a record.

Definition at line 87 of file Key.h.

87 { return _offset; }

◆ hash_value()

template<typename T >
std::size_t lsst::afw::table::Key< T >::hash_value ( ) const
inlinenoexcept

Return a hash of this object.

Definition at line 81 of file Key.h.

81  {
82  // Completely arbitrary seed
83  return utils::hashCombine(17, _offset, this->getElementCount());
84  }

◆ isValid()

template<typename T >
bool lsst::afw::table::Key< T >::isValid ( ) const
inlinenoexcept

Return true if the key was initialized to valid offset.

This does not guarantee that a key is valid with any particular schema, or even that any schemas still exist in which this key is valid.

A key that is default constructed will always be invalid.

Definition at line 97 of file Key.h.

97 { return _offset >= 0; }

◆ operator!=() [1/2]

template<typename T >
bool lsst::afw::table::Key< T >::operator!= ( Key< T > const &  other) const
inlinenoexcept

Definition at line 77 of file Key.h.

77 { return !this->operator==(other); }

◆ operator!=() [2/2]

template<typename T >
template<typename OtherT >
bool lsst::afw::table::Key< T >::operator!= ( Key< OtherT > const &  other) const
inlinenoexcept

Definition at line 70 of file Key.h.

70  {
71  return true;
72  }

◆ operator=() [1/2]

template<typename T >
Key& lsst::afw::table::Key< T >::operator= ( Key< T > &&  )
defaultnoexcept

◆ operator=() [2/2]

template<typename T >
Key& lsst::afw::table::Key< T >::operator= ( Key< T > const &  )
defaultnoexcept

◆ operator==() [1/2]

template<typename T >
bool lsst::afw::table::Key< T >::operator== ( Key< T > const &  other) const
inlinenoexcept

Definition at line 74 of file Key.h.

74  {
75  return _offset == other._offset && this->getElementCount() == other.getElementCount();
76  }

◆ operator==() [2/2]

template<typename T >
template<typename OtherT >
bool lsst::afw::table::Key< T >::operator== ( Key< OtherT > const &  other) const
inlinenoexcept

Equality comparison.

Two keys with different types are never equal. Keys with the same type are equal if they point to the same location in a table, regardless of what Schema they were constructed from (for instance, if a field has a different name in one Schema than another, but is otherwise the same, the two keys will be equal).

Definition at line 66 of file Key.h.

66  {
67  return false;
68  }

Friends And Related Function Documentation

◆ BaseRecord

template<typename T >
friend class BaseRecord
friend

Definition at line 120 of file Key.h.

◆ detail::Access

template<typename T >
friend class detail::Access
friend

Definition at line 119 of file Key.h.

◆ operator<<

template<typename T >
std::ostream& operator<< ( std::ostream os,
Key< T > const &  key 
)
friend

Stringification.

Definition at line 113 of file Key.h.

113  {
114  return os << "Key<" << Key<T>::getTypeString() << ">(offset=" << key.getOffset()
115  << ", nElements=" << key.getElementCount() << ")";
116  }

The documentation for this class was generated from the following files:
other
ItemVariant const * other
Definition: Schema.cc:56
os
std::ostream * os
Definition: Schema.cc:746
lsst::utils::hashCombine
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35
lsst::afw::table::FieldBase::makeDefault
static FieldBase makeDefault() noexcept
Needed to allow Keys to be default-constructed.
Definition: FieldBase.h:71
key
Key< U > key
Definition: Schema.cc:281
lsst::afw::table::Key::operator==
bool operator==(Key< OtherT > const &other) const noexcept
Equality comparison.
Definition: Key.h:66