aboutsummaryrefslogtreecommitdiffstats
path: root/include/qpdf/PointerHolder.hh
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-02-04 15:46:55 +0100
committerJay Berkenbilt <ejb@ql.org>2022-02-04 19:12:37 +0100
commitf727bc94432905d79af23cf0aef14854965da2cd (patch)
treef4d3d41c28bb0f1536bf609bcbbdb2ec83b339dd /include/qpdf/PointerHolder.hh
parentf76191f0c217f48b5a935fa7170771fdfb66e2cb (diff)
downloadqpdf-f727bc94432905d79af23cf0aef14854965da2cd.tar.zst
PointerHolder: add get() and use_count() for forward compatibility
PointerHolder will be replaced with shared_ptr, so let people start moving.
Diffstat (limited to 'include/qpdf/PointerHolder.hh')
-rw-r--r--include/qpdf/PointerHolder.hh20
1 files changed, 20 insertions, 0 deletions
diff --git a/include/qpdf/PointerHolder.hh b/include/qpdf/PointerHolder.hh
index a85df8bb..bc60f7f0 100644
--- a/include/qpdf/PointerHolder.hh
+++ b/include/qpdf/PointerHolder.hh
@@ -22,6 +22,14 @@
#ifndef POINTERHOLDER_HH
#define POINTERHOLDER_HH
+// In qpdf 11, PointerHolder will be derived from std::shared_ptr and
+// will also include a fix to incorrect semantics of const
+// PointerHolder objects. PointerHolder only allows a const
+// PointerHolder to return a const pointer. This is wrong. Use a
+// PointerHolder<const T> for that. A const PointerHolder should just
+// not allow you to change what it points to. This is consistent with
+// how regular pointers and standard library shared pointers work.
+
// This class is basically std::shared_ptr but predates that by
// several years.
@@ -119,6 +127,12 @@ class PointerHolder
return this->data->pointer < rhs.data->pointer;
}
+ // get() is for interface compatibility with std::shared_ptr
+ T* get() const
+ {
+ return this->data->pointer;
+ }
+
// NOTE: The pointer returned by getPointer turns into a pumpkin
// when the last PointerHolder that contains it disappears.
T* getPointer()
@@ -134,6 +148,12 @@ class PointerHolder
return this->data->refcount;
}
+ // use_count() is for compatibility with std::shared_ptr
+ long use_count()
+ {
+ return static_cast<long>(this->data->refcount);
+ }
+
T const& operator*() const
{
return *this->data->pointer;