]> git.tdb.fi Git - libs/core.git/blob - source/io/base.cpp
926440a9c4575da477b37e4ad60eea3593ef86a4
[libs/core.git] / source / io / base.cpp
1 #include "base.h"
2 #include "poll.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace IO {
8
9 Base::Base():
10         mode(M_READ),
11         eof_flag(false)
12 { }
13
14 Base::~Base()
15 {
16         signal_deleted.emit();
17 }
18
19 bool Base::getline(string &line)
20 {
21         line.clear();
22
23         if(eof_flag)
24                 return false;
25
26         while(1)
27         {
28                 int c = get();
29                 if(c==-1 || c=='\n')
30                         break;
31                 line += c;
32         }
33
34         return !eof_flag || !line.empty();
35 }
36
37 int Base::get()
38 {
39         char c;
40         if(do_read(&c, 1)==0)
41                 return -1;
42         return static_cast<unsigned char>(c);
43 }
44
45 } // namespace IO
46 } // namespace Msp