2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-03 19:00:51 +00:00

Use anonymous namespaces for file-private classes

This commit is contained in:
Jay Berkenbilt 2022-04-16 13:21:57 -04:00
parent 38edca820e
commit 75fe4f60c3
15 changed files with 435 additions and 362 deletions

View File

@ -6,7 +6,8 @@
qpdf 11. qpdf 11.
* Perform code cleanup including some source-compatible but not * Perform code cleanup including some source-compatible but not
binary compatible changes to function signatures. binary compatible changes to function signatures, use of anonymous
namespaces, and use of "= default" and "= delete" in declarations.
2022-04-09 Jay Berkenbilt <ejb@ql.org> 2022-04-09 Jay Berkenbilt <ejb@ql.org>

2
TODO
View File

@ -479,8 +479,6 @@ This is a list of changes to make next time there is an ABI change.
Comments appear in the code prefixed by "ABI". Always Search for ABI Comments appear in the code prefixed by "ABI". Always Search for ABI
in source and header files to find items not listed here. in source and header files to find items not listed here.
* See where anonymous namespaces can be used to keep things private to
a source file. Search for `(class|struct)` in **/*.cc.
* Having QPDFObjectHandle setters return Class& to allow for * Having QPDFObjectHandle setters return Class& to allow for
use of fluent interfaces. This includes array and dictionary use of fluent interfaces. This includes array and dictionary
mutators. mutators.

View File

@ -14,12 +14,15 @@
# error "qpdf does not support libjpeg built with BITS_IN_JSAMPLE != 8" # error "qpdf does not support libjpeg built with BITS_IN_JSAMPLE != 8"
#endif #endif
struct qpdf_jpeg_error_mgr namespace
{ {
struct jpeg_error_mgr pub; struct qpdf_jpeg_error_mgr
jmp_buf jmpbuf; {
std::string msg; struct jpeg_error_mgr pub;
}; jmp_buf jmpbuf;
std::string msg;
};
} // namespace
static void static void
error_handler(j_common_ptr cinfo) error_handler(j_common_ptr cinfo)
@ -147,13 +150,16 @@ Pl_DCT::finish()
} }
} }
struct dct_pipeline_dest namespace
{ {
struct jpeg_destination_mgr pub; /* public fields */ struct dct_pipeline_dest
unsigned char* buffer; {
size_t size; struct jpeg_destination_mgr pub; /* public fields */
Pipeline* next; unsigned char* buffer;
}; size_t size;
Pipeline* next;
};
} // namespace
static void static void
init_pipeline_destination(j_compress_ptr) init_pipeline_destination(j_compress_ptr)

View File

