]> git.tdb.fi Git - libs/core.git/commitdiff
Add a constructor to ZlibCompressed that takes a mode parameter
authorMikko Rasa <tdb@tdb.fi>
Sat, 5 Jan 2013 09:39:24 +0000 (11:39 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 5 Jan 2013 09:39:24 +0000 (11:39 +0200)
source/io/zlibcompressed.cpp
source/io/zlibcompressed.h

index 90b54a214bed69ce272952e3ebad8ca05e6ff1d4..a5588534cc140ab1608dd31171854144917ebcc5 100644 (file)
@@ -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)
index fa7a15315ccb09a7a44a1671e85d26f3ea5b3bc6..30894cb9cf2345e7e5d79ed742dfe74e115ab99c 100644 (file)
@@ -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();