LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
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