]> git.tdb.fi Git - libs/core.git/blob - source/base.cpp
Style update: spaces around assignments
[libs/core.git] / source / base.cpp
1 /* $Id$
2
3 This file is part of libmspio
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7 #include "base.h"
8 #include "poll.h"
9
10 using namespace std;
11
12 namespace Msp {
13 namespace IO {
14
15 bool Base::getline(string &line)
16 {
17         line.clear();
18
19         if(eof_flag)
20                 return false;
21
22         while(1)
23         {
24                 int c = get();
25                 if(c==-1 || c=='\n')
26                         break;
27                 line += c;
28         }
29
30         return !eof_flag || !line.empty();
31 }
32
33 int Base::get()
34 {
35         char c;
36         if(do_read(&c, 1)==0)
37                 return -1;
38         return static_cast<unsigned char>(c);
39 }
40
41 void Base::event(PollEvent ev)
42 {
43         if(ev&P_INPUT)
44                 signal_data_available.emit();
45
46         on_event(ev);
47 }
48
49 Base::~Base()
50 {
51         signal_deleted.emit();
52 }
53
54 Base::Base():
55         mode(M_READ),
56         events(P_NONE),
57         eof_flag(false)
58 { }
59
60 void Base::set_events(PollEvent e)
61 {
62         events = e;
63         signal_events_changed.emit(events);
64 }
65
66 } // namespace IO
67 } // namespace Msp