Template Class Safe::Access#
Defined in File Safe.h
Nested Relationships#
This class is a nested type of Template Class Safe.
Class Documentation#
-
template<template<typename> class LockType, AccessMode Mode>
class Access# Manages a mutex and gives pointer-like access to a value object.
- Template Parameters:
LockType – The type of the Lock object that manages the mutex, example: std::lock_guard.
Mode – Determines the access mode of the Access object. Can be either AccessMode::ReadOnly or AccessMode::ReadWrite.
Public Types
-
using ConstPointerType = const ConstIfReadOnlyValueType*#
-
using PointerType = ConstIfReadOnlyValueType*#
-
using ConstReferenceType = const ConstIfReadOnlyValueType&#
-
using ReferenceType = ConstIfReadOnlyValueType&#
Public Functions
-
template<typename ...OtherLockArgs>
inline explicit Access(ReferenceType value, MutexType &mutex, OtherLockArgs&&... otherLockArgs)# Construct an Access object from a possibly const reference to the value object and any additional argument needed to construct the Lock object.
- Parameters:
value – Reference to the value.
otherLockArgs – Arguments needed to construct the Lock object.
-
template<typename ...OtherLockArgs>
inline explicit Access(const Safe &safe, OtherLockArgs&&... otherLockArgs)# Construct a read-only Access object from a const Safe object and any additional argument needed to construct the Lock object.
If needed, you can provide additional arguments to construct the Lock object (such as std::adopt_lock). The mutex from the Lockable object is already passed to the Lock object’s constructor though, you must not provide it.
- Parameters:
safe – The const Safe object to give protected access to.
otherLockArgs – Other arguments needed to construct the Lock object.
-
template<typename ...OtherLockArgs>
inline explicit Access(Safe &safe, OtherLockArgs&&... otherLockArgs)# Construct a read-write Access object from a Safe object and any additional argument needed to construct the Lock object.
If needed, you can provide additional arguments to construct the Lock object (such as std::adopt_lock). The mutex from the Safe object is already passed to the Lock object’s constructor though, you must not provide it.
- Parameters:
safe – The Safe object to give protected access to.
otherLockArgs – Other arguments needed to construct the Lock object.
-
template<template<typename> class OtherLockType, AccessMode OtherMode, typename ...OtherLockArgs>
inline explicit Access(Access<OtherLockType, OtherMode> &otherAccess, OtherLockArgs&&... otherLockArgs)# Construct an Access object from another one.
Note
OtherLockType must implement release() like std::unique_lock does.
- Parameters:
otherAccess – The Acces sobject to construct from.
otherLockArgs – Other arguments needed to construct the lock object.
-
inline constexpr ConstPointerType operator->() const noexcept#
Const accessor to the value.
- Returns:
Const pointer to the protected value.
-
inline constexpr PointerType operator->() noexcept#
Accessor to the value.
- Returns:
Pointer to the protected value.
-
inline constexpr ConstReferenceType operator*() const noexcept#
Const accessor to the value.
- Returns:
Const reference to the protected value.
-
inline constexpr ReferenceType operator*() noexcept#
Accessor to the value.
- Returns:
Reference to the protected value.