From e2975b9ed0f675d1f740d65fd67c6cd99812bd1e Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 5 Jan 2022 16:06:10 -0500 Subject: [PATCH] QPDFJob: de-templatize do_process and do_process_once --- libqpdf/QPDFJob.cc | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 86e813bb..4a2d5012 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -1830,11 +1830,9 @@ ImageOptimizer::provideStreamData(int, int, Pipeline* pipeline) false, false); } -template static PointerHolder do_process_once( - void (QPDF::*fn)(T, char const*), - T item, char const* password, - QPDFJob& o, bool empty) + std::function fn, + char const* password, QPDFJob& o, bool empty) { PointerHolder pdf = new QPDF; set_qpdf_options(*pdf, o); @@ -1844,16 +1842,14 @@ static PointerHolder do_process_once( } else { - ((*pdf).*fn)(item, password); + fn(pdf.getPointer(), password); } return pdf; } -template static PointerHolder do_process( - void (QPDF::*fn)(T, char const*), - T item, char const* password, - QPDFJob& o, bool empty) + std::function fn, + char const* password, QPDFJob& o, bool empty) { // If a password has been specified but doesn't work, try other // passwords that are equivalent in different character encodings. @@ -1882,7 +1878,7 @@ static PointerHolder do_process( { // There is no password, or we're not doing recovery, so just // do the normal processing with the supplied password. - return do_process_once(fn, item, password, o, empty); + return do_process_once(fn, password, o, empty); } // Get a list of otherwise encoded strings. Keep in scope for this @@ -1916,7 +1912,7 @@ static PointerHolder do_process( { try { - return do_process_once(fn, item, *iter, o, empty); + return do_process_once(fn, *iter, o, empty); } catch (QPDFExc& e) { @@ -1946,14 +1942,19 @@ PointerHolder QPDFJob::processFile(char const* filename, char const* password) { QPDFJob& o = *this; // QXXXQ - return do_process(&QPDF::processFile, filename, password, o, - strcmp(filename, "") == 0); + auto f1 = std::mem_fn(&QPDF::processFile); + auto fn = std::bind( + f1, std::placeholders::_1, filename, std::placeholders::_2); + return do_process(fn, password, o, strcmp(filename, "") == 0); } static PointerHolder process_input_source( PointerHolder is, char const* password, QPDFJob& o) { - return do_process(&QPDF::processInputSource, is, password, o, false); + auto f1 = std::mem_fn(&QPDF::processInputSource); + auto fn = std::bind( + f1, std::placeholders::_1, is, std::placeholders::_2); + return do_process(fn, password, o, false); } void