diff options
author | Jay Berkenbilt <ejb@ql.org> | 2019-06-22 03:32:47 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2019-06-22 16:13:27 +0200 |
commit | 79f6b4823b95b65290a045a59fdd4a8d9b302708 (patch) | |
tree | b94d273dd51e64a7144b669cf5ed91d826cc1387 /libqpdf/Pl_Flate.cc | |
parent | 864a546af6e1c17e0de2dc2be6da105f454b6e54 (diff) | |
download | qpdf-79f6b4823b95b65290a045a59fdd4a8d9b302708.tar.zst |
Convert remaining public classes to use Members pattern
Have classes contain only a single private member of type
PointerHolder<Members>. This makes it safe to change the structure of
the Members class without breaking binary compatibility. Many of the
classes already follow this pattern quite successfully. This brings in
the rest of the class that are part of the public API.
Diffstat (limited to 'libqpdf/Pl_Flate.cc')
-rw-r--r-- | libqpdf/Pl_Flate.cc | 66 |
1 files changed, 39 insertions, 27 deletions
diff --git a/libqpdf/Pl_Flate.cc b/libqpdf/Pl_Flate.cc index 67e02d2d..c42d3c28 100644 --- a/libqpdf/Pl_Flate.cc +++ b/libqpdf/Pl_Flate.cc @@ -6,12 +6,12 @@ #include <qpdf/QUtil.hh> #include <qpdf/QIntC.hh> -Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next, - action_e action, unsigned int out_bufsize_int) : - Pipeline(identifier, next), - out_bufsize(QIntC::to_size(out_bufsize_int)), +Pl_Flate::Members::Members(size_t out_bufsize, + action_e action) : + out_bufsize(out_bufsize), action(action), - initialized(false) + initialized(false), + zdata(0) { this->outbuf = new unsigned char[out_bufsize]; // Indirect through zdata to reach the z_stream so we don't have @@ -38,7 +38,7 @@ Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next, zstream.avail_out = QIntC::to_uint(out_bufsize); } -Pl_Flate::~Pl_Flate() +Pl_Flate::Members::~Members() { delete [] this->outbuf; this->outbuf = 0; @@ -60,10 +60,21 @@ Pl_Flate::~Pl_Flate() this->zdata = 0; } +Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next, + action_e action, unsigned int out_bufsize_int) : + Pipeline(identifier, next), + m(new Members(QIntC::to_size(out_bufsize_int), action)) +{ +} + +Pl_Flate::~Pl_Flate() +{ +} + void Pl_Flate::write(unsigned char* data, size_t len) { - if (this->outbuf == 0) + if (this->m->outbuf == 0) { throw std::logic_error( this->identifier + @@ -79,7 +90,7 @@ Pl_Flate::write(unsigned char* data, size_t len) { size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); handleData(buf, bytes, - (action == a_inflate ? Z_SYNC_FLUSH : Z_NO_FLUSH)); + (this->m->action == a_inflate ? Z_SYNC_FLUSH : Z_NO_FLUSH)); bytes_left -= bytes; buf += bytes; } @@ -94,11 +105,11 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush) "Pl_Flate: zlib doesn't support data" " blocks larger than int"); } - z_stream& zstream = *(static_cast<z_stream*>(this->zdata)); + z_stream& zstream = *(static_cast<z_stream*>(this->m->zdata)); zstream.next_in = data; zstream.avail_in = QIntC::to_uint(len); - if (! this->initialized) + if (! this->m->initialized) { int err = Z_OK; @@ -109,7 +120,7 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wold-style-cast" #endif - if (this->action == a_deflate) + if (this->m->action == a_deflate) { err = deflateInit(&zstream, Z_DEFAULT_COMPRESSION); } @@ -123,7 +134,7 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush) #endif checkError("Init", err); - this->initialized = true; + this->m->initialized = true; } int err = Z_OK; @@ -131,7 +142,7 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush) bool done = false; while (! done) { - if (action == a_deflate) + if (this->m->action == a_deflate) { err = deflate(&zstream, flush); } @@ -139,7 +150,7 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush) { err = inflate(&zstream, flush); } - if ((action == a_inflate) && (err != Z_OK) && zstream.msg && + if ((this->m->action == a_inflate) && (err != Z_OK) && zstream.msg && (strcmp(zstream.msg, "incorrect data check") == 0)) { // Other PDF readers ignore this specific error. Combining @@ -172,12 +183,12 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush) done = true; } uLong ready = - QIntC::to_ulong(this->out_bufsize - zstream.avail_out); + QIntC::to_ulong(this->m->out_bufsize - zstream.avail_out); if (ready > 0) { - this->getNext()->write(this->outbuf, ready); - zstream.next_out = this->outbuf; - zstream.avail_out = QIntC::to_uint(this->out_bufsize); + this->getNext()->write(this->m->outbuf, ready); + zstream.next_out = this->m->outbuf; + zstream.avail_out = QIntC::to_uint(this->m->out_bufsize); } } break; @@ -194,16 +205,16 @@ Pl_Flate::finish() { try { - if (this->outbuf) + if (this->m->outbuf) { - if (this->initialized) + if (this->m->initialized) { - z_stream& zstream = *(static_cast<z_stream*>(this->zdata)); + z_stream& zstream = *(static_cast<z_stream*>(this->m->zdata)); unsigned char buf[1]; buf[0] = '\0'; handleData(buf, 0, Z_FINISH); int err = Z_OK; - if (action == a_deflate) + if (this->m->action == a_deflate) { err = deflateEnd(&zstream); } @@ -211,12 +222,12 @@ Pl_Flate::finish() { err = inflateEnd(&zstream); } - this->initialized = false; + this->m->initialized = false; checkError("End", err); } - delete [] this->outbuf; - this->outbuf = 0; + delete [] this->m->outbuf; + this->m->outbuf = 0; } } catch (std::exception& e) @@ -230,10 +241,11 @@ Pl_Flate::finish() void Pl_Flate::checkError(char const* prefix, int error_code) { - z_stream& zstream = *(static_cast<z_stream*>(this->zdata)); + z_stream& zstream = *(static_cast<z_stream*>(this->m->zdata)); if (error_code != Z_OK) { - char const* action_str = (action == a_deflate ? "deflate" : "inflate"); + char const* action_str = + (this->m->action == a_deflate ? "deflate" : "inflate"); std::string msg = this->identifier + ": " + action_str + ": " + prefix + ": "; |