Skip to content

Engine → Core → string_id.h

string_id

Syntax

class CONJURE_API string_id

Constructors

AccessSignatureDescription
publicconstexpr string_id() noexcept = default;The null id: hash 0, no name.
publicconstexpr explicit string_id( std::string_view name);Hashes name. When constant-evaluated (constexpr variables, static or namespace- scope ids with a literal name) the id is only hashed; otherwise the name is also interned so view()/c_str() can resolve it later. See the header comment for the exact rules; use intern() where interning must be guaranteed.

Variables

AccessNameTypeDefaultDescription
privatemHashu640

Functions

Public

c_str

[[nodiscard]] const char *c_str() const noexcept;

The interned name as a null-terminated string, or "" when unknown.

from_hash

[[nodiscard]] static constexpr string_id from_hash(
    u64 hash) noexcept;

Wraps an already computed hash (deserialisation, C# interop). Nothing is interned.

hash

[[nodiscard]] constexpr u64 hash() const noexcept;

The 64-bit FNV-1a hash of the name. 0 for the null id.

intern

[[nodiscard]] static string_id intern(
    std::string_view name);

Hashes and interns name in every context, including for ids that were first created in constant expressions. Never constexpr, so it is the right initialiser for static and namespace-scope ids whose names must be visible to tools.

interned_count

[[nodiscard]] static usize interned_count() noexcept;

Number of names currently interned in the process-wide table.

is_null

[[nodiscard]] constexpr bool is_null() const noexcept;

True for the default-constructed id (hash 0).

null

[[nodiscard]] static constexpr string_id null() noexcept;

The null id. Equivalent to string_id().

to_string

[[nodiscard]] std::string to_string() const;

The interned name when known, otherwise "#" followed by the 16-digit hex hash.

view

[[nodiscard]] std::string_view view() const noexcept;

The interned name, or an empty view when this id was never interned.

Operator Overloads

Public

operator<=>

[[nodiscard]] constexpr auto operator<=>(
    const string_id &) const noexcept = default;

operator==

[[nodiscard]] constexpr bool operator==(
    const string_id &) const noexcept = default;