Commit 0afaaea22a0a8697aee42ce6183bf4441d07018b

Authored by m-holger
Committed by m-holger
1 parent 5a33c75b

Deprecate QPDFObjectHandle::isInitialized and remove from library

examples/pdf-mod-info.cc
... ... @@ -131,7 +131,7 @@ main(int argc, char* argv[])
131 131 QPDFObjectHandle fileinfo;
132 132  
133 133 for (auto const& it: Keys) {
134   - if (!fileinfo.isInitialized()) {
  134 + if (!fileinfo) {
135 135 if (filetrailer.hasKey("/Info")) {
136 136 QTC::TC("examples", "pdf-mod-info has info");
137 137 fileinfo = filetrailer.getKey("/Info");
... ...
include/qpdf/QPDFObjectHandle.hh
... ... @@ -300,8 +300,7 @@ class QPDFObjectHandle
300 300 QPDF_DLL
301 301 explicit inline operator bool() const noexcept;
302 302  
303   - QPDF_DLL
304   - inline bool isInitialized() const;
  303 + [[deprecated("use operator bool()")]] QPDF_DLL inline bool isInitialized() const;
305 304  
306 305 // This method returns true if the QPDFObjectHandle objects point to exactly the same underlying
307 306 // object, meaning that changes to one are reflected in the other, or "if you paint one, the
... ...
include/qpdf/QPDFObjectHandle_future.hh
... ... @@ -300,8 +300,7 @@ class QPDFObjectHandle
300 300 QPDF_DLL
301 301 explicit inline operator bool() const noexcept;
302 302  
303   - QPDF_DLL
304   - inline bool isInitialized() const noexcept;
  303 + [[deprecated("use operator bool()")]] QPDF_DLL inline bool isInitialized() const noexcept;
305 304  
306 305 // This method returns true if the QPDFObjectHandle objects point to exactly the same underlying
307 306 // object, meaning that changes to one are reflected in the other, or "if you paint one, the
... ...
libqpdf/NNTree.cc
... ... @@ -188,7 +188,7 @@ NNTreeIterator::resetLimits(QPDFObjectHandle node, std::list<PathElement>::itera
188 188 }
189 189 }
190 190 }
191   - if (first.isInitialized() && last.isInitialized()) {
  191 + if (first && last) {
192 192 auto limits = QPDFObjectHandle::newArray();
193 193 limits.appendItem(first);
194 194 limits.appendItem(last);
... ...
libqpdf/QPDF.cc
... ... @@ -526,7 +526,7 @@ QPDF::warn(
526 526 void
527 527 QPDF::setTrailer(QPDFObjectHandle obj)
528 528 {
529   - if (m->trailer.isInitialized()) {
  529 + if (m->trailer) {
530 530 return;
531 531 }
532 532 m->trailer = obj;
... ... @@ -591,7 +591,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
591 591 }
592 592 }
593 593 m->file->seek(pos, SEEK_SET);
594   - } else if (!m->trailer.isInitialized() && t1.isWord("trailer")) {
  594 + } else if (!m->trailer && t1.isWord("trailer")) {
595 595 auto pos = m->file->tell();
596 596 QPDFObjectHandle t = readTrailer();
597 597 if (!t.isDictionary()) {
... ... @@ -606,7 +606,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
606 606 }
607 607 m->deleted_objects.clear();
608 608  
609   - if (!m->trailer.isInitialized()) {
  609 + if (!m->trailer) {
610 610 qpdf_offset_t max_offset{0};
611 611 // If there are any xref streams, take the last one to appear.
612 612 for (auto const& iter: m->xref_table) {
... ... @@ -640,7 +640,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
640 640 }
641 641 }
642 642  
643   - if (!m->trailer.isInitialized()) {
  643 + if (!m->trailer) {
644 644 // We could check the last encountered object to see if it was an xref stream. If so, we
645 645 // could try to get the trailer from there. This may make it possible to recover files with
646 646 // bad startxref pointers even when they have object streams.
... ... @@ -730,7 +730,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
730 730 }
731 731 }
732 732  
733   - if (!m->trailer.isInitialized()) {
  733 + if (!m->trailer) {
734 734 throw damagedPDF("", 0, "unable to find trailer while reading xref");
735 735 }
736 736 int size = m->trailer.getKey("/Size").getIntValueAsInt();
... ... @@ -1000,7 +1000,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
1000 1000 throw damagedPDF("", "expected trailer dictionary");
1001 1001 }
1002 1002  
1003   - if (!m->trailer.isInitialized()) {
  1003 + if (!m->trailer) {
1004 1004 setTrailer(cur_trailer);
1005 1005  
1006 1006 if (!m->trailer.hasKey("/Size")) {
... ... @@ -1258,7 +1258,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
1258 1258 }
1259 1259 }
1260 1260  
1261   - if (!m->trailer.isInitialized()) {
  1261 + if (!m->trailer) {
1262 1262 setTrailer(dict);
1263 1263 }
1264 1264  
... ... @@ -2052,7 +2052,7 @@ QPDF::makeIndirectFromQPDFObject(std::shared_ptr<QPDFObject> const& obj)
2052 2052 QPDFObjectHandle
2053 2053 QPDF::makeIndirectObject(QPDFObjectHandle oh)
2054 2054 {
2055   - if (!oh.isInitialized()) {
  2055 + if (!oh) {
2056 2056 throw std::logic_error("attempted to make an uninitialized QPDFObjectHandle indirect");
2057 2057 }
2058 2058 return makeIndirectFromQPDFObject(oh.getObj());
... ... @@ -2163,7 +2163,7 @@ QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh)
2163 2163 void
2164 2164 QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh)
2165 2165 {
2166   - if (!oh.isInitialized() || (oh.isIndirect() && !(oh.isStream() && oh.getObjGen() == og))) {
  2166 + if (!oh || (oh.isIndirect() && !(oh.isStream() && oh.getObjGen() == og))) {
2167 2167 QTC::TC("qpdf", "QPDF replaceObject called with indirect object");
2168 2168 throw std::logic_error("QPDF::replaceObject called with indirect object handle");
2169 2169 }
... ...
libqpdf/QPDFFormFieldObjectHelper.cc
... ... @@ -396,7 +396,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name)
396 396 } else {
397 397 annot = kid;
398 398 }
399   - if (!annot.isInitialized()) {
  399 + if (!annot) {
400 400 QTC::TC("qpdf", "QPDFObjectHandle broken radio button");
401 401 this->oh.warnIfPossible("unable to set the value of this radio button");
402 402 continue;
... ... @@ -459,7 +459,7 @@ QPDFFormFieldObjectHelper::setCheckBoxValue(bool value)
459 459 // Set /AS to the on value or /Off in addition to setting /V.
460 460 QPDFObjectHandle name = QPDFObjectHandle::newName(value ? on_value : "/Off");
461 461 setFieldAttribute("/V", name);
462   - if (!annot.isInitialized()) {
  462 + if (!annot) {
463 463 QTC::TC("qpdf", "QPDFObjectHandle broken checkbox");
464 464 this->oh.warnIfPossible("unable to set the value of this checkbox");
465 465 return;
... ... @@ -815,7 +815,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& ao
815 815 QPDFObjectHandle resources = AS.getDict().getKey("/Resources");
816 816 QPDFObjectHandle font = getFontFromResource(resources, font_name);
817 817 bool found_font_in_dr = false;
818   - if (!font.isInitialized()) {
  818 + if (!font) {
819 819 QPDFObjectHandle dr = getDefaultResources();
820 820 font = getFontFromResource(dr, font_name);
821 821 found_font_in_dr = font.isDictionary();
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -2165,7 +2165,7 @@ QPDFObjectHandle::parseContentStream_data(
2165 2165 input->seek(offset, SEEK_SET);
2166 2166 auto obj =
2167 2167 QPDFParser(*input, "content", tokenizer, nullptr, context, false).parse(empty, true);
2168   - if (!obj.isInitialized()) {
  2168 + if (!obj) {
2169 2169 // EOF
2170 2170 break;
2171 2171 }
... ... @@ -2520,7 +2520,7 @@ QPDFObjectHandle::makeDirect(bool allow_streams)
2520 2520 void
2521 2521 QPDFObjectHandle::assertInitialized() const
2522 2522 {
2523   - if (!isInitialized()) {
  2523 + if (!obj) {
2524 2524 throw std::logic_error("operation attempted on uninitialized QPDFObjectHandle");
2525 2525 }
2526 2526 }
... ... @@ -3018,34 +3018,30 @@ QPDFObjectHandle::QPDFArrayItems::end()
3018 3018 QPDFObjGen
3019 3019 QPDFObjectHandle::getObjGen() const
3020 3020 {
3021   - return isInitialized() ? obj->getObjGen() : QPDFObjGen();
  3021 + return obj ? obj->getObjGen() : QPDFObjGen();
3022 3022 }
3023 3023  
3024 3024 // Indirect object accessors
3025 3025 QPDF*
3026 3026 QPDFObjectHandle::getOwningQPDF() const
3027 3027 {
3028   - return isInitialized() ? this->obj->getQPDF() : nullptr;
  3028 + return obj ? obj->getQPDF() : nullptr;
3029 3029 }
3030 3030  
3031 3031 QPDF&
3032 3032 QPDFObjectHandle::getQPDF(std::string const& error_msg) const
3033 3033 {
3034   - auto result = isInitialized() ? this->obj->getQPDF() : nullptr;
3035   - if (result == nullptr) {
3036   - throw std::runtime_error(
3037   - error_msg.empty() ? "attempt to use a null qpdf object" : error_msg);
  3034 + if (auto result = obj ? obj->getQPDF() : nullptr) {
  3035 + return *result;
3038 3036 }
3039   - return *result;
  3037 + throw std::runtime_error(error_msg.empty() ? "attempt to use a null qpdf object" : error_msg);
3040 3038 }
3041 3039  
3042 3040 void
3043 3041 QPDFObjectHandle::setParsedOffset(qpdf_offset_t offset)
3044 3042 {
3045   - // This is called during parsing on newly created direct objects,
3046   - // so we can't call dereference() here.
3047   - if (isInitialized()) {
3048   - this->obj->setParsedOffset(offset);
  3043 + if (obj) {
  3044 + obj->setParsedOffset(offset);
3049 3045 }
3050 3046 }
3051 3047  
... ...
libqpdf/QPDFOutlineDocumentHelper.cc
... ... @@ -67,7 +67,7 @@ QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name)
67 67 {
68 68 QPDFObjectHandle result;
69 69 if (name.isName()) {
70   - if (!m->dest_dict.isInitialized()) {
  70 + if (!m->dest_dict) {
71 71 m->dest_dict = qpdf.getRoot().getKey("/Dests");
72 72 }
73 73 QTC::TC("qpdf", "QPDFOutlineDocumentHelper name named dest");
... ... @@ -85,7 +85,7 @@ QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name)
85 85 }
86 86 }
87 87 }
88   - if (!result.isInitialized()) {
  88 + if (!result) {
89 89 return QPDFObjectHandle::newNull();
90 90 }
91 91 if (result.isDictionary()) {
... ...
libqpdf/QPDFOutlineObjectHelper.cc
... ... @@ -59,8 +59,8 @@ QPDFOutlineObjectHelper::getDest()
59 59 QTC::TC("qpdf", "QPDFOutlineObjectHelper action dest");
60 60 dest = A.getKey("/D");
61 61 }
62   - if (!dest.isInitialized()) {
63   - dest = QPDFObjectHandle::newNull();
  62 + if (!dest) {
  63 + return QPDFObjectHandle::newNull();
64 64 }
65 65  
66 66 if (dest.isName() || dest.isString()) {
... ...
libqpdf/QPDFWriter.cc
... ... @@ -1381,7 +1381,7 @@ QPDFWriter::unparseObject(
1381 1381 }
1382 1382 }
1383 1383  
1384   - if (extensions.isInitialized()) {
  1384 + if (extensions) {
1385 1385 std::set<std::string> keys = extensions.getKeys();
1386 1386 if (keys.count("/ADBE") > 0) {
1387 1387 have_extensions_adbe = true;
... ... @@ -1412,7 +1412,7 @@ QPDFWriter::unparseObject(
1412 1412 }
1413 1413 }
1414 1414  
1415   - if (extensions.isInitialized()) {
  1415 + if (extensions) {
1416 1416 QTC::TC("qpdf", "QPDFWriter preserve Extensions");
1417 1417 QPDFObjectHandle adbe = extensions.getKey("/ADBE");
1418 1418 if (adbe.isDictionary() &&
... ...
libqpdf/QPDF_Stream.cc
... ... @@ -661,18 +661,17 @@ void
661 661 QPDF_Stream::replaceFilterData(
662 662 QPDFObjectHandle const& filter, QPDFObjectHandle const& decode_parms, size_t length)
663 663 {
664   - if (filter.isInitialized()) {
665   - this->stream_dict.replaceKey("/Filter", filter);
  664 + if (filter) {
  665 + stream_dict.replaceKey("/Filter", filter);
666 666 }
667   - if (decode_parms.isInitialized()) {
668   - this->stream_dict.replaceKey("/DecodeParms", decode_parms);
  667 + if (decode_parms) {
  668 + stream_dict.replaceKey("/DecodeParms", decode_parms);
669 669 }
670 670 if (length == 0) {
671 671 QTC::TC("qpdf", "QPDF_Stream unknown stream length");
672   - this->stream_dict.removeKey("/Length");
  672 + stream_dict.removeKey("/Length");
673 673 } else {
674   - this->stream_dict.replaceKey(
675   - "/Length", QPDFObjectHandle::newInteger(QIntC::to_longlong(length)));
  674 + stream_dict.replaceKey("/Length", QPDFObjectHandle::newInteger(QIntC::to_longlong(length)));
676 675 }
677 676 }
678 677  
... ...
libqpdf/QPDF_json.cc
... ... @@ -325,7 +325,7 @@ QPDF::JSONReactor::anyErrors() const
325 325 void
326 326 QPDF::JSONReactor::containerStart()
327 327 {
328   - if (next_obj.isInitialized()) {
  328 + if (next_obj) {
329 329 stack.emplace_back(next_state, std::move(next_obj));
330 330 next_obj = QPDFObjectHandle();
331 331 } else {
... ... @@ -558,7 +558,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const&amp; key, JSON const&amp; value)
558 558 throw std::logic_error("stack empty in st_object_top");
559 559 }
560 560 auto& tos = stack.back();
561   - if (!tos.object.isInitialized()) {
  561 + if (!tos.object) {
562 562 throw std::logic_error("current object uninitialized in st_object_top");
563 563 }
564 564 if (key == "value") {
... ... @@ -767,7 +767,7 @@ QPDF::JSONReactor::makeObject(JSON const&amp; value)
767 767 result = QPDFObjectHandle::newNull();
768 768 }
769 769 }
770   - if (!result.isInitialized()) {
  770 + if (!result) {
771 771 throw std::logic_error("JSONReactor::makeObject didn't initialize the object");
772 772 }
773 773  
... ...
libqpdf/qpdf-c.cc
... ... @@ -955,7 +955,7 @@ qpdf_oh_is_initialized(qpdf_data qpdf, qpdf_oh oh)
955 955 {
956 956 QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_initialized");
957 957 return do_with_oh<QPDF_BOOL>(
958   - qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isInitialized(); });
  958 + qpdf, oh, return_false, [](QPDFObjectHandle& o) { return static_cast<bool>(o); });
959 959 }
960 960  
961 961 QPDF_BOOL
... ...
qpdf/test_driver.cc
... ... @@ -1428,7 +1428,7 @@ test_42(QPDF&amp; pdf, char const* arg2)
1428 1428 assert(i == ai.end());
1429 1429 ++i;
1430 1430 assert(i == ai.end());
1431   - assert(!i_value.isInitialized());
  1431 + assert(!i_value);
1432 1432 --i;
1433 1433 assert(i_value.getName() == "/Item2");
1434 1434 assert(i->getName() == "/Item2");
... ... @@ -1444,7 +1444,7 @@ test_42(QPDF&amp; pdf, char const* arg2)
1444 1444 ++i;
1445 1445 ++i;
1446 1446 assert(i == di.end());
1447   - assert(!i_value.second.isInitialized());
  1447 + assert(!i_value.second);
1448 1448 }
1449 1449 assert("" == qtest.getStringValue());
1450 1450 array.getArrayItem(-1).assertNull();
... ... @@ -1542,7 +1542,7 @@ test_42(QPDF&amp; pdf, char const* arg2)
1542 1542 assert(m1.a == 0 && m1.b == 0 && m1.c == 0 && m1.d == 0 && m1.e == 0 && m1.f == 0);
1543 1543 // Uninitialized
1544 1544 QPDFObjectHandle uninitialized;
1545   - assert(!uninitialized.isInitialized());
  1545 + assert(!uninitialized);
1546 1546 assert(!uninitialized.isInteger());
1547 1547 assert(!uninitialized.isDictionary());
1548 1548 assert(!uninitialized.isScalar());
... ... @@ -1692,7 +1692,7 @@ test_46(QPDF&amp; pdf, char const* arg2)
1692 1692 assert(iter1_val.first == 2);
1693 1693 ++iter1;
1694 1694 assert(iter1 == new1.end());
1695   - assert(!iter1_val.second.isInitialized());
  1695 + assert(!iter1_val.second);
1696 1696 ++iter1;
1697 1697 assert(iter1->first == 1);
1698 1698 --iter1;
... ... @@ -1842,7 +1842,7 @@ test_48(QPDF&amp; pdf, char const* arg2)
1842 1842 assert(iter1_val.first == "2");
1843 1843 ++iter1;
1844 1844 assert(iter1 == new1.end());
1845   - assert(!iter1_val.second.isInitialized());
  1845 + assert(!iter1_val.second);
1846 1846 ++iter1;
1847 1847 assert(iter1->first == "1");
1848 1848 --iter1;
... ...