LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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