跳转至

cf::ui::core::TokenRegistry

Thread-safe token registry. More...

#include <token.hpp>

Public Types

Name
template <typenameT >
using cf::expected< T, TokenError >
Result
Result type for token operations.

Public Functions

Name
TokenRegistry & get()
Gets the singleton registry instance.
TokenRegistry(constTokenRegistry & ) =delete
TokenRegistry & operator=(constTokenRegistry & ) =delete
TokenRegistry(TokenRegistry && ) =delete
TokenRegistry & operator=(TokenRegistry && ) =delete
template <typenameTokenToken ,typename... Args>
Result< void >
register_token(Args &&... args)
Registers a static token with a value.
template <typenameTokenToken >
Result< typename TokenToken::value_type * >
get()
Gets a static token's value.
template <typenameTokenToken >
Result< consttypename TokenToken::value_type * >
get_const() const
Gets a static token's value (const).
template <typenameT ,typename... Args>
Result< void >
register_dynamic(std::string_view name, Args &&... args)
Registers a dynamic token (forwarding constructor).
template <typenameT >
Result< void >
register_dynamic(std::string_view name, constT & value)
Registers a dynamic token (copy).
template <typenameT >
Result< void >
register_dynamic(std::string_view name, T && value)
Registers a dynamic token (move).
template <typenameT >
Result< T * >
get_dynamic(std::string_view name)
Gets a dynamic token's value.
template <typenameT >
Result< T * >
get_dynamic_by_hash(uint64_t hash)
Gets a dynamic token's value by hash.
template <typenameT >
Result< constT * >
get_dynamic_const(std::string_view name) const
Gets a dynamic token's value (const).
bool contains(uint64_t hash) const
Checks if a token exists by hash.
bool contains(std::string_view name) const
Checks if a dynamic token exists by name.
bool remove(uint64_t hash)
Removes a token from the registry by hash.
bool remove(std::string_view name)
Removes a dynamic token from the registry by name.
size_t size() const
Gets the number of registered tokens.
template <typenameTokenToken ,typename... Args>
auto
register_token(Args &&... args)
template <typenameTokenToken >
auto
get()
template <typenameTokenToken >
auto
get_const() const
template <typenameT ,typename... Args>
auto
register_dynamic(std::string_view name, Args &&... args)
template <typenameT >
auto
register_dynamic(std::string_view name, constT & value)
template <typenameT >
auto
register_dynamic(std::string_view name, T && value)
template <typenameT >
auto
get_by_hash_impl(uint64_t hash, const std::string & name_hint)
template <typenameT >
auto
get_by_hash_impl_const(uint64_t hash, const std::string & name_hint) const
template <typenameT >
auto
get_dynamic(std::string_view name)
template <typenameT >
auto
get_dynamic_by_hash(uint64_t hash)
template <typenameT >
auto
get_dynamic_const(std::string_view name) const

Detailed Description

class cf::ui::core::TokenRegistry;

Thread-safe token registry.

Note: Thread-safe for all operations.

Warning: Token registration is relatively expensive; design for infrequent writes.

Uses std::shared_mutex to allow concurrent reads while serialising writes. All get() calls hold the shared lock for the duration of the access, which prevents use-after-free when a concurrent writer calls remove().

auto& registry = TokenRegistry::get();
registry.register_token<StaticToken<int, "settings"_hash>>(42);
registry.register_dynamic("userId", 12345);
auto result = registry.get_dynamic<int>("userId");
if (result) { int id = *result; }

Public Types Documentation

using Result

template <typenameT >
using cf::ui::core::TokenRegistry::Result =  cf::expected<T, TokenError>;

Result type for token operations.

Public Functions Documentation

function get

static inline TokenRegistry & get()

Gets the singleton registry instance.

Exceptions:

  • None

Return: Reference to the singleton registry instance.

Since: 0.1

Note: Thread-safe singleton initialization.

Warning: None

Gets the singleton TokenRegistry instance.

function TokenRegistry

TokenRegistry(
    constTokenRegistry & 
) =delete

function operator=

TokenRegistry & operator=(
    constTokenRegistry & 
) =delete

function TokenRegistry

TokenRegistry(
    TokenRegistry && 
) =delete

function operator=

TokenRegistry & operator=(
    TokenRegistry && 
) =delete

function register_token

template <typenameTokenToken ,
typename... Args>
Result< void > register_token(
    Args &&... args
)

Registers a static token with a value.

Parameters:

  • args Arguments to construct the value.

Template Parameters:

  • TokenToken StaticToken type (contains T and Hash).
  • Args Constructor argument types.

Return: Result containing void or TokenError::AlreadyRegistered.