@ -50,60 +50,64 @@ static char const* EMPTY_PDF = (
"110\n" "110\n"
"%%EOF\n"); "%%EOF\n");
class InvalidInputSource: public InputSource namespace
{ {
public: class InvalidInputSource: public InputSource
virtual ~InvalidInputSource() = default;
virtual qpdf_offset_t
findAndSkipNextEOL() override
{ {
throwException(); public:
return 0; virtual ~InvalidInputSource() = default;
} virtual qpdf_offset_t
virtual std::string const& findAndSkipNextEOL() override
getName() const override {
{ throwException();
static std::string name("closed input source"); return 0;
return name; }
} virtual std::string const&
virtual qpdf_offset_t getName() const override
tell() override {
{ static std::string name("closed input source");
throwException(); return name;
return 0; }
} virtual qpdf_offset_t
virtual void tell() override
seek(qpdf_offset_t offset, int whence) override {
{ throwException();
throwException(); return 0;
} }
virtual void virtual void
rewind() override seek(qpdf_offset_t offset, int whence) override
{ {
throwException(); throwException();
} }
virtual size_t virtual void
read(char* buffer, size_t length) override rewind() override
{ {
throwException(); throwException();
return 0; }
} virtual size_t
virtual void read(char* buffer, size_t length) override
unreadCh(char ch) override {
{ throwException();
throwException(); return 0;
} }
virtual void
unreadCh(char ch) override
{
throwException();
}
private: private:
void void
throwException() throwException()
{ {
throw std::logic_error( throw std::logic_error(
"QPDF operation attempted on a QPDF object with no input source." "QPDF operation attempted on a QPDF object with no input "
" QPDF operations are invalid before processFile (or another" "source."
" process method) or after closeInputSource"); " QPDF operations are invalid before processFile (or another"
} " process method) or after closeInputSource");
}; }
};
} // namespace
QPDF::ForeignStreamData::ForeignStreamData( QPDF::ForeignStreamData::ForeignStreamData(
std::shared_ptr<EncryptionParameters> encp, std::shared_ptr<EncryptionParameters> encp,

View File

@ -543,20 +543,25 @@ QPDFAcroFormDocumentHelper::adjustInheritedFields(
} }
} }
class ResourceReplacer: public QPDFObjectHandle::TokenFilter namespace
{ {
public: class ResourceReplacer: public QPDFObjectHandle::TokenFilter
ResourceReplacer( {
std::map<std::string, std::map<std::string, std::string>> const& dr_map, public:
std::map<std::string, std::map<std::string, std::set<size_t>>> const& ResourceReplacer(
rnames); std::map<std::string, std::map<std::string, std::string>> const&
virtual ~ResourceReplacer() = default; dr_map,
virtual void handleToken(QPDFTokenizer::Token const&) override; std::map<
std::string,
std::map<std::string, std::set<size_t>>> const& rnames);
virtual ~ResourceReplacer() = default;
virtual void handleToken(QPDFTokenizer::Token const&) override;
private: private:
size_t offset; size_t offset;
std::map<std::string, std::map<size_t, std::string>> to_replace; std::map<std::string, std::map<size_t, std::string>> to_replace;
}; };
} // namespace
ResourceReplacer::ResourceReplacer( ResourceReplacer::ResourceReplacer(
std::map<std::string, std::map<std::string, std::string>> const& dr_map, std::map<std::string, std::map<std::string, std::string>> const& dr_map,

View File

@ -508,29 +508,32 @@ QPDFFormFieldObjectHelper::generateAppearance(QPDFAnnotationObjectHelper& aoh)
} }
} }
class ValueSetter: public QPDFObjectHandle::TokenFilter namespace
{ {
public: class ValueSetter: public QPDFObjectHandle::TokenFilter
ValueSetter( {
std::string const& DA, public:
std::string const& V, ValueSetter(
std::vector<std::string> const& opt, std::string const& DA,
double tf, std::string const& V,
QPDFObjectHandle::Rectangle const& bbox); std::vector<std::string> const& opt,
virtual ~ValueSetter() = default; double tf,
virtual void handleToken(QPDFTokenizer::Token const&); QPDFObjectHandle::Rectangle const& bbox);
virtual void handleEOF(); virtual ~ValueSetter() = default;
void writeAppearance(); virtual void handleToken(QPDFTokenizer::Token const&);
virtual void handleEOF();
void writeAppearance();
private: private:
std::string DA; std::string DA;
std::string V; std::string V;
std::vector<std::string> opt; std::vector<std::string> opt;
double tf; double tf;
QPDFObjectHandle::Rectangle bbox; QPDFObjectHandle::Rectangle bbox;
enum { st_top, st_bmc, st_emc, st_end } state; enum { st_top, st_bmc, st_emc, st_end } state;
bool replaced; bool replaced;
}; };
} // namespace
ValueSetter::ValueSetter( ValueSetter::ValueSetter(
std::string const& DA, std::string const& DA,
@ -701,27 +704,30 @@ ValueSetter::writeAppearance()
write("ET\nQ\nEMC"); write("ET\nQ\nEMC");
} }
class TfFinder: public QPDFObjectHandle::TokenFilter namespace
{ {
public: class TfFinder: public QPDFObjectHandle::TokenFilter
TfFinder();
virtual ~TfFinder()
{ {
} public:
virtual void handleToken(QPDFTokenizer::Token const&); TfFinder();
double getTf(); virtual ~TfFinder()
std::string getFontName(); {
std::string getDA(); }
virtual void handleToken(QPDFTokenizer::Token const&);
double getTf();
std::string getFontName();
std::string getDA();
private: private:
double tf; double tf;
int tf_idx; int tf_idx;
std::string font_name; std::string font_name;
double last_num; double last_num;
int last_num_idx; int last_num_idx;
std::string last_name; std::string last_name;
std::vector<std::string> DA; std::vector<std::string> DA;
}; };
} // namespace
TfFinder::TfFinder() : TfFinder::TfFinder() :
tf(11.0), tf(11.0),

View File

