9 Slice::Slice(Seekable &b, SeekOffset s, SeekOffset l):
17 throw invalid_argument("Slice");
19 Base::Synchronize sync(below);
20 mode = below.get_mode()&M_RDWR;
21 below.signal_flush_required.connect(sigc::mem_fun(this, &Slice::flush));
24 void Slice::set_block(bool)
26 throw logic_error("Slice::set_block");
29 void Slice::set_inherit(bool)
31 throw logic_error("Slice::set_inherit");
39 unsigned Slice::prepare_op(unsigned size, Mode m)
45 SeekOffset pos = below.seek(start_offset+position, S_BEG)-start_offset;
47 throw runtime_error("failed to restore position");
48 sync_position = false;
51 SeekOffset remaining = length-position;
54 if(!size && m==M_READ)
60 unsigned Slice::do_write(const char *data, unsigned size)
62 Base::Synchronize sync(below);
63 size = prepare_op(size, M_WRITE);
67 unsigned len = below.write(data, size);
72 unsigned Slice::do_read(char *data, unsigned size)
74 Base::Synchronize sync(below);
75 size = prepare_op(size, M_READ);
79 unsigned len = below.read(data, size);
80 if(!len && below.eof())
86 unsigned Slice::put(char c)
88 Base::Synchronize sync(below);
89 if(!prepare_op(1, M_WRITE))
92 unsigned len = below.put(c);
99 Base::Synchronize sync(below);
100 if(!prepare_op(1, M_READ))
104 if(c==-1 && below.eof())
111 const Handle &Slice::get_handle(Mode)
113 throw logic_error("Slice::get_handle");
116 SeekOffset Slice::seek(SeekOffset off, SeekType type)
118 Base::Synchronize sync(below);
125 throw invalid_argument("Slice::seek");
127 if(off<start_offset || off>start_offset+length)
128 throw bad_seek(off, type);
130 signal_flush_required.emit();
132 position = below.seek(off, S_BEG)-start_offset;
133 sync_position = false;