9 Slice::Slice(Seekable &b, SeekOffset s, SeekOffset l):
15 throw invalid_argument("Slice");
17 Base::Synchronize sync(below);
18 mode = below.get_mode()&M_RDWR;
19 below.signal_flush_required.connect(sigc::mem_fun(this, &Slice::flush));
22 void Slice::set_block(bool)
24 throw logic_error("Slice::set_block");
27 void Slice::set_inherit(bool)
29 throw logic_error("Slice::set_inherit");
37 unsigned Slice::prepare_op(unsigned size, Mode m)
43 SeekOffset pos = below.seek(start_offset+position, S_BEG)-start_offset;
45 throw runtime_error("failed to restore position");
46 sync_position = false;
49 SeekOffset remaining = length-position;
52 if(!size && m==M_READ)
58 size_t Slice::do_write(const char *data, size_t size)
60 Base::Synchronize sync(below);
61 size = prepare_op(size, M_WRITE);
65 size_t len = below.write(data, size);
70 size_t Slice::do_read(char *data, size_t size)
72 Base::Synchronize sync(below);
73 size = prepare_op(size, M_READ);
77 size_t len = below.read(data, size);
78 if(!len && below.eof())
84 size_t Slice::put(char c)
86 Base::Synchronize sync(below);
87 if(!prepare_op(1, M_WRITE))
90 size_t len = below.put(c);
97 Base::Synchronize sync(below);
98 if(!prepare_op(1, M_READ))
102 if(c==-1 && below.eof())
109 const Handle &Slice::get_handle(Mode)
111 throw logic_error("Slice::get_handle");
114 SeekOffset Slice::seek(SeekOffset off, SeekType type)
116 Base::Synchronize sync(below);
123 throw invalid_argument("Slice::seek");
125 if(off<start_offset || off>start_offset+length)
126 throw bad_seek(off, type);
128 signal_flush_required.emit();
130 position = below.seek(off, S_BEG)-start_offset;
131 sync_position = false;