template<class Resource, class Lock = Mutex>
Mutable class
A thread-safe mutable wrapper for a resource.
Template parameters | |
---|---|
Resource | The type of the resource to be encapsulated. |
Lock | The type of the lock to use for thread-safety (default is Mutex). |
The Mutable class encapsulates a resource and provides both read and write access with optional thread-safety. When RODIN_THREAD_SAFE is defined, all modifying and accessing operations are protected by a lock of type Lock (defaulting to Mutex).
Constructors, destructors, conversion operators
- Mutable() constexpr
- Default constructor.
- Mutable(const Resource& resource) constexpr
- Constructs a Mutable object from a const reference.
- Mutable(Resource&& resource) constexpr
- Constructs a Mutable object by moving a resource.
- Mutable(Mutable&& other) constexpr
- Move constructor.
- Mutable(const Mutable& other) constexpr
- Copy constructor.
Public functions
- auto operator=(const Resource& resource) -> Mutable& constexpr
- Assignment operator from a Resource.
- auto operator=(Resource&& resource) -> Mutable& constexpr
- Move assignment operator from a Resource.
- auto operator=(const Mutable& other) -> Mutable& constexpr
- Copy assignment operator.
- auto operator=(Mutable&& other) -> Mutable& constexpr
- Move assignment operator.
- auto write() -> Resource& constexpr
- Provides non-const (write) access to the encapsulated resource.
- auto read() const -> const Resource& constexpr
- Provides read-only access to the encapsulated resource.
-
template<class F>auto read(F&& f) const -> Mutable& constexpr
- Executes a callable with read-only access to the resource.
-
template<class F>auto write(F&& f) -> Mutable& constexpr
- Executes a callable with write access to the resource.
Function documentation
template<class Resource, class Lock>
Mutable& Rodin:: Threads:: Mutable<Resource, Lock>:: operator=(const Resource& resource) constexpr
Assignment operator from a Resource.
Parameters | |
---|---|
resource | The new value to assign to the resource. |
Returns | A reference to this Mutable object. |
Assigns a new value to the encapsulated resource. In thread-safe builds, the assignment is performed under lock protection.
template<class Resource, class Lock>
Mutable& Rodin:: Threads:: Mutable<Resource, Lock>:: operator=(Resource&& resource) constexpr
Move assignment operator from a Resource.
Parameters | |
---|---|
resource | The resource to move into this object. |
Returns | A reference to this Mutable object. |
Moves a new value into the encapsulated resource. In thread-safe builds, the assignment is performed under lock protection.
template<class Resource, class Lock>
Mutable& Rodin:: Threads:: Mutable<Resource, Lock>:: operator=(const Mutable& other) constexpr
Copy assignment operator.
Parameters | |
---|---|
other | The Mutable object to copy from. |
Returns | A reference to this Mutable object. |
Assigns the resource from another Mutable object. In thread-safe builds, the assignment is performed under lock protection.
template<class Resource, class Lock>
Mutable& Rodin:: Threads:: Mutable<Resource, Lock>:: operator=(Mutable&& other) constexpr
Move assignment operator.
Parameters | |
---|---|
other | The Mutable object to move from. |
Returns | A reference to this Mutable object. |
Transfers the resource from another Mutable object into this one. In thread-safe builds, the assignment is performed under lock protection.
template<class Resource, class Lock>
Resource& Rodin:: Threads:: Mutable<Resource, Lock>:: write() constexpr
Provides non-const (write) access to the encapsulated resource.
Returns | A reference to the resource. |
---|
template<class Resource, class Lock>
const Resource& Rodin:: Threads:: Mutable<Resource, Lock>:: read() const constexpr
Provides read-only access to the encapsulated resource.
Returns | A const reference to the resource. |
---|
template<class Resource, class Lock>
template<class F>
Mutable& Rodin:: Threads:: Mutable<Resource, Lock>:: read(F&& f) const constexpr
Executes a callable with read-only access to the resource.
Template parameters | |
---|---|
F | The type of the callable. |
Parameters | |
f | The callable to execute. |
Returns | A reference to this Mutable object. |
The callable is invoked with a const reference to the resource. Note: The parameter name for the callable is intentionally omitted.
template<class Resource, class Lock>
template<class F>
Mutable& Rodin:: Threads:: Mutable<Resource, Lock>:: write(F&& f) constexpr
Executes a callable with write access to the resource.
Template parameters | |
---|---|
F | The type of the callable. |
Parameters | |
f | The callable to execute. |
Returns | A reference to this Mutable object. |
The callable is invoked with a non-const reference to the resource. In thread-safe builds, the operation is performed under lock protection.