LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
Key.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #ifndef AFW_TABLE_Key_h_INCLUDED
3 #define AFW_TABLE_Key_h_INCLUDED
4 
6 
8 #include "lsst/afw/table/Flag.h"
10 
11 namespace lsst {
12 namespace afw {
13 namespace table {
14 
15 namespace detail {
16 
17 class Access;
18 
19 } // namespace detail
20 
52 template <typename T>
53 class Key : public KeyBase<T>, public FieldBase<T> {
54 public:
56 
65  template <typename OtherT>
66  bool operator==(Key<OtherT> const& other) const noexcept {
67  return false;
68  }
69  template <typename OtherT>
70  bool operator!=(Key<OtherT> const& other) const noexcept {
71  return true;
72  }
73 
74  bool operator==(Key const& other) const noexcept {
75  return _offset == other._offset && this->getElementCount() == other.getElementCount();
76  }
77  bool operator!=(Key const& other) const noexcept { return !this->operator==(other); }
79 
81  std::size_t hash_value() const noexcept {
82  // Completely arbitrary seed
83  return utils::hashCombine(17, _offset, this->getElementCount());
84  }
85 
87  int getOffset() const noexcept { return _offset; }
88 
97  bool isValid() const noexcept { return _offset >= 0; }
98 
104  Key() noexcept : FieldBase<T>(FieldBase<T>::makeDefault()), _offset(-1) {}
105 
106  Key(Key const&) noexcept = default;
107  Key(Key&&) noexcept = default;
108  Key& operator=(Key const&) noexcept = default;
109  Key& operator=(Key&&) noexcept = default;
110  ~Key() noexcept = default;
111 
113  inline friend std::ostream& operator<<(std::ostream& os, Key<T> const& key) {
114  return os << "Key<" << Key<T>::getTypeString() << ">(offset=" << key.getOffset()
115  << ", nElements=" << key.getElementCount() << ")";
116  }
117 
118 private:
119  friend class detail::Access;
120  friend class BaseRecord;
121 
122  explicit Key(int offset, FieldBase<T> const& fb = FieldBase<T>()) noexcept
123  : FieldBase<T>(fb), _offset(offset) {}
124 
125  int _offset;
126 };
127 } // namespace table
128 } // namespace afw
129 } // namespace lsst
130 
131 namespace std {
132 template <typename T>
133 struct hash<lsst::afw::table::Key<T>> {
136  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
137 };
138 } // namespace std
139 
140 #endif // !AFW_TABLE_Key_h_INCLUDED
ItemVariant const * other
Definition: Schema.cc:56
Key< U > key
Definition: Schema.cc:281
std::ostream * os
Definition: Schema.cc:746
Base class for all records.
Definition: BaseRecord.h:31
A base class for Key that allows subfield keys to be extracted for some field types.
Definition: KeyBase.h:20
A class used as a handle to a particular field in a table.
Definition: Key.h:53
bool operator==(Key< OtherT > const &other) const noexcept
Equality comparison.
Definition: Key.h:66
bool operator!=(Key const &other) const noexcept
Definition: Key.h:77
Key() noexcept
Default construct a field.
Definition: Key.h:104
Key(Key &&) noexcept=default
bool isValid() const noexcept
Return true if the key was initialized to valid offset.
Definition: Key.h:97
std::size_t hash_value() const noexcept
Return a hash of this object.
Definition: Key.h:81
bool operator==(Key const &other) const noexcept
Definition: Key.h:74
int getOffset() const noexcept
Return the offset (in bytes) of this field within a record.
Definition: Key.h:87
bool operator!=(Key< OtherT > const &other) const noexcept
Definition: Key.h:70
Key(Key const &) noexcept=default
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35
A base class for image defects.
STL namespace.
Field base class default implementation (used for numeric scalars and lsst::geom::Angle).
Definition: FieldBase.h:43
static std::string getTypeString()
Return a string description of the field type.
Definition: FieldBase.cc:56
static FieldBase makeDefault() noexcept
Needed to allow Keys to be default-constructed.
Definition: FieldBase.h:71
int getElementCount() const noexcept
Return the number of subfield elements (always one for scalars).
Definition: FieldBase.h:50
size_t operator()(argument_type const &obj) const noexcept
Definition: Key.h:136