LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
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
bool operator!=(Key const &other) const noexcept
Equality comparison.
Definition: Key.h:77
bool operator==(Key< OtherT > const &other) const noexcept
Equality comparison.
Definition: Key.h:66
Field base class default implementation (used for numeric scalars and lsst::geom::Angle).
Definition: FieldBase.h:43
int 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
Equality comparison.
Definition: Key.h:74
bool operator!=(Key< OtherT > const &other) const noexcept
Equality comparison.
Definition: Key.h:70
std::size_t hash_value() const noexcept
Return a hash of this object.
Definition: Key.h:81
STL namespace.
bool isValid() const noexcept
Return true if the key was initialized to valid offset.
Definition: Key.h:97
A base class for image defects.
Base class for all records.
Definition: BaseRecord.h:31
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
Key< U > key
Definition: Schema.cc:281
ItemVariant const * other
Definition: Schema.cc:56
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35
static std::string getTypeString()
Return a string description of the field type.
Definition: FieldBase.cc:56
size_t operator()(argument_type const &obj) const noexcept
Definition: Key.h:136
STL class.
Key() noexcept
Default construct a field.
Definition: Key.h:104
std::ostream * os
Definition: Schema.cc:746