aboutsummaryrefslogtreecommitdiffstats
path: root/libtests
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 /libtests
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 'libtests')
-rw-r--r--libtests/pointer_holder.cc16
-rw-r--r--libtests/qtest/ph/ph.out12
2 files changed, 21 insertions, 7 deletions
diff --git a/libtests/pointer_holder.cc b/libtests/pointer_holder.cc
index 469bfc21..913449e4 100644
--- a/libtests/pointer_holder.cc
+++ b/libtests/pointer_holder.cc
@@ -4,8 +4,6 @@
#include <stdlib.h>
#include <list>
-#include <qpdf/QUtil.hh>
-
class Object
{
public:
@@ -47,13 +45,20 @@ Object::hello() const
typedef PointerHolder<Object> ObjectHolder;
-void callHello(ObjectHolder const& oh)
+void callHello(ObjectHolder& oh)
{
oh.getPointer()->hello();
oh->hello();
(*oh).hello();
}
+void callHelloWithGet(ObjectHolder const& oh)
+{
+ oh.get()->hello();
+ oh->hello();
+ (*oh).hello();
+}
+
int main(int argc, char* argv[])
{
std::list<ObjectHolder> ol1;
@@ -66,7 +71,7 @@ int main(int argc, char* argv[])
std::cout << "oh1 refcount = " << oh1.getRefcount() << std::endl;
ObjectHolder oh2(oh1);
std::cout << "oh1 refcount = " << oh1.getRefcount() << std::endl;
- std::cout << "oh2 refcount = " << oh2.getRefcount() << std::endl;
+ std::cout << "oh2 refcount = " << oh2.use_count() << std::endl;
ObjectHolder oh3(new Object);
ObjectHolder oh4;
ObjectHolder oh5;
@@ -89,12 +94,15 @@ int main(int argc, char* argv[])
ol1.push_back(oh3);
Object* o3 = new Object;
oh0 = o3;
+ PointerHolder<Object const> oh6(new Object());
+ oh6->hello();
}
ol1.front().getPointer()->hello();
ol1.front()->hello();
(*ol1.front()).hello();
callHello(ol1.front());
+ callHelloWithGet(ol1.front());
ol1.pop_front();
std::cout << "array" << std::endl;
PointerHolder<Object> oarr1_ph(true, new Object[2]);
diff --git a/libtests/qtest/ph/ph.out b/libtests/qtest/ph/ph.out
index 5d249712..a7efe1bb 100644
--- a/libtests/qtest/ph/ph.out
+++ b/libtests/qtest/ph/ph.out
@@ -10,17 +10,23 @@ destroyed Object, id 2
equal okay
less than okay
created Object, id 3
+created Object, id 4
+calling Object::hello const for 4
+destroyed Object, id 4
+calling Object::hello for 1
+calling Object::hello for 1
+calling Object::hello for 1
+calling Object::hello for 1
calling Object::hello for 1
calling Object::hello for 1
calling Object::hello for 1
-calling Object::hello const for 1
calling Object::hello const for 1
calling Object::hello const for 1
array
-created Object, id 4
created Object, id 5
+created Object, id 6
goodbye
+destroyed Object, id 6
destroyed Object, id 5
-destroyed Object, id 4
destroyed Object, id 3
destroyed Object, id 1