21 template<
typename _Ty>
33 static std::mutex
mtx;
86 ptr = smartPointer.ptr;
87 smartPointer.ptr =
nullptr;
107 std::lock_guard<std::mutex> lockGuard(mtx);
130 std::lock_guard<std::mutex> lockGuard(mtx);
131 if (this->ptr == ptr)
134 construct((_Ty*)ptr);
137 this->ptr = (_Ty*)ptr;
154 inline auto get()
const -> _Ty*
193 static void construct(_Ty *ptr)
198 if (useCountMap.find(ptr) != useCountMap.end())
201 useCountMap[
ptr] = 1;
203 static void destruct(_Ty *ptr)
208 if (useCountMap.find(ptr) != useCountMap.end())
209 if (--useCountMap[ptr] == 0)
211 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.
Top level namespace of products built from samchon.
static std::map< _Ty *, size_t > useCountMap
Map of use count of each pointer.