1#include "boost/preprocessor/seq/for_each.hpp"
2#include "boost/preprocessor/tuple/to_seq.hpp"
16 std::visit([](
auto & pair) {
std::swap(pair.first, pair.second); }, v);
23struct KeyPairCompareEqual {
26 return std::visit([
this](
auto const & pair) ->
bool {
return this->_target == pair.first; }, v);
29 explicit KeyPairCompareEqual(Key<T>
const &
target) : _target(
target) {}
32 Key<T>
const &_target;
37struct MapMinimalSchema {
39 void operator()(SchemaItem<U>
const &item)
const {
43 SchemaItem<U> inputItem =
_mapper->getInputSchema().find(item.key);
44 outputKey =
_mapper->addMapping(item.key);
45 }
catch (pex::exceptions::NotFoundError &) {
46 outputKey =
_mapper->addOutputField(item.field);
49 outputKey =
_mapper->addOutputField(item.field);
51 assert(outputKey == item.key);
54 explicit MapMinimalSchema(SchemaMapper *
mapper,
bool doMap) :
_mapper(
mapper), _doMap(doMap) {}
64 void operator()(SchemaItem<T>
const &item)
const {
65 Field<T>
field(prefix + item.field.getName(), item.field.getDoc(), item.field.getUnits(), item.field);
66 mapper->addMapping(item.key, field);
69 explicit AddMapped(SchemaMapper *mapper_) :
mapper(mapper_) {}
78 void operator()(SchemaItem<T>
const &item)
const {
79 Field<T>
field(
prefix + item.field.getName(), item.field.getDoc(), item.field.getUnits(), item.field);
80 mapper->addOutputField(field);
83 explicit AddUnmapped(SchemaMapper *mapper_) :
mapper(mapper_) {}
89struct RemoveMinimalSchema {
91 void operator()(SchemaItem<T>
const &item)
const {
93 mapper->addMapping(item.key);
97 RemoveMinimalSchema(SchemaMapper *mapper_, Schema
const &minimal_) :
mapper(mapper_),
minimal(minimal_) {}
131 typename Impl::KeyPairMap::iterator i =
134 if (i != _impl->_map.
end()) {
147 typename Impl::KeyPairMap::iterator i =
149 if (i != _impl->_map.
end()) {
162 typename Impl::KeyPairMap::iterator i =
164 if (i != _impl->_map.
end()) {
182 "Must add minimal schema to mapper before adding any other fields");
184 MapMinimalSchema
f(
this,
doMap);
196 std::swap(_impl->_input, _impl->_output);
207 typename Impl::KeyPairMap::iterator i =
209 if (i == _impl->_map.
end()) {
212 return std::get<std::pair<Key<T>,
Key<T>>>(*i).second;
221 (boost::format(
"prefix vector size (%d) must be the same as input vector size (%d)") %
247#define INSTANTIATE_LAYOUTMAPPER(r, data, elem) \
248 template Key<elem> SchemaMapper::addOutputField(Field<elem> const &, bool); \
249 template Key<elem> SchemaMapper::addMapping(Key<elem> const &, bool); \
250 template Key<elem> SchemaMapper::addMapping(Key<elem> const &, Field<elem> const &, bool); \
251 template Key<elem> SchemaMapper::addMapping(Key<elem> const &, std::string const &, bool); \
252 template bool SchemaMapper::isMapped(Key<elem> const &) const; \
253 template Key<elem> SchemaMapper::getMapping(Key<elem> const &) const;
Key< Flag > const & target
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
#define INSTANTIATE_LAYOUTMAPPER(r, data, elem)
Tag types used to declare specialized field types.
Defines the fields and offsets for a table.
void forEach(F &func) const
Apply a functor to each SchemaItem in the Schema.
void setAliasMap(std::shared_ptr< AliasMap > aliases)
Set the alias map.
std::shared_ptr< AliasMap > getAliasMap() const
Return the map of aliases.
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
void replaceField(Key< T > const &key, Field< T > const &field)
Replace the Field (name/description) for an existing Key.
SchemaItem< T > find(std::string const &name) const
Find a SchemaItem in the Schema by name.
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).
SchemaMapper()
Construct an empty mapper; useless unless you assign a fully-constructed one to it.
SchemaMapper & operator=(SchemaMapper const &other)
Assignment (copy-on-write).
Key< T > addMapping(Key< T > const &inputKey, bool doReplace=false)
Add a new field to the output Schema that is a copy of a field in the input Schema.
static SchemaMapper removeMinimalSchema(Schema const &input, Schema const &minimal)
Create a mapper by removing fields from the front of a schema.
static std::vector< SchemaMapper > join(std::vector< Schema > const &inputs, std::vector< std::string > const &prefixes=std::vector< std::string >())
Combine a sequence of schemas into one, creating a SchemaMapper for each.
Schema & editOutputSchema()
Return a reference to the output schema that allows it to be modified in place.
Key< T > getMapping(Key< T > const &inputKey) const
Return the output Key corresponding to the given input Key, or raise NotFoundError.
bool isMapped(Key< T > const &inputKey) const
Return true if the given input Key is mapped to an output Key.
void addMinimalSchema(Schema const &minimal, bool doMap=true)
Add the given minimal schema to the output schema.
void invert()
Swap the input and output schemas in-place.
A private implementation class to hide the messy details of SchemaMapper.
decltype(makeKeyPairVariantType(FieldTypes{})) KeyPairVariant
A Variant type that can hold any one of the allowed pairx types.
Reports attempts to exceed implementation-defined length limits for some classes.
Reports errors in the logical structure of the program.
Reports attempts to access elements using an invalid key.
T emplace_back(T... args)
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 AFW_TABLE_FIELD_TYPE_N
#define AFW_TABLE_FIELD_TYPE_TUPLE