LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
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.
 

Public Member Functions

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

Friends

class Schema
 
class SubSchema
 

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() {}

◆ 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() {}

◆ 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 {
68 std::string result(name);
69 _apply(result);
70 return result;
71}
py::object result
Definition _schema.cc:429

◆ 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 111 of file AliasMap.cc.

111 {
112 return std::includes(begin(), end(), other.begin(), other.end());
113}
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 90 of file AliasMap.cc.

90 {
91 bool result = _internal.erase(alias);
92 auto table = _table.lock();
93 if (table) {
94 table->handleAliasChange(alias);
95 }
96 return result;
97}
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
T find(T... args)

◆ getTable()

std::shared_ptr< BaseTable > lsst::afw::table::AliasMap::getTable ( ) const
inline

Definition at line 121 of file AliasMap.h.

121{ return _table.lock(); }

◆ hash_value()

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

Return a hash of this object.

Definition at line 101 of file AliasMap.cc.

101 {
102 // Warning: this algorithm will be invalid if _internal is replaced by an unsorted map
103 // Completely arbitrary seed
104 std::size_t result = 42;
105 for (const auto& entry : _internal) {
106 result = cpputils::hashCombine(result, entry.first, entry.second);
107 }
108 return result;
109}
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 99 of file AliasMap.cc.

99{ 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 auto table = _table.lock();
85 if (table) {
86 table->handleAliasChange(alias);
87 }
88}
Key< Flag > const & target

◆ setTable()

void lsst::afw::table::AliasMap::setTable ( std::shared_ptr< BaseTable > table)
inline

Definition at line 122 of file AliasMap.h.

122{ _table = table; }

◆ 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 Symbol Documentation

◆ Schema

Definition at line 125 of file AliasMap.h.

◆ SubSchema

Definition at line 126 of file AliasMap.h.


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