fsm
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
escad::basic_hashed_string< Char > Class Template Reference

Zero overhead unique identifier. More...

#include <hashed_string.h>

Inheritance diagram for escad::basic_hashed_string< Char >:
Inheritance graph
[legend]
Collaboration diagram for escad::basic_hashed_string< Char >:
Collaboration graph
[legend]

Public Types

using value_type = typename base_type::value_type
 Character type.
 
using size_type = typename base_type::size_type
 Unsigned integer type.
 
using hash_type = typename base_type::hash_type
 Unsigned integer type.
 

Public Member Functions

constexpr basic_hashed_string () noexcept
 Constructs an empty hashed string.
 
constexpr basic_hashed_string (const value_type *str, const size_type len) noexcept
 Constructs a hashed string from a string view. More...
 
template<std::size_t N>
constexpr basic_hashed_string (const value_type(&str)[N]) noexcept
 Constructs a hashed string from an array of const characters. More...
 
constexpr basic_hashed_string (const_wrapper wrapper) noexcept
 Explicit constructor on purpose to avoid constructing a hashed string directly from a const value_type *. More...
 
constexpr size_type size () const noexcept
 Returns the size a hashed string. More...
 
constexpr const value_typedata () const noexcept
 Returns the human-readable representation of a hashed string. More...
 
constexpr hash_type value () const noexcept
 Returns the numeric representation of a hashed string. More...
 
constexpr operator const value_type * () const noexcept
 Returns the human-readable representation of a hashed string. More...
 
constexpr operator hash_type () const noexcept
 Returns the numeric representation of a hashed string. More...
 

Static Public Member Functions

static constexpr hash_type value (const value_type *str, const size_type len) noexcept
 Returns directly the numeric representation of a string view. More...
 
template<std::size_t N>
static constexpr hash_type value (const value_type(&str)[N]) noexcept
 Returns directly the numeric representation of a string. More...
 
static constexpr hash_type value (const_wrapper wrapper) noexcept
 Returns directly the numeric representation of a string. More...
 

Detailed Description

template<typename Char>
class escad::basic_hashed_string< Char >

Zero overhead unique identifier.

A hashed string is a compile-time tool that allows users to use human-readable identifiers in the codebase while using their numeric counterparts at runtime.
Because of that, a hashed string can also be used in constant expressions if required.

Warning
This class doesn't take ownership of user-supplied strings nor does it make a copy of them.
Template Parameters
CharCharacter type.

Constructor & Destructor Documentation

◆ basic_hashed_string() [1/3]

template<typename Char >
constexpr escad::basic_hashed_string< Char >::basic_hashed_string ( const value_type str,
const size_type  len 
)
inlinenoexcept

Constructs a hashed string from a string view.

Parameters
strHuman-readable identifier.
lenLength of the string to hash.

◆ basic_hashed_string() [2/3]

template<typename Char >
template<std::size_t N>
constexpr escad::basic_hashed_string< Char >::basic_hashed_string ( const value_type(&)  str[N])
inlinenoexcept

Constructs a hashed string from an array of const characters.

Template Parameters
NNumber of characters of the identifier.
Parameters
strHuman-readable identifier.

◆ basic_hashed_string() [3/3]

template<typename Char >
constexpr escad::basic_hashed_string< Char >::basic_hashed_string ( const_wrapper  wrapper)
inlineexplicitnoexcept

Explicit constructor on purpose to avoid constructing a hashed string directly from a const value_type *.

Warning
The lifetime of the string is not extended nor is it copied.
Parameters
wrapperHelps achieving the purpose by relying on overloading.

Member Function Documentation

◆ data()

template<typename Char >
constexpr const value_type* escad::basic_hashed_string< Char >::data ( ) const
inlinenoexcept

Returns the human-readable representation of a hashed string.

Returns
The string used to initialize the hashed string.

◆ operator const value_type *()

template<typename Char >
constexpr escad::basic_hashed_string< Char >::operator const value_type * ( ) const
inlinenoexcept

Returns the human-readable representation of a hashed string.

Returns
The string used to initialize the hashed string.

◆ operator hash_type()

template<typename Char >
constexpr escad::basic_hashed_string< Char >::operator hash_type ( ) const
inlinenoexcept

Returns the numeric representation of a hashed string.

Returns
The numeric representation of the hashed string.

◆ size()

template<typename Char >
constexpr size_type escad::basic_hashed_string< Char >::size ( ) const
inlinenoexcept

Returns the size a hashed string.

Returns
The size of the hashed string.

◆ value() [1/4]

template<typename Char >
static constexpr hash_type escad::basic_hashed_string< Char >::value ( const value_type str,
const size_type  len 
)
inlinestaticnoexcept

Returns directly the numeric representation of a string view.

Parameters
strHuman-readable identifier.
lenLength of the string to hash.
Returns
The numeric representation of the string.

◆ value() [2/4]

template<typename Char >
template<std::size_t N>
static constexpr hash_type escad::basic_hashed_string< Char >::value ( const value_type(&)  str[N])
inlinestaticnoexcept

Returns directly the numeric representation of a string.

Template Parameters
NNumber of characters of the identifier.
Parameters
strHuman-readable identifier.
Returns
The numeric representation of the string.

◆ value() [3/4]

template<typename Char >
static constexpr hash_type escad::basic_hashed_string< Char >::value ( const_wrapper  wrapper)
inlinestaticnoexcept

Returns directly the numeric representation of a string.

Parameters
wrapperHelps achieving the purpose by relying on overloading.
Returns
The numeric representation of the string.

◆ value() [4/4]

template<typename Char >
constexpr hash_type escad::basic_hashed_string< Char >::value ( ) const
inlinenoexcept

Returns the numeric representation of a hashed string.

Returns
The numeric representation of the hashed string.

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