LSSTApplications  19.0.0-10-g920eed2,19.0.0-11-g48a0200+2,19.0.0-18-gfc4e62b+13,19.0.0-2-g3b2f90d+2,19.0.0-2-gd671419+5,19.0.0-20-g5a5a17ab+11,19.0.0-21-g2644856+13,19.0.0-23-g84eeccb+1,19.0.0-24-g878c510+1,19.0.0-25-g6c8df7140,19.0.0-25-gb330496+1,19.0.0-3-g2b32d65+5,19.0.0-3-g8227491+12,19.0.0-3-g9c54d0d+12,19.0.0-3-gca68e65+8,19.0.0-3-gcfc5f51+5,19.0.0-3-ge110943+11,19.0.0-3-ge74d124,19.0.0-3-gfe04aa6+13,19.0.0-30-g9c3fd16+1,19.0.0-4-g06f5963+5,19.0.0-4-g3d16501+13,19.0.0-4-g4a9c019+5,19.0.0-4-g5a8b323,19.0.0-4-g66397f0+1,19.0.0-4-g8278b9b+1,19.0.0-4-g8557e14,19.0.0-4-g8964aba+13,19.0.0-4-ge404a01+12,19.0.0-5-g40f3a5a,19.0.0-5-g4db63b3,19.0.0-5-gfb03ce7+13,19.0.0-6-gbaebbfb+12,19.0.0-61-gec4c6e08+1,19.0.0-7-g039c0b5+11,19.0.0-7-gbea9075+4,19.0.0-7-gc567de5+13,19.0.0-71-g41c0270,19.0.0-9-g2f02add+1,19.0.0-9-g463f923+12,w.2020.22
LSSTDataManagementBasePackage
SchemaMapper.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #ifndef AFW_TABLE_SchemaMapper_h_INCLUDED
3 #define AFW_TABLE_SchemaMapper_h_INCLUDED
4 
5 #include <memory>
6 
8 
9 namespace lsst {
10 namespace afw {
11 namespace table {
12 
13 class BaseRecord;
14 
21 class SchemaMapper final {
22 public:
24  Schema const getInputSchema() const { return _impl->_input; }
25 
27  Schema const getOutputSchema() const { return _impl->_output; }
28 
30  Schema& editOutputSchema() { return _impl->_output; }
31 
33  template <typename T>
34  Key<T> addOutputField(Field<T> const& newField, bool doReplace = false) {
35  return _impl->_output.addField(newField, doReplace);
36  }
37 
48  template <typename T>
49  Key<T> addMapping(Key<T> const& inputKey, bool doReplace = false);
50 
61  template <typename T>
62  Key<T> addMapping(Key<T> const& inputKey, Field<T> const& outputField, bool doReplace = false);
63 
74  template <typename T>
75  Key<T> addMapping(Key<T> const& inputKey, std::string const& outputName, bool doReplace = true);
76 
82  template <typename T>
83  Key<T> addMapping(Key<T> const& inputKey, char const* outputName, bool doReplace = true) = delete;
84 
97  template <typename Predicate>
98  void addMappingsWhere(Predicate predicate, bool doReplace = true);
99 
110  void addMinimalSchema(Schema const& minimal, bool doMap = true);
111 
122  static SchemaMapper removeMinimalSchema(Schema const& input, Schema const& minimal);
123 
125  void invert();
126 
128  template <typename T>
129  bool isMapped(Key<T> const& inputKey) const;
130 
132  template <typename T>
133  Key<T> getMapping(Key<T> const& inputKey) const;
134 
148  template <typename F>
149  void forEach(F&& func) const {
150  Impl::VisitorWrapper<F> visitor(std::forward<F>(func));
151  std::for_each(_impl->_map.begin(), _impl->_map.end(), visitor);
152  }
153 
155  explicit SchemaMapper();
156 
172  explicit SchemaMapper(Schema const& input, Schema const& output);
173 
191  explicit SchemaMapper(Schema const& input, bool shareAliasMap = false);
192 
196 
200 
202 
213  std::vector<Schema> const& inputs,
215 
216 private:
217  template <typename Predicate>
218  struct AddMappingsWhere {
219  template <typename T>
220  void operator()(SchemaItem<T> const& item) const {
221  if (predicate(item)) mapper->addMapping(item.key, doReplace);
222  }
223 
224  AddMappingsWhere(SchemaMapper* mapper_, Predicate predicate_, bool doReplace_)
225  : mapper(mapper_), predicate(predicate_), doReplace(doReplace_) {}
226 
228  Predicate predicate;
229  bool doReplace;
230  };
231 
232  typedef detail::SchemaMapperImpl Impl;
233 
234  std::unique_ptr<Impl> _impl;
235 };
236 
237 template <typename Predicate>
238 void SchemaMapper::addMappingsWhere(Predicate predicate, bool doReplace) {
239  _impl->_input.forEach(AddMappingsWhere<Predicate>(this, predicate, doReplace));
240 }
241 } // namespace table
242 } // namespace afw
243 } // namespace lsst
244 
245 #endif // !AFW_TABLE_SchemaMapper_h_INCLUDED
lsst::afw::table::SchemaMapper::addMappingsWhere
void addMappingsWhere(Predicate predicate, bool doReplace=true)
Add mappings for all fields that match criteria defined by a predicate.
Definition: SchemaMapper.h:238
std::for_each
T for_each(T... args)
lsst::afw::table::SchemaMapper::addOutputField
Key< T > addOutputField(Field< T > const &newField, bool doReplace=false)
Add a new field to the output Schema that is not connected to the input Schema.
Definition: SchemaMapper.h:34
std::string
STL class.
lsst::afw::table::Schema::addField
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
Definition: Schema.cc:668
lsst::afw::table::SchemaMapper::isMapped
bool isMapped(Key< T > const &inputKey) const
Return true if the given input Key is mapped to an output Key.
Definition: SchemaMapper.cc:208
lsst::afw::table::SchemaMapper::invert
void invert()
Swap the input and output schemas in-place.
Definition: SchemaMapper.cc:202
lsst::afw::table::SchemaItem::key
Key< T > key
Definition: SchemaImpl.h:26
std::vector
STL class.
lsst::afw::table::SchemaMapper::forEach
void forEach(F &&func) const
Call the given functor for each key pair in the mapper.
Definition: SchemaMapper.h:149
lsst::afw::table::SchemaMapper::getInputSchema
Schema const getInputSchema() const
Return the input schema (copy-on-write).
Definition: SchemaMapper.h:24
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::table::Schema
Defines the fields and offsets for a table.
Definition: Schema.h:50
lsst::afw::table::SchemaMapper::editOutputSchema
Schema & editOutputSchema()
Return a reference to the output schema that allows it to be modified in place.
Definition: SchemaMapper.h:30
lsst::afw::table::Schema::forEach
void forEach(F &&func) const
Apply a functor to each SchemaItem in the Schema.
Definition: Schema.h:212
minimal
Schema minimal
Definition: SchemaMapper.cc:107
lsst::afw::table::SchemaMapper::getMapping
Key< T > getMapping(Key< T > const &inputKey) const
Return the output Key corresponding to the given input Key, or raise NotFoundError.
Definition: SchemaMapper.cc:213
lsst::afw::table::SchemaMapper::~SchemaMapper
~SchemaMapper()
lsst::afw::table::detail::SchemaMapperImpl::VisitorWrapper
A functor-wrapper used in the implementation of SchemaMapper::forEach.
Definition: SchemaMapperImpl.h:54
lsst::afw::table::SchemaMapper::operator=
SchemaMapper & operator=(SchemaMapper const &other)
Assignment (copy-on-write).
Definition: SchemaMapper.cc:126
lsst::afw::table::SchemaMapper::addMapping
Key< T > addMapping(Key< T > const &inputKey, char const *outputName, bool doReplace=true)=delete
This deliberately deleted overload ensures we don't accidentally cast string literals to bool.
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::afw::table::SchemaMapper
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
lsst::afw::table::SchemaItem
A simple pair-like struct for mapping a Field (name and description) with a Key (used for actual data...
Definition: SchemaImpl.h:25
SchemaMapperImpl.h
lsst::afw::table::SchemaMapper::SchemaMapper
SchemaMapper()
Construct an empty mapper; useless unless you assign a fully-constructed one to it.
Definition: SchemaMapper.cc:112
lsst::afw::table::Key
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::afw::table::SchemaMapper::addMapping
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.
Definition: SchemaMapper.cc:137
lsst::afw::table::SchemaMapper::removeMinimalSchema
static SchemaMapper removeMinimalSchema(Schema const &input, Schema const &minimal)
Create a mapper by removing fields from the front of a schema.
Definition: SchemaMapper.cc:195
lsst::afw::table::SchemaMapper::join
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.
Definition: SchemaMapper.cc:222
lsst::afw::table::Field
A description of a field in a table.
Definition: Field.h:24
std::vector::begin
T begin(T... args)
lsst::afw::table::SchemaMapper::getOutputSchema
Schema const getOutputSchema() const
Return the output schema (copy-on-write).
Definition: SchemaMapper.h:27
lsst::afw::table::SchemaMapper::addMinimalSchema
void addMinimalSchema(Schema const &minimal, bool doMap=true)
Add the given minimal schema to the output schema.
Definition: SchemaMapper.cc:186
mapper
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
std::vector::end
T end(T... args)
std::unique_ptr< Impl >