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