function get

template <typenameTokenToken >
Result< typename TokenToken::value_type * > get()

Gets a static token's value.

Template Parameters:

Return: Result containing pointer to the token's value or TokenError.

function get_const

template <typenameTokenToken >
Result< consttypename TokenToken::value_type * > get_const() const

Gets a static token's value (const).

Template Parameters:

Return: Result containing const pointer to the token's value or TokenError.

function register_dynamic

template <typenameT ,
typename... Args>
Result< void > register_dynamic(
    std::string_view name,
    Args &&... args
)

Registers a dynamic token (forwarding constructor).

Return: Result containing void or TokenError::AlreadyRegistered.

function register_dynamic

template <typenameT >
Result< void > register_dynamic(
    std::string_view name,
    constT & value
)

Registers a dynamic token (copy).

Return: Result containing void or TokenError::AlreadyRegistered.

function register_dynamic

template <typenameT >
Result< void > register_dynamic(
    std::string_view name,
    T && value
)

Registers a dynamic token (move).

Return: Result containing void or TokenError::AlreadyRegistered.

function get_dynamic

template <typenameT >
Result< T * > get_dynamic(
    std::string_view name
)

Gets a dynamic token's value.

Return: Result containing pointer to the token's value or TokenError.

function get_dynamic_by_hash

template <typenameT >
Result< T * > get_dynamic_by_hash(
    uint64_t hash
)

Gets a dynamic token's value by hash.

Return: Result containing pointer to the token's value or TokenError.

function get_dynamic_const

template <typenameT >
Result< constT * > get_dynamic_const(
    std::string_view name
) const

Gets a dynamic token's value (const).

Return: Result containing const pointer to the token's value or TokenError.

function contains

inline bool contains(
    uint64_t hash
) const

Checks if a token exists by hash.

Parameters:

  • hash Hash value of the token to check.

Exceptions:

  • None

Return:

  • true if the token exists, false otherwise.
  • true if the token exists, false otherwise.

Since: 0.1

Note: Thread-safe for concurrent reads.

Warning: None

function contains

inline bool contains(
    std::string_view name
) const

Checks if a dynamic token exists by name.

Parameters:

  • name Name of the token to check.

Exceptions:

  • None

Return:

  • true if the token exists, false otherwise.
  • true if the token exists, false otherwise.

Since: 0.1

Note: Thread-safe for concurrent reads.

Warning: None

Checks if a token exists by name.

function remove

inline bool remove(
    uint64_t hash
)

Removes a token from the registry by hash.

Parameters:

  • hash Hash value of the token to remove.

Exceptions:

  • None

Return:

  • true if removed, false if not found.
  • true if the token was removed, false if not found.

Since: 0.1

Note: Thread-safe for exclusive access.

Warning: None

function remove

inline bool remove(
    std::string_view name
)

Removes a dynamic token from the registry by name.

Parameters:

  • name Name of the token to remove.

Exceptions:

  • None

Return:

  • true if removed, false if not found.
  • true if the token was removed, false if not found.

Since: 0.1

Note: Thread-safe for exclusive access.

Warning: None

Removes a token from the registry by name.

function size

inline size_t size() const

Gets the number of registered tokens.

Exceptions:

  • None

Return:

  • Number of tokens in the registry.
  • Number of tokens in the registry.

Since: 0.1

Note: Thread-safe for concurrent reads.

Warning: None

function register_token

template <typenameTokenToken ,
typename... Args>
auto register_token(
    Args &&... args
)

function get

template <typenameTokenToken >
auto get()

function get_const

template <typenameTokenToken >
auto get_const() const

function register_dynamic

template <typenameT ,
typename... Args>
auto register_dynamic(
    std::string_view name,
    Args &&... args
)

function register_dynamic

template <typenameT >
auto register_dynamic(
    std::string_view name,
    constT & value
)

function register_dynamic

template <typenameT >
auto register_dynamic(
    std::string_view name,
    T && value
)

function get_by_hash_impl

template <typenameT >
auto get_by_hash_impl(
    uint64_t hash,
    const std::string & name_hint
)

function get_by_hash_impl_const

template <typenameT >
auto get_by_hash_impl_const(
    uint64_t hash,
    const std::string & name_hint
) const

function get_dynamic

template <typenameT >
auto get_dynamic(
    std::string_view name
)

function get_dynamic_by_hash

template <typenameT >
auto get_dynamic_by_hash(
    uint64_t hash
)

function get_dynamic_const

template <typenameT >
auto get_dynamic_const(
    std::string_view name
) const

Updated on 2026-03-09 at 10:14:00 +0000