1#ifndef NE_STL_INCLUDENE_STL_SHARED_PTR_H
2#define NE_STL_INCLUDENE_STL_SHARED_PTR_H
11typedef struct _cblock {
17void cblock_release(cblock*& ptr) {
21void object_release(TObj*& ptr) {
48 cblock_ = memory::new_obj<cblock>();
61 cblock_->shared_count.operator++();
71 cblock_->shared_count.operator++();
80 cblock_->shared_count.operator++();
92 cblock_->shared_count.operator++();
100 inline operator bool()
const {
return data_ !=
nullptr; }
121 cblock_ = memory::new_obj<cblock>();
129 cblock_->shared_count.operator--();
130 if (
cblock_->shared_count <= 0) {
159 cblock_->weak_count.operator++();
168 cblock_->weak_count.operator++();
191 cblock_->weak_count.operator--();
208template <
class T,
class... TArgs>
212template <
class T1,
class T2>
Definition: ne_stl_smart_ptr.h:30
_shared_ptr(const _weak_ptr< T > &wp)
Definition: ne_stl_smart_ptr.h:74
_shared_ptr & operator=(const _shared_ptr &sp)
Definition: ne_stl_smart_ptr.h:84
_shared_ptr(std::nullptr_t)
Definition: ne_stl_smart_ptr.h:51
void dec_shared_count()
Definition: ne_stl_smart_ptr.h:125
nstd::cblock * cblock_
Definition: ne_stl_smart_ptr.h:141
void(* release_)(T *&pdata)
Definition: ne_stl_smart_ptr.h:142
void reset(T *data)
Definition: ne_stl_smart_ptr.h:118
T * get() const
Definition: ne_stl_smart_ptr.h:103
void reset()
Definition: ne_stl_smart_ptr.h:112
T * data_
Definition: ne_stl_smart_ptr.h:140
_shared_ptr(const _shared_ptr &sp)
Definition: ne_stl_smart_ptr.h:55
~_shared_ptr()
Definition: ne_stl_smart_ptr.h:83
_shared_ptr(const _shared_ptr< D > &sp)
Definition: ne_stl_smart_ptr.h:65
T & operator*() const
Definition: ne_stl_smart_ptr.h:107
bool operator!=(std::nullptr_t) const
Definition: ne_stl_smart_ptr.h:102
bool operator==(std::nullptr_t) const
Definition: ne_stl_smart_ptr.h:101
_shared_ptr(T *data)
Definition: ne_stl_smart_ptr.h:43
std::remove_extent_t< T > element_type
Definition: ne_stl_smart_ptr.h:37
void(* release_block_)(nstd::cblock *&pdata)
Definition: ne_stl_smart_ptr.h:143
T * operator->() const
Definition: ne_stl_smart_ptr.h:105
_shared_ptr()
Definition: ne_stl_smart_ptr.h:38
_shared_ptr & operator=(std::nullptr_t)
Definition: ne_stl_smart_ptr.h:96
Definition: ne_stl_smart_ptr.h:146
T * data_
Definition: ne_stl_smart_ptr.h:199
_weak_ptr(const _shared_ptr< T > &sp)
Definition: ne_stl_smart_ptr.h:162
nstd::cblock * cblock_
Definition: ne_stl_smart_ptr.h:200
~_weak_ptr()
Definition: ne_stl_smart_ptr.h:171
_weak_ptr(const _weak_ptr &wp)
Definition: ne_stl_smart_ptr.h:153
void(* release_block_)(nstd::cblock *&pdata)
Definition: ne_stl_smart_ptr.h:202
void reset()
Definition: ne_stl_smart_ptr.h:179
void dec_weak_count()
Definition: ne_stl_smart_ptr.h:187
_weak_ptr & operator=(const _weak_ptr &wp)
Definition: ne_stl_smart_ptr.h:172
bool expired() const
Definition: ne_stl_smart_ptr.h:178
_shared_ptr< T > lock() const
Definition: ne_stl_smart_ptr.h:177
void(* release_)(T *&pdata)
Definition: ne_stl_smart_ptr.h:201
_weak_ptr()
Definition: ne_stl_smart_ptr.h:148
Definition: ne_stl_any.h:7
nstd::shared_ptr< T > make_shared(TArgs &&... args)
Definition: ne_stl_smart_ptr.h:209
shared_ptr< T1 > dynamic_pointer_cast(const shared_ptr< T2 > &other) noexcept
Definition: ne_stl_smart_ptr.h:213
nstd::atomic_int shared_count
Definition: ne_stl_smart_ptr.h:14
nstd::atomic_int weak_count
Definition: ne_stl_smart_ptr.h:13
unsigned char bool
Definition: stdbool.h:25
static bool delete_obj(TObject *&object)
Definition: ne_stl_memory.h:47