Commit 5039da0b91a981b438cbb1c7a7325fde12e2632b

Authored by Jay Berkenbilt
1 parent d88231e0

Add QPDFObjectHandle::getObjGen()

This is safer than getObjectID() and getGeneration() for many uses.
ChangeLog
1 1 2013-06-14 Jay Berkenbilt <ejb@ql.org>
2 2  
  3 + * Add new QPDFObjectHandle::getObjGen() method and indiciate in
  4 + comments that its use is favored over getObjectID() and
  5 + getGeneration() for most cases.
  6 +
3 7 * Add new QPDFObjGen object to represent an object ID/generation
4 8 pair.
5 9  
... ...
include/qpdf/QPDFObjectHandle.hh
... ... @@ -16,6 +16,7 @@
16 16 #include <set>
17 17 #include <map>
18 18  
  19 +#include <qpdf/QPDFObjGen.hh>
19 20 #include <qpdf/PointerHolder.hh>
20 21 #include <qpdf/Buffer.hh>
21 22 #include <qpdf/InputSource.hh>
... ... @@ -454,7 +455,17 @@ class QPDFObjectHandle
454 455 QPDFObjectHandle const& filter,
455 456 QPDFObjectHandle const& decode_parms);
456 457  
457   - // return 0 for direct objects
  458 + // Access object ID and generation. For direct objects, return
  459 + // object ID 0.
  460 +
  461 + // NOTE: Be careful about calling getObjectID() and
  462 + // getGeneration() directly as this can lead to the pattern of
  463 + // depending on object ID or generation without the other. In
  464 + // general, when keeping track of object IDs, it's better to use
  465 + // QPDFObjGen instead.
  466 +
  467 + QPDF_DLL
  468 + QPDFObjGen getObjGen() const;
458 469 QPDF_DLL
459 470 int getObjectID() const;
460 471 QPDF_DLL
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -535,6 +535,12 @@ QPDFObjectHandle::replaceStreamData(PointerHolder&lt;StreamDataProvider&gt; provider,
535 535 provider, filter, decode_parms);
536 536 }
537 537  
  538 +QPDFObjGen
  539 +QPDFObjectHandle::getObjGen() const
  540 +{
  541 + return QPDFObjGen(this->objid, this->generation);
  542 +}
  543 +
538 544 int
539 545 QPDFObjectHandle::getObjectID() const
540 546 {
... ...