LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
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 { namespace afw { namespace table {
12 
13 namespace detail {
14 
15 class Access;
16 
17 } // namespace detail
18 
28 template <>
29 struct FieldBase<Flag> {
30 
31  typedef bool Value;
32  typedef std::int64_t Element;
33 
35  int getElementCount() const { return 1; }
36 
38  static std::string getTypeString() { return "Flag"; }
39 
40 #ifndef SWIG_BUG_3465431_FIXED
41  // SWIG uses this template to define the interface for the other specializations.
42  // We can add other methods to full specializations using %extend, but we can't add
43  // constructors that way.
44  FieldBase() {}
45  FieldBase(int) {
46  throw LSST_EXCEPT(
47  lsst::pex::exceptions::LogicError,
48  "Constructor disabled (it only appears to exist as a workaround for a SWIG bug)."
49  );
50  }
51 #endif
52 
53 protected:
54 
56  void stream(std::ostream & os) const {}
57 
58 };
59 
63 template <>
64 class KeyBase< Flag > {
65 public:
66  static bool const HAS_NAMED_SUBFIELDS = false;
67 
69  Key<FieldBase<Flag>::Element> getStorage() const;
70 };
71 
83 template <>
84 class Key<Flag> : public KeyBase<Flag>, public FieldBase<Flag> {
85 public:
86 
88 
97  template <typename OtherT> bool operator==(Key<OtherT> const & other) const { return false; }
98  template <typename OtherT> bool operator!=(Key<OtherT> const & other) const { return true; }
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 
135  friend class detail::Access;
136  friend class BaseRecord;
137 
139  Value getValue(Element const * p, ndarray::Manager::Ptr const &) const {
140  return (*p) & (Element(1) << _bit);
141  }
142 
144  void setValue(Element * p, ndarray::Manager::Ptr const &, Value v) const {
145  if (v) {
146  *p |= (Element(1) << _bit);
147  } else {
148  *p &= ~(Element(1) << _bit);
149  }
150  }
151 
152  explicit Key(int offset, int bit) : _offset(offset), _bit(bit) {}
153 
154  int _offset;
155  int _bit;
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:48
int getOffset() const
Return the offset in bytes of the integer element that holds this field&#39;s bit.
Definition: Flag.h:105
bool operator!=(Key< OtherT > const &other) const
Equality comparison.
Definition: Flag.h:98
bool operator!=(Key const &other) const
Equality comparison.
Definition: Flag.h:101
int getElementCount() const
Return the number of subfield elements (always one for scalars).
Definition: Flag.h:35
bool operator==(Key< OtherT > const &other) const
Equality comparison.
Definition: Key.h:63
Key(int offset, int bit)
Definition: Flag.h:152
static bool const HAS_NAMED_SUBFIELDS
Definition: KeyBase.h:19
void setValue(Element *p, ndarray::Manager::Ptr const &, Value v) const
Used to implement RecordBase::set.
Definition: Flag.h:144
static std::string getTypeString()
Return a string description of the field type.
std::int64_t Element
the actual storage type (shared by multiple flag fields)
Definition: Flag.h:32
bool operator==(Key< OtherT > const &other) const
Equality comparison.
Definition: Flag.h:97
Value getValue(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement RecordBase::get.
Definition: Flag.h:139
bool operator==(Key const &other) const
Equality comparison.
Definition: Flag.h:100
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
A base class for Key that allows subfield keys to be extracted for some field types.
Definition: KeyBase.h:17
void stream(std::ostream &os) const
Defines how fields are printed.
Definition: Flag.h:56
bool Value
the type returned by BaseRecord::get
Definition: Flag.h:31
Base class for all records.
Definition: BaseRecord.h:27
A class used as a handle to a particular field in a table.
Definition: fwd.h:44
bool isValid() const
Return true if the key was initialized to valid offset.
Definition: Flag.h:118
static std::string getTypeString()
Return a string description of the field type.
Definition: Flag.h:38
Key()
Default construct a field.
Definition: Flag.h:125
T Element
the type of subfields (the same as the type itself for scalars)
Definition: FieldBase.h:53
int getBit() const
The index of this field&#39;s bit within the integer it shares with other Flag fields.
Definition: Flag.h:108