summaryrefslogtreecommitdiffstats
path: root/src/lib/netlist/plib/pstream.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/netlist/plib/pstream.h')
-rw-r--r--src/lib/netlist/plib/pstream.h47
1 files changed, 13 insertions, 34 deletions
diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h
index 59406eab025..1e9a3ed6a1c 100644
--- a/src/lib/netlist/plib/pstream.h
+++ b/src/lib/netlist/plib/pstream.h
@@ -9,7 +9,6 @@
#include <cstdarg>
#include <cstddef>
-#include <stdexcept>
#include "pconfig.h"
#include "pstring.h"
@@ -28,7 +27,7 @@ public:
using pos_type = std::size_t;
- static const pos_type SEEK_EOF = (pos_type) -1;
+ static constexpr pos_type SEEK_EOF = (pos_type) -1;
explicit pstream(const unsigned flags) : m_flags(flags)
{
@@ -37,12 +36,10 @@ public:
{
}
- bool bad() const { return ((m_flags & FLAG_ERROR) != 0); }
bool seekable() const { return ((m_flags & FLAG_SEEKABLE) != 0); }
void seek(const pos_type n)
{
- check_seekable();
return vseek(n);
}
@@ -55,12 +52,8 @@ protected:
virtual void vseek(const pos_type n) = 0;
virtual pos_type vtell() = 0;
- static const unsigned FLAG_EOF = 0x01;
- static const unsigned FLAG_ERROR = 0x02;
- static const unsigned FLAG_SEEKABLE = 0x04;
- static const unsigned FLAG_CLOSED = 0x08; /* convenience flag */
-
- bool closed() { return ((m_flags & FLAG_CLOSED) != 0); }
+ static constexpr unsigned FLAG_EOF = 0x01;
+ static constexpr unsigned FLAG_SEEKABLE = 0x04;
void set_flag(const unsigned flag)
{
@@ -70,19 +63,6 @@ protected:
{
m_flags &= ~flag;
}
-
- void check_not_eof() const
- {
- if (m_flags & FLAG_EOF)
- throw pexception("unexpected eof");
- }
-
- void check_seekable() const
- {
- if (!(m_flags & FLAG_SEEKABLE))
- throw pexception("stream is not seekable");
- }
-
unsigned flags() const { return m_flags; }
private:
@@ -101,15 +81,15 @@ public:
explicit pistream(const unsigned flags) : pstream(flags) {}
virtual ~pistream() {}
- bool eof() const { return ((flags() & FLAG_EOF) != 0) || bad(); }
+ bool eof() const { return ((flags() & FLAG_EOF) != 0); }
/* this digests linux & dos/windows text files */
bool readline(pstring &line);
- bool read(char &c)
+ bool readbyte(char &b)
{
- return (read(&c, 1) == 1);
+ return (read(&b, 1) == 1);
}
unsigned read(void *buf, const unsigned n)
@@ -122,6 +102,7 @@ protected:
virtual unsigned vread(void *buf, const unsigned n) = 0;
private:
+ pstringbuffer m_linebuf;
};
// -----------------------------------------------------------------------------
@@ -232,10 +213,8 @@ public:
explicit pofilestream(const pstring &fname);
virtual ~pofilestream();
- void close();
-
protected:
- pofilestream(void *file, const bool do_close);
+ pofilestream(void *file, const pstring name, const bool do_close);
/* write n bytes to stream */
virtual void vwrite(const void *buf, const unsigned n) override;
virtual void vseek(const pos_type n) override;
@@ -245,8 +224,9 @@ private:
void *m_file;
pos_type m_pos;
bool m_actually_close;
+ pstring m_filename;
- void init(void *file);
+ void init();
};
// -----------------------------------------------------------------------------
@@ -283,10 +263,8 @@ public:
explicit pifilestream(const pstring &fname);
virtual ~pifilestream();
- void close();
-
protected:
- pifilestream(void *file, const bool do_close);
+ pifilestream(void *file, const pstring name, const bool do_close);
/* read up to n bytes from stream */
virtual unsigned vread(void *buf, const unsigned n) override;
@@ -297,8 +275,9 @@ private:
void *m_file;
pos_type m_pos;
bool m_actually_close;
+ pstring m_filename;
- void init(void *file);
+ void init();
};
// -----------------------------------------------------------------------------