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
Access.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #ifndef AFW_TABLE_DETAIL_Access_h_INCLUDED
3 #define AFW_TABLE_DETAIL_Access_h_INCLUDED
4 
5 #include <cstring>
6 
7 #include "ndarray/Manager.h"
11 
12 namespace lsst { namespace afw { namespace table {
13 
14 class BaseRecord;
15 class BaseTable;
16 
17 namespace detail {
18 
29 class Access {
30 public:
31 
33  template <typename T>
35  if (!static_cast<Key<T> const &>(kb).isValid()) {
36  throw LSST_EXCEPT(
37  pex::exceptions::LogicError,
38  (boost::format("Cannot extract subfield key from invalid key of type '%s' "
39  "(most often this is caused by failing to setup centroid or shape slots)")
40  % Key<T>::getTypeString()).str()
41  );
42  }
44  static_cast<Key<T> const &>(kb).getOffset() + n * sizeof(typename Key<T>::Element)
45  );
46  }
47 
49  template <typename T>
50  static Key< Array<T> > extractRange(KeyBase< Array<T> > const & kb, int begin, int end) {
51  if (!static_cast<Key< Array<T> > const &>(kb).isValid()) {
52  throw LSST_EXCEPT(
53  pex::exceptions::LogicError,
54  (boost::format("Cannot extract subfield key from invalid key of type '%s' ")
55  % Key<T>::getTypeString()).str()
56  );
57  }
58  return Key< Array<T> >(
59  static_cast<Key< Array<T> > const &>(kb).getOffset() + begin * sizeof(typename Key<T>::Element),
60  end - begin
61  );
62  }
63 
65  template <typename T>
66  static Key<T> makeKey(int offset) {
67  return Key<T>(offset);
68  }
69 
71  template <typename T>
72  static Key<T> makeKey(Field<T> const & field, int offset) {
73  return Key<T>(offset, field);
74  }
75 
77  static Key<Flag> makeKey(int offset, int bit) {
78  return Key<Flag>(offset, bit);
79  }
80 
82  static void padSchema(Schema & schema, int bytes) {
83  schema._edit();
84  schema._impl->_recordSize += bytes;
85  }
86 
87 };
88 
89 }}}} // namespace lsst::afw::table::detail
90 
91 #endif // !AFW_TABLE_DETAIL_Access_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:46
boost::shared_ptr< Impl > _impl
Definition: Schema.h:293
static void padSchema(Schema &schema, int bytes)
Definition: Access.h:82
afw::table::Schema schema
Definition: GaussianPsf.cc:41
static Key< T > makeKey(int offset)
Definition: Access.h:66
Definition of Manager, which manages the ownership of array data.
void _edit()
Copy on write; should be called by all mutators (except for alias mutators).
static Key< Array< T > > extractRange(KeyBase< Array< T > > const &kb, int begin, int end)
Definition: Access.h:50
static Key< T > makeKey(Field< T > const &field, int offset)
Definition: Access.h:72
static Key< typename Key< T >::Element > extractElement(KeyBase< T > const &kb, int n)
Definition: Access.h:34
A description of a field in a table.
Definition: Field.h:22
static Key< Flag > makeKey(int offset, int bit)
Definition: Access.h:77
Tag types used to declare specialized field types.
Definition: misc.h:35
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
A class used as a handle to a particular field in a table.
Definition: fwd.h:44
Key specialization for Flag.
Definition: Flag.h:82
table::Key< int > field
Definition: ApCorrMap.cc:72