X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fbuffered.cpp;h=9f001fbe9ae94b944611f368416799ceab836a04;hp=f53d2fc23fa49e38ede87da0188b40d3cfeadb50;hb=HEAD;hpb=c7afef88380ebebc8c2b04e48664d73281ec8848 diff --git a/source/io/buffered.cpp b/source/io/buffered.cpp index f53d2fc..9f001fb 100644 --- a/source/io/buffered.cpp +++ b/source/io/buffered.cpp @@ -1,6 +1,7 @@ #include +#include #include "buffered.h" -#include "except.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(end-begin), size); + len = min(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(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 Exception("Buffered doesn't support events"); -} - } // namespace IO } // namespace Msp