]> git.tdb.fi Git - libs/core.git/blob - source/io/base.cpp
Add a few missing default initializers
[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 { }
11
12 Base::~Base()
13 {
14         signal_deleted.emit();
15         delete mutex;
16 }
17
18 void Base::check_access(Mode m) const
19 {
20         if(!(mode&m))
21                 throw invalid_access(m);
22 }
23
24 bool Base::getline(string &line)
25 {
26         line.clear();
27
28         if(eof_flag)
29                 return false;
30
31         while(!eof())
32         {
33                 int c = get();
34                 if(c==-1 || c=='\n')
35                         break;
36                 line += c;
37         }
38
39         return !eof_flag || !line.empty();
40 }
41
42 int Base::get()
43 {
44         char c;
45         if(do_read(&c, 1)==0)
46                 return -1;
47         return static_cast<unsigned char>(c);
48 }
49
50 void Base::set_eof()
51 {
52         if(!eof_flag)
53         {
54                 eof_flag = true;
55                 signal_end_of_file.emit();
56         }
57 }
58
59
60 Base::Synchronize::Synchronize(Base &i):
61         io(i)
62 {
63         if(!io.mutex)
64                 io.mutex = new Mutex;
65         io.mutex->lock();
66 }
67
68 Base::Synchronize::~Synchronize()
69 {
70         io.mutex->unlock();
71 }
72
73 } // namespace IO
74 } // namespace Msp