]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/memory.cpp
Add a mode parameter to Memory constructor with non-const pointers
[libs/core.git] / source / io / memory.cpp
index 274f6bae91c1a6a1d53f67be3872319bdae85bc2..bc14ff1fd4e832967b93f346a7fd4de29c74f552 100644 (file)
@@ -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();
@@ -70,6 +72,8 @@ unsigned Memory::put(char c)
 
 bool Memory::getline(string &line)
 {
+       check_access(M_READ);
+
        if(pos==end)
        {
                set_eof();
@@ -84,6 +88,8 @@ bool Memory::getline(string &line)
 
 int Memory::get()
 {
+       check_access(M_READ);
+
        if(pos==end)
        {
                set_eof();