]> git.tdb.fi Git - libs/core.git/blob - source/io/slice.h
Use #ifdef _WIN32 rather than WIN32
[libs/core.git] / source / io / slice.h
1 #ifndef MSP_IO_SLICE_H_
2 #define MSP_IO_SLICE_H_
3
4 #include "seekable.h"
5
6 namespace Msp {
7 namespace IO {
8
9 /**
10 Presents a part of seekable I/O object as if it was a complete object.  This
11 allows in-place access to embedded resources where the loader expects to
12 receive a complete file.
13
14 When a Slice is created, its read/write offset is placed at the beginning of
15 its range.  If the offset of the underlying object is changed, the Slice will
16 restore it before the next access.  This enables multiple Slices to be created
17 on top of the same object.
18 */
19 class Slice: public Seekable, public sigc::trackable
20 {
21 private:
22         Seekable &below;
23         SeekOffset start_offset;
24         SeekOffset length;
25         SeekOffset position;
26         bool sync_position;
27
28 public:
29         Slice(Seekable &, SeekOffset, SeekOffset);
30
31 private:
32         void flush();
33
34         unsigned prepare_op(unsigned, Mode);
35 protected:
36         virtual unsigned do_write(const char *, unsigned);
37         virtual unsigned do_read(char *, unsigned);
38
39 public:
40         virtual unsigned put(char);
41         virtual int get();
42
43         virtual SeekOffset seek(SeekOffset, SeekType);
44         virtual SeekOffset tell() const { return position; }
45 };
46
47 } // namespace IO
48 } // namespace Msp
49
50 #endif