]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/memory.cpp
Wrap seek in a helper function and make it compatible with 64-bit offsets
[libs/core.git] / source / io / memory.cpp
index 6ea130b54ae134478ab40851f4c49cf1d68ad439..4a6296b44a907321a5e04a585e229523ff7caf86 100644 (file)
@@ -1,6 +1,6 @@
 #include <algorithm>
 #include <cstring>
-#include "except.h"
+#include "handle.h"
 #include "memory.h"
 
 using namespace std;
@@ -88,7 +88,7 @@ int Memory::get()
        return static_cast<unsigned char>(*pos++);
 }
 
-unsigned Memory::seek(int off, SeekType type)
+SeekOffset Memory::seek(SeekOffset off, SeekType type)
 {
        char *new_pos;
        if(type==S_BEG)
@@ -98,29 +98,19 @@ 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_pos<begin || new_pos>end)
-               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");
-       }
+       if(m==M_WRITE && !(mode&M_WRITE))
+               throw invalid_access(M_WRITE);
 }
 
 } // namespace IO