]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/buffered.cpp
Add move semantics to Variant
[libs/core.git] / source / io / buffered.cpp
index f72522361b1d013d8f79d21fedefff910d0b1c1c..9f001fbe9ae94b944611f368416799ceab836a04 100644 (file)
@@ -1,6 +1,7 @@
 #include <cstring>
-#include <stdexcept>
+#include <msp/core/except.h>
 #include "buffered.h"
+#include "handle.h"
 
 using namespace std;
 
@@ -12,8 +13,7 @@ Buffered::Buffered(Base &b, unsigned s):
        buf_size(s),
        buf(new char[buf_size]),
        begin(buf),
-       end(buf),
-       cur_op(M_NONE)
+       end(buf)
 {
        mode = below.get_mode();
        below.signal_flush_required.connect(sigc::mem_fun(this, &Buffered::flush));
@@ -31,6 +31,16 @@ Buffered::~Buffered()
        delete[] buf;
 }
 
+void Buffered::set_block(bool)
+{
+       throw unsupported("Buffered::set_block");
+}
+
+void Buffered::set_inherit(bool)
+{
+       throw unsupported("Buffered::set_block");
+}
+
 void Buffered::flush()
 {
        if(cur_op==M_WRITE)
@@ -40,17 +50,17 @@ void Buffered::flush()
                {
                        unsigned len = below.write(begin, used);
 
-                       begin=end = buf;
+                       begin = end = buf;
 
                        if(len<used)
                                throw runtime_error("Couldn't flush all data");
                }
        }
        else if(cur_op==M_READ)
-               begin=end = buf;
+               begin = end = buf;
 }
 
-unsigned Buffered::do_write(const char *data, unsigned size)
+size_t Buffered::do_write(const char *data, size_t size)
 {
        set_op(M_WRITE);
 
@@ -81,7 +91,7 @@ unsigned Buffered::do_write(const char *data, unsigned size)
        }
 }
 
-unsigned Buffered::do_read(char *data, unsigned size)
+size_t Buffered::do_read(char *data, size_t size)
 {
        set_op(M_READ);
 
@@ -99,8 +109,8 @@ unsigned Buffered::do_read(char *data, unsigned size)
        {
                // Give out whatever is in the buffer already
                memcpy(data, begin, end-begin);
-               unsigned ret = end-begin;
-               begin=end = buf;
+               size_t ret = end-begin;
+               begin = end = buf;
 
                data += ret;
                size -= ret;
@@ -108,10 +118,10 @@ unsigned Buffered::do_read(char *data, unsigned size)
                if(size<buf_size)
                {
                        // Fill the buffer and serve the rest of the request from it
-                       unsigned len = below.read(end, buf+buf_size-end);
+                       size_t len = below.read(end, buf+buf_size-end);
                        end += len;
 
-                       len = min(static_cast<unsigned>(end-begin), size);
+                       len = min<size_t>(end-begin, size);
                        memcpy(data, begin, len);
                        begin += len;
                        ret += len;
@@ -126,7 +136,7 @@ unsigned Buffered::do_read(char *data, unsigned size)
        }
 }
 
-unsigned Buffered::put(char c)
+size_t Buffered::put(char c)
 {
        set_op(M_WRITE);
 
@@ -139,7 +149,7 @@ unsigned Buffered::put(char c)
                return do_write(&c, 1);
 }
 
-bool Buffered::getline(std::string &line)
+bool Buffered::getline(string &line)
 {
        set_op(M_READ);
 
@@ -167,6 +177,11 @@ int Buffered::get()
        return static_cast<unsigned char>(c);
 }
 
+const Handle &Buffered::get_handle(Mode)
+{
+       throw unsupported("Buffered::get_handle");
+}
+
 void Buffered::set_op(Mode op)
 {
        if(op!=cur_op)
@@ -174,15 +189,10 @@ void Buffered::set_op(Mode op)
        cur_op = op;
 }
 
-unsigned Buffered::get_current_size() const
+size_t Buffered::get_current_size() const
 {
        return end-begin;
 }
 
-Handle Buffered::get_event_handle()
-{
-       throw logic_error("Buffered doesn't support events");
-}
-
 } // namespace IO
 } // namespace Msp