22 template<
typename _Ty>
34 static std::mutex
mtx;
87 ptr = smartPointer.ptr;
88 smartPointer.ptr =
nullptr;
108 std::lock_guard<std::mutex> lockGuard(mtx);
131 std::lock_guard<std::mutex> lockGuard(mtx);
132 if (this->ptr == ptr)
135 construct((_Ty*)ptr);
138 this->ptr = (_Ty*)ptr;
155 inline auto get()
const -> _Ty*
194 static void construct(_Ty *ptr)
199 if (useCountMap.find(ptr) != useCountMap.end())
202 useCountMap[
ptr] = 1;
204 static void destruct(_Ty *ptr)
209 if (useCountMap.find(ptr) != useCountMap.end())
210 if (--useCountMap[ptr] == 0)
212 useCountMap.erase(ptr);
SmartPointer(const _Ty *ptr)
Constrct from pointer.
auto operator->() const -> _Ty *
Dereference object membr.
SmartPointer(SmartPointer &&smartPointer)
Move constructor.
void reset(const _Ty *ptr)
Reset pointer.
static std::mutex mtx
Mutex assigned to useCountMap.
~SmartPointer()
Destroy SmartPointer.
SmartPointer(const SmartPointer &smartPointer)
Copy Constructor.
SmartPointer()
Default Constructor.
_Ty * ptr
A pointer managed by SmartPointer.
auto operator*() const -> _Ty &
Dereference object.
static std::map< _Ty *, size_t > useCountMap
TreeMap of use count of each pointer.