@ -2,32 +2,35 @@
#include <qpdf/NNTree.hh> #include <qpdf/NNTree.hh>
class NameTreeDetails: public NNTreeDetails namespace
{ {
public: class NameTreeDetails: public NNTreeDetails
virtual std::string const&
itemsKey() const override
{ {
static std::string k("/Names"); public:
return k; virtual std::string const&
} itemsKey() const override
virtual bool {
keyValid(QPDFObjectHandle oh) const override static std::string k("/Names");
{ return k;
return oh.isString();
}
virtual int
compareKeys(QPDFObjectHandle a, QPDFObjectHandle b) const override
{
if (!(keyValid(a) && keyValid(b))) {
// We don't call this without calling keyValid first
throw std::logic_error("comparing invalid keys");
} }
auto as = a.getUTF8Value(); virtual bool
auto bs = b.getUTF8Value(); keyValid(QPDFObjectHandle oh) const override
return ((as < bs) ? -1 : (as > bs) ? 1 : 0); {
} return oh.isString();
}; }
virtual int
compareKeys(QPDFObjectHandle a, QPDFObjectHandle b) const override
{
if (!(keyValid(a) && keyValid(b))) {
// We don't call this without calling keyValid first
throw std::logic_error("comparing invalid keys");
}
auto as = a.getUTF8Value();
auto bs = b.getUTF8Value();
return ((as < bs) ? -1 : (as > bs) ? 1 : 0);
}
};
} // namespace
static NameTreeDetails name_tree_details; static NameTreeDetails name_tree_details;

View File

@ -3,32 +3,35 @@
#include <qpdf/NNTree.hh> #include <qpdf/NNTree.hh>
#include <qpdf/QIntC.hh> #include <qpdf/QIntC.hh>
class NumberTreeDetails: public NNTreeDetails namespace
{ {
public: class NumberTreeDetails: public NNTreeDetails
virtual std::string const&
itemsKey() const override
{ {
static std::string k("/Nums"); public:
return k; virtual std::string const&
} itemsKey() const override
virtual bool {
keyValid(QPDFObjectHandle oh) const override static std::string k("/Nums");
{ return k;
return oh.isInteger();
}
virtual int
compareKeys(QPDFObjectHandle a, QPDFObjectHandle b) const override
{
if (!(keyValid(a) && keyValid(b))) {
// We don't call this without calling keyValid first
throw std::logic_error("comparing invalid keys");
} }
auto as = a.getIntValue(); virtual bool
auto bs = b.getIntValue(); keyValid(QPDFObjectHandle oh) const override
return ((as < bs) ? -1 : (as > bs) ? 1 : 0); {
} return oh.isInteger();
}; }
virtual int
compareKeys(QPDFObjectHandle a, QPDFObjectHandle b) const override
{
if (!(keyValid(a) && keyValid(b))) {
// We don't call this without calling keyValid first
throw std::logic_error("comparing invalid keys");
}
auto as = a.getIntValue();
auto bs = b.getIntValue();
return ((as < bs) ? -1 : (as > bs) ? 1 : 0);
}
};
} // namespace
static NumberTreeDetails number_tree_details; static NumberTreeDetails number_tree_details;

View File

