182 using RWLock = std::unique_lock<std::shared_mutex>;
183 using RLock = std::shared_lock<std::shared_mutex>;
206 ~rone() { ++m_Dest; }
221 explicit RWLEnvelope()
222 : _item(ContainerType {})
241 explicit RWLEnvelope(RWLEnvelope<ContainerType>&& src)
noexcept
246 if (
auto [o, wl] = src.writeLock(); wl)
249 _item = std::move(o);
251 _rwa = std::exchange(src._rwa, 0);
273 explicit RWLEnvelope(ContainerType&& src)
274 : _item(std::move(src))
297 explicit RWLEnvelope(std::initializer_list<T> init)
299 _item = ContainerType(init);
317 void reassign(ContainerType&& src)
319 RWLock myWriterLock(_sMutex);
320 _item = std::move(src);
338 explicit RWLEnvelope(
const ContainerType& arg)
340 RWLock myWriterLock(_sMutex);
375 template <
typename Callback,
typename... Args>
377 auto observe(Callback cbf, Args&&... args)
const
379 RLock myLock(_sMutex);
380 return cbf(_item, std::forward<Args>(args)...);
413 template <
typename Callback,
typename... Args>
415 auto mutate(Callback cbf, Args&&... args)
417 RWLock myWriterLock(_sMutex);
422 return cbf(_item, std::forward<Args>(args)...);
447 [[nodiscard]] ContainerType snapshot()
const
449 RLock myLock(_sMutex);
478 [[nodiscard]] std::tuple<const ContainerType&, RLock> readLock() {
return {std::ref(_item), RLock(_sMutex)}; }
503 [[nodiscard]] std::tuple<ContainerType&, RWLock> writeLock() {
return {std::ref(_item), RWLock(_sMutex)}; }
506#ifdef INCLUDE_NLOHMANN_JSON_HPP_
527 operator nlohmann::json()
const
529 RLock myLock(_sMutex);
530 return {{
"storage", _item}, {
"_typver",
"RWLEnvelope/1.5.1"}, {
"readWriteActions", _rwa}};
545 mutable std::shared_mutex _sMutex {};