ECSTASY
All in the name
Loading...
Searching...
No Matches
LockableView.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_THREAD_LOCKABLEVIEW_HPP_
13#define ECSTASY_THREAD_LOCKABLEVIEW_HPP_
14
16
17namespace ecstasy::thread
18{
26 public:
27 virtual ~LockableViewBase() = default;
28 };
29
42 template <Lockable L>
44 public:
46 using LockableType = L;
48 using WrappedType = L;
49
57 LockableView(L &lockable) : _lockable(lockable)
58 {
59 _lockable.lock();
60 }
61
72 LockableView(const LockableView<L> &other) noexcept : _lockable(other._lockable)
73 {
74 _lockable.lock();
75 }
76
89 LockableView(const LockableView<L> &&other) noexcept : _lockable(other._lockable)
90 {
91 _lockable.lock();
92 }
93
101 {
102 _lockable.unlock();
103 }
104
113 [[nodiscard]] L &operator*() noexcept
114 {
115 return _lockable;
116 }
117
126 [[nodiscard]] L *operator->() noexcept
127 {
128 return &_lockable;
129 }
130
142 [[nodiscard]] L *operator->() const noexcept
143 {
144 return &_lockable;
145 }
146
155 [[nodiscard]] L &get() noexcept
156 {
157 return _lockable;
158 }
159
168 [[nodiscard]] L &get() const noexcept
169 {
170 return _lockable;
171 }
172
173 private:
175 };
176
177} // namespace ecstasy::thread
178
179#endif /* !ECSTASY_THREAD_LOCKABLEVIEW_HPP_ */
Non template base class for LockableView<T> types.
virtual ~LockableViewBase()=default
Thread safe view of a Lockable object.
L * operator->() noexcept
Access the internal lockable object pointer.
L & get() const noexcept
Access the internal lockable object.
L LockableType
Type of the Lockable object.
LockableView(const LockableView< L > &other) noexcept
Copy constructor.
L WrappedType
QueryableWrapper Constraint
~LockableView()
Destroy the view, unlocking the internal lockable.
LockableView(L &lockable)
Construct a new Lockable View.
L & get() noexcept
Access the internal lockable object.
L & operator*() noexcept
Access the internal lockable object.
L * operator->() const noexcept
Access the internal lockable object pointer.
LockableView(const LockableView< L > &&other) noexcept
Move constructor.
Namespace regrouping the thread safe ecstasy symbols.
Definition include.hpp:26