17 struct RecordInitializer {
34 void operator()(SchemaItem<T>
const &item)
const {
36 item.key.getElementCount());
40 void operator()(SchemaItem<Array<T> >
const &item)
const {
41 if (item.key.isVariableLength()) {
43 new (
data + item.key.getOffset()) ndarray::Array<T, 1, 1>();
46 item.key.getElementCount());
50 void operator()(SchemaItem<std::string>
const &item)
const {
51 if (item.key.isVariableLength()) {
55 fill(
reinterpret_cast<char *
>(
data + item.key.getOffset()), item.key.getElementCount());
59 void operator()(SchemaItem<Flag>
const &item)
const {}
67 void operator()(Key<U>
const& inputKey, Key<U>
const& outputKey)
const {
69 std::copy(inputElem, inputElem + inputKey.getElementCount(), _outputRecord->getElement(outputKey));
73 void operator()(Key<Array<U> >
const& inputKey, Key<Array<U> >
const& outputKey)
const {
74 if (inputKey.isVariableLength() != outputKey.isVariableLength()) {
76 "At least one input array field is variable-length"
77 " and the correponding output is not, or vice-versa");
79 if (inputKey.isVariableLength()) {
80 ndarray::Array<U, 1, 1> value = ndarray::copy(_inputRecord->get(inputKey));
81 _outputRecord->set(outputKey, value);
85 std::copy(inputElem, inputElem + inputKey.getElementCount(), _outputRecord->getElement(outputKey));
88 void operator()(Key<std::string>
const& inputKey, Key<std::string>
const& outputKey)
const {
89 if (inputKey.isVariableLength() != outputKey.isVariableLength()) {
91 "At least one input string field is variable-length "
92 "and the correponding output is not, or vice-versa");
94 if (inputKey.isVariableLength()) {
96 _outputRecord->set(outputKey, value);
99 char const* inputElem = _inputRecord->getElement(inputKey);
100 std::copy(inputElem, inputElem + inputKey.getElementCount(), _outputRecord->getElement(outputKey));
103 void operator()(Key<Flag>
const& inputKey, Key<Flag>
const& outputKey)
const {
104 _outputRecord->set(outputKey, _inputRecord->get(inputKey));
107 template <
typename U>
108 void operator()(SchemaItem<U>
const& item)
const {
109 (*this)(item.key, item.key);
112 CopyValue(BaseRecord
const* inputRecord, BaseRecord* outputRecord)
113 : _inputRecord(inputRecord), _outputRecord(outputRecord) {}
116 BaseRecord
const* _inputRecord;
117 BaseRecord* _outputRecord;
133 "Unequal schemas between input record and mapper.");
137 "Unequal schemas between output record and mapper.");
139 mapper.forEach(CopyValue(&other,
this));
146 _manager(
std::move(
data.manager))
148 RecordInitializer f = {
reinterpret_cast<char *
>(_data)};
149 _table->getSchema().forEach(f);
154 os << item.field.getName() <<
": " << this->
get(item.key) <<
std::endl;
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Base class for all records.
void assign(BaseRecord const &other)
Copy all field values from other to this, requiring that they have equal schemas.
Schema getSchema() const
Return the Schema that holds this record's fields and keys.
BaseRecord(ConstructionToken const &, detail::RecordData &&data)
Construct a record with uninitialized data.
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
virtual void _assign(BaseRecord const &other)
Called by assign() after transferring fields to allow subclass data members to be copied.
virtual void _stream(std::ostream &os) const
Called by operator<<.
void forEach(F &func) const
Apply a functor to each SchemaItem in the Schema.
int contains(Schema const &other, int flags=EQUAL_KEYS) const
Test whether the given schema is a subset of this.
A mapping between the keys of two Schemas, used to copy data between them.
Schema const getOutputSchema() const
Return the output schema (copy-on-write).
A class representing an angle.
Reports invalid arguments.
Reports errors in the logical structure of the program.
std::ostream & operator<<(std::ostream &os, BaseRecord const &record)
A base class for image defects.
typename FieldBase< T >::Element Element
Type used to store field data in the table (a field may have multiple elements).
Helper struct that contains the information passed from BaseTable to BaseRecord at construction.