LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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
static Key< Array< T > > extractRange(KeyBase< Array< T > > const &kb, int begin, int end)
Definition: Access.h:50
Defines the fields and offsets for a table.
Definition: Schema.h:46
static void padSchema(Schema &schema, int bytes)
Definition: Access.h:82
Definition of Manager, which manages the ownership of array data.
static Key< T > makeKey(int offset)
Definition: Access.h:66
static Key< T > makeKey(Field< T > const &field, int offset)
Definition: Access.h:72
T Element
the type of subfields (the same as the type itself for scalars)
Definition: FieldBase.h:53
tbl::Key< int > field
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
Tag types used to declare specialized field types.
Definition: misc.h:35
tbl::Schema schema
boost::shared_ptr< Impl > _impl
Definition: Schema.h:293
#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
void _edit()
Copy on write; should be called by all mutators (except for alias mutators).
static Key< Flag > makeKey(int offset, int bit)
Definition: Access.h:77