ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::thread::LockableView< L > Class Template Reference

Thread safe view of a Lockable object. More...

#include <LockableView.hpp>

Inheritance diagram for ecstasy::thread::LockableView< L >:
Collaboration diagram for ecstasy::thread::LockableView< L >:

Public Types

using LockableType = L
 Type of the Lockable object.
 
using WrappedType = L
 QueryableWrapper Constraint
 

Public Member Functions

 LockableView (L &lockable)
 Construct a new Lockable View.
 
 LockableView (const LockableView< L > &other) noexcept
 Copy constructor.
 
 LockableView (const LockableView< L > &&other) noexcept
 Move constructor.
 
 ~LockableView ()
 Destroy the view, unlocking the internal lockable.
 
L & operator* () noexcept
 Access the internal lockable object.
 
L * operator-> () noexcept
 Access the internal lockable object pointer.
 
L * operator-> () const noexcept
 Access the internal lockable object pointer.
 
L & get () noexcept
 Access the internal lockable object.
 
L & get () const noexcept
 Access the internal lockable object.
 
- Public Member Functions inherited from ecstasy::thread::LockableViewBase
virtual ~LockableViewBase ()=default
 

Private Attributes

L & _lockable
 

Detailed Description

template<Lockable L>
class ecstasy::thread::LockableView< L >

Thread safe view of a Lockable object.

This view lock the object on construction and unlock it on destruction.

Note
If L is of type const SharedRecursiveMutex, the view will be read only and the lock will be shared.
It can be seen as a thread safe reference wrapper.
Template Parameters
LType of the Lockable object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-03)

Definition at line 43 of file LockableView.hpp.

Member Typedef Documentation

◆ LockableType

template<Lockable L>
using ecstasy::thread::LockableView< L >::LockableType = L

Type of the Lockable object.

Definition at line 46 of file LockableView.hpp.

◆ WrappedType

template<Lockable L>
using ecstasy::thread::LockableView< L >::WrappedType = L

QueryableWrapper Constraint

Definition at line 48 of file LockableView.hpp.

Constructor & Destructor Documentation

◆ LockableView() [1/3]

template<Lockable L>
ecstasy::thread::LockableView< L >::LockableView ( L &  lockable)
inline

Construct a new Lockable View.

Parameters
[in]lockable
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-03)

Definition at line 57 of file LockableView.hpp.

57 : _lockable(lockable)
58 {
59 _lockable.lock();
60 }

◆ LockableView() [2/3]

template<Lockable L>
ecstasy::thread::LockableView< L >::LockableView ( const LockableView< L > &  other)
inlinenoexcept

Copy constructor.

Note
This relock the object.
Parameters
[in]otherOther Lockable View to copy.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-03)

Definition at line 72 of file LockableView.hpp.

72 : _lockable(other._lockable)
73 {
74 _lockable.lock();
75 }

◆ LockableView() [3/3]

template<Lockable L>
ecstasy::thread::LockableView< L >::LockableView ( const LockableView< L > &&  other)
inlinenoexcept

Move constructor.

Warning
This doesn't really take the lock from other, it just lock the object again. This is because we can't unset the reference of other and it will unlock the object on destruction.
This act as the copy constructor.
Parameters
[in]otherOther Lockable View to move.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-03)

Definition at line 89 of file LockableView.hpp.

89 : _lockable(other._lockable)
90 {
91 _lockable.lock();
92 }

◆ ~LockableView()

template<Lockable L>
ecstasy::thread::LockableView< L >::~LockableView ( )
inline

Destroy the view, unlocking the internal lockable.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-03)

Definition at line 100 of file LockableView.hpp.

101 {
102 _lockable.unlock();
103 }

Member Function Documentation

◆ get() [1/2]

template<Lockable L>
L & ecstasy::thread::LockableView< L >::get ( ) const
inlinenoexcept

Access the internal lockable object.

Returns
L& Reference to the internal lockable object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-10-18)

Definition at line 168 of file LockableView.hpp.

169 {
170 return _lockable;
171 }

◆ get() [2/2]

template<Lockable L>
L & ecstasy::thread::LockableView< L >::get ( )
inlinenoexcept

Access the internal lockable object.

Returns
L& Reference to the internal lockable object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-10-18)

Definition at line 155 of file LockableView.hpp.

156 {
157 return _lockable;
158 }

◆ operator*()

template<Lockable L>
L & ecstasy::thread::LockableView< L >::operator* ( )
inlinenoexcept

Access the internal lockable object.

Returns
L& Reference to the internal lockable object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-03)

Definition at line 113 of file LockableView.hpp.

114 {
115 return _lockable;
116 }

◆ operator->() [1/2]

template<Lockable L>
L * ecstasy::thread::LockableView< L >::operator-> ( ) const
inlinenoexcept

Access the internal lockable object pointer.

Warning
This method is const but the object is not. The view does not change the constness of the object, for ensured const access use LockableView<const L>.
Returns
L* Pointer to the internal lockable object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-03)

Definition at line 142 of file LockableView.hpp.

143 {
144 return &_lockable;
145 }

◆ operator->() [2/2]

template<Lockable L>
L * ecstasy::thread::LockableView< L >::operator-> ( )
inlinenoexcept

Access the internal lockable object pointer.

Returns
L* Pointer to the internal lockable object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-03)

Definition at line 126 of file LockableView.hpp.

127 {
128 return &_lockable;
129 }

Member Data Documentation

◆ _lockable

template<Lockable L>
L& ecstasy::thread::LockableView< L >::_lockable
private

Definition at line 174 of file LockableView.hpp.


The documentation for this class was generated from the following file: