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)
unsigned Memory::do_read(char *buf, unsigned size)
{
+ check_access(M_READ);
+
if(pos==end)
{
set_eof();
unsigned Memory::put(char c)
{
check_access(M_WRITE);
+
+ if(pos==end)
+ return 0;
+
*pos++ = c;
return 1;
}
bool Memory::getline(string &line)
{
+ check_access(M_READ);
+
if(pos==end)
{
set_eof();
int Memory::get()
{
+ check_access(M_READ);
+
if(pos==end)
{
set_eof();
throw invalid_argument("Memory::seek");
if(new_pos<begin || new_pos>end)
- throw out_of_range("Memory::seek");
+ throw bad_seek(off, type);
pos = new_pos;
+ eof_flag = false;
return pos-begin;
}