LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | Friends | List of all members
lsst::afw::table::AliasMap Class Referencefinal

Mapping class that holds aliases for a Schema. More...

#include <AliasMap.h>

Public Types

using Iterator = std::map< std::string, std::string >::const_iterator
 An iterator over alias->target pairs. More...
 

Public Member Functions

 AliasMap ()
 
 AliasMap (AliasMap const &other)
 Deep-copy an AliasMap. More...
 
 AliasMap (AliasMap &&other)
 
AliasMapoperator= (AliasMap const &)=default
 
AliasMapoperator= (AliasMap &&)=default
 
 ~AliasMap ()=default
 
Iterator begin () const
 Return a iterator to the beginning of the map. More...
 
Iterator end () const
 Return a iterator to one past the end of the map. More...
 
std::size_t size () const
 Return the number of aliases. More...
 
bool empty () const
 Return the true if there are no aliases. More...
 
std::string apply (std::string const &name) const
 Apply any aliases that match the given field name and return a de-aliased name. More...
 
std::string get (std::string const &alias) const
 Return the target of the given alias. More...
 
void set (std::string const &alias, std::string const &target)
 Add an alias to the schema or replace an existing one. More...
 
bool erase (std::string const &alias)
 Remove an alias from the schema if it is present. More...
 
bool operator== (AliasMap const &other) const
 Equality comparison. More...
 
bool operator!= (AliasMap const &other) const
 
std::size_t hash_value () const noexcept
 Return a hash of this object. More...
 
bool contains (AliasMap const &other) const
 Return true if all aliases in this are also in other (with the same targets). More...
 

Friends

class Schema
 
class SubSchema
 
class BaseTable
 

Detailed Description

Mapping class that holds aliases for a Schema.

Aliases need not be complete, but they must match to the beginning of a field name to be useful. For example, if "a_b_c" is a true field name, "x_->a_b" is a valid alias that will cause "x_y_c" to map to "a_b_c", but "y_z->b_c" will not cause "a_y_z" to be matched.

Aliases are not checked to see if they match any existing fields, and if an alias has the same name as a field name, it will take precedence and hide the true field.

Unlike the other components of a Schema, aliases can be modified and removed, even after a Table has been constructed from the Schema.

AliasMaps are shared when Schemas are copy-constructed, but can be separated manually by calling Schema::disconnectAliases() or Schema::setAliasMap(). In addition, the AliasMap is deep-copied when used to construct a Table (or Catalog).

