From e0266badf098a5cec2512eb693bca771e35fd3ab Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 5 Jan 2013 11:39:24 +0200 Subject: [PATCH] Add a constructor to ZlibCompressed that takes a mode parameter --- source/io/zlibcompressed.cpp | 28 +++++++++++++++++++++------- source/io/zlibcompressed.h | 8 ++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/source/io/zlibcompressed.cpp b/source/io/zlibcompressed.cpp index 90b54a2..a558853 100644 --- a/source/io/zlibcompressed.cpp +++ b/source/io/zlibcompressed.cpp @@ -38,18 +38,32 @@ ZlibCompressed::Private::Private() ZlibCompressed::ZlibCompressed(Base &b, unsigned level): - below(b), - buffer_size(1024), - in_buffer(0), - out_buffer(0), - stream_end(false), - priv(0) + below(b) { -#ifdef WITH_ZLIB mode = below.get_mode()&M_RDWR; if(mode!=M_READ && mode!=M_WRITE) throw invalid_access(mode); + init(level); +} + +ZlibCompressed::ZlibCompressed(Base &b, Mode m, unsigned level): + below(b) +{ + mode = m&below.get_mode()&M_RDWR; + if(mode!=M_READ && mode!=M_WRITE) + throw invalid_access(m); + + init(level); +} + +void ZlibCompressed::init(unsigned level) +{ +#ifdef WITH_ZLIB + buffer_size = 1024; + in_buffer = 0; + out_buffer = 0; + stream_end = false; priv = new Private; if(mode==M_WRITE) diff --git a/source/io/zlibcompressed.h b/source/io/zlibcompressed.h index fa7a153..30894cb 100644 --- a/source/io/zlibcompressed.h +++ b/source/io/zlibcompressed.h @@ -46,6 +46,14 @@ public: compression quality, ranging from 1 (fastest) to 9 (best compression). */ ZlibCompressed(Base &, unsigned level = 9); + /** Creates a zlib de/compression object. Mode must be either read or + write, and compatible with the underlying object. */ + ZlibCompressed(Base &, Mode, unsigned level = 9); + +private: + void init(unsigned); + +public: virtual ~ZlibCompressed(); void flush(); -- 2.45.2