]> git.tdb.fi Git - libs/core.git/blob - source/io/memory.h
Use nullptr instead of 0 for pointers
[libs/core.git] / source / io / memory.h
1 #ifndef MSP_IO_MEMORY_H_
2 #define MSP_IO_MEMORY_H_
3
4 #include "seekable.h"
5
6 namespace Msp {
7 namespace IO {
8
9 class Memory: public Seekable
10 {
11 private:
12         char *begin = nullptr;
13         char *end = nullptr;
14         char *pos = nullptr;
15
16 public:
17         Memory(char *d, std::size_t s, Mode m = M_RDWR): Memory(d, d+s, m) { }
18         Memory(char *, char *, Mode = M_RDWR);
19         Memory(const char *d, std::size_t s): Memory(const_cast<char *>(d), const_cast<char *>(d+s), M_READ) { }
20         Memory(const char *b, const char *e): Memory(const_cast<char *>(b), const_cast<char *>(e), M_READ) { }
21
22         virtual void set_block(bool);
23         virtual void set_inherit(bool);
24
25 private:
26         virtual std::size_t do_write(const char *, std::size_t);
27         virtual std::size_t do_read(char *, std::size_t);
28 public:
29         virtual std::size_t put(char);
30         virtual bool getline(std::string &);
31         virtual int get();
32
33         virtual const Handle &get_handle(Mode);
34
35         virtual SeekOffset seek(SeekOffset, SeekType);
36         virtual SeekOffset tell() const { return pos-begin; }
37 };
38
39 } // namespace IO
40 } // namespace Msp
41
42 #endif