Commit e2975b9ed0f675d1f740d65fd67c6cd99812bd1e
1 parent
2f631997
QPDFJob: de-templatize do_process and do_process_once
Showing
1 changed file
with
15 additions
and
14 deletions
libqpdf/QPDFJob.cc
| ... | ... | @@ -1830,11 +1830,9 @@ ImageOptimizer::provideStreamData(int, int, Pipeline* pipeline) |
| 1830 | 1830 | false, false); |
| 1831 | 1831 | } |
| 1832 | 1832 | |
| 1833 | -template <typename T> | |
| 1834 | 1833 | static PointerHolder<QPDF> do_process_once( |
| 1835 | - void (QPDF::*fn)(T, char const*), | |
| 1836 | - T item, char const* password, | |
| 1837 | - QPDFJob& o, bool empty) | |
| 1834 | + std::function<void(QPDF*, char const*)> fn, | |
| 1835 | + char const* password, QPDFJob& o, bool empty) | |
| 1838 | 1836 | { |
| 1839 | 1837 | PointerHolder<QPDF> pdf = new QPDF; |
| 1840 | 1838 | set_qpdf_options(*pdf, o); |
| ... | ... | @@ -1844,16 +1842,14 @@ static PointerHolder<QPDF> do_process_once( |
| 1844 | 1842 | } |
| 1845 | 1843 | else |
| 1846 | 1844 | { |
| 1847 | - ((*pdf).*fn)(item, password); | |
| 1845 | + fn(pdf.getPointer(), password); | |
| 1848 | 1846 | } |
| 1849 | 1847 | return pdf; |
| 1850 | 1848 | } |
| 1851 | 1849 | |
| 1852 | -template <typename T> | |
| 1853 | 1850 | static PointerHolder<QPDF> do_process( |
| 1854 | - void (QPDF::*fn)(T, char const*), | |
| 1855 | - T item, char const* password, | |
| 1856 | - QPDFJob& o, bool empty) | |
| 1851 | + std::function<void(QPDF*, char const*)> fn, | |
| 1852 | + char const* password, QPDFJob& o, bool empty) | |
| 1857 | 1853 | { |
| 1858 | 1854 | // If a password has been specified but doesn't work, try other |
| 1859 | 1855 | // passwords that are equivalent in different character encodings. |
| ... | ... | @@ -1882,7 +1878,7 @@ static PointerHolder<QPDF> do_process( |
| 1882 | 1878 | { |
| 1883 | 1879 | // There is no password, or we're not doing recovery, so just |
| 1884 | 1880 | // do the normal processing with the supplied password. |
| 1885 | - return do_process_once(fn, item, password, o, empty); | |
| 1881 | + return do_process_once(fn, password, o, empty); | |
| 1886 | 1882 | } |
| 1887 | 1883 | |
| 1888 | 1884 | // Get a list of otherwise encoded strings. Keep in scope for this |
| ... | ... | @@ -1916,7 +1912,7 @@ static PointerHolder<QPDF> do_process( |
| 1916 | 1912 | { |
| 1917 | 1913 | try |
| 1918 | 1914 | { |
| 1919 | - return do_process_once(fn, item, *iter, o, empty); | |
| 1915 | + return do_process_once(fn, *iter, o, empty); | |
| 1920 | 1916 | } |
| 1921 | 1917 | catch (QPDFExc& e) |
| 1922 | 1918 | { |
| ... | ... | @@ -1946,14 +1942,19 @@ PointerHolder<QPDF> |
| 1946 | 1942 | QPDFJob::processFile(char const* filename, char const* password) |
| 1947 | 1943 | { |
| 1948 | 1944 | QPDFJob& o = *this; // QXXXQ |
| 1949 | - return do_process(&QPDF::processFile, filename, password, o, | |
| 1950 | - strcmp(filename, "") == 0); | |
| 1945 | + auto f1 = std::mem_fn<void(char const*, char const*)>(&QPDF::processFile); | |
| 1946 | + auto fn = std::bind( | |
| 1947 | + f1, std::placeholders::_1, filename, std::placeholders::_2); | |
| 1948 | + return do_process(fn, password, o, strcmp(filename, "") == 0); | |
| 1951 | 1949 | } |
| 1952 | 1950 | |
| 1953 | 1951 | static PointerHolder<QPDF> process_input_source( |
| 1954 | 1952 | PointerHolder<InputSource> is, char const* password, QPDFJob& o) |
| 1955 | 1953 | { |
| 1956 | - return do_process(&QPDF::processInputSource, is, password, o, false); | |
| 1954 | + auto f1 = std::mem_fn(&QPDF::processInputSource); | |
| 1955 | + auto fn = std::bind( | |
| 1956 | + f1, std::placeholders::_1, is, std::placeholders::_2); | |
| 1957 | + return do_process(fn, password, o, false); | |
| 1957 | 1958 | } |
| 1958 | 1959 | |
| 1959 | 1960 | void | ... | ... |