25 #ifndef __I6ENGINE_UTILS_SHAREDPTR_H__
26 #define __I6ENGINE_UTILS_SHAREDPTR_H__
49 template<
typename T,
typename U>
52 template<
typename T,
typename Base>
55 template<
typename T1,
typename T2,
typename U>
58 template<
typename T,
typename U,
typename... Args>
67 template<
typename T,
typename U>
69 template<
typename T1,
typename T2,
typename U1>
71 template<
typename T1,
typename U2,
typename... Args>
74 template<
typename V,
typename W>
76 template<
typename V,
typename W>
84 sharedPtr() : _sharedPtrWrapper(nullptr), _ptr(nullptr) {
90 explicit sharedPtr(T * ptr) : _sharedPtrWrapper(nullptr), _ptr(ptr) {
91 _sharedPtrWrapper = std::make_shared<sharedPtrWrapper<U>>(ptr);
97 sharedPtr(
const sharedPtr & other) : _sharedPtrWrapper(other._sharedPtrWrapper), _ptr(other._ptr) {
104 other._sharedPtrWrapper =
nullptr;
105 other._ptr =
nullptr;
125 if (*
this == other) {
128 _sharedPtrWrapper = other._sharedPtrWrapper;
138 if (*
this == other) {
141 _sharedPtrWrapper = other._sharedPtrWrapper;
143 other._sharedPtrWrapper =
nullptr;
144 other._ptr =
nullptr;
154 if (*
this == other) {
157 _sharedPtrWrapper = other._sharedPtrWrapper;
174 return _ptr == other._ptr;
181 return _ptr == other;
185 return self == other;
189 return !(*
this == other);
193 return self != other;
197 return !(*
this == other);
208 sharedPtr<U, U>::clearList.clear();
219 std::shared_ptr<sharedPtrWrapper<U>> _sharedPtrWrapper;
228 static std::mutex clearListLock;
229 static std::list<U *> clearList;
232 template<
typename T,
typename U> std::mutex sharedPtr<T, U>::clearListLock;
233 template<
typename T,
typename U> std::list<U *> sharedPtr<T, U>::clearList;
244 template<
typename T1,
typename T2,
typename U>
246 T1 * t1 =
dynamic_cast<T1 *
>(base._ptr);
257 template<
typename T,
typename U,
typename... Args>
262 T * ptr =
new T(args...);
263 std::shared_ptr<sharedPtrWrapper<U>> sC = std::make_shared<sharedPtrWrapper<U>>(ptr);
friend sharedPtr< T1, U2 > make_shared(Args &&...)
T * operator->() const
-> operator returning stored pointer
bool operator!=(const T *other) const
sharedPtr(T *ptr)
normal constructor taking pointer to object to be stored
const sharedPtr & operator=(const sharedPtr &other)
assignment operator
A weak pointer observing a sharedPtr.
friend bool operator!=(const T *other, const sharedPtr &self)
struct handling threadsafe destruction of the wrapped pointer
~sharedPtr()
destructor, adding pointer of object to clearList if last reference was deleted
const sharedPtr & operator=(const sharedPtr< V, U > &other)
upcast, derived => base
const sharedPtr & operator=(sharedPtr &&other)
move assignment operator
friend sharedPtr< T1, U1 > dynamic_pointer_cast(const sharedPtr< T2, U1 > &)
T * get_pointer(const sharedPtr< T, U > &p)
gets pointer of a shared pointer necessary for luabind and boost::python
static void clear()
deletes all pointers in clearList
A shared pointer counting references and adds objects being not referenced any more to an internal li...
sharedPtr(const sharedPtr< V, U > &other)
upcast derived => base
sharedPtr< T1, U > dynamic_pointer_cast(const sharedPtr< T2, U > &)
casts a sharedPtr of dynamic type T2 to dynamic type T1
T * get() const
returns the contained pointer
sharedPtr< T, U > make_shared(Args &&...)
sharedPtr()
default constructor creating a sharedPtr containing a nullptr
bool operator==(const sharedPtr &other) const
comparison between two shared pointer
bool operator==(const T *other) const
comparison between shared and normal pointer
sharedPtr(sharedPtr &&other)
move constructor
friend bool operator==(const T *other, const sharedPtr &self)
sharedPtr(const sharedPtr &other)
copy constructor sharing reference and incrementing refCounter
bool operator!=(const sharedPtr &other) const