Class AliasMap

Class Documentation

class AliasMap

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.

Unnamed Group

bool operator==(AliasMap const &other) const

Equality comparison

bool operator!=(AliasMap const &other) const

Public Types

typedef std::map<std::string, std::string>::const_iterator Iterator

An iterator over alias->target pairs.

Public Functions

AliasMap()
AliasMap(AliasMap const &other)

Deep-copy an AliasMap

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

AliasMap(AliasMap &&other)
AliasMap &operator=(AliasMap const&)
AliasMap &operator=(AliasMap&&)
~AliasMap()
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.

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");

std::string get(std::string const &alias) const

Return the target of the given alias

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

Exceptions
  • pex::exceptions::NotFoundError: if no alias with the given name exists

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.

Return

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

std::size_t hash_value() const

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).