1 #include "boost/preprocessor/seq/for_each.hpp" 2 #include "boost/preprocessor/tuple/to_seq.hpp" 16 bool operator()(SchemaItem<Flag>
const &item)
const {
return item.key ==
target; }
18 explicit MatchKey(Key<Flag>
const &t) :
target(t) {}
24 bool operator()(SchemaItem<Flag>
const &item)
const {
return item.field.getName() ==
target; }
34 IntT r =
std::find_if(_items.begin(), _items.end(), MatchKey(key)) - _items.begin();
37 (boost::format(
"'%s' not found in BitsColumn") % key).str());
43 IntT r =
std::find_if(_items.begin(), _items.end(), MatchName(name)) - _items.begin();
46 (boost::format(
"'%s' not found in BitsColumn") % name).str());
51 BitsColumn::BitsColumn(
int size) : _array(ndarray::allocate(size)) { _array.deep() =
IntT(0); }
62 ndarray::Manager::Ptr
const &manager_)
63 : recordCount(recordCount_), buf(buf_), table(table_), manager(manager_) {}
72 return ndarray::external(reinterpret_cast<T *>(reinterpret_cast<char *>(_impl->buf) + key.
getOffset()),
73 ndarray::makeVector(_impl->recordCount),
74 ndarray::makeVector(
int(_impl->table->getSchema().getRecordSize() /
sizeof(T))),
80 if (
key.isVariableLength()) {
83 return ndarray::external(
84 reinterpret_cast<T *>(reinterpret_cast<char *>(_impl->buf) +
key.getOffset()),
85 ndarray::makeVector(_impl->recordCount,
key.getSize()),
86 ndarray::makeVector(
int(_impl->table->getSchema().getRecordSize() /
sizeof(T)), 1),
90 ndarray::result_of::vectorize<detail::FlagExtractor, ndarray::Array<Field<Flag>::Element
const, 1> >::type
95 reinterpret_cast<char *>(_impl->buf) + key.
getOffset()),
96 ndarray::makeVector(_impl->recordCount),
97 ndarray::makeVector(
int(_impl->table->getSchema().getRecordSize() /
104 ndarray::ArrayRef<BitsColumn::IntT, 1, 1> array = result._array.deep();
107 (boost::format(
"Too many keys passed to getBits(); %d > %d.") %
keys.size() %
114 result._items.push_back(getSchema().find(
keys[i]));
121 struct ExtractFlagItems {
122 template <
typename T>
134 ExtractFlagItems func = {&result._items};
135 getSchema().forEach(func);
138 (boost::format(
"Too many Flag keys in schema; %d > %d.") % result._items.size() %
142 ndarray::ArrayRef<BitsColumn::IntT, 1, 1> array = result._array.deep();
159 ndarray::Manager::Ptr
const &manager)
160 : _impl(
std::make_shared<
Impl>(table, recordCount, buf, manager)) {}
164 #define INSTANTIATE_COLUMNVIEW_SCALAR(r, data, elem) \ 165 template ndarray::ArrayRef<elem, 1> const BaseColumnView::operator[](Key<elem> const &) const; 170 #define INSTANTIATE_COLUMNVIEW_ARRAY(r, data, elem) \ 171 template ndarray::ArrayRef<elem, 2, 1> const BaseColumnView::operator[](Key<Array<elem> > const &) const; #define INSTANTIATE_COLUMNVIEW_ARRAY(r, data, elem)
#define AFW_TABLE_SCALAR_FIELD_TYPE_N
Column-wise view into a sequence of records that have been allocated contiguously.
A packed representation of a collection of Flag field columns.
BaseColumnView & operator=(BaseColumnView const &)
Key< Flag > const & target
int getOffset() const
Return the offset (in bytes) of this field within a record.
BitsColumn getAllBits() const
Return an integer array with all Flag fields repacked into individual bits.
std::shared_ptr< BaseTable > getTable() const
Return the table that owns the records.
std::vector< SchemaItem< Flag > > * items
IntT getBit(Key< Flag > const &key) const
BitsColumn getBits(std::vector< Key< Flag > > const &keys) const
Return an integer array with the given Flag fields repacked into individual bits. ...
#define INSTANTIATE_COLUMNVIEW_SCALAR(r, data, elem)
std::shared_ptr< BaseTable > table
A base class for image defects.
#define AFW_TABLE_SCALAR_FIELD_TYPE_TUPLE
#define AFW_TABLE_ARRAY_FIELD_TYPE_N
Impl(std::shared_ptr< BaseTable > const &table_, int recordCount_, void *buf_, ndarray::Manager::Ptr const &manager_)
A description of a field in a table.
Tag types used to declare specialized field types.
BaseColumnView(BaseColumnView const &)
std::unique_ptr< SchemaItem< U > > result
ndarray::ArrayRef< T, 1 > const operator[](Key< T > const &key) const
Return a 1-d array corresponding to a scalar field (or subfield).
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,...)
A class used as a handle to a particular field in a table.
Key specialization for Flag.
ndarray::Manager::Ptr manager
int getOffset() const
Return the offset in bytes of the integer element that holds this field's bit.
#define AFW_TABLE_ARRAY_FIELD_TYPE_TUPLE
A simple pair-like struct for mapping a Field (name and description) with a Key (used for actual data...