]> git.tdb.fi Git - libs/core.git/blobdiff - source/memory.cpp
Move class members and comments around
[libs/core.git] / source / memory.cpp
index c44554ae5a4f9b59f7347befabc552c3fe190bf8..6ea130b54ae134478ab40851f4c49cf1d68ad439 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of libmspio
-Copyright © 2009 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <algorithm>
 #include <cstring>
 #include "except.h"
@@ -27,7 +20,7 @@ Memory::Memory(char *b, char *e)
 
 Memory::Memory(const char *cd, unsigned s)
 {
-       char *d=const_cast<char *>(cd);
+       char *d = const_cast<char *>(cd);
        init(d, d+s, M_READ);
 }
 
@@ -38,25 +31,49 @@ Memory::Memory(const char *b, const char *e)
 
 void Memory::init(char *b, char *e, Mode m)
 {
-       begin=b;
-       end=e;
-       pos=begin;
-       mode=m;
+       begin = b;
+       end = e;
+       pos = begin;
+       mode = m;
+}
+
+unsigned Memory::do_write(const char *buf, unsigned size)
+{
+       check_mode(M_WRITE);
+
+       size = min<unsigned>(size, end-pos);
+       memcpy(pos, buf, size);
+       pos += size;
+       return size;
+}
+
+unsigned Memory::do_read(char *buf, unsigned size)
+{
+       if(pos==end)
+       {
+               eof_flag = true;
+               return 0;
+       }
+
+       size = min<unsigned>(size, end-pos);
+       memcpy(buf, pos, size);
+       pos += size;
+       return size;
 }
 
 unsigned Memory::put(char c)
 {
        check_mode(M_WRITE);
-       *pos++=c;
+       *pos++ = c;
        return 1;
 }
 
 bool Memory::getline(string &line)
 {
-       char *nl=find(pos, end, '\n');
+       char *nl = find(pos, end, '\n');
        line.assign(pos, nl);
-       bool result=(nl!=pos);
-       pos=nl;
+       bool result = (nl!=pos);
+       pos = nl;
        return result;
 }
 
@@ -64,7 +81,7 @@ int Memory::get()
 {
        if(pos==end)
        {
-               eof_flag=true;
+               eof_flag = true;
                return -1;
        }
 
@@ -75,18 +92,18 @@ unsigned Memory::seek(int off, SeekType type)
 {
        char *new_pos;
        if(type==S_BEG)
-               new_pos=begin+off;
+               new_pos = begin+off;
        else if(type==S_CUR)
-               new_pos=pos+off;
+               new_pos = pos+off;
        else if(type==S_END)
-               new_pos=end+off;
+               new_pos = end+off;
        else
                throw InvalidParameterValue("Invalid seek type");
 
        if(new_pos<begin || new_pos>end)
                throw InvalidParameterValue("Invalid seek offset");
 
-       pos=new_pos;
+       pos = new_pos;
        return pos-begin;
 }
 
@@ -95,30 +112,6 @@ Handle Memory::get_event_handle()
        throw Exception("Memory doesn't support events");
 }
 
-unsigned Memory::do_write(const char *buf, unsigned size)
-{
-       check_mode(M_WRITE);
-
-       size=min<unsigned>(size, end-pos);
-       memcpy(pos, buf, size);
-       pos+=size;
-       return size;
-}
-
-unsigned Memory::do_read(char *buf, unsigned size)
-{
-       if(pos==end)
-       {
-               eof_flag=true;
-               return 0;
-       }
-
-       size=min<unsigned>(size, end-pos);
-       memcpy(buf, pos, size);
-       pos+=size;
-       return size;
-}
-
 void Memory::check_mode(Mode m) const
 {
        if(m==M_WRITE)