X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fmemory.cpp;h=274f6bae91c1a6a1d53f67be3872319bdae85bc2;hp=af6ef3d44ce386ce2bd7d2caaf8b1a8de24a9fa7;hb=bff25a255af05f1ddd6c956a97fa6b8c50c9b22d;hpb=c21ab7e49852585df01b4cc19599e25a918b581b diff --git a/source/io/memory.cpp b/source/io/memory.cpp index af6ef3d..274f6ba 100644 --- a/source/io/memory.cpp +++ b/source/io/memory.cpp @@ -39,7 +39,7 @@ void Memory::init(char *b, char *e, Mode m) unsigned Memory::do_write(const char *buf, unsigned size) { - check_mode(M_WRITE); + check_access(M_WRITE); size = min(size, end-pos); memcpy(pos, buf, size); @@ -51,7 +51,7 @@ unsigned Memory::do_read(char *buf, unsigned size) { if(pos==end) { - eof_flag = true; + set_eof(); return 0; } @@ -63,32 +63,37 @@ unsigned Memory::do_read(char *buf, unsigned size) unsigned Memory::put(char c) { - check_mode(M_WRITE); + check_access(M_WRITE); *pos++ = c; return 1; } bool Memory::getline(string &line) { + if(pos==end) + { + set_eof(); + return false; + } + char *nl = find(pos, end, '\n'); line.assign(pos, nl); - bool result = (nl!=pos); - pos = nl; - return result; + pos = (nl==end ? end : nl+1); + return true; } int Memory::get() { if(pos==end) { - eof_flag = true; + set_eof(); return -1; } return static_cast(*pos++); } -unsigned Memory::seek(int off, SeekType type) +SeekOffset Memory::seek(SeekOffset off, SeekType type) { char *new_pos; if(type==S_BEG) @@ -107,11 +112,5 @@ unsigned Memory::seek(int off, SeekType type) return pos-begin; } -void Memory::check_mode(Mode m) const -{ - if(m==M_WRITE && !(mode&M_WRITE)) - throw invalid_access(M_WRITE); -} - } // namespace IO } // namespace Msp