Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
BlockName Class Reference

Block identifier with alias support. More...

#include <BlockName.h>

Public Member Functions

 BlockName ()=default
 Default constructor.
 
 BlockName (const std::string &name)
 Constructs a BlockName from a single std::string.
 
 BlockName (const char *name)
 Constructs a BlockName from a C-style string.
 
 BlockName (std::initializer_list< std::string > names)
 Constructs a BlockName from an initializer list of aliases.
 
 BlockName (const std::unordered_set< std::string > &names)
 Constructs a BlockName from an existing set of aliases.
 
std::unordered_set< std::string > get_alias () const
 Returns the set of aliases associated with this block.
 
const std::string & canonical () const
 
 operator std::string () const
 Implicit conversion to std::string.
 
bool hasAlias (const std::string &alias) const
 Checks whether a given alias is registered for this block.
 
std::string to_string () const
 Returns a string representation of the block name.
 
bool operator== (const BlockName &other) const
 Equality comparison between two BlockName objects.
 
bool operator!= (const BlockName &other) const
 Inequality comparison between two BlockName objects.
 
bool operator== (const std::string &name) const
 Comparison between a BlockName and a std::string.
 
bool operator== (const char *name) const
 Comparison between a BlockName and a C-style string.
 
bool operator!= (const std::string &name) const
 Inequality comparison between a BlockName and a std::string.
 
BlockNameaddAlias (const std::string &alias)
 Adds a new alias to this block.
 
BlockNameaddAliases (const std::unordered_set< std::string > &as)
 
void to_upper ()
 Converts all aliases to upper-case in-place.
 
bool operator< (const BlockName &other) const
 Strict ordering operator for BlockName.
 

Friends

BlockName operator+ (const std::string &lhs, const BlockName &rhs)
 Concatenation operator between a prefix string and a BlockName.
 
std::ostream & operator<< (std::ostream &os, const BlockName &block)
 Stream output operator for BlockName.
 

Detailed Description

Block identifier with alias support.

A BlockName internally stores a set of strings, each string being an alias that can refer to the same physical block. This is useful when supporting multiple conventions or legacy naming schemes (e.g. "SMINPUTS" vs "SMINPUT" or different capitalization).

Key design points:

  • The internal representation is an unordered_set of strings.
  • Two BlockName instances are considered equal if they share at least one alias (see operator==(const BlockName&)).
  • Implicit conversion to std::string returns an arbitrary alias (the first in the internal set) and issues a warning if more than one alias is present.
  • The to_upper() method can be used to normalize all aliases to upper case, which is often convenient for SLHA/LHA parsing.

Definition at line 59 of file BlockName.h.

Constructor & Destructor Documentation

◆ BlockName() [1/5]

BlockName::BlockName ( )
default

Default constructor.

Creates an empty BlockName without any aliases.

◆ BlockName() [2/5]

BlockName::BlockName ( const std::string &  name)

Constructs a BlockName from a single std::string.

The provided string is inserted as the only alias of the block.

Parameters
nameInitial block name / alias.

Definition at line 3 of file BlockName.cpp.

◆ BlockName() [3/5]

BlockName::BlockName ( const char *  name)

Constructs a BlockName from a C-style string.

The provided C-string is converted to std::string and stored as the only alias of the block.

Parameters
nameInitial block name / alias (C-string).

Definition at line 7 of file BlockName.cpp.

◆ BlockName() [4/5]

BlockName::BlockName ( std::initializer_list< std::string >  names)

Constructs a BlockName from an initializer list of aliases.

All strings in names are inserted into the internal alias set.

Example:

BlockName b{"SMINPUTS", "sminputs"};
Block identifier with alias support.
Definition BlockName.h:59
Parameters
namesList of aliases to associate with the block.

Definition at line 11 of file BlockName.cpp.

◆ BlockName() [5/5]

BlockName::BlockName ( const std::unordered_set< std::string > &  names)

Constructs a BlockName from an existing set of aliases.

The provided set is copied into the internal representation.

Parameters
namesSet of aliases for the block.

Definition at line 15 of file BlockName.cpp.

Member Function Documentation

◆ addAlias()

BlockName & BlockName::addAlias ( const std::string &  alias)

Adds a new alias to this block.

Inserts alias into the internal alias set. If the alias already exists, the set is unchanged.

Parameters
aliasNew alias to add.
Returns
Reference to the current BlockName (for chaining).

Definition at line 68 of file BlockName.cpp.

◆ addAliases()

BlockName & BlockName::addAliases ( const std::unordered_set< std::string > &  as)

◆ canonical()

const std::string & BlockName::canonical ( ) const

Return the stable primary alias used for serialization.

Definition at line 26 of file BlockName.cpp.

◆ get_alias()

std::unordered_set< std::string > BlockName::get_alias ( ) const

