9 Slice::Slice(Seekable &b, SeekOffset s, SeekOffset l):
17 throw invalid_argument("Slice");
19 mode = below.get_mode()&M_RDWR;
20 below.signal_flush_required.connect(sigc::mem_fun(this, &Slice::flush));
28 unsigned Slice::prepare_op(unsigned size, Mode m)
33 seek(position, S_BEG);
35 SeekOffset remaining = start_offset+length-position;
38 if(!size && m==M_READ)
44 unsigned Slice::do_write(const char *data, unsigned size)
46 size = prepare_op(size, M_WRITE);
50 unsigned len = below.write(data, size);
55 unsigned Slice::do_read(char *data, unsigned size)
57 size = prepare_op(size, M_READ);
61 unsigned len = below.read(data, size);
62 if(!len && below.eof())
68 unsigned Slice::put(char c)
70 if(!prepare_op(1, M_WRITE))
73 unsigned len = below.put(c);
80 if(!prepare_op(1, M_READ))
84 if(c==-1 && below.eof())
91 SeekOffset Slice::seek(SeekOffset off, SeekType type)
98 off += start_offset+length;
100 if(off<start_offset || off>start_offset+length)
101 throw bad_seek(off, type);
103 signal_flush_required.emit();
105 position = below.seek(off, S_BEG)-start_offset;
106 sync_position = false;