Commit 4b73d057fb637bb2c2810aaf9fefdfe9b8beaef6
1 parent
f7978db1
QPDFObjGen : tidy QPDF_Stream
Change method signatures to use QPDFObjGen. Replace QPDF_Stream::objid and generation with QPDF_Stream::og.
Showing
3 changed files
with
24 additions
and
35 deletions
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -2634,8 +2634,8 @@ QPDFObjectHandle::newStream( |
| 2634 | 2634 | qpdf_offset_t offset, |
| 2635 | 2635 | size_t length) |
| 2636 | 2636 | { |
| 2637 | - QPDFObjectHandle result = QPDFObjectHandle(QPDF_Stream::create( | |
| 2638 | - qpdf, og.getObj(), og.getGen(), stream_dict, offset, length)); | |
| 2637 | + QPDFObjectHandle result = QPDFObjectHandle( | |
| 2638 | + QPDF_Stream::create(qpdf, og, stream_dict, offset, length)); | |
| 2639 | 2639 | if (offset) { |
| 2640 | 2640 | result.setParsedOffset(offset); |
| 2641 | 2641 | } |
| ... | ... | @@ -2651,11 +2651,11 @@ QPDFObjectHandle::newStream(QPDF* qpdf) |
| 2651 | 2651 | } |
| 2652 | 2652 | QTC::TC("qpdf", "QPDFObjectHandle newStream"); |
| 2653 | 2653 | QPDFObjectHandle stream_dict = newDictionary(); |
| 2654 | - QPDFObjectHandle result = qpdf->makeIndirectObject( | |
| 2655 | - QPDFObjectHandle(QPDF_Stream::create(qpdf, 0, 0, stream_dict, 0, 0))); | |
| 2654 | + QPDFObjectHandle result = qpdf->makeIndirectObject(QPDFObjectHandle( | |
| 2655 | + QPDF_Stream::create(qpdf, QPDFObjGen(), stream_dict, 0, 0))); | |
| 2656 | 2656 | result.dereference(); |
| 2657 | 2657 | QPDF_Stream* stream = dynamic_cast<QPDF_Stream*>(result.obj.get()); |
| 2658 | - stream->setObjGen(result.getObjectID(), result.getGeneration()); | |
| 2658 | + stream->setObjGen(result.getObjGen()); | |
| 2659 | 2659 | return result; |
| 2660 | 2660 | } |
| 2661 | 2661 | ... | ... |
libqpdf/QPDF_Stream.cc
| ... | ... | @@ -110,14 +110,12 @@ StreamBlobProvider::operator()(Pipeline* p) |
| 110 | 110 | |
| 111 | 111 | QPDF_Stream::QPDF_Stream( |
| 112 | 112 | QPDF* qpdf, |
| 113 | - int objid, | |
| 114 | - int generation, | |
| 113 | + QPDFObjGen const& og, | |
| 115 | 114 | QPDFObjectHandle stream_dict, |
| 116 | 115 | qpdf_offset_t offset, |
| 117 | 116 | size_t length) : |
| 118 | 117 | qpdf(qpdf), |
| 119 | - objid(objid), | |
| 120 | - generation(generation), | |
| 118 | + og(og), | |
| 121 | 119 | filter_on_write(true), |
| 122 | 120 | stream_dict(stream_dict), |
| 123 | 121 | offset(offset), |
| ... | ... | @@ -128,22 +126,18 @@ QPDF_Stream::QPDF_Stream( |
| 128 | 126 | "object for dictionary"); |
| 129 | 127 | } |
| 130 | 128 | setDescription( |
| 131 | - this->qpdf, | |
| 132 | - this->qpdf->getFilename() + ", stream object " + | |
| 133 | - QPDFObjGen(objid, generation).unparse(' ')); | |
| 129 | + qpdf, qpdf->getFilename() + ", stream object " + og.unparse(' ')); | |
| 134 | 130 | } |
| 135 | 131 | |
| 136 | 132 | std::shared_ptr<QPDFObject> |
| 137 | 133 | QPDF_Stream::create( |
| 138 | 134 | QPDF* qpdf, |
| 139 | - int objid, | |
| 140 | - int generation, | |
| 135 | + QPDFObjGen const& og, | |
| 141 | 136 | QPDFObjectHandle stream_dict, |
| 142 | 137 | qpdf_offset_t offset, |
| 143 | 138 | size_t length) |
| 144 | 139 | { |
| 145 | - return do_create( | |
| 146 | - new QPDF_Stream(qpdf, objid, generation, stream_dict, offset, length)); | |
| 140 | + return do_create(new QPDF_Stream(qpdf, og, stream_dict, offset, length)); | |
| 147 | 141 | } |
| 148 | 142 | |
| 149 | 143 | std::shared_ptr<QPDFObject> |
| ... | ... | @@ -180,22 +174,21 @@ QPDF_Stream::releaseResolved() |
| 180 | 174 | } |
| 181 | 175 | |
| 182 | 176 | void |
| 183 | -QPDF_Stream::setObjGen(int objid, int generation) | |
| 177 | +QPDF_Stream::setObjGen(QPDFObjGen const& og) | |
| 184 | 178 | { |
| 185 | - if (!((this->objid == 0) && (this->generation == 0))) { | |
| 179 | + if (this->og.isIndirect()) { | |
| 186 | 180 | throw std::logic_error( |
| 187 | 181 | "attempt to set object ID and generation of a stream" |
| 188 | 182 | " that already has them"); |
| 189 | 183 | } |
| 190 | - this->objid = objid; | |
| 191 | - this->generation = generation; | |
| 184 | + this->og = og; | |
| 192 | 185 | } |
| 193 | 186 | |
| 194 | 187 | std::string |
| 195 | 188 | QPDF_Stream::unparse() |
| 196 | 189 | { |
| 197 | 190 | // Unparse stream objects as indirect references |
| 198 | - return QPDFObjGen(objid, generation).unparse(' ') + " R"; | |
| 191 | + return og.unparse(' ') + " R"; | |
| 199 | 192 | } |
| 200 | 193 | |
| 201 | 194 | JSON |
| ... | ... | @@ -617,8 +610,8 @@ QPDF_Stream::pipeStreamData( |
| 617 | 610 | Pl_Count count("stream provider count", pipeline); |
| 618 | 611 | if (this->stream_provider->supportsRetry()) { |
| 619 | 612 | if (!this->stream_provider->provideStreamData( |
| 620 | - this->objid, | |
| 621 | - this->generation, | |
| 613 | + og.getObj(), | |
| 614 | + og.getGen(), | |
| 622 | 615 | &count, |
| 623 | 616 | suppress_warnings, |
| 624 | 617 | will_retry)) { |
| ... | ... | @@ -627,7 +620,7 @@ QPDF_Stream::pipeStreamData( |
| 627 | 620 | } |
| 628 | 621 | } else { |
| 629 | 622 | this->stream_provider->provideStreamData( |
| 630 | - this->objid, this->generation, &count); | |
| 623 | + og.getObj(), og.getGen(), &count); | |
| 631 | 624 | } |
| 632 | 625 | qpdf_offset_t actual_length = count.getCount(); |
| 633 | 626 | qpdf_offset_t desired_length = 0; |
| ... | ... | @@ -640,9 +633,8 @@ QPDF_Stream::pipeStreamData( |
| 640 | 633 | // This would be caused by programmer error on the |
| 641 | 634 | // part of a library user, not by invalid input data. |
| 642 | 635 | throw std::runtime_error( |
| 643 | - "stream data provider for " + | |
| 644 | - QPDFObjGen(objid, generation).unparse(' ') + " provided " + | |
| 645 | - QUtil::int_to_string(actual_length) + | |
| 636 | + "stream data provider for " + og.unparse(' ') + | |
| 637 | + " provided " + QUtil::int_to_string(actual_length) + | |
| 646 | 638 | " bytes instead of expected " + |
| 647 | 639 | QUtil::int_to_string(desired_length) + " bytes"); |
| 648 | 640 | } |
| ... | ... | @@ -658,7 +650,7 @@ QPDF_Stream::pipeStreamData( |
| 658 | 650 | QTC::TC("qpdf", "QPDF_Stream pipe original stream data"); |
| 659 | 651 | if (!QPDF::Pipe::pipeStreamData( |
| 660 | 652 | this->qpdf, |
| 661 | - QPDFObjGen(this->objid, this->generation), | |
| 653 | + og, | |
| 662 | 654 | this->offset, |
| 663 | 655 | this->length, |
| 664 | 656 | this->stream_dict, | ... | ... |
libqpdf/qpdf/QPDF_Stream.hh
| ... | ... | @@ -19,8 +19,7 @@ class QPDF_Stream: public QPDFObject |
| 19 | 19 | virtual ~QPDF_Stream() = default; |
| 20 | 20 | static std::shared_ptr<QPDFObject> create( |
| 21 | 21 | QPDF*, |
| 22 | - int objid, | |
| 23 | - int generation, | |
| 22 | + QPDFObjGen const& og, | |
| 24 | 23 | QPDFObjectHandle stream_dict, |
| 25 | 24 | qpdf_offset_t offset, |
| 26 | 25 | size_t length); |
| ... | ... | @@ -78,7 +77,7 @@ class QPDF_Stream: public QPDFObject |
| 78 | 77 | // Replace object ID and generation. This may only be called if |
| 79 | 78 | // object ID and generation are 0. It is used by QPDFObjectHandle |
| 80 | 79 | // when adding streams to files. |
| 81 | - void setObjGen(int objid, int generation); | |
| 80 | + void setObjGen(QPDFObjGen const& og); | |
| 82 | 81 | |
| 83 | 82 | protected: |
| 84 | 83 | virtual void releaseResolved(); |
| ... | ... | @@ -86,8 +85,7 @@ class QPDF_Stream: public QPDFObject |
| 86 | 85 | private: |
| 87 | 86 | QPDF_Stream( |
| 88 | 87 | QPDF*, |
| 89 | - int objid, | |
| 90 | - int generation, | |
| 88 | + QPDFObjGen const& og, | |
| 91 | 89 | QPDFObjectHandle stream_dict, |
| 92 | 90 | qpdf_offset_t offset, |
| 93 | 91 | size_t length); |
| ... | ... | @@ -111,8 +109,7 @@ class QPDF_Stream: public QPDFObject |
| 111 | 109 | void setDictDescription(); |
| 112 | 110 | |
| 113 | 111 | QPDF* qpdf; |
| 114 | - int objid; | |
| 115 | - int generation; | |
| 112 | + QPDFObjGen og; | |
| 116 | 113 | bool filter_on_write; |
| 117 | 114 | QPDFObjectHandle stream_dict; |
| 118 | 115 | qpdf_offset_t offset; | ... | ... |