summaryrefslogtreecommitdiff
path: root/core/fxcrt
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt')
-rw-r--r--core/fxcrt/cfx_count_ref_unittest.cpp9
-rw-r--r--core/fxcrt/include/cfx_count_ref.h11
2 files changed, 8 insertions, 12 deletions
diff --git a/core/fxcrt/cfx_count_ref_unittest.cpp b/core/fxcrt/cfx_count_ref_unittest.cpp
index 2a36292b54..7651c93f25 100644
--- a/core/fxcrt/cfx_count_ref_unittest.cpp
+++ b/core/fxcrt/cfx_count_ref_unittest.cpp
@@ -109,19 +109,16 @@ TEST(fxcrt, CountRefGetModify) {
Observer observer;
{
CFX_CountRef<Object> ptr;
- ptr.MakePrivateCopy(&observer, std::string("one"));
- EXPECT_NE(nullptr, ptr.GetObject());
+ EXPECT_NE(nullptr, ptr.GetPrivateCopy(&observer, std::string("one")));
EXPECT_EQ(1, observer.GetConstructionCount("one"));
EXPECT_EQ(0, observer.GetDestructionCount("one"));
- ptr.MakePrivateCopy(&observer, std::string("one"));
- EXPECT_NE(nullptr, ptr.GetObject());
+ EXPECT_NE(nullptr, ptr.GetPrivateCopy(&observer, std::string("one")));
EXPECT_EQ(1, observer.GetConstructionCount("one"));
EXPECT_EQ(0, observer.GetDestructionCount("one"));
{
CFX_CountRef<Object> other(ptr);
- ptr.MakePrivateCopy(&observer, std::string("one"));
- EXPECT_NE(nullptr, ptr.GetObject());
+ EXPECT_NE(nullptr, ptr.GetPrivateCopy(&observer, std::string("one")));
EXPECT_EQ(2, observer.GetConstructionCount("one"));
EXPECT_EQ(0, observer.GetDestructionCount("one"));
}
diff --git a/core/fxcrt/include/cfx_count_ref.h b/core/fxcrt/include/cfx_count_ref.h
index 0837894c66..817ce95add 100644
--- a/core/fxcrt/include/cfx_count_ref.h
+++ b/core/fxcrt/include/cfx_count_ref.h
@@ -29,16 +29,17 @@ class CFX_CountRef {
return *this;
}
- void Clear() { m_pObject.Reset(); }
+ void SetNull() { m_pObject.Reset(); }
ObjClass* GetObject() { return m_pObject.Get(); }
const ObjClass* GetObject() const { return m_pObject.Get(); }
template <typename... Args>
- void MakePrivateCopy(Args... params) {
+ ObjClass* GetPrivateCopy(Args... params) {
if (!m_pObject)
- m_pObject.Reset(new CountedObj(params...));
- else if (!m_pObject->HasOneRef())
+ return New(params...);
+ if (!m_pObject->HasOneRef())
m_pObject.Reset(new CountedObj(*m_pObject));
+ return m_pObject.Get();
}
bool operator==(const CFX_CountRef& that) const {
@@ -46,8 +47,6 @@ class CFX_CountRef {
}
bool operator!=(const CFX_CountRef& that) const { return !(*this == that); }
operator bool() const { return m_pObject; }
- ObjClass& operator*() const { return *m_pObject.Get(); }
- ObjClass* operator->() const { return m_pObject.Get(); }
private:
class CountedObj : public ObjClass {