]> git.tdb.fi Git - libs/datafile.git/blob - source/input.cpp
Cosmetic changes
[libs/datafile.git] / source / input.cpp
1 #include <msp/io/zlibcompressed.h>
2 #include "input.h"
3
4 namespace Msp {
5 namespace DataFile {
6
7 Input::Input(IO::Base &i):
8         in(&i),
9         compressed(0),
10         line(1),
11         next(-1)
12 { }
13
14 Input::~Input()
15 {
16         delete compressed;
17 }
18
19 void Input::set_decompress()
20 {
21         compressed = new IO::ZlibCompressed(*in, IO::M_READ);
22         in = compressed;
23 }
24
25 int Input::get()
26 {
27         int c = next;
28         next = -1;
29         if(c<0)
30                 c = in->get();
31         
32         if(c=='\n')
33                 ++line;
34
35         return c;
36 }
37
38 int Input::peek()
39 {
40         if(next<0)
41                 next = in->get();
42         return next;
43 }
44
45 Input::operator bool() const
46 {
47         return next>=0 || !in->eof();
48 }
49
50 } // namespace DataFile
51 } // namespace Msp