signal_deleted.emit();
}
+void Base::check_access(Mode m) const
+{
+ if(!(mode&m))
+ throw invalid_access(m);
+}
+
bool Base::getline(string &line)
{
line.clear();
Mode get_mode() const { return mode; }
protected:
+ void check_access(Mode) const;
+
virtual unsigned do_write(const char *, unsigned) = 0;
virtual unsigned do_read(char *, unsigned) = 0;
void Console::set_local_echo(bool e)
{
- if(!(mode&M_READ))
- throw invalid_access(M_READ);
+ check_access(M_READ);
#ifdef WIN32
DWORD m;
void Console::set_line_buffer(bool l)
{
- if(!(mode&M_READ))
- throw invalid_access(M_READ);
+ check_access(M_READ);
#ifdef WIN32
DWORD m;
void Console::get_size(unsigned &rows, unsigned &cols)
{
- if(!(mode&M_WRITE))
- throw invalid_access(M_WRITE);
+ check_access(M_WRITE);
#ifdef WIN32
// XXX Figure out how to do this
unsigned Console::do_write(const char *buf, unsigned len)
{
- if(!(mode&M_WRITE))
- throw invalid_access(M_WRITE);
+ check_access(M_WRITE);
return sys_write(handle, buf, len);
}
unsigned Console::do_read(char *buf, unsigned len)
{
- if(!(mode&M_READ))
- throw invalid_access(M_READ);
+ check_access(M_READ);
unsigned ret = sys_read(handle, buf, len);
if(ret==0)
void File::set_block(bool b)
{
- check_access(M_NONE);
-
mode = (mode&~M_NONBLOCK);
if(b)
mode = (mode|M_NONBLOCK);
SeekOffset File::seek(SeekOffset off, SeekType type)
{
- check_access(M_NONE);
-
signal_flush_required.emit();
off = sys_seek(handle, off, type);
eof_flag = false;
SeekOffset File::tell() const
{
- check_access(M_NONE);
-
return sys_seek(const_cast<Handle &>(handle), 0, S_CUR);
}
-void File::check_access(Mode m) const
-{
- if(!handle || (m && !(mode&m)))
- throw invalid_access(m);
-}
-
} // namespace IO
} // namespace Msp
virtual SeekOffset seek(SeekOffset, SeekType);
virtual SeekOffset tell() const;
-
-private:
- void check_access(Mode) const;
};
inline File::CreateMode operator|(File::CreateMode m, File::CreateMode n)
unsigned Memory::do_write(const char *buf, unsigned size)
{
- check_mode(M_WRITE);
+ check_access(M_WRITE);
size = min<unsigned>(size, end-pos);
memcpy(pos, buf, size);
unsigned Memory::put(char c)
{
- check_mode(M_WRITE);
+ check_access(M_WRITE);
*pos++ = c;
return 1;
}
return pos-begin;
}
-void Memory::check_mode(Mode m) const
-{
- if(m==M_WRITE && !(mode&M_WRITE))
- throw invalid_access(M_WRITE);
-}
-
} // namespace IO
} // namespace Msp
virtual SeekOffset seek(SeekOffset, SeekType);
virtual SeekOffset tell() const { return pos-begin; }
-
-private:
- void check_mode(Mode) const;
};
} // namespace IO