lsst.afw  16.0-51-gb4b4a8566+2
Flag.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #ifndef LSST_AFW_TABLE_Flag_h_INCLUDED
3 #define LSST_AFW_TABLE_Flag_h_INCLUDED
4 
5 #include <cstdint>
6 
7 #include "lsst/afw/table/misc.h"
10 
11 namespace lsst {
12 namespace afw {
13 namespace table {
14 
15 namespace detail {
16 
17 class Access;
18 
19 } // namespace detail
20 
30 template <>
31 struct FieldBase<Flag> {
32  typedef bool Value;
34 
36  int getElementCount() const { return 1; }
37 
39  static std::string getTypeString() { return "Flag"; }
40 
41  // Only the first of these constructors is valid for this specializations, but
42  // it's convenient to be able to instantiate both, since the other is used
43  // by other specializations.
44  FieldBase() = default;
45  FieldBase(int) {
47  "Constructor disabled (this Field type is not sized).");
48  }
49 
50  FieldBase(FieldBase const &) = default;
51  FieldBase(FieldBase &&) = default;
52  FieldBase &operator=(FieldBase const &) = default;
53  FieldBase &operator=(FieldBase &&) = default;
54  ~FieldBase() = default;
55 
56 protected:
58  void stream(std::ostream &os) const {}
59 };
60 
64 template <>
65 class KeyBase<Flag> {
66 public:
67  static bool const HAS_NAMED_SUBFIELDS = false;
68 
70  Key<FieldBase<Flag>::Element> getStorage() const;
71 
72  KeyBase() = default;
73  KeyBase(KeyBase const &) = default;
74  KeyBase(KeyBase &&) = default;
75  KeyBase &operator=(KeyBase const &) = default;
76  KeyBase &operator=(KeyBase &&) = default;
77  ~KeyBase() = default;
78 };
79 
91 template <>
92 class Key<Flag> : public KeyBase<Flag>, public FieldBase<Flag> {
93 public:
95 
104  template <typename OtherT>
105  bool operator==(Key<OtherT> const &other) const {
106  return false;
107  }
108  template <typename OtherT>
109  bool operator!=(Key<OtherT> const &other) const {
110  return true;
111  }
112 
113  bool operator==(Key const &other) const { return _offset == other._offset && _bit == other._bit; }
114  bool operator!=(Key const &other) const { return !this->operator==(other); }
116 
118  int getOffset() const { return _offset; }
119 
121  int getBit() const { return _bit; }
122 
131  bool isValid() const { return _offset >= 0; }
132 
138  Key() : FieldBase<Flag>(), _offset(-1), _bit(0) {}
139 
140  Key(Key const &) = default;
141  Key(Key &&) = default;
142  Key &operator=(Key const &) = default;
143  Key &operator=(Key &&) = default;
144  ~Key() = default;
145 
147  inline friend std::ostream &operator<<(std::ostream &os, Key<Flag> const &key) {
148  return os << "Key['" << Key<Flag>::getTypeString() << "'](offset=" << key.getOffset()
149  << ", bit=" << key.getBit() << ")";
150  }
151 
152 private:
153  friend class detail::Access;
154  friend class BaseRecord;
155 
157  Value getValue(Element const *p, ndarray::Manager::Ptr const &) const {
158  return (*p) & (Element(1) << _bit);
159  }
160 
162  void setValue(Element *p, ndarray::Manager::Ptr const &, Value v) const {
163  if (v) {
164  *p |= (Element(1) << _bit);
165  } else {
166  *p &= ~(Element(1) << _bit);
167  }
168  }
169 
170  explicit Key(int offset, int bit) : _offset(offset), _bit(bit) {}
171 
172  int _offset;
173  int _bit;
174 };
175 } // namespace table
176 } // namespace afw
177 } // namespace lsst
178 
179 #endif // !LSST_AFW_TABLE_Flag_h_INCLUDED
Field base class default implementation (used for numeric scalars and lsst::geom::Angle).
Definition: FieldBase.h:43
Key()
Default construct a field.
Definition: Flag.h:138
bool Value
the type returned by BaseRecord::get
Definition: Flag.h:32
bool operator==(CoordKey const &lhs, CoordKey const &rhs)
Compare CoordKeys for equality using the constituent Keys.
ItemVariant const * other
Definition: Schema.cc:55
bool isValid() const
Return true if the key was initialized to valid offset.
Definition: Flag.h:131
STL class.
A base class for image defects.
bool operator!=(Key< OtherT > const &other) const
Equality comparison.
Definition: Flag.h:109
Key< U > key
Definition: Schema.cc:280
static std::string getTypeString()
Return a string description of the field type.
Definition: Flag.h:39
int getBit() const
The index of this field&#39;s bit within the integer it shares with other Flag fields.
Definition: Flag.h:121
#define LSST_EXCEPT(type,...)
A base class for Key that allows subfield keys to be extracted for some field types.
Definition: KeyBase.h:20
bool operator==(Key const &other) const
Equality comparison.
Definition: Flag.h:113
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
int getElementCount() const
Return the number of subfield elements (always one for scalars).
Definition: Flag.h:36
void stream(std::ostream &os) const
Defines how fields are printed.
Definition: Flag.h:58
bool operator==(Key< OtherT > const &other) const
Equality comparison.
Definition: Flag.h:105
int getOffset() const
Return the offset in bytes of the integer element that holds this field&#39;s bit.
Definition: Flag.h:118
std::ostream * os
Definition: Schema.cc:737
static std::string getTypeString()
Return a string description of the field type.
Definition: FieldBase.cc:56
STL class.
std::int64_t Element
the actual storage type (shared by multiple flag fields)
Definition: Flag.h:33
bool operator!=(Key const &other) const
Equality comparison.
Definition: Flag.h:114