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));
29 unsigned Slice::prepare_op(unsigned size, Mode m)
35 SeekOffset pos = below.seek(start_offset+position, S_BEG)-start_offset;
37 throw runtime_error("failed to restore position");
38 sync_position = false;
41 SeekOffset remaining = start_offset+length-position;
44 if(!size && m==M_READ)
50 unsigned Slice::do_write(const char *data, unsigned size)
52 Base::Synchronize sync(below);
53 size = prepare_op(size, M_WRITE);
57 unsigned len = below.write(data, size);
62 unsigned Slice::do_read(char *data, unsigned size)
64 Base::Synchronize sync(below);
65 size = prepare_op(size, M_READ);
69 unsigned len = below.read(data, size);
70 if(!len && below.eof())
76 unsigned Slice::put(char c)
78 Base::Synchronize sync(below);
79 if(!prepare_op(1, M_WRITE))
82 unsigned len = below.put(c);
89 Base::Synchronize sync(below);
90 if(!prepare_op(1, M_READ))
94 if(c==-1 && below.eof())
101 SeekOffset Slice::seek(SeekOffset off, SeekType type)
103 Base::Synchronize sync(below);
110 throw invalid_argument("Slice::seek");
112 if(off<start_offset || off>start_offset+length)
113 throw bad_seek(off, type);
115 signal_flush_required.emit();
117 position = below.seek(off, S_BEG)-start_offset;
118 sync_position = false;