X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Finput.cpp;h=4a44dea05228ae14d1d91e698ebe4eecf98cb662;hp=0f23bb29b9797bff09fc738dc52be6e7aeddf8e7;hb=b39ce68f12c30eedb272b65fe78baec5864d89ca;hpb=98f563736e0837a429714b98656215503c607710 diff --git a/source/input.cpp b/source/input.cpp index 0f23bb2..4a44dea 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -1,24 +1,33 @@ -/* -This file is part of libmspparser -Copyright © 2006 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ +#include #include "input.h" namespace Msp { -namespace Parser { +namespace DataFile { -Input::Input(std::istream &i): - in(i), +Input::Input(IO::Base &i): + in(&i), + compressed(0), line(1), next(-1) { } +Input::~Input() +{ + delete compressed; +} + +void Input::set_decompress() +{ + compressed = new IO::ZlibCompressed(*in, IO::M_READ); + in = compressed; +} + int Input::get() { - int c=next; - next=-1; - if(c<0) c=in.get(); + int c = next; + next = -1; + if(c<0) + c = in->get(); if(c=='\n') ++line; @@ -29,9 +38,14 @@ int Input::get() int Input::peek() { if(next<0) - next=in.get(); + next = in->get(); return next; } -} // namespace Parser +Input::operator bool() const +{ + return next>=0 || !in->eof(); +} + +} // namespace DataFile } // namespace Msp