16 std::atomic<int> useCnt;
17 std::atomic<int> weakCnt;
26 const int cnt = ++useCnt;
36 const int cnt = ++weakCnt;
44 if (cnt == 0 || useCnt.compare_exchange_strong(cnt, cnt + 1)) {
51 const int cnt = --useCnt;
59 const int cnt = --weakCnt;
124 block = alignedNew<Detail::ControlBlock<T>>(
ptr);
133 this->copyBlock(other);
136 template <
typename T2>
139 this->copyBlock(other);
146 other.block =
nullptr;
149 template <
typename T2>
154 other.block =
nullptr;
157 template <
typename T2>
168 this->copyBlock(other);
172 template <
typename T2>
176 this->copyBlock(other);
186 template <
typename T2>
192 other.block =
nullptr;
216 return ptr !=
nullptr;
220 return ptr ==
nullptr;
254 template <
typename... TArgs>
255 INLINE decltype(
auto) operator()(TArgs&&... args)
const {
257 return (*
ptr)(std::forward<TArgs>(args)...);
261 template <
typename T2>
275 template <
typename T>
280 template <
typename T>
285 template <
typename T>
290 template <
typename T>
295 template <
typename T>
297 return ptr1.
get() == ptr2.
get();
300 template <
typename T>
302 return ptr1.
get() != ptr2.
get();
305 template <
typename T>
307 return ptr1.
get() < ptr2.
get();
310 template <
typename T>
320 : block(other.block) {
326 template <
typename T2>
328 : block(other.block) {
334 template <
typename T2>
358 template <
typename T2>
377 ptr.
ptr =
static_cast<T*
>(block->
getPtr());
409 template <
typename T,
typename... TArgs>
411 return SharedPtr<T>(alignedNew<T>(std::forward<TArgs>(args)...));
414 template <
typename T>
439 template <
typename T,
typename TEnabler =
void>
441 static constexpr
bool value =
false;
443 template <
typename T>
448 template <
typename T>
450 ptr->setWeakPtr(ptr);
453 template <
typename T>
INLINE void alignedDelete(T *ptr)
Deletes an object previously allocated using alignedNew.
#define SPH_ASSERT(x,...)
Simplified implementation of std::unique_ptr, using only default deleter.
uint32_t Size
Integral type used to index arrays (by default).
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
INLINE SharedPtr< T > makeShared(TArgs &&... args)
bool operator==(const SharedPtr< T > &ptr, std::nullptr_t)
std::enable_if_t< IsShareFromThis< T >::value > setSharedFromThis(const SharedPtr< T > &ptr)
bool operator!=(const SharedPtr< T > &ptr, std::nullptr_t)
bool operator<(const SharedPtr< T > &ptr1, const SharedPtr< T > &ptr2)
Wrapper of pointer that deletes the resource from destructor.
INLINE void decreaseUseCnt()
INLINE int getUseCount() const
INLINE int increaseWeakCnt()
INLINE void deleteBlock()
INLINE void decreaseWeakCnt()
INLINE int increaseUseCnt()
virtual void deletePtr()=0
INLINE bool increaseUseCntIfNonzero()
INLINE ControlBlockHolder()
virtual void * getPtr()=0
virtual void deletePtr() override
virtual INLINE void * getPtr() override
Non-owning wrapper of pointer.
void setWeakPtr(const WeakPtr< T > &weakPtr)
WeakPtr< T > weakFromThis() const
SharedPtr< T > sharedFromThis() const
SharedPtr & operator=(const SharedPtr &other)
INLINE RawPtr< T > get() const
INLINE T & operator*() const
SharedPtr(AutoPtr< T2 > &&ptr)
SharedPtr & operator=(SharedPtr &&other)
INLINE Size getUseCount()
SharedPtr(std::nullptr_t)
SharedPtr(const SharedPtr &other)
Detail::ControlBlockHolder * block
SharedPtr(T *ptr, Detail::ControlBlockHolder *block)
SharedPtr(SharedPtr &&other)
SharedPtr(const SharedPtr< T2 > &other)
SharedPtr(SharedPtr< T2 > &&other)
friend class SharedFromThis
INLINE T * operator->() const
SharedPtr & operator=(const SharedPtr< T2 > &other)
SharedPtr & operator=(std::nullptr_t)
INLINE bool operator!() const
SharedPtr & operator=(SharedPtr< T2 > &&other)
SharedPtr< T > lock() const
INLINE bool operator!() const
WeakPtr & operator=(const WeakPtr &other)
WeakPtr & operator=(const WeakPtr< T2 > &other)
WeakPtr(const WeakPtr< T2 > &other)
WeakPtr(const WeakPtr &other)
WeakPtr & operator=(std::nullptr_t)
INLINE Size getUseCount() const
WeakPtr(const SharedPtr< T2 > &ptr)
void swap(Sph::Array< T, TCounter > &ar1, Sph::Array< T, TCounter > &ar2)
static constexpr bool value
Base class for all polymorphic objects.