18 struct RecordInitializer {
26 static void fill(
double *element,
int size) {
31 fill(reinterpret_cast<double *>(element), size);
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;
124 if (this->getSchema() != other.
getSchema()) {
127 this->getSchema().forEach(CopyValue(&other,
this));
128 this->_assign(other);
134 "Unequal schemas between input record and mapper.");
138 "Unequal schemas between output record and mapper.");
140 mapper.
forEach(CopyValue(&other,
this));
141 this->_assign(other);
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;
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
friend std::ostream & operator<<(std::ostream &os, BaseRecord const &record)
Write the record's content out, one field on each line.
void forEach(F &&func) const
Call the given functor for each key pair in the mapper.
Helper struct that contains the information passed from BaseTable to BaseRecord at construction...
Schema const getInputSchema() const
Return the input schema (copy-on-write).
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.
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 base class for image defects.
int contains(Schema const &other, int flags=EQUAL_KEYS) const
Test whether the given schema is a subset of this.
Schema getSchema() const
Return the Schema that holds this record's fields and keys.
Reports errors in the logical structure of the program.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Base class for all records.
BaseRecord(ConstructionToken const &, detail::RecordData &&data)
Construct a record with uninitialized data.
FieldBase< T >::Element Element
Type used to store field data in the table (a field may have multiple elements).
Reports invalid arguments.
ItemVariant const * other
void assign(BaseRecord const &other)
Copy all field values from other to this, requiring that they have equal schemas. ...