X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fio%2Fmemory.cpp;h=6ccf84654764cbe8086a3ac841330580d302dcd1;hb=df5ab3d867c51d72344e443e3adb05bfa29a2b53;hp=6ea130b54ae134478ab40851f4c49cf1d68ad439;hpb=c7afef88380ebebc8c2b04e48664d73281ec8848;p=libs%2Fcore.git diff --git a/source/io/memory.cpp b/source/io/memory.cpp index 6ea130b..6ccf846 100644 --- a/source/io/memory.cpp +++ b/source/io/memory.cpp @@ -1,6 +1,6 @@ #include #include -#include "except.h" +#include "handle.h" #include "memory.h" using namespace std; @@ -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); @@ -63,7 +63,7 @@ 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; } @@ -88,7 +88,7 @@ int Memory::get() 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) @@ -98,30 +98,14 @@ unsigned Memory::seek(int off, SeekType type) else if(type==S_END) new_pos = end+off; else - throw InvalidParameterValue("Invalid seek type"); + throw invalid_argument("Memory::seek"); if(new_posend) - throw InvalidParameterValue("Invalid seek offset"); + throw out_of_range("Memory::seek"); pos = new_pos; return pos-begin; } -Handle Memory::get_event_handle() -{ - throw Exception("Memory doesn't support events"); -} - -void Memory::check_mode(Mode m) const -{ - if(m==M_WRITE) - { - if(!(mode&M_WRITE)) - throw InvalidState("Memory is not writable"); - if(pos==end) - throw InvalidState("Attempt to write past end of Memory"); - } -} - } // namespace IO } // namespace Msp