In order to allow Tables to react to changes in aliases (which may be used to define cached Keys held by the table, as in SourceTable's "slots" mechanism), an AliasMap that is part of a Schema held by a Table will hold a pointer to that Table, and call BaseTable::handleAliasChanges() when its aliases are set or removed.

Definition at line 36 of file AliasMap.h.

Member Typedef Documentation

◆ Iterator

An iterator over alias->target pairs.

Definition at line 57 of file AliasMap.h.

Constructor & Destructor Documentation

◆ AliasMap() [1/3]

lsst::afw::table::AliasMap::AliasMap ( )
inline

Definition at line 41 of file AliasMap.h.

41 : _internal(), _table(nullptr) {}

◆ AliasMap() [2/3]

lsst::afw::table::AliasMap::AliasMap ( AliasMap const &  other)
inline

Deep-copy an AliasMap.

The new AliasMap will not be linked to any tables, even if other is.

Definition at line 48 of file AliasMap.h.

48 : _internal(other._internal), _table(nullptr) {}

◆ AliasMap() [3/3]

lsst::afw::table::AliasMap::AliasMap ( AliasMap &&  other)
inline

Definition at line 50 of file AliasMap.h.

50 : AliasMap(other) {}

◆ ~AliasMap()

lsst::afw::table::AliasMap::~AliasMap ( )
default

Member Function Documentation

◆ apply()

std::string lsst::afw::table::AliasMap::apply ( std::string const &  name) const

Apply any aliases that match the given field name and return a de-aliased name.

Given a string that starts with any alias in the map, this returns a string with the part of the string that matches the alias replaced by that alias's target. The longest such alias is used.

For example:

m = AliasMap();
m.set("q", "a");
m.set("q1", "b");
assert(m.apply("q3") == "a3");
assert(m.apply("q12") == "b2");

Definition at line 67 of file AliasMap.cc.

67  {
69  _apply(result);
70  return result;
71 }
py::object result
Definition: _schema.cc:429
table::Key< std::string > name
Definition: Amplifier.cc:116

◆ begin()

Iterator lsst::afw::table::AliasMap::begin ( ) const
inline

Return a iterator to the beginning of the map.

Definition at line 60 of file AliasMap.h.

60 { return _internal.begin(); }
T begin(T... args)

◆ contains()

bool lsst::afw::table::AliasMap::contains ( AliasMap const &  other) const

Return true if all aliases in this are also in other (with the same targets).

Definition at line 109 of file AliasMap.cc.

109  {
110  return std::includes(begin(), end(), other.begin(), other.end());
111 }
Iterator begin() const
Return a iterator to the beginning of the map.
Definition: AliasMap.h:60
Iterator end() const
Return a iterator to one past the end of the map.
Definition: AliasMap.h:63
T includes(T... args)

◆ empty()

bool lsst::afw::table::AliasMap::empty ( ) const
inline

Return the true if there are no aliases.

Definition at line 69 of file AliasMap.h.

69 { return _internal.empty(); }
T empty(T... args)

◆ end()

Iterator lsst::afw::table::AliasMap::end ( ) const
inline

Return a iterator to one past the end of the map.

Definition at line 63 of file AliasMap.h.

63 { return _internal.end(); }
T end(T... args)

◆ erase()

bool lsst::afw::table::AliasMap::erase ( std::string const &  alias)

Remove an alias from the schema if it is present.

Returns
True if an alias was erased, and false if no such alias was found.

Definition at line 89 of file AliasMap.cc.

89  {
90  bool result = _internal.erase(alias);
91  if (_table) {
92  _table->handleAliasChange(alias);
93  }
94  return result;
95 }
virtual void handleAliasChange(std::string const &alias)
Definition: BaseTable.h:208
T erase(T... args)

◆ get()

std::string lsst::afw::table::AliasMap::get ( std::string const &  alias) const

Return the target of the given alias.

Unlike apply(), this will not return partial matches.

Exceptions
pex::exceptions::NotFoundErrorif no alias with the given name exists

Definition at line 73 of file AliasMap.cc.

73  {
74  Iterator i = _internal.find(name);
75  if (i == _internal.end()) {
76  throw LSST_EXCEPT(pex::exceptions::NotFoundError,
77  (boost::format("Alias '%s' not found") % name).str());
78  }
79  return i->second;
80 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
std::map< std::string, std::string >::const_iterator Iterator
An iterator over alias->target pairs.
Definition: AliasMap.h:57
T find(T... args)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ hash_value()

std::size_t lsst::afw::table::AliasMap::hash_value ( ) const
noexcept

Return a hash of this object.

Definition at line 99 of file AliasMap.cc.

99  {
100  // Warning: this algorithm will be invalid if _internal is replaced by an unsorted map
101  // Completely arbitrary seed
102  std::size_t result = 42;
103  for (const auto& entry : _internal) {
104  result = utils::hashCombine(result, entry.first, entry.second);
105  }
106  return result;
107 }
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35

◆ operator!=()

bool lsst::afw::table::AliasMap::operator!= ( AliasMap const &  other) const
inline

Definition at line 112 of file AliasMap.h.

112 { return !(other == *this); }

◆ operator=() [1/2]

AliasMap& lsst::afw::table::AliasMap::operator= ( AliasMap &&  )
default

◆ operator=() [2/2]

AliasMap& lsst::afw::table::AliasMap::operator= ( AliasMap const &  )
default

◆ operator==()

bool lsst::afw::table::AliasMap::operator== ( AliasMap const &  other) const

Equality comparison.

Definition at line 97 of file AliasMap.cc.

97 { return _internal == other._internal; }

◆ set()

void lsst::afw::table::AliasMap::set ( std::string const &  alias,
std::string const &  target 
)

Add an alias to the schema or replace an existing one.

Definition at line 82 of file AliasMap.cc.

82  {
83  _internal[alias] = target;
84  if (_table) {
85  _table->handleAliasChange(alias);
86  }
87 }
Key< Flag > const & target

◆ size()

std::size_t lsst::afw::table::AliasMap::size ( ) const
inline

Return the number of aliases.

Definition at line 66 of file AliasMap.h.

66 { return _internal.size(); }
T size(T... args)

Friends And Related Function Documentation

◆ BaseTable

friend class BaseTable
friend

Definition at line 124 of file AliasMap.h.

◆ Schema

friend class Schema
friend

Definition at line 122 of file AliasMap.h.

◆ SubSchema

friend class SubSchema
friend

Definition at line 123 of file AliasMap.h.


The documentation for this class was generated from the following files: