EnTT  3.5.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
entt::basic_hashed_string< Char > Class Template Reference

Zero overhead unique identifier. More...

#include <hashed_string.hpp>

Public Types

using value_type = Char
 Character type.
 
using hash_type = id_type
 Unsigned integer type.
 

Public Member Functions

constexpr basic_hashed_string () noexcept
 Constructs an empty hashed string.
 
template<std::size_t N>
constexpr basic_hashed_string (const value_type(&curr)[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 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...
 
constexpr bool operator== (const basic_hashed_string &other) const noexcept
 Compares two hashed strings. More...
 

Static Public Member Functions

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 hash_type value (const_wrapper wrapper) noexcept
 Returns directly the numeric representation of a string. More...
 
static hash_type value (const value_type *str, std::size_t size) noexcept
 Returns directly the numeric representation of a string view. More...
 

Detailed Description

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

Zero overhead unique identifier.

A hashed string is a compile-time tool that allows users to use human-readable identifers 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.

Template Parameters
CharCharacter type.

Definition at line 64 of file hashed_string.hpp.

Constructor & Destructor Documentation

◆ basic_hashed_string() [1/2]

template<typename Char >
template<std::size_t N>
constexpr entt::basic_hashed_string< Char >::basic_hashed_string ( const value_type(&)  curr[N])
inlineconstexprnoexcept

Constructs a hashed string from an array of const characters.

Forcing template resolution avoids implicit conversions. An human-readable identifier can be anything but a plain, old bunch of characters.
Example of use:

basic_hashed_string<char> hs{"my.png"};
Template Parameters
NNumber of characters of the identifier.
Parameters
currHuman-readable identifer.

Definition at line 151 of file hashed_string.hpp.

◆ basic_hashed_string() [2/2]

template<typename Char >
constexpr entt::basic_hashed_string< Char >::basic_hashed_string ( const_wrapper  wrapper)
inlineexplicitconstexprnoexcept

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

Parameters
wrapperHelps achieving the purpose by relying on overloading.

Definition at line 160 of file hashed_string.hpp.

Member Function Documentation

◆ data()

template<typename Char >
constexpr const value_type* entt::basic_hashed_string< Char >::data ( ) const
inlineconstexprnoexcept

Returns the human-readable representation of a hashed string.

Returns
The string used to initialize the instance.

Definition at line 168 of file hashed_string.hpp.

◆ operator const value_type *()

template<typename Char >
constexpr entt::basic_hashed_string< Char >::operator const value_type * ( ) const
inlineconstexprnoexcept

Returns the human-readable representation of a hashed string.

Returns
The string used to initialize the instance.

Definition at line 181 of file hashed_string.hpp.

◆ operator hash_type()

template<typename Char >
constexpr entt::basic_hashed_string< Char >::operator hash_type ( ) const
inlineconstexprnoexcept

Returns the numeric representation of a hashed string.

Returns
The numeric representation of the instance.

Definition at line 187 of file hashed_string.hpp.

◆ operator==()

template<typename Char >
constexpr bool entt::basic_hashed_string< Char >::operator== ( const basic_hashed_string< Char > &  other) const
inlineconstexprnoexcept

Compares two hashed strings.

Parameters
otherHashed string with which to compare.
Returns
True if the two hashed strings are identical, false otherwise.

Definition at line 194 of file hashed_string.hpp.

◆ value() [1/4]

template<typename Char >
constexpr hash_type entt::basic_hashed_string< Char >::value ( ) const
inlineconstexprnoexcept

Returns the numeric representation of a hashed string.

Returns
The numeric representation of the instance.

Definition at line 176 of file hashed_string.hpp.

◆ value() [2/4]

template<typename Char >
static hash_type entt::basic_hashed_string< Char >::value ( const value_type str,
std::size_t  size 
)
inlinestaticnoexcept

Returns directly the numeric representation of a string view.

Parameters
strHuman-readable identifer.
sizeLength of the string to hash.
Returns
The numeric representation of the string.

Definition at line 125 of file hashed_string.hpp.

◆ value() [3/4]

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

Returns directly the numeric representation of a string.

Forcing template resolution avoids implicit conversions. An human-readable identifier can be anything but a plain, old bunch of characters.
Example of use:

const auto value = basic_hashed_string<char>::to_value("my.png");
Template Parameters
NNumber of characters of the identifier.
Parameters
strHuman-readable identifer.
Returns
The numeric representation of the string.

Definition at line 106 of file hashed_string.hpp.

◆ value() [4/4]

template<typename Char >
static hash_type entt::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.

Definition at line 115 of file hashed_string.hpp.


The documentation for this class was generated from the following file:
entt::basic_hashed_string::value
constexpr hash_type value() const noexcept
Returns the numeric representation of a hashed string.
Definition: hashed_string.hpp:176