X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fbuffered.cpp;fp=source%2Fbuffered.cpp;h=0000000000000000000000000000000000000000;hp=f53d2fc23fa49e38ede87da0188b40d3cfeadb50;hb=6e0fd758970bcb5bad5e3f2454b694cc4d7b4b66;hpb=b97d4e9f86e90254ab9edef7ee62a910f6333c78 diff --git a/source/buffered.cpp b/source/buffered.cpp deleted file mode 100644 index f53d2fc..0000000 --- a/source/buffered.cpp +++ /dev/null @@ -1,188 +0,0 @@ -#include -#include "buffered.h" -#include "except.h" - -using namespace std; - -namespace Msp { -namespace IO { - -Buffered::Buffered(Base &b, unsigned s): - below(b), - buf_size(s), - buf(new char[buf_size]), - begin(buf), - end(buf), - cur_op(M_NONE) -{ - mode = below.get_mode(); - below.signal_flush_required.connect(sigc::mem_fun(this, &Buffered::flush)); -} - -Buffered::~Buffered() -{ - try - { - flush(); - } - catch(...) - { } - - delete[] buf; -} - -void Buffered::flush() -{ - if(cur_op==M_WRITE) - { - unsigned used = end-begin; - if(used) - { - unsigned len = below.write(begin, used); - - begin=end = buf; - - if(len(end-begin), size); - memcpy(data, begin, len); - begin += len; - ret += len; - } - else - // Read the rest directly from the underlying object - ret += below.read(data, size); - - eof_flag = (below.eof() && begin==end); - - return ret; - } -} - -unsigned Buffered::put(char c) -{ - set_op(M_WRITE); - - if(end(*begin++); - - char c; - if(do_read(&c, 1)==0) - return -1; - return static_cast(c); -} - -void Buffered::set_op(Mode op) -{ - if(op!=cur_op) - flush(); - cur_op = op; -} - -unsigned Buffered::get_current_size() const -{ - return end-begin; -} - -Handle Buffered::get_event_handle() -{ - throw Exception("Buffered doesn't support events"); -} - -} // namespace IO -} // namespace Msp