Returns the set of aliases associated with this block.

The returned set is a copy; modifications to it do not affect the original BlockName instance.

Returns
A copy of the internal alias set.

Definition at line 22 of file BlockName.cpp.

◆ hasAlias()

bool BlockName::hasAlias ( const std::string &  alias) const

Checks whether a given alias is registered for this block.

Parameters
aliasAlias to look for.
Returns
true if alias is in the internal alias set, false otherwise.

Definition at line 37 of file BlockName.cpp.

◆ operator std::string()

BlockName::operator std::string ( ) const

Implicit conversion to std::string.

If the block has exactly one alias, that alias is returned. If multiple aliases are present, a warning is emitted via LOG_WARN and one arbitrary alias (the first element of the internal set) is returned, thus potentially discarding information.

Returns
One alias representing this block (or an empty string if no aliases are stored).

Definition at line 33 of file BlockName.cpp.

◆ operator!=() [1/2]

bool BlockName::operator!= ( const BlockName other) const

Inequality comparison between two BlockName objects.

Parameters
otherBlockName to compare with.
Returns
true if the blocks do not share any common alias.

Definition at line 52 of file BlockName.cpp.

◆ operator!=() [2/2]

bool BlockName::operator!= ( const std::string &  name) const

Inequality comparison between a BlockName and a std::string.

Parameters
nameAlias to check.
Returns
true if name is not a known alias of this block.

Definition at line 64 of file BlockName.cpp.

◆ operator<()

bool BlockName::operator< ( const BlockName other) const

Strict ordering operator for BlockName.

The ordering is defined by:

  • first constructing two std::set<std::string> from the alias sets of *this and other, and
  • then performing the standard lexicographic comparison between those ordered sets.

This makes BlockName usable as a key in ordered containers such as std::map or std::set.

Parameters
otherBlockName to compare with.
Returns
true if the sorted alias set of *this is lexicographically smaller than that of other.

Definition at line 103 of file BlockName.cpp.

◆ operator==() [1/3]

bool BlockName::operator== ( const BlockName other) const

Equality comparison between two BlockName objects.

Two BlockName objects are considered equal if they share at least one common alias. In particular, this means that:

  • equality is not simply based on the exact same alias set,
  • blocks with disjoint alias sets are considered different.
Parameters
otherBlockName to compare with.
Returns
true if there exists at least one alias common to both blocks.

Definition at line 45 of file BlockName.cpp.

◆ operator==() [2/3]

bool BlockName::operator== ( const char *  name) const

Comparison between a BlockName and a C-style string.

Equivalent to comparing with a std::string constructed from name.

Parameters
nameAlias to check (C-string).
Returns
true if name is a known alias, false otherwise.

Definition at line 60 of file BlockName.cpp.

◆ operator==() [3/3]

bool BlockName::operator== ( const std::string &  name) const

Comparison between a BlockName and a std::string.

Returns true if name is one of the aliases of this block.

Parameters
nameAlias to check.
Returns
true if name is a known alias, false otherwise.

Definition at line 56 of file BlockName.cpp.

◆ to_string()

std::string BlockName::to_string ( ) const

Returns a string representation of the block name.

Equivalent to the implicit conversion operator to std::string. Mainly provided for explicit, non-implicit usage.

Returns
One alias representing this block, or an empty string if none.

Definition at line 41 of file BlockName.cpp.

◆ to_upper()

void BlockName::to_upper ( )

Converts all aliases to upper-case in-place.

For each stored alias, all characters are transformed using std::toupper. The resulting set of upper-case aliases replaces the original one.

This is often used to enforce the conventional SLHA behavior that block names are case-insensitive but typically stored in upper case.

Definition at line 92 of file BlockName.cpp.

Friends And Related Symbol Documentation

◆ operator+

BlockName operator+ ( const std::string &  lhs,
const BlockName rhs 
)
friend

Concatenation operator between a prefix string and a BlockName.

Creates a new BlockName whose aliases are obtained by prefixing each alias of rhs with lhs.

Example:

BlockName b{"MASS","mass"};
BlockName c = "BLOCK_" + b; // aliases: {"BLOCK_MASS", "BLOCK_mass"}
Parameters
lhsPrefix string.
rhsBlockName whose aliases will be prefixed.
Returns
A new BlockName with concatenated aliases.

Definition at line 74 of file BlockName.cpp.

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const BlockName block 
)
friend

Stream output operator for BlockName.

All aliases are written to the stream, separated by '/'. The order is determined by the iteration order of the internal unordered_set and is therefore not guaranteed to be stable.

Example output: "SMINPUTS/sminputs".

Parameters
osOutput stream.
blockBlockName to print.
Returns
Reference to the output stream.

Definition at line 82 of file BlockName.cpp.


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