1 #ifndef MSP_IO_SLICE_H_
2 #define MSP_IO_SLICE_H_
4 #include <msp/core/mspcore_api.h>
11 Presents a part of seekable I/O object as if it was a complete object. This
12 allows in-place access to embedded resources where the loader expects to
13 receive a complete file.
15 When a Slice is created, its read/write offset is placed at the beginning of
16 its range. If the offset of the underlying object is changed, the Slice will
17 restore it before the next access. This enables multiple Slices to be created
18 on top of the same object.
20 class MSPCORE_API Slice: public Seekable, public sigc::trackable
24 SeekOffset start_offset = 0;
25 SeekOffset length = 0;
26 SeekOffset position = 0;
27 bool sync_position = true;
30 Slice(Seekable &, SeekOffset, SeekOffset);
32 void set_block(bool) override;
33 void set_inherit(bool) override;
38 unsigned prepare_op(unsigned, Mode);
40 std::size_t do_write(const char *, std::size_t) override;
41 std::size_t do_read(char *, std::size_t) override;
44 std::size_t put(char) override;
47 const Handle &get_handle(Mode) override;
49 SeekOffset seek(SeekOffset, SeekType) override;
50 SeekOffset tell() const override { return position; }