X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fmemory.cpp;h=f64b4be9e52edcb6fcae3bb94c99d69595fd4e80;hp=274f6bae91c1a6a1d53f67be3872319bdae85bc2;hb=3f7aa81d9212811b323d89949adcccda212cbed3;hpb=d16185720fa344263367dbd50c61bfc8183d99a4 diff --git a/source/io/memory.cpp b/source/io/memory.cpp index 274f6ba..f64b4be 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(); @@ -109,6 +119,7 @@ SeekOffset Memory::seek(SeekOffset off, SeekType type) throw out_of_range("Memory::seek"); pos = new_pos; + eof_flag = false; return pos-begin; }