]> git.tdb.fi Git - libs/core.git/blob - source/io/buffered.h
bda2318ba5e7370205157f6242355c042f60c68d
[libs/core.git] / source / io / buffered.h
1 #ifndef MSP_IO_BUFFERED_H_
2 #define MSP_IO_BUFFERED_H_
3
4 #include <sigc++/trackable.h>
5 #include "base.h"
6
7 namespace Msp {
8 namespace IO {
9
10 class Buffered: public Base, public sigc::trackable
11 {
12 private:
13         Base &below;
14         unsigned buf_size;
15         char *buf;
16         char *begin;
17         char *end;
18         Mode cur_op;
19
20 public:
21         Buffered(Base &, unsigned =8192);
22         ~Buffered();
23
24         void flush();
25
26 protected:
27         unsigned do_write(const char *, unsigned);
28         unsigned do_read(char *, unsigned);
29 public:
30         unsigned put(char);
31
32         bool getline(std::string &);
33         int get();
34
35 private:
36         void set_op(Mode);
37 public:
38         Mode get_current_op() const { return cur_op; }
39         unsigned get_current_size() const;
40 };
41
42 } // namespace IO
43 } // namespace Msp
44
45 #endif