Commit 8ded7ff5f395eff6d265f4339438b58d964d2389
1 parent
32d14f31
Refactor `QPDF` type conversion helpers: relocate methods to `qpdf::Doc::Common`…
…, replace direct calls with `QIntC` equivalents, and clean up `QPDF.hh`.
Showing
6 changed files
with
36 additions
and
31 deletions
examples/pdf-custom-filter.cc
include/qpdf/QPDF.hh
| @@ -37,7 +37,6 @@ | @@ -37,7 +37,6 @@ | ||
| 37 | #include <qpdf/Buffer.hh> | 37 | #include <qpdf/Buffer.hh> |
| 38 | #include <qpdf/InputSource.hh> | 38 | #include <qpdf/InputSource.hh> |
| 39 | #include <qpdf/PDFVersion.hh> | 39 | #include <qpdf/PDFVersion.hh> |
| 40 | -#include <qpdf/QIntC.hh> | ||
| 41 | #include <qpdf/QPDFExc.hh> | 40 | #include <qpdf/QPDFExc.hh> |
| 42 | #include <qpdf/QPDFObjGen.hh> | 41 | #include <qpdf/QPDFObjGen.hh> |
| 43 | #include <qpdf/QPDFObjectHandle.hh> | 42 | #include <qpdf/QPDFObjectHandle.hh> |
| @@ -803,32 +802,6 @@ class QPDF | @@ -803,32 +802,6 @@ class QPDF | ||
| 803 | // JSON import | 802 | // JSON import |
| 804 | void importJSON(std::shared_ptr<InputSource>, bool must_be_complete); | 803 | void importJSON(std::shared_ptr<InputSource>, bool must_be_complete); |
| 805 | 804 | ||
| 806 | - // Type conversion helper methods | ||
| 807 | - template <typename T> | ||
| 808 | - static qpdf_offset_t | ||
| 809 | - toO(T const& i) | ||
| 810 | - { | ||
| 811 | - return QIntC::to_offset(i); | ||
| 812 | - } | ||
| 813 | - template <typename T> | ||
| 814 | - static size_t | ||
| 815 | - toS(T const& i) | ||
| 816 | - { | ||
| 817 | - return QIntC::to_size(i); | ||
| 818 | - } | ||
| 819 | - template <typename T> | ||
| 820 | - static int | ||
| 821 | - toI(T const& i) | ||
| 822 | - { | ||
| 823 | - return QIntC::to_int(i); | ||
| 824 | - } | ||
| 825 | - template <typename T> | ||
| 826 | - static unsigned long long | ||
| 827 | - toULL(T const& i) | ||
| 828 | - { | ||
| 829 | - return QIntC::to_ulonglong(i); | ||
| 830 | - } | ||
| 831 | - | ||
| 832 | class Members; | 805 | class Members; |
| 833 | 806 | ||
| 834 | // Keep all member variables inside the Members object, which we dynamically allocate. This | 807 | // Keep all member variables inside the Members object, which we dynamically allocate. This |
libqpdf/QPDF.cc
| @@ -761,7 +761,10 @@ QPDF::pipeStreamData( | @@ -761,7 +761,10 @@ QPDF::pipeStreamData( | ||
| 761 | auto buf = file->read(length, offset); | 761 | auto buf = file->read(length, offset); |
| 762 | if (buf.size() != length) { | 762 | if (buf.size() != length) { |
| 763 | throw qpdf_for_warning.m->c.damagedPDF( | 763 | throw qpdf_for_warning.m->c.damagedPDF( |
| 764 | - *file, "", offset + toO(buf.size()), "unexpected EOF reading stream data"); | 764 | + *file, |
| 765 | + "", | ||
| 766 | + offset + QIntC::to_offset(buf.size()), | ||
| 767 | + "unexpected EOF reading stream data"); | ||
| 765 | } | 768 | } |
| 766 | pipeline->write(buf.data(), length); | 769 | pipeline->write(buf.data(), length); |
| 767 | attempted_finish = true; | 770 | attempted_finish = true; |
libqpdf/QPDF_encryption.cc
| @@ -1010,7 +1010,7 @@ QPDF::decryptString(std::string& str, QPDFObjGen og) | @@ -1010,7 +1010,7 @@ QPDF::decryptString(std::string& str, QPDFObjGen og) | ||
| 1010 | // Using std::shared_ptr guarantees that tmp will be freed even if rc4.process throws an | 1010 | // Using std::shared_ptr guarantees that tmp will be freed even if rc4.process throws an |
| 1011 | // exception. | 1011 | // exception. |
| 1012 | auto tmp = QUtil::make_unique_cstr(str); | 1012 | auto tmp = QUtil::make_unique_cstr(str); |
| 1013 | - RC4 rc4(QUtil::unsigned_char_pointer(key), toI(key.length())); | 1013 | + RC4 rc4(QUtil::unsigned_char_pointer(key), QIntC::to_int(key.length())); |
| 1014 | auto data = QUtil::unsigned_char_pointer(tmp.get()); | 1014 | auto data = QUtil::unsigned_char_pointer(tmp.get()); |
| 1015 | rc4.process(data, vlen, data); | 1015 | rc4.process(data, vlen, data); |
| 1016 | str = std::string(tmp.get(), vlen); | 1016 | str = std::string(tmp.get(), vlen); |
libqpdf/QPDF_objects.cc
| @@ -1138,7 +1138,7 @@ QPDF::getObjectCount() | @@ -1138,7 +1138,7 @@ QPDF::getObjectCount() | ||
| 1138 | if (!m->obj_cache.empty()) { | 1138 | if (!m->obj_cache.empty()) { |
| 1139 | og = (*(m->obj_cache.rbegin())).first; | 1139 | og = (*(m->obj_cache.rbegin())).first; |
| 1140 | } | 1140 | } |
| 1141 | - return toS(og.getObj()); | 1141 | + return QIntC::to_size(og.getObj()); |
| 1142 | } | 1142 | } |
| 1143 | 1143 | ||
| 1144 | std::vector<QPDFObjectHandle> | 1144 | std::vector<QPDFObjectHandle> |
libqpdf/qpdf/QPDF_private.hh
| @@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
| 3 | 3 | ||
| 4 | #include <qpdf/QPDF.hh> | 4 | #include <qpdf/QPDF.hh> |
| 5 | 5 | ||
| 6 | +#include <qpdf/QIntC.hh> | ||
| 6 | #include <qpdf/QPDFAcroFormDocumentHelper.hh> | 7 | #include <qpdf/QPDFAcroFormDocumentHelper.hh> |
| 7 | #include <qpdf/QPDFEmbeddedFileDocumentHelper.hh> | 8 | #include <qpdf/QPDFEmbeddedFileDocumentHelper.hh> |
| 8 | #include <qpdf/QPDFLogger.hh> | 9 | #include <qpdf/QPDFLogger.hh> |
| @@ -323,13 +324,39 @@ class QPDF::Doc | @@ -323,13 +324,39 @@ class QPDF::Doc | ||
| 323 | } | 324 | } |
| 324 | 325 | ||
| 325 | protected: | 326 | protected: |
| 327 | + // Type conversion helper methods | ||
| 328 | + template <typename T> | ||
| 329 | + static qpdf_offset_t | ||
| 330 | + toO(T const& i) | ||
| 331 | + { | ||
| 332 | + return QIntC::to_offset(i); | ||
| 333 | + } | ||
| 334 | + template <typename T> | ||
| 335 | + static size_t | ||
| 336 | + toS(T const& i) | ||
| 337 | + { | ||
| 338 | + return QIntC::to_size(i); | ||
| 339 | + } | ||
| 340 | + template <typename T> | ||
| 341 | + static int | ||
| 342 | + toI(T const& i) | ||
| 343 | + { | ||
| 344 | + return QIntC::to_int(i); | ||
| 345 | + } | ||
| 346 | + template <typename T> | ||
| 347 | + static unsigned long long | ||
| 348 | + toULL(T const& i) | ||
| 349 | + { | ||
| 350 | + return QIntC::to_ulonglong(i); | ||
| 351 | + } | ||
| 352 | + | ||
| 326 | QPDF& qpdf; | 353 | QPDF& qpdf; |
| 327 | QPDF::Members* m; | 354 | QPDF::Members* m; |
| 328 | 355 | ||
| 329 | qpdf::Doc::Config& cf; | 356 | qpdf::Doc::Config& cf; |
| 330 | QPDF::Doc::Pages& pages; | 357 | QPDF::Doc::Pages& pages; |
| 331 | QPDF::Doc::Objects& objects; | 358 | QPDF::Doc::Objects& objects; |
| 332 | - }; | 359 | + }; // class qpdf::Doc::Common |
| 333 | 360 | ||
| 334 | Doc() = delete; | 361 | Doc() = delete; |
| 335 | Doc(Doc const&) = delete; | 362 | Doc(Doc const&) = delete; |