LSSTApplications  19.0.0-11-g2ce9f25+4,20.0.0+1,20.0.0+10,20.0.0+11,20.0.0+13,20.0.0+2,20.0.0+3,20.0.0+4,20.0.0+6,20.0.0-1-g10df615+10,20.0.0-1-g253301a+5,20.0.0-1-g596936a+11,20.0.0-1-g8a53f90+1,20.0.0-1-gc96f8cb+12,20.0.0-1-gd1c87d7+1,20.0.0-17-g41c5faf,20.0.0-2-g04cfba9+4,20.0.0-2-gd11eeda,20.0.0-2-gec03fae+3,20.0.0-3-g082faa5+1,20.0.0-3-gbdbfa727+3,20.0.0-3-gc53c7b6,20.0.0-4-gde602ef96+4,20.0.0-4-ge48a6ca+6,20.0.0-4-ge987224+1,20.0.0-8-g7eef53f7+7,20.0.0-9-g8e1b333,w.2020.28
LSSTDataManagementBasePackage
Public Member Functions | Friends | List of all members
lsst::afw::table::SubSchema Class Referencefinal

A proxy type for name lookups in a Schema. More...

#include <Schema.h>

Public Member Functions

std::string join (std::string const &a, std::string const &b) const
 Join strings using the field delimiter appropriate for this Schema. More...
 
std::string join (std::string const &a, std::string const &b, std::string const &c) const
 
std::string join (std::string const &a, std::string const &b, std::string const &c, std::string const &d) const
 
template<typename T >
SchemaItem< T > find (std::string const &name) const
 Find a nested SchemaItem by name. More...
 
template<typename F >
void findAndApply (std::string const &name, F &&func) const
 Find a nested SchemaItem by name and run a functor on it. More...
 
template<typename F >
void apply (F &&func) const
 Run functor on the SchemaItem represented by this SubSchema. More...
 
SubSchema operator[] (std::string const &name) const
 Return a nested proxy. More...
 
std::string const & getPrefix () const
 Return the prefix that defines this SubSchema relative to its parent Schema. More...
 
std::set< std::stringgetNames (bool topOnly=false) const
 Return a set of nested names that start with the SubSchema's prefix. More...
 
template<typename T >
 operator Key< T > () const
 Implicit conversion to the appropriate Key type. More...
 
template<typename T >
 operator Field< T > () const
 Implicit conversion to the appropriate Key type. More...
 

Friends

class Schema
 

Detailed Description

A proxy type for name lookups in a Schema.

Elements of schema names are assumed to be separated by underscores ("a_b_c"); an incomplete lookup is one that does not resolve to a field. Not that even complete lookups can have nested names; a Point field, for instance, has "x" and "y" nested names.

This proxy object is implicitly convertible to both the appropriate Key type and the appropriate Field type, if the name is a complete one, and supports additional find() operations for nested names.

SubSchema is implemented as a proxy that essentially calls Schema::find after concatenating strings. It does not provide any performance advantage over using Schema::find directly. It is also lazy, so looking up a name prefix that does not exist within the schema is not considered an error until the proxy is used.

Some examples:

Schema schema(false);
Key<int> a_i = schema.addField<int>("a_i", "integer field");
Key< Point<double> > a_p = schema.addField< Point<double> >("a_p", "point field");

assert(schema["a_i"] == a_i);
SubSchema a = schema["a"];
assert(a["i"] == a_i);
Field<int> f_a_i = schema["a_i"];
assert(f_a_i.getDoc() == "integer field");
assert(schema["a_i"] == "a_i");
assert(schema.find("a_p_x") == a_p.getX());

Definition at line 357 of file Schema.h.

Member Function Documentation

◆ apply()

template<typename F >
void lsst::afw::table::SubSchema::apply ( F &&  func) const
inline

Run functor on the SchemaItem represented by this SubSchema.

The given functor must have an overloaded function call operator that accepts any SchemaItem type (the same as a functor provided to apply or Schema::forEach).

Exceptions
Throwspex::exceptions::NotFoundError if the SubSchemas prefix does not correspond to the full name of a regular field (not a named subfield).

Definition at line 402 of file Schema.h.

