LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
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: