]> git.tdb.fi Git - libs/core.git/blob - source/io/base.cpp
Fix an overload resolution problem in formatting values for key_error
[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 void Base::check_access(Mode m) const
20 {
21         if(!(mode&m))
22                 throw invalid_access(m);
23 }
24
25 bool Base::getline(string &line)
26 {
27         line.clear();
28
29         if(eof_flag)
30                 return false;
31
32         while(1)
33         {
34                 int c = get();
35                 if(c==-1 || c=='\n')
36                         break;
37                 line += c;
38         }
39
40         return !eof_flag || !line.empty();
41 }
42
43 int Base::get()
44 {
45         char c;
46         if(do_read(&c, 1)==0)
47                 return -1;
48         return static_cast<unsigned char>(c);
49 }
50
51 void Base::set_eof()
52 {
53         if(!eof_flag)
54         {
55                 eof_flag = true;
56                 signal_end_of_file.emit();
57         }
58 }
59
60 const Handle &Base::get_handle(Mode)
61 {
62         throw logic_error("Base::get_handle");
63 }
64
65 } // namespace IO
66 } // namespace Msp