]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/slice.cpp
Add move semantics to Variant
[libs/core.git] / source / io / slice.cpp
index 59a7cde301b463d492fb79ef11733702d60d512e..9ca5966c30acd1c03a18af313bbad5cc34737c81 100644 (file)
@@ -1,4 +1,4 @@
-#include <stdexcept>
+#include <msp/core/except.h>
 #include "slice.h"
 
 using namespace std;
@@ -9,18 +9,26 @@ namespace IO {
 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;
@@ -38,7 +46,7 @@ unsigned Slice::prepare_op(unsigned size, Mode m)
                sync_position = false;
        }
 
-       SeekOffset remaining = start_offset+length-position;
+       SeekOffset remaining = length-position;
        if(size>remaining)
                size = remaining;
        if(!size && m==M_READ)
@@ -47,39 +55,39 @@ unsigned Slice::prepare_op(unsigned size, Mode m)
        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;
 }
@@ -88,7 +96,7 @@ int Slice::get()
 {
        Base::Synchronize sync(below);
        if(!prepare_op(1, M_READ))
-               return 0;
+               return -1;
 
        int c = below.get();
        if(c==-1 && below.eof())
@@ -98,6 +106,11 @@ int Slice::get()
        return c;
 }
 
+const Handle &Slice::get_handle(Mode)
+{
+       throw unsupported("Slice::get_handle");
+}
+
 SeekOffset Slice::seek(SeekOffset off, SeekType type)
 {
        Base::Synchronize sync(below);