-#include <stdexcept>
+#include <msp/core/except.h>
#include "slice.h"
using namespace std;
Slice::Slice(Seekable &b, SeekOffset s, SeekOffset l):
below(b),
start_offset(s),
- length(l),
- position(0),
- sync_position(true)
+ length(l)
{
if(s<0 || l<0)
- throw invalid_argument("Slice");
+ throw invalid_argument("Slice::Slice");
Base::Synchronize sync(below);
mode = below.get_mode()&M_RDWR;
below.signal_flush_required.connect(sigc::mem_fun(this, &Slice::flush));
}
+void Slice::set_block(bool)
+{
+ throw unsupported("Slice::set_block");
+}
+
+void Slice::set_inherit(bool)
+{
+ throw unsupported("Slice::set_inherit");
+}
+
void Slice::flush()
{
sync_position = true;
return size;
}
-unsigned Slice::do_write(const char *data, unsigned size)
+size_t Slice::do_write(const char *data, size_t size)
{
Base::Synchronize sync(below);
size = prepare_op(size, M_WRITE);
if(!size)
return 0;
- unsigned len = below.write(data, size);
+ size_t len = below.write(data, size);
position += len;
return len;
}
-unsigned Slice::do_read(char *data, unsigned size)
+size_t Slice::do_read(char *data, size_t size)
{
Base::Synchronize sync(below);
size = prepare_op(size, M_READ);
if(!size)
return 0;
- unsigned len = below.read(data, size);
+ size_t len = below.read(data, size);
if(!len && below.eof())
set_eof();
position += len;
return len;
}
-unsigned Slice::put(char c)
+size_t Slice::put(char c)
{
Base::Synchronize sync(below);
if(!prepare_op(1, M_WRITE))
return 0;
- unsigned len = below.put(c);
+ size_t len = below.put(c);
position += len;
return len;
}
{
Base::Synchronize sync(below);
if(!prepare_op(1, M_READ))
- return 0;
+ return -1;
int c = below.get();
if(c==-1 && below.eof())
return c;
}
+const Handle &Slice::get_handle(Mode)
+{
+ throw unsupported("Slice::get_handle");
+}
+
SeekOffset Slice::seek(SeekOffset off, SeekType type)
{
Base::Synchronize sync(below);