lsst.afw  14.0-38-g278b05818
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() {}
45  FieldBase(int) {
47  "Constructor disabled (this Field type is not sized).");
48  }
49 
50 protected:
52  void stream(std::ostream &os) const {}
53 };
54 
58 template <>
59 class KeyBase<Flag> {
60 public:
61  static bool const HAS_NAMED_SUBFIELDS = false;
62 
64  Key<FieldBase<Flag>::Element> getStorage() const;
65 };
66 
78 template <>
79 class Key<Flag> : public KeyBase<Flag>, public FieldBase<Flag> {
80 public:
82 
91  template <typename OtherT>
92  bool operator==(Key<OtherT> const &other) const {
93  return false;
94  }
95  template <typename OtherT>
96  bool operator!=(Key<OtherT> const &other) const {
97  return true;
98  }
99 
100  bool operator==(Key const &other) const { return _offset == other._offset && _bit == other._bit; }
101  bool operator!=(Key const &other) const { return !this->operator==(other); }
103 
105  int getOffset() const { return _offset; }
106 
108  int getBit() const { return _bit; }
109 
118  bool isValid() const { return _offset >= 0; }
119 
125  Key() : FieldBase<Flag>(), _offset(-1), _bit(0) {}
126 
128  inline friend std::ostream &operator<<(std::ostream &os, Key<Flag> const &key) {
129  return os << "Key['" << Key<Flag>::getTypeString() << "'](offset=" << key.getOffset()
130  << ", bit=" << key.getBit() << ")";
131  }
132 
133 private:
134  friend class detail::Access;
135  friend class BaseRecord;
136 
138  Value getValue(Element const *p, ndarray::Manager::Ptr const &) const {
139  return (*p) & (Element(1) << _bit);
140  }
141 
143  void setValue(Element *p, ndarray::Manager::Ptr const &, Value v) const {
144  if (v) {
145  *p |= (Element(1) << _bit);
146  } else {
147  *p &= ~(Element(1) << _bit);
148  }
149  }
150 
151  explicit Key(int offset, int bit) : _offset(offset), _bit(bit) {}
152 
153  int _offset;
154  int _bit;
155 };
156 }
157 }
158 } // namespace lsst::afw::table
159 
160 #endif // !LSST_AFW_TABLE_Flag_h_INCLUDED
Field base class default implementation (used for numeric scalars and Angle).
Definition: FieldBase.h:44
Key()
Default construct a field.
Definition: Flag.h:125
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.
bool isValid() const
Return true if the key was initialized to valid offset.
Definition: Flag.h:118
STL class.
A base class for image defects.
bool operator!=(Key< OtherT > const &other) const
Equality comparison.
Definition: Flag.h:96
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:108
#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:100
Base class for all records.
Definition: BaseRecord.h:29
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:52
bool operator==(Key< OtherT > const &other) const
Equality comparison.
Definition: Flag.h:92
int getOffset() const
Return the offset in bytes of the integer element that holds this field&#39;s bit.
Definition: Flag.h:105
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:101
static std::string getTypeString()
Return a string description of the field type.