18 struct RecordInitializer {
35 void operator()(SchemaItem<T>
const &item)
const {
37 item.key.getElementCount());
41 void operator()(SchemaItem<Array<T> >
const &item)
const {
42 if (item.key.isVariableLength()) {
44 new (
data + item.key.getOffset()) ndarray::Array<T, 1, 1>();
47 item.key.getElementCount());
51 void operator()(SchemaItem<std::string>
const &item)
const {
52 if (item.key.isVariableLength()) {
56 fill(
reinterpret_cast<char *
>(
data + item.key.getOffset()), item.key.getElementCount());
60 void operator()(SchemaItem<Flag>
const &item)
const {}
68 void operator()(Key<U>
const& inputKey, Key<U>
const& outputKey)
const {
70 std::copy(inputElem, inputElem + inputKey.getElementCount(), _outputRecord->getElement(outputKey));
74 void operator()(Key<Array<U> >
const& inputKey, Key<Array<U> >
const& outputKey)
const {
75 if (inputKey.isVariableLength() != outputKey.isVariableLength()) {
77 "At least one input array field is variable-length"
78 " and the correponding output is not, or vice-versa");
80 if (inputKey.isVariableLength()) {
81 ndarray::Array<U, 1, 1> value = ndarray::copy(_inputRecord->get(inputKey));
82 _outputRecord->set(outputKey, value);
86 std::copy(inputElem, inputElem + inputKey.getElementCount(), _outputRecord->getElement(outputKey));
89 void operator()(Key<std::string>
const& inputKey, Key<std::string>
const& outputKey)
const {
90 if (inputKey.isVariableLength() != outputKey.isVariableLength()) {
92 "At least one input string field is variable-length "
93 "and the correponding output is not, or vice-versa");
95 if (inputKey.isVariableLength()) {
97 _outputRecord->set(outputKey, value);
100 char const* inputElem = _inputRecord->getElement(inputKey);
101 std::copy(inputElem, inputElem + inputKey.getElementCount(), _outputRecord->getElement(outputKey));
104 void operator()(Key<Flag>
const& inputKey, Key<Flag>
const& outputKey)
const {
105 _outputRecord->set(outputKey, _inputRecord->get(inputKey));
108 template <
typename U>
109 void operator()(SchemaItem<U>
const& item)
const {
110 (*this)(item.key, item.key);
113 CopyValue(BaseRecord
const* inputRecord, BaseRecord* outputRecord)
114 : _inputRecord(inputRecord), _outputRecord(outputRecord) {}
117 BaseRecord
const* _inputRecord;
118 BaseRecord* _outputRecord;
132 if (!
other.getSchema().contains(
mapper.getInputSchema())) {
134 "Unequal schemas between input record and mapper.");
138 "Unequal schemas between output record and mapper.");
147 _manager(
std::move(
data.manager))
149 RecordInitializer f = {
reinterpret_cast<char *
>(_data)};
150 _table->getSchema().forEach(f);
155 os << item.field.getName() <<
": " << this->
get(item.key) <<
std::endl;
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
ItemVariant const * other
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.
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.
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.