template<class Resource>
Unsafe class
A wrapper that manages unsafe access to a resource.
Template parameters | |
---|---|
Resource | The type of the resource to be encapsulated. |
The Unsafe class encapsulates a resource and provides controlled access to it. In builds where RODIN_THREAD_SAFE is defined and in debug mode, write operations are guarded to prevent concurrent modifications which could lead to data races. In other configurations, it forwards operations directly to the underlying resource.
Constructors, destructors, conversion operators
- Unsafe() defaulted constexpr
- Default constructor.
- Unsafe(const Resource& resource) constexpr
- Constructs an Unsafe wrapper from a const reference to a resource.
- Unsafe(Resource&& resource) constexpr
- Constructs an Unsafe wrapper by moving a resource.
- Unsafe(Unsafe&& other) constexpr
- Move constructor.
- Unsafe(const Unsafe& other) constexpr
- Copy constructor.
Public functions
- auto operator=(const Resource& resource) -> Unsafe& constexpr
- Assigns a new value to the encapsulated resource.
- auto operator=(Resource&& resource) -> Unsafe& constexpr
- Assigns a new value to the encapsulated resource using move semantics.
- auto operator=(const Unsafe& other) -> Unsafe& constexpr
- Copy assignment operator.
- auto operator=(Unsafe&& other) -> Unsafe& constexpr
- Move assignment operator.
- auto read() const -> const Resource& constexpr
- Provides read-only access to the encapsulated resource.
-
template<class F>auto write(F&& f) -> Unsafe& constexpr
- Modifies the encapsulated resource.
Function documentation
template<class Resource>
Rodin:: Threads:: Unsafe<Resource>:: Unsafe() defaulted constexpr
Default constructor.
Initializes the encapsulated resource using its default constructor.
template<class Resource>
Unsafe& Rodin:: Threads:: Unsafe<Resource>:: operator=(const Resource& resource) constexpr
Assigns a new value to the encapsulated resource.
Parameters | |
---|---|
resource | The new value for the resource. |
Returns | A reference to this Unsafe object. |
This operator assigns a new value to the resource. In thread-safe debug builds, the operation is protected by a lock to ensure that no concurrent write occurs.
template<class Resource>
Unsafe& Rodin:: Threads:: Unsafe<Resource>:: operator=(Resource&& resource) constexpr
Assigns a new value to the encapsulated resource using move semantics.
Parameters | |
---|---|
resource | The new value for the resource. |
Returns | A reference to this Unsafe object. |
This operator moves a new value into the resource. In thread-safe debug builds, the operation is protected by a lock to ensure exclusive access.
template<class Resource>
const Resource& Rodin:: Threads:: Unsafe<Resource>:: read() const constexpr
Provides read-only access to the encapsulated resource.
Returns | A const reference to the resource. |
---|
template<class Resource>
template<class F>
Unsafe& Rodin:: Threads:: Unsafe<Resource>:: write(F&& f) constexpr
Modifies the encapsulated resource.
Template parameters | |
---|---|
F | A callable type that can be invoked with a reference to Resource. |
Parameters | |
f | The callable that modifies the resource. |
Returns | A reference to this Unsafe object. |
Accepts a callable that takes a non-const reference to the resource and applies modifications. In thread-safe debug builds, the operation is protected by a lock to ensure exclusive access.