aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-27 11:21:36 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-27 11:21:36 +0000
commit4d2b4b9f631cea8744b56b44adf3cf05d9e0c3aa (patch)
treec2d9d3413c28661a388cfbb8bdaa5d6928c28f21
parent571329770d39cabccccb6d2f3858f64066d72e0c (diff)
downloadpaludis-4d2b4b9f631cea8744b56b44adf3cf05d9e0c3aa.tar.gz
paludis-4d2b4b9f631cea8744b56b44adf3cf05d9e0c3aa.tar.xz
Add assign, zero methods to CountedPtr for convenience.
-rw-r--r--paludis/counted_ptr.hh32
-rw-r--r--paludis/counted_ptr_TEST.cc12
2 files changed, 44 insertions, 0 deletions
diff --git a/paludis/counted_ptr.hh b/paludis/counted_ptr.hh
index 2f1c191..783df2d 100644
--- a/paludis/counted_ptr.hh
+++ b/paludis/counted_ptr.hh
@@ -419,6 +419,22 @@ namespace paludis
}
/**
+ * Explicit assignment, from a raw pointer.
+ */
+ const CountedPtr & assign(T_ * const other)
+ {
+ return operator= (CountedPtr<T_, count_policy::ExternalCountTag>(other));
+ }
+
+ /**
+ * Explicit assignment to zero.
+ */
+ const CountedPtr & zero()
+ {
+ return operator= (CountedPtr<T_, count_policy::ExternalCountTag>(0));
+ }
+
+ /**
* Fetch our reference count pointer.
*/
unsigned * reference_count_pointer() const
@@ -498,6 +514,22 @@ namespace paludis
}
/**
+ * Explicit assignment, from a raw pointer.
+ */
+ const CountedPtr & assign(T_ * const other)
+ {
+ return operator= (CountedPtr<T_, count_policy::InternalCountTag>(other));
+ }
+
+ /**
+ * Explicit assignment to zero.
+ */
+ const CountedPtr & zero()
+ {
+ return operator= (CountedPtr<T_, count_policy::InternalCountTag>(0));
+ }
+
+ /**
* Fetch our reference count pointer.
*/
unsigned * reference_count_pointer() const
diff --git a/paludis/counted_ptr_TEST.cc b/paludis/counted_ptr_TEST.cc
index 30df20c..5e2c9a0 100644
--- a/paludis/counted_ptr_TEST.cc
+++ b/paludis/counted_ptr_TEST.cc
@@ -208,6 +208,12 @@ namespace test_cases
TEST_CHECK_EQUAL(*i, 30);
TEST_CHECK_EQUAL(*i2, 10);
TEST_CHECK_EQUAL(*i3, 30);
+
+ i.assign(new int(50));
+ TEST_CHECK_EQUAL(*i, 50);
+
+ i.zero();
+ TEST_CHECK(! i);
}
} test_counted_ptr_assign_pointer;
@@ -344,6 +350,12 @@ namespace test_cases
TEST_CHECK_EQUAL(*i, 30);
TEST_CHECK_EQUAL(*i2, 10);
TEST_CHECK_EQUAL(*i3, 30);
+
+ i.assign(new MyClass(50));
+ TEST_CHECK_EQUAL(*i, 50);
+
+ i.zero();
+ TEST_CHECK(! i);
}
} test_counted_ptr_internal_assign_pointer;