aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/qpdf/PointerHolder.hh18
-rw-r--r--libtests/pointer_holder.cc17
-rw-r--r--libtests/qtest/ph/ph.out5
3 files changed, 40 insertions, 0 deletions
diff --git a/include/qpdf/PointerHolder.hh b/include/qpdf/PointerHolder.hh
index ad5d1039..6ff69117 100644
--- a/include/qpdf/PointerHolder.hh
+++ b/include/qpdf/PointerHolder.hh
@@ -124,6 +124,24 @@ class PointerHolder
return this->data->refcount;
}
+ T const& operator*() const
+ {
+ return *this->data->pointer;
+ }
+ T& operator*()
+ {
+ return *this->data->pointer;
+ }
+
+ T const* operator->() const
+ {
+ return this->data->pointer;
+ }
+ T* operator->()
+ {
+ return this->data->pointer;
+ }
+
private:
void init(Data* data)
{
diff --git a/libtests/pointer_holder.cc b/libtests/pointer_holder.cc
index 173a8266..c255df5a 100644
--- a/libtests/pointer_holder.cc
+++ b/libtests/pointer_holder.cc
@@ -12,6 +12,7 @@ class Object
Object();
~Object();
void hello();
+ void hello() const;
private:
static int next_id;
@@ -38,8 +39,21 @@ Object::hello()
std::cout << "calling Object::hello for " << this->id << std::endl;
}
+void
+Object::hello() const
+{
+ std::cout << "calling Object::hello const for " << this->id << std::endl;
+}
+
typedef PointerHolder<Object> ObjectHolder;
+void callHello(ObjectHolder const& oh)
+{
+ oh.getPointer()->hello();
+ oh->hello();
+ (*oh).hello();
+}
+
int main(int argc, char* argv[])
{
std::list<ObjectHolder> ol1;
@@ -74,6 +88,9 @@ int main(int argc, char* argv[])
}
ol1.front().getPointer()->hello();
+ ol1.front()->hello();
+ (*ol1.front()).hello();
+ callHello(ol1.front());
ol1.pop_front();
std::cout << "goodbye" << std::endl;
return 0;
diff --git a/libtests/qtest/ph/ph.out b/libtests/qtest/ph/ph.out
index 37f63822..1326e489 100644
--- a/libtests/qtest/ph/ph.out
+++ b/libtests/qtest/ph/ph.out
@@ -7,6 +7,11 @@ equal okay
less than okay
created Object, id 3
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
goodbye
destroyed Object, id 3
destroyed Object, id 1