LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
LSSTDataManagementBasePackage
KeyBase.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 #include "boost/preprocessor/seq/for_each.hpp"
4 #include "boost/preprocessor/tuple/to_seq.hpp"
5 
8 #include "lsst/afw/table/Flag.h"
10 
11 namespace lsst {
12 namespace afw {
13 namespace table {
14 
16  return detail::Access::extractElement(*this, 0);
17 }
18 
20 
21 template <typename T>
23 
24 template <typename U>
26 
27 template <typename U>
28 std::vector<U> KeyBase<Array<U>>::extractVector(BaseRecord const &record) const {
29  Key<Array<U>> const *self = static_cast<Key<Array<U>> const *>(this);
30  std::vector<U> result(self->getSize());
31  typename Key<Array<U>>::ConstReference array = record[*self];
32  std::copy(array.begin(), array.end(), result.begin());
33  return result;
34 }
35 
36 template <typename U>
37 void KeyBase<Array<U>>::assignVector(BaseRecord &record, std::vector<U> const &values) const {
38  Key<Array<U>> const *self = static_cast<Key<Array<U>> const *>(this);
39  std::copy(values.begin(), values.end(), record[*self].begin());
40 }
41 
42 template <typename U>
43 Key<U> KeyBase<Array<U>>::operator[](int i) const {
44  Key<Array<U>> const *self = static_cast<Key<Array<U>> const *>(this);
45  if (self->isVariableLength()) {
47  "Cannot get Keys to elements of variable-length arrays.");
48  }
49  if (i >= self->getSize() || i < 0) {
50  throw LSST_EXCEPT(lsst::pex::exceptions::LengthError, "Array key index out of range.");
51  }
52  return detail::Access::extractElement(*this, i);
53 }
54 
55 template <typename U>
56 Key<Array<U>> KeyBase<Array<U>>::slice(int begin, int end) const {
57  Key<Array<U>> const *self = static_cast<Key<Array<U>> const *>(this);
58  if (self->isVariableLength()) {
60  "Cannot get Keys to slices of variable-length arrays.");
61  }
62  if (begin > self->getSize() || begin < 0) {
63  throw LSST_EXCEPT(lsst::pex::exceptions::LengthError, "Array key begin index out of range.");
64  }
65  if (end > self->getSize() || end < 0) {
66  throw LSST_EXCEPT(lsst::pex::exceptions::LengthError, "Array key end index out of range.");
67  }
68  return detail::Access::extractRange(*this, begin, end);
69 }
70 
71 //----- Explicit instantiation ------------------------------------------------------------------------------
72 
73 #define INSTANTIATE_KEY(r, data, elem) template class KeyBase<elem>;
74 
76  BOOST_PP_TUPLE_TO_SEQ(AFW_TABLE_FIELD_TYPE_N, AFW_TABLE_FIELD_TYPE_TUPLE))
77 } // namespace table
78 } // namespace afw
79 } // namespace lsst
static Key< Array< T > > extractRange(KeyBase< Array< T > > const &kb, int begin, int end)
Definition: Access.h:51
T copy(T... args)
Reports attempts to exceed implementation-defined length limits for some classes. ...
Definition: Runtime.h:76
T end(T... args)
#define AFW_TABLE_FIELD_TYPE_TUPLE
Definition: types.h:44
#define INSTANTIATE_KEY(r, data, elem)
Definition: KeyBase.cc:73
A base class for image defects.
static Key< typename Key< T >::Element > extractElement(KeyBase< T > const &kb, int n)
Definition: Access.h:35
static bool const HAS_NAMED_SUBFIELDS
Definition: KeyBase.h:22
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_COLUMNVIEW_SCALAR, _, BOOST_PP_TUPLE_TO_SEQ(AFW_TABLE_SCALAR_FIELD_TYPE_N, AFW_TABLE_SCALAR_FIELD_TYPE_TUPLE)) BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_COLUMNVIEW_ARRAY
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
A base class for Key that allows subfield keys to be extracted for some field types.
Definition: KeyBase.h:20
STL class.
Base class for all records.
Definition: BaseRecord.h:31
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
T begin(T... args)
py::object result
Definition: _schema.cc:429
int end
#define AFW_TABLE_FIELD_TYPE_N
Definition: types.h:39