LSSTApplications  20.0.0
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>
25 bool const KeyBase<Array<U>>::HAS_NAMED_SUBFIELDS;
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
std::vector
STL class.
INSTANTIATE_KEY
#define INSTANTIATE_KEY(r, data, elem)
Definition: KeyBase.cc:73
lsst::afw::table::KeyBase
A base class for Key that allows subfield keys to be extracted for some field types.
Definition: KeyBase.h:20
lsst::afw
Definition: imageAlgorithm.dox:1
end
int end
Definition: BoundedField.cc:105
BaseRecord.h
lsst::afw::table::detail::Access::extractRange
static Key< Array< T > > extractRange(KeyBase< Array< T > > const &kb, int begin, int end)
Definition: Access.h:51
lsst::pex::exceptions::LengthError
Reports attempts to exceed implementation-defined length limits for some classes.
Definition: Runtime.h:76
lsst::afw::table::BaseRecord
Base class for all records.
Definition: BaseRecord.h:31
lsst::pex::exceptions::LogicError
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
lsst::afw::table::Key
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
lsst::afw::table::_
_
Definition: BaseColumnView.cc:188
std::copy
T copy(T... args)
result
py::object result
Definition: _schema.cc:429
AFW_TABLE_FIELD_TYPE_TUPLE
#define AFW_TABLE_FIELD_TYPE_TUPLE
Definition: types.h:44
lsst::afw::table::BOOST_PP_SEQ_FOR_EACH
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
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::afw::table::detail::Access::extractElement
static Key< typename Key< T >::Element > extractElement(KeyBase< T > const &kb, int n)
Definition: Access.h:35
std::vector::begin
T begin(T... args)
KeyBase.h
std::vector::end
T end(T... args)
AFW_TABLE_FIELD_TYPE_N
#define AFW_TABLE_FIELD_TYPE_N
Definition: types.h:39
Access.h
Flag.h