Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Unified Diff: core/include/fxcrt/fx_basic.h

Issue 889673003: Replace CFX_SmartPointer cast operator with Get() method. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698