X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fio%2Fmemory.cpp;h=37954cca5bea6bb95a62a5afdfc094009584ba83;hb=8a3d4f05f46bcd6dda9fc28794d4ac84d0d96f08;hp=274f6bae91c1a6a1d53f67be3872319bdae85bc2;hpb=d16185720fa344263367dbd50c61bfc8183d99a4;p=libs%2Fcore.git diff --git a/source/io/memory.cpp b/source/io/memory.cpp index 274f6ba..37954cc 100644 --- a/source/io/memory.cpp +++ b/source/io/memory.cpp @@ -8,14 +8,14 @@ using namespace std; namespace Msp { namespace IO { -Memory::Memory(char *d, unsigned s) +Memory::Memory(char *d, unsigned s, Mode m) { - init(d, d+s, M_RDWR); + init(d, d+s, m); } -Memory::Memory(char *b, char *e) +Memory::Memory(char *b, char *e, Mode m) { - init(b, e, M_RDWR); + init(b, e, m); } Memory::Memory(const char *cd, unsigned s) @@ -49,6 +49,8 @@ unsigned Memory::do_write(const char *buf, unsigned size) unsigned Memory::do_read(char *buf, unsigned size) { + check_access(M_READ); + if(pos==end) { set_eof(); @@ -64,12 +66,18 @@ unsigned Memory::do_read(char *buf, unsigned size) unsigned Memory::put(char c) { check_access(M_WRITE); + + if(pos==end) + return 0; + *pos++ = c; return 1; } bool Memory::getline(string &line) { + check_access(M_READ); + if(pos==end) { set_eof(); @@ -84,6 +92,8 @@ bool Memory::getline(string &line) int Memory::get() { + check_access(M_READ); + if(pos==end) { set_eof(); @@ -106,9 +116,10 @@ SeekOffset Memory::seek(SeekOffset off, SeekType type) throw invalid_argument("Memory::seek"); if(new_posend) - throw out_of_range("Memory::seek"); + throw bad_seek(off, type); pos = new_pos; + eof_flag = false; return pos-begin; }