LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
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.
ItemVariant const * other
Definition: Schema.cc:56
bool isValid() const noexcept
Return true if the key was initialized to valid offset.
Definition: Key.h:97
A base class for image defects.
Key< U > key
Definition: Schema.cc:281
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
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35
std::ostream * os
Definition: Schema.cc:746
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