Template Class Safe#

Nested Relationships#

Nested Types#

Class Documentation#

template<typename ValueType, typename MutexType = INTERNAL::DefaultMutex>
class Safe#

Wraps a value together with a mutex.

Template Parameters:
  • ValueType – The type of the value to protect.

  • MutexType – The type of the mutex.

Public Types

template<template<typename> class LockType = INTERNAL::DefaultReadOnlyLock>
using ReadAccess = Access<LockType, AccessMode::ReadOnly>#
template<template<typename> class LockType = INTERNAL::DefaultReadWriteLock>
using WriteAccess = Access<LockType, AccessMode::ReadWrite>#

Public Functions

Safe() = default#

Construct a Safe object.

template<typename ...ValueArgs>
inline explicit Safe(DefaultConstructMutex _, ValueArgs&&... valueArgs)#

Construct a Safe object with default construction of the mutex and perfect forwarding of the other arguments to construct the value object.

Parameters:

valueArgs – Perfect forwarding arguments to construct the value object.

template<typename MutexArg, typename ...ValueArgs>
inline explicit Safe(MutexArg &&mutexArg, ValueArgs&&... valueArgs)#

Construct a Safe object, forwarding the first argument to construct the mutex and the other arguments to construct the value object.

Parameters:
  • mutexArg – Perfect forwarding argument to construct the mutex object.

  • valueArgs – Perfect forwarding arguments to construct the value object.

consteval Safe(const Safe&) = delete#
consteval Safe(Safe&&) = delete#
consteval Safe &operator=(const Safe&) = delete#
consteval Safe &operator=(Safe&&) = delete#
template<template<typename> class LockType = INTERNAL::DefaultReadOnlyLock>
inline ReadAccess<LockType> ReadLock() const#
template<template<typename> class LockType = INTERNAL::DefaultReadOnlyLock, typename ...LockArgs>
inline ReadAccess<LockType> ReadLock(LockArgs&&... lockArgs) const#
template<template<typename> class LockType = INTERNAL::DefaultReadWriteLock>
inline WriteAccess<LockType> WriteLock()#
template<template<typename> class LockType = INTERNAL::DefaultReadWriteLock, typename ...LockArgs>
inline WriteAccess<LockType> WriteLock(LockArgs&&... lockArgs)#
template<template<typename> class LockType = INTERNAL::DefaultReadOnlyLock, typename ...LockArgs>
inline RemoveRefValueType Copy(LockArgs&&... lockArgs) const#
template<template<typename> class LockType = INTERNAL::DefaultReadWriteLock, typename ...LockArgs>
inline void Assign(ConstValueReferenceType value, LockArgs&&... lockArgs)#
template<template<typename> class LockType = INTERNAL::DefaultReadWriteLock, typename ...LockArgs>
inline void Assign(RemoveRefValueType &&value, LockArgs&&... lockArgs)#
inline constexpr ConstValueReferenceType GetUnsafe() const noexcept#

Unsafe const accessor to the value.

Note

If you use this function, you exit the realm of safety!

Returns:

Const reference to the value object.

inline constexpr ValueReferenceType GetUnsafe() noexcept#

Unsafe accessor to the value.

Note

If you use this function, you exit the realm of safety!

Returns:

Reference to the value object.

inline MutexReferenceType GetMutex() const noexcept#

Accessor to the mutex.

Note

Use this to lock multiple Safe objects at the same time by using std::scoped_lock.

Returns:

Reference to the mutex.