File include/brisk/core/Utilities.hpp
¶
Cache
class¶
template <typename T, typename... Args> Cache
A caching structure that stores a value and its associated parameters.
Updates the value if the input parameters change.
Template param T
The type of the cached value.
Template param Args
The types of the parameters used to generate the cached value.
data
variable (Cache::data
)¶
optional<T> data
The cached value.
parameters
variable (Cache::parameters
)¶
std::tuple<Args...> parameters
The tuple storing the input parameters associated with the cached value.
update
function (Cache::update
)¶
template <typename Fn>
void update(Fn &&fn, const Args &...args)
Updates the cached value by calling the provided function if the input parameters change.
Template param Fn
The type of the function used to compute the value.
Param fn
The function to compute the value.
Param args
The input parameters for the function.
operator()
function (Cache::operator()
)¶
template <typename Fn>
T &operator()(Fn &&fn, const Args &...args)
Calls the provided function and updates the cached value if necessary, then returns the cached
value.
Template param Fn
The type of the function used to compute the value.
Param fn
The function to compute the value.
Param args
The input parameters for the function.
Returns The updated cached value.
get
function (Cache::get
)¶
T &get()
Returns a reference to the cached value.
Returns A reference to the cached value.
const T &get() const
Returns a constant reference to the cached value.
Returns A constant reference to the cached value.
IfChanged
class¶
template <typename... Args> IfChanged
A utility that checks if the given arguments have changed since the last call.
Template param Args
The types of the arguments to track.
data
variable (IfChanged::data
)¶
optional<std::tuple<Args...>> data
The last stored tuple of arguments.
operator()
function (IfChanged::operator()
)¶
bool operator()(const Args &...args)
Checks if the given arguments have changed since the last call.
Param args
The arguments to check for changes.
Returns True if the arguments have changed, otherwise false.
reset
function (IfChanged::reset
)¶
void reset()
Resets the internal state, clearing the stored arguments.
PossiblyShared
class¶
template <typename T> PossiblyShared
A structure that holds either a shared or unique value of type T.
Template param T
The type of the held value.
PossiblyShared<T>
function (PossiblyShared::PossiblyShared<T>
)¶
PossiblyShared(const T ©) : value(copy)
Constructs a PossiblyShared object with a copy of the given value.
Param copy
The value to copy.
PossiblyShared(std::remove_const_t<T> &©)
: value(std::move(copy))
Constructs a PossiblyShared object with a moved value.
Param copy
The value to move.
PossiblyShared(T *ptr) : shared(ptr)
Constructs a PossiblyShared object with a shared pointer to the value.
Param ptr
A pointer to the shared value.
operator*
function (PossiblyShared::operator*
)¶
T &operator*() const
Dereferences the PossiblyShared object.
Returns A reference to the held value.
operator->
function (PossiblyShared::operator->
)¶
T *operator->() const
Accesses members of the held value.
Returns A pointer to the held value.
isShared
function (PossiblyShared::isShared
)¶
bool isShared() const
Checks if the PossiblyShared object holds a shared value.
Returns True if the value is shared, otherwise false.
value
variable (PossiblyShared::value
)¶
mutable optional<std::remove_const_t<T>> value
Optionally holds the unique value if it is not shared.
shared
variable (PossiblyShared::shared
)¶
T *shared = nullptr
Pointer to the shared value, if applicable.
InstanceCache
class¶
template <typename T> InstanceCache
A cache that stores an instance of a value and can be copied or moved.
Template param T
The type of the cached value.
InstanceCache<T>
function (InstanceCache::InstanceCache<T>
)¶
template <typename... Args>
InstanceCache(Args &&...args) noexcept(
std::is_nothrow_constructible_v<T, Args...>)
: value
Constructs an InstanceCache object with the given arguments.
Template param Args
The types of the arguments used to construct the value.
Param args
The arguments used to construct the value.
InstanceCache(const InstanceCache &other) noexcept(
std::is_nothrow_default_constructible_v<T>)
: value
Copy constructor. Initializes the value with default construction instead of copying.
InstanceCache(InstanceCache &&other) noexcept(
std::is_nothrow_default_constructible_v<T>)
: value
Move constructor. Initializes the value with default construction instead of moving.
operator=
function (InstanceCache::operator=
)¶
InstanceCache &operator=(const InstanceCache &other)
Copy assignment operator. Does nothing and returns *this.
InstanceCache &operator=(InstanceCache &&other)
Move assignment operator. Does nothing and returns *this.
~InstanceCache<T>
function (InstanceCache::~InstanceCache<T>
)¶
~InstanceCache() = default
Destructor.
value
variable (InstanceCache::value
)¶
T value
The cached value.
SimpleCache
class¶
template <typename CachedValue, equality_comparable Key,
typename Class,
CachedValue (Class::*Func)(const Key &)>
SimpleCache
A simple cache that stores a value based on a key and a member function of a class.
Template param CachedValue
The type of the cached value.
Template param Key
The type of the key.
Template param Class
The class type containing the member function.
Template param Func
The member function that returns the cached value.
self
variable (SimpleCache::self
)¶
Class *self
Pointer to the instance of the class that holds the member function.
key
function (SimpleCache::key
)¶
const Key &key() const
Returns the key associated with the cached value.
Returns The key associated with the cached value.
get
function (SimpleCache::get
)¶
const CachedValue &get() const
Returns the cached value.
Returns The cached value.
update
function (SimpleCache::update
)¶
bool update(const Key &key)
Updates the cache if the key has changed by invoking the member function.
Param key
The key to check and update.
Returns True if the cache was updated, otherwise false.
m_cache
variable (SimpleCache::m_cache
)¶
std::optional<std::pair<Key, CachedValue>> m_cache
Optionally holds the cached key-value pair.
CacheWithInvalidation
class¶
template <typename CachedValue, equality_comparable Key,
typename Class,
CachedValue (Class::*Func)(const Key &)>
CacheWithInvalidation
A cache that stores a value based on a key and invalidates it when the key changes.
Template param CachedValue
The type of the cached value.
Template param Key
The type of the key.
Template param Class
The class type containing the member function.
Template param Func
The member function that returns the cached value.
self
variable (CacheWithInvalidation::self
)¶
Class *self
Pointer to the instance of the class that holds the member function.
m_key
variable (CacheWithInvalidation::m_key
)¶
Key m_key
The key associated with the cached value.
m_value
variable (CacheWithInvalidation::m_value
)¶
mutable std::optional<CachedValue> m_value
Optionally holds the cached value.
operator->
function (CacheWithInvalidation::operator->
)¶
const CachedValue *operator->() const
Returns a pointer to the cached value, updating it if necessary.
Returns A pointer to the cached value.
key
function (CacheWithInvalidation::key
)¶
const Key &key() const
Returns the key associated with the cached value.
Returns The key associated with the cached value.
value
function (CacheWithInvalidation::value
)¶
const CachedValue &value() const
Returns the cached value, updating it if necessary.
Returns The cached value.
update
function (CacheWithInvalidation::update
)¶
void update() const
Updates the cached value if it is not already set.
invalidate
function (CacheWithInvalidation::invalidate
)¶
bool invalidate(const Key &key, bool force = false)
Invalidates the cached value if the key has changed.
Param key
The new key to check.
Returns True if the cache was invalidated, otherwise false.
ImplicitContextScope
class¶
template <typename T, typename Tag = T> ImplicitContextScope
ImplicitContextStorage
class (Internal::ImplicitContextStorage
)¶
template <typename T, typename Tag, bool thread>
ImplicitContextStorage
template <typename T, typename Tag> ImplicitContextStorage
template <typename T, typename Tag> ImplicitContextStorage
ImplicitContext
class¶
template <typename T, typename Tag = T, bool thread = true>
ImplicitContext
template <typename T, typename Tag, bool thread>
ImplicitContext
ImplicitContextScope
class¶
template <typename T, typename Tag> ImplicitContextScope
ScopedValue
class¶
template <typename T> ScopedValue
A RAII-style helper class for temporarily changing a value and restoring it upon scope exit.
The ScopedValue
template class allows temporarily modifying a value within a given scope. When the
object of ScopedValue
goes out of scope, it automatically restores the original value.
Template param T
The type of the value being managed.
ScopedValue<T>
function (ScopedValue::ScopedValue<T>
)¶
ScopedValue(T &target, T newValue)
: target(target), saved(std::move(target))
Constructs a ScopedValue
object that changes the target value to newValue
and saves the
original value.
Param target
The reference to the value that will be modified.
Param newValue
The new value to set for target
.
~ScopedValue<T>
function (ScopedValue::~ScopedValue<T>
)¶
~ScopedValue()
Restores the original value when the ScopedValue
object goes out of scope.
target
variable (ScopedValue::target
)¶
T &target
The reference to the value being modified.
saved
variable (ScopedValue::saved
)¶
T saved
The original value saved for restoration.
<deduction guide for ScopedValue>
function¶
template <typename T> ScopedValue(T &, T)->ScopedValue<T>
Type deduction guide for ScopedValue
.
Template param T
The type of the value being managed.
ScopeExit
class¶
template <typename Fn> ScopeExit
A RAII-style helper class for executing a callable object upon scope exit.
The ScopeExit
template class allows the user to specify a function or lambda that will be executed
when the ScopeExit
object goes out of scope.
Template param Fn
The type of the callable object to be executed.
ScopeExit<Fn>
function (ScopeExit::ScopeExit<Fn>
)¶
template <typename Fn_>
ScopeExit(Fn_ &&fn) : fn(std::forward<Fn_>(fn))
Constructs a ScopeExit
object with a callable function or lambda.
Template param Fn_
The type of the callable object.
Param fn
The callable object to be executed upon scope exit.
~ScopeExit<Fn>
function (ScopeExit::~ScopeExit<Fn>
)¶
~ScopeExit()
Executes the callable object when the ScopeExit
object goes out of scope.
fn
variable (ScopeExit::fn
)¶
Fn fn
The callable object to be executed upon scope exit.
KeyValue
typedef¶
template <typename Key, typename Value>
KeyValue = std::pair<Key, Value>
A type alias for a key-value pair.
This alias represents a standard pair containing a key of type Key
and a value of type Value.
Template param Key
The type of the key.
Template param Value
The type of the value.
KeyValue = std::pair<Key, Value>
A type alias for a key-value pair.
This alias represents a standard pair containing a key of type Key
and a value of type Value.
Template param Key
The type of the key.
Template param Value
The type of the value.
findValue
function¶
template <typename V, typename T>
inline optional<size_t>
findValue(const std::vector<V> &list, const T &value)
Finds the index of a specified value in a list.
Searches for the given value in a vector of type V.
Returns the index of the value if found, otherwise returns nullopt.
Template param V
The type of the values in the list.
Template param T
The type of the value to find.
Param list
The list to search through.
Param value
The value to find.
Returns optional<size_t> The index of the found value, or nullopt if not found.
template <typename K, typename V>
inline optional<size_t>
findValue(const KeyValueOrderedList<K, V> &list,
const V &value)
Finds the index of a specified value in a key-value ordered list.
Searches for the given value in a KeyValueOrderedList.
Returns the index of the value if found, otherwise returns nullopt.
Template param K
The type of the keys.
Template param V
The type of the values.
Param list
The list to search through.
Param value
The value to find.
Returns optional<size_t> The index of the found value, or nullopt if not found.
findKey
function¶
template <typename K, typename V>
inline optional<size_t>
findKey(const KeyValueOrderedList<K, V> &list,
const K &name)
Finds the index of a specified key in a key-value ordered list.
Searches for the given key in a KeyValueOrderedList.
Returns the index of the key if found, otherwise returns nullopt.
Template param K
The type of the keys.
Template param V
The type of the values.
Param list
The list to search through.
Param name
The key to find.
Returns optional<size_t> The index of the found key, or nullopt if not found.
findKeyIt
function¶
template <typename K, typename V>
inline auto findKeyIt(const KeyValueOrderedList<K, V> &list,
const K &name)
Finds an iterator to a specified key in a key-value ordered list.
Searches for the given key in a KeyValueOrderedList and returns an iterator
to the found element.
Template param K
The type of the keys.
Template param V
The type of the values.
Param list
The list to search through.
Param name
The key to find.
Returns Iterator to the found key or list.end() if not found.
valueToKey
function¶
template <typename K, typename V>
inline optional<K>
valueToKey(const KeyValueOrderedList<K, V> &list,
const V &value)
Converts a value to its corresponding key in a key-value ordered list.
Searches for the given value and returns the associated key if found,
otherwise returns nullopt.
Template param K
The type of the keys.
Template param V
The type of the values.
Param list
The list to search through.
Param value
The value to find.
Returns optional<K> The associated key, or nullopt if not found.
keyToValue
function¶
template <typename K, typename V>
inline optional<V>
keyToValue(const KeyValueOrderedList<K, V> &list,
const K &name)
Converts a key to its corresponding value in a key-value ordered list.
Searches for the given key and returns the associated value if found,
otherwise returns nullopt.
Template param K
The type of the keys.
Template param V
The type of the values.
Param list
The list to search through.
Param name
The key to find.
Returns optional<V> The associated value, or nullopt if not found.
setValueByKey
function¶
template <typename K, typename V>
inline void setValueByKey(KeyValueOrderedList<K, V> &list,
const K &key, V value)
Sets a value by its corresponding key in a key-value ordered list.
Updates the value associated with the given key if it exists,
otherwise adds a new key-value pair to the list.
Template param K
The type of the keys.
Template param V
The type of the values.
Param list
The list to update.
Param key
The key for which to set the value.
Param value
The value to set.
removeValueByKey
function¶
template <typename K, typename V>
inline void
removeValueByKey(KeyValueOrderedList<K, V> &list,
const K &key)
Removes a value by its corresponding key in a key-value ordered list.
Searches for the specified key and removes the associated key-value pair
if found.
Template param K
The type of the keys.
Template param V
The type of the values.
Param list
The list from which to remove the key-value pair.
Param key
The key to remove.
keyToValue
function¶
template <typename V, typename K>
inline optional<V> keyToValue(const std::vector<V> &list,
K(V::*field),
const K &fieldValue)
Finds a value in a vector by a specified field.
Searches for the given name in a vector of objects of type V by accessing
the specified field.
Template param V
The type of the objects in the list.
Template param K
The type of the field used for searching.
Param list
The list to search through.
Param field
Pointer to the field to compare.
Param fieldValue
The value to find.
Returns optional<V> The found value, or nullopt if not found.
findKey
function¶
template <typename V, typename K>
inline optional<size_t> findKey(const std::vector<V> &list,
K(V::*field),
const K &fieldValue)
Finds the index of a value in a vector by a specified field.
Searches for the given value in a vector of objects of type V by accessing
the specified field.
Template param V
The type of the objects in the list.
Template param K
The type of the field used for searching.
Param list
The list to search through.
Param field
Pointer to the field to compare.
Param fieldValue
The value to find.
Returns optional<size_t> The index of the found key, or nullopt if not found.
staticMap
function¶
template <typename Tout, typename Tin, typename... Args>
constexpr Tout staticMap(Tin value, Tout fallback) noexcept
A compile-time function for mapping values.
Always returns the fallback value.
Template param Tout
The type of the fallback value.
Template param Tin
The type of the input value.
Template param Args
Additional argument types (unused).
Param value
The value to compare.
Param fallback
The fallback value to return.
Returns Tout The fallback value.
template <typename Tout, typename Tin, typename... Args>
constexpr Tout staticMap(Tin value,
std::type_identity_t<Tin> in,
Tout out, Args... args) noexcept
A compile-time function for mapping values.
Compares the input value with the specified type and returns
the corresponding output if found.
Template param Tout
The type of the output value.
Template param Tin
The type of the input value.
Template param Args
Additional argument types for comparison.
Param value
The value to compare.
Param in
The input type to match.
Param out
The output value to return if a match is found.
Param args
Additional arguments for further comparisons.
Returns Tout The corresponding output value.
ClonablePtr
class¶
template <typename T> ClonablePtr
AutoSingleton
class¶
template <typename T> AutoSingleton
A utility structure to provide automatic singleton management.
This struct manages the creation of a singleton instance of type T
using std::unique_ptr
.
The instance is lazily created upon the first access.
Template param T
The type of the singleton instance to manage.
operator->
function (AutoSingleton::operator->
)¶
T *operator->()
Provides access to the singleton instance of type T
.
This operator ensures the creation of the singleton instance (if not already created)
and returns a pointer to it.
Returns T* Pointer to the singleton instance of type T
.
operator type-parameter-0-0 *
function (AutoSingleton::operator type-parameter-0-0 *
)¶
operator T *() noexcept
Implicit conversion to pointer of type T
.
This conversion operator allows the AutoSingleton
object to be used
as a pointer to the singleton instance of type T
. This simplifies the
access to the singleton object without needing to call the operator-\>()
explicitly.
Returns T* Pointer to the singleton instance of type T
.
Auto-generated from sources, Revision , https://github.com/brisklib/brisk/blob//include/brisk/