@ -32,9 +32,12 @@
#include <stdexcept> #include <stdexcept>
#include <stdlib.h> #include <stdlib.h>
class TerminateParsing namespace
{ {
}; class TerminateParsing
{
};
} // namespace
QPDFObjectHandle::StreamDataProvider::StreamDataProvider(bool supports_retry) : QPDFObjectHandle::StreamDataProvider::StreamDataProvider(bool supports_retry) :
supports_retry(supports_retry) supports_retry(supports_retry)
@ -74,23 +77,26 @@ QPDFObjectHandle::StreamDataProvider::supportsRetry()
return this->supports_retry; return this->supports_retry;
} }
class CoalesceProvider: public QPDFObjectHandle::StreamDataProvider namespace
{ {
public: class CoalesceProvider: public QPDFObjectHandle::StreamDataProvider
CoalesceProvider(
QPDFObjectHandle containing_page, QPDFObjectHandle old_contents) :
containing_page(containing_page),
old_contents(old_contents)
{ {
} public:
virtual ~CoalesceProvider() = default; CoalesceProvider(
virtual void QPDFObjectHandle containing_page, QPDFObjectHandle old_contents) :
provideStreamData(int objid, int generation, Pipeline* pipeline); containing_page(containing_page),
old_contents(old_contents)
{
}
virtual ~CoalesceProvider() = default;
virtual void
provideStreamData(int objid, int generation, Pipeline* pipeline);
private: private:
QPDFObjectHandle containing_page; QPDFObjectHandle containing_page;
QPDFObjectHandle old_contents; QPDFObjectHandle old_contents;
}; };
} // namespace
void void
CoalesceProvider::provideStreamData(int, int, Pipeline* p) CoalesceProvider::provideStreamData(int, int, Pipeline* p)
@ -167,18 +173,21 @@ QPDFObjectHandle::ParserCallbacks::terminateParsing()
throw TerminateParsing(); throw TerminateParsing();
} }
class LastChar: public Pipeline namespace
{ {
public: class LastChar: public Pipeline
LastChar(Pipeline* next); {
virtual ~LastChar() = default; public:
virtual void write(unsigned char* data, size_t len); LastChar(Pipeline* next);
virtual void finish(); virtual ~LastChar() = default;
unsigned char getLastChar(); virtual void write(unsigned char* data, size_t len);
virtual void finish();
unsigned char getLastChar();
private: private:
unsigned char last_char; unsigned char last_char;
}; };
} // namespace
LastChar::LastChar(Pipeline* next) : LastChar::LastChar(Pipeline* next) :
Pipeline("lastchar", next), Pipeline("lastchar", next),
@ -293,21 +302,24 @@ QPDFObjectHandle::getTypeName()
} }
} }
template <class T> namespace
class QPDFObjectTypeAccessor
{ {
public: template <class T>
static bool class QPDFObjectTypeAccessor
check(QPDFObject* o)
{ {
return (o && dynamic_cast<T*>(o)); public:
} static bool
static bool check(QPDFObject* o)
check(QPDFObject const* o) {
{ return (o && dynamic_cast<T*>(o));
return (o && dynamic_cast<T const*>(o)); }
} static bool
}; check(QPDFObject const* o)
{
return (o && dynamic_cast<T const*>(o));
}
};
} // namespace
bool bool
QPDFObjectHandle::isBool() QPDFObjectHandle::isBool()
@ -1435,40 +1447,46 @@ QPDFObjectHandle::replaceStreamData(
provider, filter, decode_parms); provider, filter, decode_parms);
} }
class FunctionProvider: public QPDFObjectHandle::StreamDataProvider namespace
{ {
public: class FunctionProvider: public QPDFObjectHandle::StreamDataProvider
FunctionProvider(std::function<void(Pipeline*)> provider) :
StreamDataProvider(false),
p1(provider),
p2(nullptr)
{ {
} public:
FunctionProvider(std::function<bool(Pipeline*, bool, bool)> provider) : FunctionProvider(std::function<void(Pipeline*)> provider) :
StreamDataProvider(true), StreamDataProvider(false),
p1(nullptr), p1(provider),
p2(provider) p2(nullptr)
{ {
} }
FunctionProvider(std::function<bool(Pipeline*, bool, bool)> provider) :
StreamDataProvider(true),
p1(nullptr),
p2(provider)
{
}
virtual void virtual void
provideStreamData(int, int, Pipeline* pipeline) override provideStreamData(int, int, Pipeline* pipeline) override
{ {
p1(pipeline); p1(pipeline);
} }
virtual bool virtual bool
provideStreamData( provideStreamData(
int, int, Pipeline* pipeline, bool suppress_warnings, bool will_retry) int,
override int,
{ Pipeline* pipeline,
return p2(pipeline, suppress_warnings, will_retry); bool suppress_warnings,
} bool will_retry) override
{
return p2(pipeline, suppress_warnings, will_retry);
}
private: private:
std::function<void(Pipeline*)> p1; std::function<void(Pipeline*)> p1;
std::function<bool(Pipeline*, bool, bool)> p2; std::function<bool(Pipeline*, bool, bool)> p2;
}; };
} // namespace
void void
QPDFObjectHandle::replaceStreamData( QPDFObjectHandle::replaceStreamData(

View File

@ -11,20 +11,23 @@
#include <qpdf/QUtil.hh> #include <qpdf/QUtil.hh>
#include <qpdf/ResourceFinder.hh> #include <qpdf/ResourceFinder.hh>
class ContentProvider: public QPDFObjectHandle::StreamDataProvider namespace
{ {
public: class ContentProvider: public QPDFObjectHandle::StreamDataProvider
ContentProvider(QPDFObjectHandle from_page) :
from_page(from_page)
{ {
} public:
virtual ~ContentProvider() = default; ContentProvider(QPDFObjectHandle from_page) :
virtual void from_page(from_page)
provideStreamData(int objid, int generation, Pipeline* pipeline); {
}
virtual ~ContentProvider() = default;
virtual void
provideStreamData(int objid, int generation, Pipeline* pipeline);
private: private:
QPDFObjectHandle from_page; QPDFObjectHandle from_page;
}; };
} // namespace
void void
ContentProvider::provideStreamData(int, int, Pipeline* p) ContentProvider::provideStreamData(int, int, Pipeline* p)
@ -39,23 +42,26 @@ ContentProvider::provideStreamData(int, int, Pipeline* p)
concat.manualFinish(); concat.manualFinish();
} }
class InlineImageTracker: public QPDFObjectHandle::TokenFilter namespace
{ {
public: class InlineImageTracker: public QPDFObjectHandle::TokenFilter
InlineImageTracker(QPDF*, size_t min_size, QPDFObjectHandle resources); {
virtual ~InlineImageTracker() = default; public:
virtual void handleToken(QPDFTokenizer::Token const&); InlineImageTracker(QPDF*, size_t min_size, QPDFObjectHandle resources);
QPDFObjectHandle convertIIDict(QPDFObjectHandle odict); virtual ~InlineImageTracker() = default;
virtual void handleToken(QPDFTokenizer::Token const&);
QPDFObjectHandle convertIIDict(QPDFObjectHandle odict);
QPDF* qpdf; QPDF* qpdf;
size_t min_size; size_t min_size;
QPDFObjectHandle resources; QPDFObjectHandle resources;
std::string dict_str; std::string dict_str;
std::string bi_str; std::string bi_str;
int min_suffix; int min_suffix;
bool any_images; bool any_images;
enum { st_top, st_bi } state; enum { st_top, st_bi } state;
}; };
} // namespace
InlineImageTracker::InlineImageTracker( InlineImageTracker::InlineImageTracker(
QPDF* qpdf, size_t min_size, QPDFObjectHandle resources) : QPDF* qpdf, size_t min_size, QPDFObjectHandle resources) :

