20#ifndef INCLUDED_O3TL_COW_WRAPPER_HXX
21#define INCLUDED_O3TL_COW_WRAPPER_HXX
23#include <osl/interlck.h>
54 return osl_atomic_decrement(&rCount) != 0;
171 template<
typename T,
class MTPolicy=UnsafeRefCountingPolicy>
class cow_wrapper
252 rSrc.m_pimpl =
nullptr;
293 rSrc.m_pimpl =
nullptr;
362 return a.same_object(b) || *
a == *b;
368 return !
a.same_object(b) && *
a != *b;
bool same_object(const cow_wrapper &rOther) const
true, if both cow_wrapper internally share the same object
MTPolicy::ref_count_t use_count() const
return number of shared instances (1 for unique object)
cow_wrapper()
Default-construct wrapped type instance.
cow_wrapper(const cow_wrapper &rSrc, std::nullopt_t)
value_type & make_unique()
unshare with any other cow_wrapper instance
cow_wrapper(std::nullopt_t) noexcept
cow_wrapper & operator=(const cow_wrapper &rSrc)
now sharing rSrc cow_wrapper instance with us
cow_wrapper & operator=(cow_wrapper &&rSrc) noexcept
stealing rSrc's resource
const value_type & operator*() const
cow_wrapper(value_type &&r)
Move-construct wrapped type instance from given object.
cow_wrapper(const value_type &r)
Copy-construct wrapped type instance from given object.
const_pointer operator->() const
const_pointer get() const
cow_wrapper(cow_wrapper &&rSrc) noexcept
Move-construct and steal rSrc shared resource.
cow_wrapper(const cow_wrapper &rSrc)
Shallow-copy given cow_wrapper.
bool is_unique() const
true, if not shared with any other cow_wrapper instance
void swap(cow_wrapper &r)
void swap(cow_wrapper< T, P > &a, cow_wrapper< T, P > &b)
bool operator==(const cow_wrapper< T, P > &a, const cow_wrapper< T, P > &b)
bool operator<(const cow_wrapper< A, P > &a, const cow_wrapper< B, P > &b)
bool operator!=(const cow_wrapper< T, P > &a, const cow_wrapper< T, P > &b)
static bool decrementCount(ref_count_t &rCount)
oslInterlockedCount ref_count_t
static void incrementCount(ref_count_t &rCount)
Thread-unsafe refcounting.
static bool decrementCount(ref_count_t &rCount)
static void incrementCount(ref_count_t &rCount)
shared value object - gets cloned before cow_wrapper hands out a non-const reference to it
impl_t & operator=(const impl_t &)=delete
MTPolicy::ref_count_t m_ref_count
impl_t(const impl_t &)=delete