You.i Engine
YiSharedPtr.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. All rights reserved.
2 #ifndef _YI_SHARED_PTR_H_
3 #define _YI_SHARED_PTR_H_
4 
5 #include "utility/YiRtti.h"
6 #include "utility/YiError.h"
7 
11 
12 #include <memory>
13 
19 template<typename YI_PTR_TYPE>
20 class CYIWeakPtr;
21 
117 template<typename YI_PTR_TYPE>
119 {
120  template<typename YI_OTHER_PTR_TYPE> friend class CYIWeakPtr;
121  template<typename YI_OTHER_PTR_TYPE> friend class CYISharedPtr;
122  template<typename YI_OTHER_PTR_TYPE>
124 
125 public:
129  CYISharedPtr();
130 
135  explicit CYISharedPtr(YI_PTR_TYPE *pData);
136 
140  explicit CYISharedPtr(YI_PTR_TYPE *pData, typename CYICallbackDeleter<YI_PTR_TYPE>::YI_CALLBACK pCallback);
141 
145  template<typename YI_FUNCTION_OBJECT>
146  explicit CYISharedPtr(YI_PTR_TYPE *pData, YI_FUNCTION_OBJECT functor);
147 
151  template<typename YI_OTHER_TYPE>
152  CYISharedPtr(const std::shared_ptr<YI_OTHER_TYPE> &pShared);
153 
159  template<typename YI_OTHER_PTR_TYPE>
161 
166  CYISharedPtr(const CYIWeakPtr<YI_PTR_TYPE> &rOther) = delete; // Removed because the std::shared_ptr version throws when the weak pointer is empty
167 
173  template<typename YI_OTHER_PTR_TYPE>
174  CYISharedPtr(const CYIWeakPtr<YI_OTHER_PTR_TYPE> &rOther) = delete; // Removed because the std::shared_ptr version throws when the weak pointer is empty
175 
179  ~CYISharedPtr();
180 
186  void Reset();
187 
203  YI_PTR_TYPE &operator*() const;
204 
219  YI_PTR_TYPE *operator->() const;
220 
243  bool operator!() const;
244 
267  operator bool() const;
268 
269  template<typename YI_OTHER_PTR_TYPE>
270  operator std::shared_ptr<YI_OTHER_PTR_TYPE>() const;
271 
280  template<typename YI_OTHER_PTR_TYPE>
281  CYISharedPtr<YI_PTR_TYPE> &operator=(const std::shared_ptr<YI_OTHER_PTR_TYPE> &rOther);
282 
291  template<typename YI_OTHER_PTR_TYPE>
293 
302  CYISharedPtr<YI_PTR_TYPE> &operator=(const CYIWeakPtr<YI_PTR_TYPE> &rOther) = delete; // Removed because this is not present on std::shared_ptr
303 
312  template<typename YI_OTHER_PTR_TYPE>
313  CYISharedPtr<YI_PTR_TYPE> &operator=(const CYIWeakPtr<YI_OTHER_PTR_TYPE> &rOther) = delete; // Removed because this is not present on std::shared_ptr
314 
333  YI_PTR_TYPE *Get() const;
334 
357  bool IsNull() const;
358 
369  bool IsUnique() const;
370 
374  uint32_t GetUseCount() const;
375 
399  void Swap(CYISharedPtr<YI_PTR_TYPE> &rPtr);
400 
419 
451  template<typename YI_OTHER_PTR_TYPE>
453 
523  template<typename YI_OTHER_PTR_TYPE>
525 
541  const CYIRuntimeTypeInfo *GetRuntimeTypeInfo() const;
542 
548  static const CYIRuntimeTypeInfo &GetClassTypeInfo();
549 
550 #if YI_LOG_SHARED_PTR_COUNTS
551 
554  void EnableCountsLogging();
555 #endif
556 
557 private:
558  std::shared_ptr<YI_PTR_TYPE> m_pShared;
559 };
560 
563 #include "smartptr/YiSharedPtr.inl"
564 
565 #endif /* _YI_SHARED_PTR_H_ */
static const CYIRuntimeTypeInfo & GetClassTypeInfo()
bool IsNull() const
CYISharedPtr< YI_OTHER_PTR_TYPE > DynamicCast() const
The CYIWeakPtr is a smart pointer that does not take any ownership of a dynamically allocated object...
Definition: YiSharedPtr.h:20
const CYIRuntimeTypeInfo * GetRuntimeTypeInfo() const
uint32_t GetUseCount() const
void Swap(CYISharedPtr< YI_PTR_TYPE > &rPtr)
bool operator!() const
YI_PTR_TYPE * operator->() const
bool IsUnique() const
CYISharedPtr< YI_OTHER_PTR_TYPE > StaticCast() const
YI_PTR_TYPE * Get() const
The CYISharedPtr is a smart pointer that takes a shared ownership of a dynamically allocated object...
Definition: YiSharedPtr.h:118
The abstract runtime representation of a C++ type.
Definition: YiRtti.h:48
YI_PTR_TYPE & operator*() const
CYISharedPtr< YI_PTR_TYPE > & operator=(const std::shared_ptr< YI_OTHER_PTR_TYPE > &rOther)
CYIEnableSharedFromThis<T> allows an object currently managed by a CYISharedPtr to safely generation ...
Definition: YiEnableSharedFromThis.h:61
This file contains the classes and macros used to implement RTTI in You.i Engine. ...
Definition: YiCallbackDeleter.h:41
CYIWeakPtr< YI_PTR_TYPE > ToWeakPtr() const