summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2012-07-15 07:07:53 (GMT)
committerRemko Tronçon <git@el-tramo.be>2012-07-15 07:07:53 (GMT)
commit7a591138e89ad71ee1dd9825d7705c94f9bb50d2 (patch)
tree25b9832b234d498ff359ee6d60758004a3232278 /Swiften
parentfbe2f40509da8c6c25d07de18ded3c0e3194ef6b (diff)
downloadswift-7a591138e89ad71ee1dd9825d7705c94f9bb50d2.zip
swift-7a591138e89ad71ee1dd9825d7705c94f9bb50d2.tar.bz2
Hide ZLib implementation.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Compress/ZLibCodecompressor.cpp29
-rw-r--r--Swiften/Compress/ZLibCodecompressor.h5
-rw-r--r--Swiften/Compress/ZLibCodecompressor_Private.h17
-rw-r--r--Swiften/Compress/ZLibCompressor.cpp13
-rw-r--r--Swiften/Compress/ZLibCompressor.h10
-rw-r--r--Swiften/Compress/ZLibDecompressor.cpp13
-rw-r--r--Swiften/Compress/ZLibDecompressor.h10
7 files changed, 63 insertions, 34 deletions
diff --git a/Swiften/Compress/ZLibCodecompressor.cpp b/Swiften/Compress/ZLibCodecompressor.cpp
index 0869d6b..125492a 100644
--- a/Swiften/Compress/ZLibCodecompressor.cpp
+++ b/Swiften/Compress/ZLibCodecompressor.cpp
@@ -8,18 +8,21 @@
#include <cassert>
#include <string.h>
+#include <zlib.h>
#include <Swiften/Compress/ZLibException.h>
+#include <Swiften/Compress/ZLibCodecompressor_Private.h>
namespace Swift {
static const int CHUNK_SIZE = 1024; // If you change this, also change the unittest
-ZLibCodecompressor::ZLibCodecompressor() {
- memset(&stream_, 0, sizeof(z_stream));
- stream_.zalloc = Z_NULL;
- stream_.zfree = Z_NULL;
- stream_.opaque = Z_NULL;
+
+ZLibCodecompressor::ZLibCodecompressor() : p(boost::make_shared<Private>()) {
+ memset(&p->stream, 0, sizeof(z_stream));
+ p->stream.zalloc = Z_NULL;
+ p->stream.zfree = Z_NULL;
+ p->stream.opaque = Z_NULL;
}
ZLibCodecompressor::~ZLibCodecompressor() {
@@ -27,24 +30,24 @@ ZLibCodecompressor::~ZLibCodecompressor() {
SafeByteArray ZLibCodecompressor::process(const SafeByteArray& input) {
SafeByteArray output;
- stream_.avail_in = input.size();
- stream_.next_in = reinterpret_cast<Bytef*>(const_cast<unsigned char*>(vecptr(input)));
+ p->stream.avail_in = input.size();
+ p->stream.next_in = reinterpret_cast<Bytef*>(const_cast<unsigned char*>(vecptr(input)));
int outputPosition = 0;
do {
output.resize(outputPosition + CHUNK_SIZE);
- stream_.avail_out = CHUNK_SIZE;
- stream_.next_out = reinterpret_cast<Bytef*>(vecptr(output) + outputPosition);
+ p->stream.avail_out = CHUNK_SIZE;
+ p->stream.next_out = reinterpret_cast<Bytef*>(vecptr(output) + outputPosition);
int result = processZStream();
if (result != Z_OK && result != Z_BUF_ERROR) {
- throw ZLibException(/* stream_.msg */);
+ throw ZLibException(/* p->stream.msg */);
}
outputPosition += CHUNK_SIZE;
}
- while (stream_.avail_out == 0);
- if (stream_.avail_in != 0) {
+ while (p->stream.avail_out == 0);
+ if (p->stream.avail_in != 0) {
throw ZLibException();
}
- output.resize(outputPosition - stream_.avail_out);
+ output.resize(outputPosition - p->stream.avail_out);
return output;
}
diff --git a/Swiften/Compress/ZLibCodecompressor.h b/Swiften/Compress/ZLibCodecompressor.h
index 93babf0..a125fc1 100644
--- a/Swiften/Compress/ZLibCodecompressor.h
+++ b/Swiften/Compress/ZLibCodecompressor.h
@@ -6,8 +6,6 @@
#pragma once
-#include <zlib.h>
-
#include <Swiften/Base/SafeByteArray.h>
namespace Swift {
@@ -20,6 +18,7 @@ namespace Swift {
virtual int processZStream() = 0;
protected:
- z_stream stream_;
+ class Private;
+ boost::shared_ptr<Private> p;
};
}
diff --git a/Swiften/Compress/ZLibCodecompressor_Private.h b/Swiften/Compress/ZLibCodecompressor_Private.h
new file mode 100644
index 0000000..1f24b83
--- /dev/null
+++ b/Swiften/Compress/ZLibCodecompressor_Private.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2012 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Compress/ZLibCodecompressor.h>
+
+#include <zlib.h>
+
+namespace Swift {
+ struct ZLibCodecompressor::Private {
+ z_stream stream;
+ };
+}
diff --git a/Swiften/Compress/ZLibCompressor.cpp b/Swiften/Compress/ZLibCompressor.cpp
index 5d98e38..6af8d83 100644
--- a/Swiften/Compress/ZLibCompressor.cpp
+++ b/Swiften/Compress/ZLibCompressor.cpp
@@ -7,15 +7,26 @@
#include <Swiften/Compress/ZLibCompressor.h>
#include <cassert>
+#include <zlib.h>
+
+#include <Swiften/Compress/ZLibCodecompressor_Private.h>
#pragma GCC diagnostic ignored "-Wold-style-cast"
namespace Swift {
ZLibCompressor::ZLibCompressor() {
- int result = deflateInit(&stream_, COMPRESSION_LEVEL);
+ int result = deflateInit(&p->stream, COMPRESSION_LEVEL);
assert(result == Z_OK);
(void) result;
}
+ZLibCompressor::~ZLibCompressor() {
+ deflateEnd(&p->stream);
+}
+
+int ZLibCompressor::processZStream() {
+ return deflate(&p->stream, Z_SYNC_FLUSH);
+}
+
}
diff --git a/Swiften/Compress/ZLibCompressor.h b/Swiften/Compress/ZLibCompressor.h
index 1add725..f4a8d2f 100644
--- a/Swiften/Compress/ZLibCompressor.h
+++ b/Swiften/Compress/ZLibCompressor.h
@@ -7,20 +7,14 @@
#pragma once
#include <Swiften/Compress/ZLibCodecompressor.h>
-#include <Swiften/Base/ByteArray.h>
namespace Swift {
class ZLibCompressor : public ZLibCodecompressor {
public:
ZLibCompressor();
+ ~ZLibCompressor();
- ~ZLibCompressor() {
- deflateEnd(&stream_);
- }
-
- virtual int processZStream() {
- return deflate(&stream_, Z_SYNC_FLUSH);
- }
+ virtual int processZStream();
private:
static const int COMPRESSION_LEVEL = 9;
diff --git a/Swiften/Compress/ZLibDecompressor.cpp b/Swiften/Compress/ZLibDecompressor.cpp
index ab954f4..f5df9fe 100644
--- a/Swiften/Compress/ZLibDecompressor.cpp
+++ b/Swiften/Compress/ZLibDecompressor.cpp
@@ -6,16 +6,27 @@
#include <Swiften/Compress/ZLibDecompressor.h>
+#include <zlib.h>
#include <cassert>
+#include <Swiften/Compress/ZLibCodecompressor_Private.h>
+
#pragma GCC diagnostic ignored "-Wold-style-cast"
namespace Swift {
ZLibDecompressor::ZLibDecompressor() {
- int result = inflateInit(&stream_);
+ int result = inflateInit(&p->stream);
assert(result == Z_OK);
(void) result;
}
+ZLibDecompressor::~ZLibDecompressor() {
+ inflateEnd(&p->stream);
+}
+
+int ZLibDecompressor::processZStream() {
+ return inflate(&p->stream, Z_SYNC_FLUSH);
+}
+
}
diff --git a/Swiften/Compress/ZLibDecompressor.h b/Swiften/Compress/ZLibDecompressor.h
index 67994d1..0726c8b 100644
--- a/Swiften/Compress/ZLibDecompressor.h
+++ b/Swiften/Compress/ZLibDecompressor.h
@@ -7,19 +7,13 @@
#pragma once
#include <Swiften/Compress/ZLibCodecompressor.h>
-#include <Swiften/Base/ByteArray.h>
namespace Swift {
class ZLibDecompressor : public ZLibCodecompressor {
public:
ZLibDecompressor();
+ ~ZLibDecompressor();
- ~ZLibDecompressor() {
- inflateEnd(&stream_);
- }
-
- virtual int processZStream() {
- return inflate(&stream_, Z_SYNC_FLUSH);
- }
+ virtual int processZStream();
};
}