View File

@ -20,22 +20,25 @@ is_delimiter(char ch)
return (strchr(" \t\n\v\f\r()<>[]{}/%", ch) != 0); return (strchr(" \t\n\v\f\r()<>[]{}/%", ch) != 0);
} }
class QPDFWordTokenFinder: public InputSource::Finder namespace
{ {
public: class QPDFWordTokenFinder: public InputSource::Finder
QPDFWordTokenFinder(
std::shared_ptr<InputSource> is, std::string const& str) :
is(is),
str(str)
{ {
} public:
virtual ~QPDFWordTokenFinder() = default; QPDFWordTokenFinder(
virtual bool check(); std::shared_ptr<InputSource> is, std::string const& str) :
is(is),
str(str)
{
}
virtual ~QPDFWordTokenFinder() = default;
virtual bool check();
private: private:
std::shared_ptr<InputSource> is; std::shared_ptr<InputSource> is;
std::string str; std::string str;
}; };
} // namespace
bool bool
QPDFWordTokenFinder::check() QPDFWordTokenFinder::check()

View File

@ -19,38 +19,42 @@
#include <stdexcept> #include <stdexcept>
class SF_Crypt: public QPDFStreamFilter namespace
{ {
public: class SF_Crypt: public QPDFStreamFilter
SF_Crypt() = default;
virtual ~SF_Crypt() = default;
virtual bool
setDecodeParms(QPDFObjectHandle decode_parms)
{ {
if (decode_parms.isNull()) { public:
return true; SF_Crypt() = default;
} virtual ~SF_Crypt() = default;
bool filterable = true;
for (auto const& key : decode_parms.getKeys()) { virtual bool
if (((key == "/Type") || (key == "/Name")) && setDecodeParms(QPDFObjectHandle decode_parms)
((!decode_parms.hasKey("/Type")) || {
decode_parms.isDictionaryOfType("/CryptFilterDecodeParms"))) { if (decode_parms.isNull()) {
// we handle this in decryptStream return true;
} else {
filterable = false;
} }
bool filterable = true;
for (auto const& key : decode_parms.getKeys()) {
if (((key == "/Type") || (key == "/Name")) &&
((!decode_parms.hasKey("/Type")) ||
decode_parms.isDictionaryOfType(
"/CryptFilterDecodeParms"))) {
// we handle this in decryptStream
} else {
filterable = false;
}
}
return filterable;
} }
return filterable;
}
virtual Pipeline* virtual Pipeline*
getDecodePipeline(Pipeline*) getDecodePipeline(Pipeline*)
{ {
// Not used -- handled by pipeStreamData // Not used -- handled by pipeStreamData
return nullptr; return nullptr;
} }
}; };
} // namespace
std::map<std::string, std::string> QPDF_Stream::filter_abbreviations = { std::map<std::string, std::string> QPDF_Stream::filter_abbreviations = {
// The PDF specification provides these filter abbreviations for // The PDF specification provides these filter abbreviations for

View File

@ -251,22 +251,25 @@ static unsigned short mac_roman_to_unicode[] = {
0x02c7, // 0xff 0x02c7, // 0xff
}; };
class FileCloser namespace
{ {
public: class FileCloser
FileCloser(FILE* f) :
f(f)
{ {
} public:
FileCloser(FILE* f) :
f(f)
{
}
~FileCloser() ~FileCloser()
{ {
fclose(f); fclose(f);
} }
private: private:
FILE* f; FILE* f;
}; };
} // namespace
template <typename T> template <typename T>
static std::string static std::string
@ -1052,17 +1055,20 @@ QUtil::toUTF16(unsigned long uval)
// Random data support // Random data support
class RandomDataProviderProvider namespace
{ {
public: class RandomDataProviderProvider
RandomDataProviderProvider(); {
void setProvider(RandomDataProvider*); public:
RandomDataProvider* getProvider(); RandomDataProviderProvider();
void setProvider(RandomDataProvider*);
RandomDataProvider* getProvider();
private: private:
RandomDataProvider* default_provider; RandomDataProvider* default_provider;
RandomDataProvider* current_provider; RandomDataProvider* current_provider;
}; };
} // namespace
RandomDataProviderProvider::RandomDataProviderProvider() : RandomDataProviderProvider::RandomDataProviderProvider() :
default_provider(CryptoRandomDataProvider::getInstance()), default_provider(CryptoRandomDataProvider::getInstance()),

View File

@ -31,47 +31,54 @@ SecureRandomDataProvider::getInstance()
# ifdef _WIN32 # ifdef _WIN32
class WindowsCryptProvider namespace
{ {
public: class WindowsCryptProvider
WindowsCryptProvider()
{ {
if (!CryptAcquireContextW( public:
&crypt_prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { WindowsCryptProvider()
throw std::runtime_error( {
"unable to acquire crypt context: " + getErrorMessage()); if (!CryptAcquireContextW(
&crypt_prov,
NULL,
NULL,
PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT)) {
throw std::runtime_error(
"unable to acquire crypt context: " + getErrorMessage());
}
}
~WindowsCryptProvider()
{
// Ignore error
CryptReleaseContext(crypt_prov, 0);
} }
}
~WindowsCryptProvider()
{
// Ignore error
CryptReleaseContext(crypt_prov, 0);
}
HCRYPTPROV crypt_prov; HCRYPTPROV crypt_prov;
private: private:
std::string std::string
getErrorMessage() getErrorMessage()
{ {
DWORD errorMessageID = ::GetLastError(); DWORD errorMessageID = ::GetLastError();
LPSTR messageBuffer = nullptr; LPSTR messageBuffer = nullptr;
size_t size = FormatMessageA( size_t size = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, NULL,
errorMessageID, errorMessageID,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPSTR>(&messageBuffer), reinterpret_cast<LPSTR>(&messageBuffer),
0, 0,
NULL); NULL);
std::string message(messageBuffer, size); std::string message(messageBuffer, size);
LocalFree(messageBuffer); LocalFree(messageBuffer);
return ( return (
"error number " + QUtil::int_to_string_base(errorMessageID, 16) + "error number " +
": " + message); QUtil::int_to_string_base(errorMessageID, 16) + ": " + message);
} }
}; };
} // namespace
# endif # endif
void void

View File

@ -60,17 +60,20 @@ _qpdf_data::_qpdf_data() :
{ {
} }
class ProgressReporter: public QPDFWriter::ProgressReporter namespace
{ {
public: class ProgressReporter: public QPDFWriter::ProgressReporter
ProgressReporter(void (*handler)(int, void*), void* data); {
virtual ~ProgressReporter() = default; public:
virtual void reportProgress(int); ProgressReporter(void (*handler)(int, void*), void* data);
virtual ~ProgressReporter() = default;
virtual void reportProgress(int);
private: private:
void (*handler)(int, void*); void (*handler)(int, void*);
void* data; void* data;
}; };
} // namespace
ProgressReporter::ProgressReporter(void (*handler)(int, void*), void* data) : ProgressReporter::ProgressReporter(void (*handler)(int, void*), void* data) :
handler(handler), handler(handler),