LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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
py::object result
Definition: schema.cc:284
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)
int end
#define AFW_TABLE_FIELD_TYPE_N
Definition: types.h:39