LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
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  std::size_t getOffset() const noexcept { return _offset; }
88 
97  bool isValid() const noexcept { return _valid; }
98 
104  Key() noexcept : FieldBase<T>(FieldBase<T>::makeDefault()), _offset(0), _valid(false) {}
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(std::size_t offset, FieldBase<T> const& fb = FieldBase<T>()) noexcept
123  : FieldBase<T>(fb), _offset(offset), _valid(true) {}
124 
125  std::size_t _offset;
126  bool _valid;
127 };
128 } // namespace table
129 } // namespace afw
130 } // namespace lsst
131 
132 namespace std {
133 template <typename T>
134 struct hash<lsst::afw::table::Key<T>> {
137  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
138 };
139 } // namespace std
140 
141 #endif // !AFW_TABLE_Key_h_INCLUDED
std::ostream * os
Definition: Schema.cc:557
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
std::size_t getOffset() const noexcept
Return the offset (in bytes) of this field within a record.
Definition: Key.h:87
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
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:41
static std::string getTypeString()
Return a string description of the field type.
Definition: FieldBase.cc:56
std::size_t getElementCount() const noexcept
Return the number of subfield elements (always one for scalars).
Definition: FieldBase.h:48
static FieldBase makeDefault() noexcept
Needed to allow Keys to be default-constructed.
Definition: FieldBase.h:69
size_t operator()(argument_type const &obj) const noexcept
Definition: Key.h:137