]> git.tdb.fi Git - libs/core.git/blob - source/base.cpp
Move class members and comments around
[libs/core.git] / source / 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         events(P_NONE),
12         eof_flag(false)
13 { }
14
15 Base::~Base()
16 {
17         signal_deleted.emit();
18 }
19
20 bool Base::getline(string &line)
21 {
22         line.clear();
23
24         if(eof_flag)
25                 return false;
26
27         while(1)
28         {
29                 int c = get();
30                 if(c==-1 || c=='\n')
31                         break;
32                 line += c;
33         }
34
35         return !eof_flag || !line.empty();
36 }
37
38 int Base::get()
39 {
40         char c;
41         if(do_read(&c, 1)==0)
42                 return -1;
43         return static_cast<unsigned char>(c);
44 }
45
46 void Base::set_events(PollEvent e)
47 {
48         events = e;
49         signal_events_changed.emit(events);
50 }
51
52 void Base::event(PollEvent ev)
53 {
54         if(ev&P_INPUT)
55                 signal_data_available.emit();
56
57         on_event(ev);
58 }
59
60 } // namespace IO
61 } // namespace Msp