]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/input.cpp
Add support for compressed datafiles
[libs/datafile.git] / source / input.cpp
index cc82227281563a195fa3a88c5d6e78ef4c44ffc1..a1d462a770d320f0a13c59175459fc8c131186b4 100644 (file)
@@ -1,19 +1,33 @@
+#include <msp/io/zlibcompressed.h>
 #include "input.h"
 
 namespace Msp {
 namespace DataFile {
 
 Input::Input(IO::Base &i):
-       in(i),
+       in(&i),
+       compressed(0),
        line(1),
        next(-1)
 { }
 
+Input::~Input()
+{
+       delete compressed;
+}
+
+void Input::set_decompress()
+{
+       compressed = new IO::ZlibCompressed(*in);
+       in = compressed;
+}
+
 int Input::get()
 {
        int c = next;
        next = -1;
-       if(c<0) c = in.get();
+       if(c<0)
+               c = in->get();
        
        if(c=='\n')
                ++line;
@@ -24,13 +38,13 @@ int Input::get()
 int Input::peek()
 {
        if(next<0)
-               next = in.get();
+               next = in->get();
        return next;
 }
 
 Input::operator bool() const
 {
-       return next>=0 || !in.eof();
+       return next>=0 || !in->eof();
 }
 
 } // namespace DataFile