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;