Chromium Code Reviews| Index: core/include/fxcrt/fx_basic.h |
| diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h |
| index 7ad44c6b4d7208a221de80a70c27aaf6944b9e14..2ffa9690525381095ab2987ec85dedd4f7ef24a3 100644 |
| --- a/core/include/fxcrt/fx_basic.h |
| +++ b/core/include/fxcrt/fx_basic.h |
| @@ -1429,30 +1429,49 @@ private: |
| T m_OldValue; |
| }; |
| +// For objects which support a Release() method as opposed to outright |
| +// explicit deletion. |
| template <class T> |
| class CFX_SmartPointer |
| { |
| public: |
| + CFX_SmartPointer() : m_pObj(nullptr) {} |
| CFX_SmartPointer(T *pObj) : m_pObj(pObj) {} |
| + CFX_SmartPointer(const CFX_SmartPointer<T>&) = delete; |
| ~CFX_SmartPointer() |
| { |
| - m_pObj->Release(); |
| + if (m_pObj) |
| + m_pObj->Release(); |
| } |
| - operator T*(void) |
| + T* Get() |
| { |
| return m_pObj; |
| } |
| - T& operator *(void) |
| + T* TakeOwnership() |
| + { |
| + T* result = m_pObj; |
| + m_pObj = nullptr; |
| + return result; |
| + } |
| + T& operator* (void) |
| { |
| return *m_pObj; |
| } |
| - T* operator ->(void) |
| + T* operator-> (void) |
| { |
| return m_pObj; |
| } |
| + T& operator= (const T* that) |
| + { |
| + if (m_pObj) |
| + m_pObj->Release(); |
| + m_pObj = that; |
|
dcheng
2015/01/31 01:41:30
I wonder if we need to worry about bizarre code li
|
| + } |
| + T& operator= (const CFX_SmartPointer<T>&) = delete; |
| protected: |
| T *m_pObj; |
| }; |
| + |
| #define FX_DATALIST_LENGTH 1024 |
| template<size_t unit> |
| class CFX_SortListArray : public CFX_Object |