LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
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 
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
ItemVariant const * other
Definition: Schema.cc:56
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
Schema minimal
T begin(T... args)
A class used as a handle to a particular field in a table.
Definition: Key.h:53
Defines the fields and offsets for a table.
Definition: Schema.h:50
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
void forEach(F &&func) const
Apply a functor to each SchemaItem in the Schema.
Definition: Schema.h:212
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
Schema const getOutputSchema() const
Return the output schema (copy-on-write).
Definition: SchemaMapper.h:27
SchemaMapper()
Construct an empty mapper; useless unless you assign a fully-constructed one to it.
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
SchemaMapper & operator=(SchemaMapper const &other)
Assignment (copy-on-write).
Schema & editOutputSchema()
Return a reference to the output schema that allows it to be modified in place.
Definition: SchemaMapper.h:30
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.
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.
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.
void forEach(F &&func) const
Call the given functor for each key pair in the mapper.
Definition: SchemaMapper.h:149
Schema const getInputSchema() const
Return the input schema (copy-on-write).
Definition: SchemaMapper.h:24
void addMappingsWhere(Predicate predicate, bool doReplace=true)
Add mappings for all fields that match criteria defined by a predicate.
Definition: SchemaMapper.h:238
T end(T... args)
T for_each(T... args)
class[[deprecated("Removed with no replacement (but see lsst::afw::image::TransmissionCurve). Will be " "removed after v22.")]] FilterProperty final
Describe the properties of a Filter (e.g.
Definition: Filter.h:53
A base class for image defects.
A description of a field in a table.
Definition: Field.h:24
A simple pair-like struct for mapping a Field (name and description) with a Key (used for actual data...
Definition: SchemaImpl.h:25
A functor-wrapper used in the implementation of SchemaMapper::forEach.