402  {
403  _impl->findAndApply(_aliases->apply(_name), std::forward<F>(func));
404  }

◆ find()

template<typename T >
SchemaItem< T > lsst::afw::table::SubSchema::find ( std::string const &  name) const

Find a nested SchemaItem by name.

Definition at line 773 of file Schema.cc.

773  {
774  return _impl->find<T>(_aliases->apply(join(_name, name)));
775 }

◆ findAndApply()

template<typename F >
void lsst::afw::table::SubSchema::findAndApply ( std::string const &  name,
F &&  func 
) const
inline

Find a nested SchemaItem by name and run a functor on it.

Names corresponding to named subfields are not accepted. The given functor must have an overloaded function call operator that accepts any SchemaItem type (the same as a functor provided to apply or Schema::forEach).

Definition at line 386 of file Schema.h.

386  {
387  _impl->findAndApply(_aliases->apply(join(_name, name)), std::forward<F>(func));
388  }

◆ getNames()

std::set< std::string > lsst::afw::table::SubSchema::getNames ( bool  topOnly = false) const

Return a set of nested names that start with the SubSchema's prefix.

Returns an instance of Python's builtin set in Python.

See also
Schema::getNames

Definition at line 781 of file Schema.cc.

781 { return _impl->getNames(topOnly, _name); }

◆ getPrefix()

std::string const& lsst::afw::table::SubSchema::getPrefix ( ) const
inline

Return the prefix that defines this SubSchema relative to its parent Schema.

Definition at line 410 of file Schema.h.

410 { return _name; }

◆ join() [1/3]

std::string lsst::afw::table::SubSchema::join ( std::string const &  a,
std::string const &  b 
) const

Join strings using the field delimiter appropriate for this Schema.

Definition at line 764 of file Schema.cc.

764  {
765  // delegate to utility funcs at top of this file
766  return afw::table::join(a, b, getDelimiter());
767 }

◆ join() [2/3]

std::string lsst::afw::table::SubSchema::join ( std::string const &  a,
std::string const &  b,
std::string const &  c 
) const
inline

Definition at line 364 of file Schema.h.

364  {
365  return join(join(a, b), c);
366  }

◆ join() [3/3]

std::string lsst::afw::table::SubSchema::join ( std::string const &  a,
std::string const &  b,
std::string const &  c,
std::string const &  d 
) const
inline

Definition at line 367 of file Schema.h.

368  {
369  return join(join(a, b), join(c, d));
370  }

◆ operator Field< T >()

template<typename T >
lsst::afw::table::SubSchema::operator Field< T > ( ) const
inline

Implicit conversion to the appropriate Key type.

Implicit conversion operators that are invoked via assignment cannot be translated to Python. Instead, the Python wrappers provide an equivalent asField() method.

Definition at line 440 of file Schema.h.

440  {
441  return _impl->find<T>(_aliases->apply(_name)).field;
442  }

◆ operator Key< T >()

template<typename T >
lsst::afw::table::SubSchema::operator Key< T > ( ) const
inline

Implicit conversion to the appropriate Key type.

Implicit conversion operators that are invoked via assignment cannot be translated to Python. Instead, the Python wrappers provide an equivalent asKey() method.

Definition at line 428 of file Schema.h.

428  {
429  return _impl->find<T>(_aliases->apply(_name)).key;
430  }

◆ operator[]()

SubSchema lsst::afw::table::SubSchema::operator[] ( std::string const &  name) const

Return a nested proxy.

Definition at line 777 of file Schema.cc.

777  {
778  return SubSchema(_impl, _aliases, join(_name, name));
779 }

Friends And Related Function Documentation

◆ Schema

friend class Schema
friend

Definition at line 445 of file Schema.h.


The documentation for this class was generated from the following files:
lsst::afw::table::SubSchema::join
std::string join(std::string const &a, std::string const &b) const
Join strings using the field delimiter appropriate for this Schema.
Definition: Schema.cc:764
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
field
table::Key< int > field
Definition: ApCorrMap.cc:77
name
std::string name
Definition: Schema.cc:194
b
table::Key< int > b
Definition: TransmissionCurve.cc:467
a
table::Key< int > a
Definition: TransmissionCurve.cc:466
key
Key< U > key
Definition: Schema.cc:281