LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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 "lsst/afw/table/misc.h"
8 
9 namespace lsst { namespace afw { namespace table {
10 
11 namespace detail {
12 
13 class Access;
14 
15 } // namespace detail
16 
26 template <>
27 struct FieldBase<Flag> {
28 
29  typedef bool Value;
30  typedef boost::int64_t Element;
31 
33  int getElementCount() const { return 1; }
34 
36  static std::string getTypeString() { return "Flag"; }
37 
38 #ifndef SWIG_BUG_3465431_FIXED
39  // SWIG uses this template to define the interface for the other specializations.
40  // We can add other methods to full specializations using %extend, but we can't add
41  // constructors that way.
42  FieldBase() {}
43  FieldBase(int) {
44  throw LSST_EXCEPT(
45  lsst::pex::exceptions::LogicError,
46  "Constructor disabled (it only appears to exist as a workaround for a SWIG bug)."
47  );
48  }
49 #endif
50 
51 protected:
52 
54  void stream(std::ostream & os) const {}
55 
56 };
57 
61 template <>
62 class KeyBase< Flag > {
63 public:
64  static bool const HAS_NAMED_SUBFIELDS = false;
65 
67  Key<FieldBase<Flag>::Element> getStorage() const;
68 };
69 
81 template <>
82 class Key<Flag> : public KeyBase<Flag>, public FieldBase<Flag> {
83 public:
84 
86 
95  template <typename OtherT> bool operator==(Key<OtherT> const & other) const { return false; }
96  template <typename OtherT> bool operator!=(Key<OtherT> const & other) const { return true; }
97 
98  bool operator==(Key const & other) const { return _offset == other._offset && _bit == other._bit; }
99  bool operator!=(Key const & other) const { return !this->operator==(other); }
101 
103  int getOffset() const { return _offset; }
104 
106  int getBit() const { return _bit; }
107 
116  bool isValid() const { return _offset >= 0; }
117 
123  Key() : FieldBase<Flag>(), _offset(-1), _bit(0) {}
124 
126  inline friend std::ostream & operator<<(std::ostream & os, Key<Flag> const & key) {
127  return os << "Key['" << Key<Flag>::getTypeString() << "'](offset=" << key.getOffset()
128  << ", bit=" << key.getBit() << ")";
129  }
130 
131 private:
132 
133  friend class detail::Access;
134  friend class BaseRecord;
135 
137  Value getValue(Element const * p, ndarray::Manager::Ptr const &) const {
138  return (*p) & (Element(1) << _bit);
139  }
140 
142  void setValue(Element * p, ndarray::Manager::Ptr const &, Value v) const {
143  if (v) {
144  *p |= (Element(1) << _bit);
145  } else {
146  *p &= ~(Element(1) << _bit);
147  }
148  }
149 
150  explicit Key(int offset, int bit) : _offset(offset), _bit(bit) {}
151 
152  int _offset;
153  int _bit;
154 };
155 
156 }}} // namespace lsst::afw::table
157 
158 #endif // !LSST_AFW_TABLE_Flag_h_INCLUDED
Field base class default implementation (used for numeric scalars and Angle).
Definition: FieldBase.h:48
Key()
Default construct a field.
Definition: Flag.h:123
bool Value
the type returned by BaseRecord::get
Definition: Flag.h:29
bool operator!=(Key const &other) const
Equality comparison.
Definition: Flag.h:99
bool operator==(Key< OtherT > const &other) const
Equality comparison.
Definition: Flag.h:95
bool operator!=(Key< OtherT > const &other) const
Equality comparison.
Definition: Flag.h:96
Key(int offset, int bit)
Definition: Flag.h:150
bool operator==(Key const &other) const
Equality comparison.
Definition: Flag.h:98
void stream(std::ostream &os) const
Defines how fields are printed.
Definition: Flag.h:54
int getBit() const
The index of this field&#39;s bit within the integer it shares with other Flag fields.
Definition: Flag.h:106
boost::intrusive_ptr< Manager > Ptr
Definition: Manager.h:42
int getOffset() const
Return the offset in bytes of the integer element that holds this field&#39;s bit.
Definition: Flag.h:103
int getElementCount() const
Return the number of subfield elements (always one for scalars).
Definition: Flag.h:33
static std::string getTypeString()
Return a string description of the field type.
Definition: Flag.h:36
static bool const HAS_NAMED_SUBFIELDS
Definition: KeyBase.h:19
Value getValue(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement RecordBase::get.
Definition: Flag.h:137
T Element
the type of subfields (the same as the type itself for scalars)
Definition: FieldBase.h:53
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
A base class for Key that allows subfield keys to be extracted for some field types.
Definition: KeyBase.h:17
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
void setValue(Element *p, ndarray::Manager::Ptr const &, Value v) const
Used to implement RecordBase::set.
Definition: Flag.h:142
bool operator==(Key< OtherT > const &other) const
Equality comparison.
Definition: Key.h:63
bool isValid() const
Return true if the key was initialized to valid offset.
Definition: Flag.h:116
boost::int64_t Element
the actual storage type (shared by multiple flag fields)
Definition: Flag.h:30
static std::string getTypeString()
Return a string description of the field type.